/* ============================================================
   INDUSTRIAS FARMACÉUTICAS GYT — Premium Dashboard UI
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --brand-dark: #064e3b;    /* Verde muy oscuro (Header) */
    --brand-primary: #059669; /* Verde esmeralda (Acentos) */
    --brand-light: #d1fae5;   /* Verde muy claro (Fondos) */
    --bg-app: #f3f4f6;        /* Fondo gris claro de la app */
    --surface: #ffffff;       /* Fondo blanco para tarjetas */
    --text-main: #111827;     /* Texto principal casi negro */
    --text-muted: #6b7280;    /* Texto secundario gris */
    --border: #e5e7eb;        /* Bordes sutiles */
    --radius-lg: 16px;
    --radius-md: 12px;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-app);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ── HEADER ────────────────────────────── */
.app-header {
    background: var(--brand-dark);
    color: white;
    padding: 0 2rem;
    height: 72px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-md);
    position: sticky;
    top: 0;
    z-index: 50;
}
.brand-container {
    display: flex;
    align-items: center;
    gap: 1rem;
}
.brand-icon {
    width: 40px;
    height: 40px;
    background: rgba(255,255,255,0.15);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.brand-icon svg { width: 24px; height: 24px; fill: currentColor; }
.brand-text h1 {
    font-size: 1.125rem;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.025em;
}
.brand-text p {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.8);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}
.main-nav {
    display: flex;
    gap: 1rem;
    margin-right: 1rem;
}
.nav-link {
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    transition: all 0.2s;
}
.nav-link:hover { color: white; background: rgba(255,255,255,0.1); }
.nav-link.active { color: white; background: rgba(255,255,255,0.15); font-weight: 600; }

.user-profile {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
}
.btn-logout {
    background: rgba(255,255,255,0.1);
    color: white;
    border: 1px solid rgba(255,255,255,0.2);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s;
}
.btn-logout:hover { background: rgba(255,255,255,0.2); }

/* ── CONTENT ────────────────────────────── */
.main-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
}

