/* ============================================
   CosechaQR - CSS Principal
   Control de Vendimia Digital
   ============================================ */

:root {
    --grape: #5B2C6F;
    --grape-light: #7D3C98;
    --grape-dark: #3B1C4F;
    --vine: #1E8449;
    --vine-light: #27AE60;
    --sand: #F5E6CA;
    --sand-light: #FDF2E0;
    --earth: #6D4C41;
    --sun: #F39C12;
    --sun-warm: #E67E22;
    --red-alert: #E74C3C;
    --white: #FEFEFE;
    --text: #2C1810;
    --text-light: #5D4037;
    --shadow: rgba(91, 44, 111, 0.15);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'DM Sans', sans-serif;
    background: var(--sand-light);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

/* ========== HEADER ========== */
.app-header {
    background: linear-gradient(135deg, var(--grape-dark) 0%, var(--grape) 50%, var(--grape-light) 100%);
    padding: 14px 16px;
    color: white;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 4px 20px var(--shadow);
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon { font-size: 26px; }

.logo h1 {
    font-family: 'Space Mono', monospace;
    font-size: 18px;
    font-weight: 700;
}

.logo span {
    font-size: 11px;
    opacity: 0.7;
    font-weight: 400;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.date-display {
    font-family: 'Space Mono', monospace;
    font-size: 11px;
    opacity: 0.8;
    text-align: right;
}

.logout-btn {
    font-size: 18px;
    text-decoration: none;
    opacity: 0.7;
    transition: opacity 0.2s;
}
.logout-btn:hover { opacity: 1; }

.live-badge-header {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255,255,255,0.15);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

/* ========== NAV TABS ========== */
.nav-tabs {
    display: flex;
    gap: 4px;
    margin-top: 10px;
}

.nav-tab {
    flex: 1;
    padding: 9px 6px;
    border: none;
    background: rgba(255,255,255,0.12);
    color: rgba(255,255,255,0.7);
    border-radius: 10px 10px 0 0;
    font-family: 'DM Sans', sans-serif;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.nav-tab.active {
    background: var(--sand-light);
    color: var(--grape);
}

.nav-tab:not(.active):hover {
    background: rgba(255,255,255,0.2);
}

/* ========== VIEW CONTAINER ========== */
.view {
    display: none;
    padding: 14px;
    max-width: 640px;
    margin: 0 auto;
}
.view.active { display: block; }

/* ========== JORNADA INFO ========== */
.jornada-info {
    background: linear-gradient(135deg, var(--sand), var(--sand-light));
    border-radius: 12px;
    padding: 12px 16px;
    margin-bottom: 14px;
    display: flex;
    justify-content: space-between;
    border: 1px solid #E0D5C5;
}

.jornada-info .label {
    font-size: 11px;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.jornada-info .value {
    font-family: 'Space Mono', monospace;
    font-size: 14px;
    font-weight: 700;
    color: var(--grape);
}

/* ========== SCANNER SECTION ========== */
.scanner-section {
    background: white;
    border-radius: 14px;
    padding: 16px;
    margin-bottom: 14px;
    box-shadow: 0 2px 12px var(--shadow);
}

.section-title {
    font-family: 'Space Mono', monospace;
    font-size: 13px;
    color: var(--grape);
    margin-bottom: 10px;
}

.select-row {
    display: flex;
    gap: 8px;
}

.select-row select {
    flex: 1;
    padding: 12px;
    border: 2px solid #E0D5C5;
    border-radius: 10px;
    font-family: 'DM Sans', sans-serif;
    font-size: 14px;
    background: white;
    color: var(--text);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%235B2C6F' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
}

.add-tacho-btn {
    padding: 12px 20px;
    background: var(--vine);
    color: white;
    border: none;
    border-radius: 10px;
    font-family: 'Space Mono', monospace;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.add-tacho-btn:hover { background: var(--vine-light); }
.add-tacho-btn:active { transform: scale(0.95); }

/* ========== COUNTER CARDS ========== */
.counters-grid {
    display: grid;
    gap: 8px;
}

.counter-card {
    background: white;
    border-radius: 12px;
    padding: 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 8px var(--shadow);
    transition: all 0.3s;
    border-left: 4px solid var(--grape-light);
}

.counter-card.just-added {
    animation: pulseGreen 0.5s ease;
    border-left-color: var(--vine);
}

@keyframes pulseGreen {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(39,174,96,0.4); }
    50% { transform: scale(1.02); box-shadow: 0 0 0 10px rgba(39,174,96,0); }
    100% { transform: scale(1); box-shadow: 0 2px 8px var(--shadow); }
}

.counter-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.counter-avatar {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--grape), var(--grape-light));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-family: 'Space Mono', monospace;
    font-weight: 700;
    font-size: 15px;
    flex-shrink: 0;
}

.counter-avatar.big {
    width: 64px;
    height: 64px;
    font-size: 24px;
    border-radius: 16px;
    margin-bottom: 8px;
}

.counter-avatar.gold {
    background: linear-gradient(135deg, var(--sun), var(--sun-warm));
}

.counter-name {
    font-weight: 600;
    font-size: 14px;
}

.counter-time {
    font-size: 11px;
    color: var(--text-light);
    margin-top: 1px;
}

.counter-number {
    display: flex;
    align-items: center;
    gap: 6px;
}

.tacho-count {
    font-family: 'Space Mono', monospace;
    font-size: 30px;
    font-weight: 700;
    color: var(--grape);
    min-width: 44px;
    text-align: center;
}

.counter-actions {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.counter-actions button {
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 700;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-plus { background: #E8F8F0; color: var(--vine); }
.btn-plus:hover { background: var(--vine); color: white; }
.btn-minus { background: #FDEDEC; color: var(--red-alert); }
.btn-minus:hover { background: var(--red-alert); color: white; }

/* ========== TOTAL BAR ========== */
.total-bar {
    background: linear-gradient(135deg, var(--grape-dark), var(--grape));
    border-radius: 14px;
    padding: 14px 18px;
    margin-top: 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: white;
}

.total-label { font-size: 13px; opacity: 0.8; }
.total-number {
    font-family: 'Space Mono', monospace;
    font-size: 34px;
    font-weight: 700;
}
.total-sub { font-size: 11px; opacity: 0.6; }

/* ========== BUTTONS ========== */
.btn-primary {
    display: inline-block;
    width: 100%;
    padding: 13px;
    background: var(--grape);
    color: white;
    border: none;
    border-radius: 12px;
    font-family: 'Space Mono', monospace;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    text-decoration: none;
}

.btn-primary:hover { background: var(--grape-light); }
.btn-secondary { background: var(--sun); }
.btn-secondary:hover { background: var(--sun-warm); }
.btn-danger { background: var(--red-alert); }
.btn-danger:hover { background: #C0392B; }
.btn-small { padding: 10px 20px; font-size: 12px; }

.btn-secondary-outline {
    display: inline-block;
    padding: 10px 20px;
    background: transparent;
    color: var(--grape);
    border: 2px solid var(--grape);
    border-radius: 10px;
    font-family: 'DM Sans', sans-serif;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.btn-secondary-outline:hover {
    background: var(--grape);
    color: white;
}

.export-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 14px;
}
.export-section > * { width: 100%; }

/* ========== CONFIG CARDS ========== */
.config-card {
    background: white;
    border-radius: 14px;
    padding: 16px;
    margin-bottom: 14px;
    box-shadow: 0 2px 12px var(--shadow);
}

.input-group {
    margin-bottom: 12px;
}

.input-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-light);
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.input-group input {
    width: 100%;
    padding: 11px 14px;
    border: 2px solid #E0D5C5;
    border-radius: 10px;
    font-family: 'DM Sans', sans-serif;
    font-size: 14px;
    transition: border-color 0.2s;
}

.input-group input:focus {
    outline: none;
    border-color: var(--grape);
}

.input-help {
    display: block;
    font-size: 11px;
    color: var(--text-light);
    margin-top: 4px;
}

/* ========== WORKER LIST ========== */
.worker-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px;
    border-bottom: 1px solid #F0E8DC;
}

.worker-item:last-child { border-bottom: none; }

.worker-item-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.worker-item-num {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: var(--grape);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Space Mono', monospace;
    font-size: 12px;
    font-weight: 700;
}

.worker-item-name { font-weight: 600; font-size: 14px; }

.worker-item-actions {
    display: flex;
    gap: 5px;
}

.btn-icon {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.btn-qr { background: #EDE7F6; color: var(--grape); }
.btn-qr:hover { background: var(--grape); color: white; }
.btn-del { background: #FDEDEC; color: var(--red-alert); }
.btn-del:hover { background: var(--red-alert); color: white; }
.btn-link { background: #E8F5E9; color: var(--vine); }
.btn-link:hover { background: var(--vine); color: white; }

/* ========== MODAL ========== */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 20px;
    backdrop-filter: blur(4px);
}

.modal-overlay.active { display: flex; }

.modal-content {
    background: white;
    border-radius: 20px;
    padding: 28px;
    max-width: 340px;
    width: 100%;
    text-align: center;
    animation: modalIn 0.3s ease;
}

@keyframes modalIn {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.modal-content h3 {
    font-family: 'Space Mono', monospace;
    color: var(--grape);
    margin-bottom: 2px;
}

.modal-content p {
    font-size: 12px;
    color: var(--text-light);
    margin-bottom: 14px;
}

#qr-container {
    display: inline-block;
    padding: 10px;
    background: white;
    border-radius: 12px;
    border: 2px solid #F0E8DC;
}

.qr-hint {
    font-size: 11px !important;
    color: #999 !important;
}

.modal-buttons {
    display: flex;
    gap: 8px;
    margin-top: 14px;
}

.modal-buttons > * { flex: 1; }

/* ========== PUBLIC VIEW ========== */
.cosechador-header {
    text-align: center;
    padding: 8px 0 16px;
}

.cosechador-header h2 {
    font-family: 'Space Mono', monospace;
    color: var(--grape);
    font-size: 17px;
}

.cosechador-header p {
    color: var(--text-light);
    font-size: 13px;
    margin-top: 2px;
}

.live-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #E8F8F0;
    color: var(--vine);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    margin-top: 8px;
}

.live-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--vine);
    animation: blink 1.5s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.public-counter-card {
    background: white;
    border-radius: 12px;
    padding: 14px 16px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 8px var(--shadow);
}

.public-counter-card.leader {
    border: 2px solid var(--sun);
}

.public-counter-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.public-count {
    font-family: 'Space Mono', monospace;
    font-size: 26px;
    font-weight: 700;
    color: var(--grape);
}

.public-count small {
    font-size: 11px;
    color: var(--text-light);
    font-weight: 400;
}

/* ========== HISTORY ========== */
.history-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 0;
    border-bottom: 1px solid #F0E8DC;
    font-size: 13px;
}

.history-icon {
    width: 26px;
    height: 26px;
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
}

.history-icon.add { background: #E8F8F0; color: var(--vine); }
.history-icon.remove { background: #FDEDEC; color: var(--red-alert); }

.history-time {
    font-family: 'Space Mono', monospace;
    font-size: 10px;
    color: var(--text-light);
    margin-left: auto;
    flex-shrink: 0;
}

/* ========== AUTH PAGES ========== */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(160deg, var(--grape-dark) 0%, var(--grape) 40%, var(--grape-light) 100%);
}

.auth-card {
    background: white;
    border-radius: 20px;
    padding: 32px 28px;
    max-width: 380px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.auth-logo {
    text-align: center;
    margin-bottom: 24px;
}

.logo-grape { font-size: 48px; display: block; margin-bottom: 8px; }

.auth-logo h1 {
    font-family: 'Space Mono', monospace;
    font-size: 24px;
    color: var(--grape);
}

.auth-logo p {
    font-size: 13px;
    color: var(--text-light);
}

.auth-card h2 {
    font-family: 'Space Mono', monospace;
    font-size: 18px;
    color: var(--text);
    margin-bottom: 2px;
}

.auth-sub {
    font-size: 13px;
    color: var(--text-light);
    margin-bottom: 20px;
}

.auth-footer {
    text-align: center;
    margin-top: 20px;
    font-size: 13px;
}

.auth-footer a {
    color: var(--grape);
    font-weight: 600;
    text-decoration: none;
}

.alert {
    padding: 10px 14px;
    border-radius: 10px;
    margin-bottom: 16px;
    font-size: 13px;
}

.alert-error { background: #FDEDEC; color: var(--red-alert); }
.alert-success { background: #E8F8F0; color: var(--vine); }

/* ========== SCAN PAGE ========== */
.scan-card { text-align: center; }

.scan-worker-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 20px;
}

.scan-worker-info h2 {
    font-size: 20px;
    margin-top: 4px;
}

.scan-worker-info p {
    font-size: 13px;
    color: var(--text-light);
}

.scan-instruction {
    font-size: 13px;
    color: var(--text-light);
    margin-bottom: 16px;
}

.pin-input-row {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-bottom: 20px;
}

.pin-box {
    width: 52px;
    height: 60px;
    border: 3px solid #E0D5C5;
    border-radius: 12px;
    text-align: center;
    font-family: 'Space Mono', monospace;
    font-size: 24px;
    font-weight: 700;
    color: var(--grape);
    transition: border-color 0.2s;
}

.pin-box:focus {
    outline: none;
    border-color: var(--grape);
}

.scan-error {
    color: var(--red-alert);
    font-size: 13px;
    margin-top: 10px;
}

.scan-success {
    margin: 20px 0;
}

.success-icon { font-size: 48px; margin-bottom: 8px; }

.success-count {
    font-family: 'Space Mono', monospace;
    font-size: 48px;
    font-weight: 700;
    color: var(--grape);
    margin: 8px 0;
}

/* ========== EMPTY STATE ========== */
.empty-state {
    text-align: center;
    padding: 30px 16px;
    color: var(--text-light);
}
.empty-state .icon { font-size: 44px; margin-bottom: 10px; }
.empty-state p { font-size: 13px; }

/* ========== TOAST ========== */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--grape-dark);
    color: white;
    padding: 10px 22px;
    border-radius: 12px;
    font-family: 'DM Sans', sans-serif;
    font-size: 13px;
    font-weight: 600;
    z-index: 300;
    transition: transform 0.3s ease;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    white-space: nowrap;
}

.toast.show { transform: translateX(-50%) translateY(0); }

/* ========== RESPONSIVE ========== */
@media (min-width: 640px) {
    .counters-grid { grid-template-columns: 1fr 1fr; }
    .view { padding: 20px; }
}

@media (max-width: 360px) {
    .nav-tab { font-size: 11px; padding: 8px 4px; }
    .tacho-count { font-size: 24px; }
    .total-number { font-size: 28px; }
}

/* ========== FOOTER ========== */
.app-footer {
    text-align: center;
    padding: 16px 12px 20px;
    border-top: 1px solid #E0D5C5;
    margin-top: 8px;
}

.app-footer p {
    font-size: 11px;
    color: #9E8E7E;
    line-height: 1.6;
    margin: 0;
}

.app-footer a {
    color: var(--grape);
    text-decoration: none;
    font-weight: 600;
}

.app-footer a:hover {
    text-decoration: underline;
}