/* ── SYNC STATUS BANNER ────────────────────────────── */
.sync-banner {
    background: var(--surface);
    border-radius: var(--radius-md);
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}
.sync-info {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}
.sync-loader {
    width: 48px;
    height: 48px;
    position: relative;
    flex-shrink: 0;
}
.sync-loader svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}
.sync-loader circle {
    fill: transparent;
    stroke-width: 4;
}
.sync-loader .track { stroke: #e5e7eb; }
.sync-loader .progress {
    stroke: var(--brand-primary);
    stroke-linecap: round;
    transition: stroke-dashoffset 1s linear;
}
.sync-countdown-text {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    color: var(--brand-dark);
}
.sync-countdown-text.urgent { color: #ef4444; }
.sync-details h3 { font-size: 0.9375rem; font-weight: 700; color: var(--text-main); margin-bottom: 0.1rem; }
.sync-details p { font-size: 0.8125rem; color: var(--text-muted); }
.sync-badge {
    background: var(--bg-app);
    color: var(--text-muted);
    padding: 0.35rem 0.85rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    border: 1px solid var(--border);
}

/* ── KPI GRID ────────────────────────────── */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}
.kpi-card {
    background: var(--surface);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 1.25rem;
    transition: transform 0.2s, box-shadow 0.2s;
}
.kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}
.kpi-icon-wrap {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    flex-shrink: 0;
}
.icon-total { background: #f3f4f6; }
.icon-ok { background: #d1fae5; }
.icon-low { background: #fef3c7; }
.icon-out { background: #fee2e2; }
.kpi-data h4 {
    font-size: 0.875rem;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 0.15rem;
}
.kpi-data .kpi-val {
    font-size: 2rem;
    font-weight: 800;
    color: var(--text-main);
    line-height: 1;
    letter-spacing: -0.025em;
}

/* ── TOOLBAR (SEARCH & FILTERS) ────────────────────────────── */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.5rem;
    justify-content: space-between;
    align-items: center;
}
.search-box {
    display: flex;
    align-items: center;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: 10px;
    padding: 0.5rem 1rem;
    width: 100%;
    max-width: 450px;
    transition: all 0.2s;
}
.search-box:focus-within {
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 4px rgba(5, 150, 105, 0.1);
}
.search-box svg { width: 20px; height: 20px; flex-shrink: 0; fill: var(--text-muted); margin-right: 0.75rem; }
.search-box input {
    border: none;
    outline: none;
    width: 100%;
    font-size: 0.95rem;
    font-family: inherit;
    color: var(--text-main);
    background: transparent;
}
.search-box input::placeholder { color: #9ca3af; }

.filters {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.filter-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 0.6rem 1.2rem;
    border-radius: 10px;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s;
}
.filter-btn:hover { background: #f9fafb; color: var(--text-main); }
.filter-btn.active {
    background: var(--text-main);
    color: white;
    border-color: var(--text-main);
}
.filter-btn.active-low { background: #d97706; color: white; border-color: #d97706; }
.filter-btn.active-out { background: #dc2626; color: white; border-color: #dc2626; }

/* ── TABLE CONTAINER ────────────────────────────── */
.table-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    overflow: hidden;
}
.table-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.table-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: -0.025em;
}
.result-tag {
    background: var(--bg-app);
    color: var(--text-muted);
    padding: 0.35rem 0.85rem;
    border-radius: 9999px;
    font-size: 0.8125rem;
    font-weight: 600;
    border: 1px solid var(--border);
}
.table-responsive {
    width: 100%;
    overflow-x: auto;
}
table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}
th {
    background: #f9fafb;
    padding: 1rem 1.5rem;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
td {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
    color: var(--text-main);
    vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background-color: #f9fafb; }

/* ── TABLE CELLS FORMATTING ────────────────────────────── */
.cell-code {
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    color: var(--brand-dark);
    font-weight: 600;
    background: var(--brand-light);
    padding: 0.35rem 0.6rem;
    border-radius: 6px;
    font-size: 0.8125rem;
    white-space: nowrap;
}
.cell-desc { font-weight: 600; color: #111827; }
.cell-unit { color: var(--text-muted); font-size: 0.8125rem; font-weight: 500; }
.cell-price { font-weight: 700; color: var(--brand-primary); font-size: 0.95rem; }
.cell-date { color: var(--text-muted); font-size: 0.8125rem; }

.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.35rem 0.85rem;
    border-radius: 9999px;
    font-size: 0.8125rem;
    font-weight: 700;
    white-space: nowrap;
}
.status-badge::before {
    content: '';
    width: 8px; height: 8px;
    border-radius: 50%;
    margin-right: 0.5rem;
}
.status-ok { background: #d1fae5; color: #065f46; }
.status-ok::before { background: #10b981; }
.status-low { background: #fef3c7; color: #92400e; }
.status-low::before { background: #f59e0b; }
.status-out { background: #fee2e2; color: #991b1b; }
.status-out::before { background: #ef4444; }

.empty-state {
    padding: 5rem 2rem;
    text-align: center;
    color: var(--text-muted);
}
.empty-icon { font-size: 3rem; margin-bottom: 1rem; opacity: 0.5; }
.empty-state h3 { font-size: 1.125rem; color: var(--text-main); margin-bottom: 0.5rem; }

/* ── UTILS ────────────────────────────── */
.text-right { text-align: right; }
.text-center { text-align: center; }
.hidden { display: none !important; } /* Para el JS */

/* RESPONSIVE */
@media (max-width: 1024px) {
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
    .app-header {
        padding: 1rem;
        height: auto;
        flex-direction: column;
        align-items: center;
        gap: 1rem;
    }
    .main-content { padding: 1rem; }
    .brand-text p { display: none; }
    .user-profile span { display: none; }
    
    .sync-banner { flex-direction: column; align-items: stretch; gap: 1rem; text-align: center; }
    .sync-badge { align-self: center; }
    
    .toolbar { flex-direction: column; align-items: stretch; }
    .search-box { max-width: 100%; }

    .brand-container {
        flex-direction: column;
        text-align: center;
    }
    .header-actions {
        width: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 1rem;
    }
    .main-nav {
        flex-wrap: wrap;
        justify-content: center;
        width: 100%;
        gap: 0.5rem;
    }
    .main-nav .nav-link {
        flex: 1 1 auto;
        text-align: center;
    }
    .user-profile {
        justify-content: center;
    }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .kpi-card { padding: 1rem; gap: 0.5rem; }
    .kpi-data .kpi-val { font-size: 1.5rem; }
    .kpi-icon-wrap { width: 48px; height: 48px; font-size: 1.25rem; }
    
    .grid-2, .grid-3 { grid-template-columns: 1fr; } /* Stack form columns */

    /* Responsive Table to Cards using data-label */
    .table-responsive {
        border: none;
    }
    .table-responsive table, .table-responsive thead, .table-responsive tbody, .table-responsive th, .table-responsive td, .table-responsive tr {
        display: block;
    }
    .table-responsive thead {
        display: none; /* Hide headers */
    }
    .table-responsive tr {
        border: 1px solid var(--border);
        border-radius: 8px;
        margin-bottom: 1rem;
        padding: 1rem;
        background: #fff;
        box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    }
    .table-responsive td {
        border: none;
        padding: 0.4rem 0;
        position: relative;
        text-align: right;
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 1rem;
    }
    .table-responsive td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-muted);
        font-size: 0.85rem;
        text-align: left;
    }
    
    /* Special handling for the very first column (usually Code/Desc) */
    .table-responsive td[data-label=""]::before {
        display: none;
    }
    .table-responsive td[data-label=""] {
        display: block;
        text-align: left;
        border-bottom: 1px solid var(--border);
        margin-bottom: 0.5rem;
        padding-bottom: 0.5rem;
    }
    .text-center, .text-right { text-align: right; }
    
    .table-input {
        width: 100px; /* Make inputs a bit wider on mobile since they have their own row */
        text-align: right;
    }
}

.form-control, .form-group input, .form-group textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
    color: var(--text-main);
    background: #f9fafb;
    transition: all 0.2s;
    outline: none;
}
.form-control:focus, .form-group input:focus, .form-group textarea:focus {
    background: var(--surface);
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 4px rgba(5, 150, 105, 0.1);
}

.btn-primary {
    width: 100%;
    background: var(--brand-primary);
    color: white;
    border: none;
    padding: 0.875rem;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    margin-top: 0.5rem;
}
.btn-primary:hover { background: #047857; }

.auth-divider { border: 0; border-top: 1px solid var(--border); margin: 1.5rem 0; }
.auth-footer { text-align: center; font-size: 0.875rem; color: var(--text-muted); }
.auth-footer a { color: var(--brand-primary); font-weight: 600; text-decoration: none; }
.auth-footer a:hover { text-decoration: underline; }

.alert {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 1.5rem;
    text-align: center;
}
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }

/* ── OMS FORMS (Pedidos) ────────────────────────────── */
.form-card {
    background: var(--surface);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    margin-bottom: 1.5rem;
}
.form-card h3 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--brand-dark);
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.5rem;
}
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }

.input-sm {
    padding: 0.4rem 0.6rem !important;
    font-size: 0.85rem !important;
}

/* Reducimos el padding en la tabla de pedidos para que entre sin scroll horizontal */
.stock-table th, .stock-table td {
    padding: 0.5rem 0.5rem !important;
    font-size: 0.8rem;
}

.table-input {
    width: 55px; /* Más pequeño para que encaje mejor */
    padding: 0.35rem 0.25rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    text-align: center;
    font-size: 0.85rem;
    outline: none;
    background: white;
}
.table-input:focus {
    border-color: var(--brand-primary);
}
.btn-danger {
    background: #fee2e2;
    color: #dc2626;
    border: none;
    padding: 0.5rem;
    border-radius: 6px;
    cursor: pointer;
}
.btn-danger:hover { background: #fca5a5; }

.totals-box {
    background: #f8faf9;
    border-radius: 12px;
    padding: 1.5rem;
    border: 1px solid var(--border);
}
.tot-row { display: flex; justify-content: space-between; margin-bottom: 0.5rem; font-size: 1rem; color: var(--text-muted); }
.tot-row.grand { font-size: 1.25rem; font-weight: 800; color: var(--brand-dark); margin-top: 0.5rem; border-top: 2px solid var(--border); padding-top: 0.5rem; }

/* ── AUTH PAGES (Login) ────────────────────────────── */
.auth-body {
    min-height: 100vh;
    background: linear-gradient(135deg, var(--brand-dark) 0%, var(--brand-primary) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}
.auth-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 3rem 2.5rem;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.25);
}

.auth-brand { text-align: center; margin-bottom: 2rem; }
.logo-badge {
    width: 64px;
    height: 64px;
    background: var(--brand-light);
    color: var(--brand-primary);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem;
}
.logo-badge svg { width: 32px; height: 32px; fill: currentColor; }
.auth-brand h1 { font-size: 1.25rem; font-weight: 700; color: var(--text-main); letter-spacing: -0.025em; line-height: 1.2; }
.auth-brand .subtitle { display: block; font-size: 1rem; color: var(--text-muted); font-weight: 600; margin-top: 0.25rem; }

.auth-card h2 { font-size: 1.25rem; font-weight: 700; color: var(--text-main); text-align: center; margin-bottom: 0.25rem; }
.auth-sub { font-size: 0.875rem; color: var(--text-muted); text-align: center; margin-bottom: 1.5rem; }

.form-group { margin-bottom: 1.25rem; }
.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 0.5rem;
}
.form-group input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
    color: var(--text-main);
    background: #f9fafb;
    transition: all 0.2s;
    outline: none;
}
.form-group input:focus {
    background: var(--surface);
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 4px rgba(5, 150, 105, 0.1);
}

.btn-primary {
    width: 100%;
    background: var(--brand-primary);
    color: white;
    border: none;
    padding: 0.875rem;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    margin-top: 0.5rem;
}
.btn-primary:hover { background: #047857; }

.auth-divider { border: 0; border-top: 1px solid var(--border); margin: 1.5rem 0; }
.auth-footer { text-align: center; font-size: 0.875rem; color: var(--text-muted); }
.auth-footer a { color: var(--brand-primary); font-weight: 600; text-decoration: none; }
.auth-footer a:hover { text-decoration: underline; }

.alert {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 1.5rem;
    text-align: center;
}
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }

/* FOOTER */
.app-footer {
    text-align: center;
    padding: 1.5rem;
    color: var(--text-muted);
    font-size: 0.85rem;
    border-top: 1px solid var(--border);
    margin-top: 2rem;
    background: var(--bg-app);
}
