/* ============================================================
   GESTORPYME — Design System
   Paleta pastel clara, tipografía limpia, UX de uso intensivo
   ============================================================ */

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

/* ── Variables ───────────────────────────────────────────── */
:root {
    /* Colores primarios */
    --c-blue:       #6B9FD4;
    --c-blue-light: #EBF3FB;
    --c-blue-dark:  #4A7DB5;

    /* Superficie */
    --c-bg:         #F4F6FA;
    --c-surface:    #FFFFFF;
    --c-surface-2:  #F8F9FC;
    --c-border:     #E4E8F0;

    /* Texto */
    --c-text:       #2D3748;
    --c-text-2:     #718096;
    --c-text-3:     #A0AEC0;

    /* Estados */
    --c-success:    #68C9A0;
    --c-success-bg: #EDFBF4;
    --c-warning:    #F6C05C;
    --c-warning-bg: #FFF8E6;
    --c-danger:     #F08080;
    --c-danger-bg:  #FFF0F0;
    --c-info:       #85C1E9;
    --c-info-bg:    #EBF5FB;

    /* Pasteles de acento */
    --c-mint:       #A8D8B9;
    --c-peach:      #F5B8A0;
    --c-lavender:   #C3B1E1;
    --c-sky:        #A8CCE8;

    /* Layout */
    --sidebar-w:    240px;
    --header-h:     60px;
    --radius:       10px;
    --radius-sm:    6px;
    --shadow:       0 2px 8px rgba(0,0,0,0.07);
    --shadow-md:    0 4px 16px rgba(0,0,0,0.10);

    /* Tipografía */
    --font-main:    'DM Sans', sans-serif;
    --font-num:     'Nunito', sans-serif;
}

/* ── Reset ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
    font-family: var(--font-main);
    background: var(--c-bg);
    color: var(--c-text);
    min-height: 100vh;
    line-height: 1.55;
}
a { color: var(--c-blue-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
ul { list-style: none; }
input, select, textarea, button { font-family: inherit; }

/* ── Layout principal ────────────────────────────────────── */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--c-surface);
    border-right: 1px solid var(--c-border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    overflow-y: auto;
}
.sidebar-logo {
    height: var(--header-h);
    display: flex;
    align-items: center;
    padding: 0 20px;
    border-bottom: 1px solid var(--c-border);
    font-family: var(--font-num);
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--c-blue-dark);
    letter-spacing: -0.3px;
}
.sidebar-logo span { color: var(--c-text-2); font-weight: 400; font-size: .8rem; margin-left: 6px; }

.sidebar-nav { padding: 12px 0; flex: 1; }
.sidebar-section {
    font-size: .68rem;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--c-text-3);
    padding: 16px 20px 6px;
}
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 20px;
    font-size: .875rem;
    color: var(--c-text-2);
    border-radius: 0;
    transition: background .15s, color .15s;
    text-decoration: none;
    border-left: 3px solid transparent;
}
.sidebar-nav a:hover {
    background: var(--c-blue-light);
    color: var(--c-blue-dark);
}
.sidebar-nav a.active {
    background: var(--c-blue-light);
    color: var(--c-blue-dark);
    border-left-color: var(--c-blue);
    font-weight: 600;
}
.sidebar-nav a .icon { font-size: 1rem; width: 18px; text-align: center; }

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--c-border);
    font-size: .8rem;
    color: var(--c-text-3);
}
.sidebar-footer strong { color: var(--c-text-2); display: block; }

/* ── Contenido principal ─────────────────────────────────── */
.main-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    min-width: 0;
}

/* ── Header de página ────────────────────────────────────── */
.page-header {
    height: var(--header-h);
    background: var(--c-surface);
    border-bottom: 1px solid var(--c-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    position: sticky;
    top: 0;
    z-index: 50;
}
.page-header h1 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--c-text);
}
.page-header .header-actions { display: flex; gap: 10px; align-items: center; }

/* ── Contenido de página ─────────────────────────────────── */
.page-body { padding: 24px 28px; }

/* ── Cards ────────────────────────────────────────────────── */
.card {
    background: var(--c-surface);
    border-radius: var(--radius);
    border: 1px solid var(--c-border);
    box-shadow: var(--shadow);
}
.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--c-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.card-header h2 { font-size: .9rem; font-weight: 600; }
.card-body { padding: 20px; }

/* ── KPI Cards ────────────────────────────────────────────── */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.kpi-card {
    background: var(--c-surface);
    border-radius: var(--radius);
    border: 1px solid var(--c-border);
    padding: 18px 20px;
    box-shadow: var(--shadow);
}
.kpi-card .kpi-label {
    font-size: .75rem;
    color: var(--c-text-2);
    margin-bottom: 6px;
    font-weight: 500;
}
.kpi-card .kpi-value {
    font-family: var(--font-num);
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--c-text);
    line-height: 1.2;
}
.kpi-card .kpi-icon {
    font-size: 1.4rem;
    margin-bottom: 8px;
}
.kpi-card.kpi-danger .kpi-value { color: var(--c-danger); }
.kpi-card.kpi-success .kpi-value { color: var(--c-success); }
.kpi-card.kpi-warning .kpi-value { color: #C8860A; }

/* ── Tablas ───────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
}
thead th {
    background: var(--c-surface-2);
    padding: 10px 14px;
    text-align: left;
    font-weight: 600;
    font-size: .78rem;
    color: var(--c-text-2);
    border-bottom: 1px solid var(--c-border);
    white-space: nowrap;
}
tbody td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--c-border);
    vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--c-surface-2); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.font-num { font-family: var(--font-num); }
.font-num.bold { font-weight: 700; }

/* ── Badges / Estado ─────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.badge-success  { background: var(--c-success-bg); color: #2D8A60; }
.badge-danger   { background: var(--c-danger-bg);  color: #C0392B; }
.badge-warning  { background: var(--c-warning-bg); color: #9A6700; }
.badge-info     { background: var(--c-info-bg);    color: #2471A3; }
.badge-gray     { background: var(--c-surface-2);  color: var(--c-text-2); border: 1px solid var(--c-border); }

/* Semáforo stock */
.stock-ok   { color: #2D8A60; font-weight: 600; }
.stock-low  { color: #9A6700; font-weight: 600; }
.stock-zero { color: #C0392B; font-weight: 600; }

/* ── Formularios ─────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }
.form-group label {
    display: block;
    font-size: .8rem;
    font-weight: 600;
    color: var(--c-text-2);
    margin-bottom: 6px;
}
.form-control {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--c-border);
    border-radius: var(--radius-sm);
    font-size: .875rem;
    color: var(--c-text);
    background: var(--c-surface);
    transition: border-color .15s, box-shadow .15s;
    outline: none;
}
.form-control:focus {
    border-color: var(--c-blue);
    box-shadow: 0 0 0 3px rgba(107,159,212,.18);
}
.form-control.error { border-color: var(--c-danger); }
.form-error {
    font-size: .75rem;
    color: var(--c-danger);
    margin-top: 4px;
}
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.form-grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

/* ── Botones ─────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: .875rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background .15s, border-color .15s, opacity .15s;
    text-decoration: none;
    white-space: nowrap;
}
.btn:hover { opacity: .88; text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary  { background: var(--c-blue);      color: #fff; border-color: var(--c-blue-dark); }
.btn-success  { background: var(--c-success);   color: #fff; border-color: #4FA87A; }
.btn-danger   { background: var(--c-danger);    color: #fff; border-color: #D06060; }
.btn-warning  { background: var(--c-warning);   color: #fff; border-color: #D4A020; }
.btn-outline  { background: transparent; color: var(--c-blue-dark); border-color: var(--c-blue); }
.btn-ghost    { background: transparent; color: var(--c-text-2); border-color: var(--c-border); }
.btn-ghost:hover { background: var(--c-surface-2); }
.btn-sm { padding: 5px 10px; font-size: .78rem; }
.btn-lg { padding: 11px 24px; font-size: 1rem; }

/* ── Alertas ─────────────────────────────────────────────── */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: .875rem;
    margin-bottom: 16px;
    border-left: 3px solid;
}
.alert-success { background: var(--c-success-bg); border-color: var(--c-success); color: #2D8A60; }
.alert-danger  { background: var(--c-danger-bg);  border-color: var(--c-danger);  color: #C0392B; }
.alert-warning { background: var(--c-warning-bg); border-color: var(--c-warning); color: #9A6700; }
.alert-info    { background: var(--c-info-bg);    border-color: var(--c-info);    color: #2471A3; }

/* ── Toast notifications ─────────────────────────────────── */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: 12px 18px;
    box-shadow: var(--shadow-md);
    font-size: .875rem;
    min-width: 240px;
    max-width: 360px;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideIn .25s ease;
}
.toast.toast-success { border-left: 3px solid var(--c-success); }
.toast.toast-error   { border-left: 3px solid var(--c-danger); }
.toast.toast-warning { border-left: 3px solid var(--c-warning); }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── Paginación ──────────────────────────────────────────── */
.pagination {
    display: flex;
    align-items: center;
    gap: 4px;
    justify-content: flex-end;
    padding-top: 16px;
    flex-wrap: wrap;
}
.pagination a, .pagination span {
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    font-size: .8rem;
    border: 1px solid var(--c-border);
    color: var(--c-text-2);
    text-decoration: none;
    transition: background .15s;
}
.pagination a:hover { background: var(--c-blue-light); color: var(--c-blue-dark); }
.pagination span.active { background: var(--c-blue); color: #fff; border-color: var(--c-blue-dark); font-weight: 600; }
.pagination span.disabled { opacity: .4; cursor: not-allowed; }

/* ── Búsqueda ────────────────────────────────────────────── */
.search-box {
    position: relative;
}
.search-box input { padding-left: 34px; }
.search-box::before {
    content: '🔍';
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: .8rem;
    pointer-events: none;
}

/* ── Steps / Wizard ──────────────────────────────────────── */
.steps {
    display: flex;
    align-items: center;
    gap: 0;
    margin-bottom: 28px;
}
.step {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}
.step-num {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--c-border);
    color: var(--c-text-3);
    font-size: .8rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.step.active .step-num  { background: var(--c-blue);    color: #fff; }
.step.done   .step-num  { background: var(--c-success);  color: #fff; }
.step-label { font-size: .8rem; color: var(--c-text-2); }
.step.active .step-label { color: var(--c-blue-dark); font-weight: 600; }
.step-line { height: 1px; flex: 1; background: var(--c-border); margin: 0 8px; }

/* ── Modal ────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.35);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal {
    background: var(--c-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    max-width: 480px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
}
.modal-header {
    padding: 18px 20px;
    border-bottom: 1px solid var(--c-border);
    font-weight: 600;
    font-size: .95rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-body { padding: 20px; }
.modal-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--c-border);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}
.btn-close {
    background: none; border: none; cursor: pointer;
    color: var(--c-text-2); font-size: 1.2rem; padding: 2px 6px;
}

/* ── Tabs ─────────────────────────────────────────────────── */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--c-border);
    margin-bottom: 20px;
}
.tab-btn {
    padding: 10px 20px;
    font-size: .875rem;
    font-weight: 600;
    color: var(--c-text-2);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    transition: color .15s, border-color .15s;
}
.tab-btn:hover { color: var(--c-blue-dark); }
.tab-btn.active { color: var(--c-blue-dark); border-bottom-color: var(--c-blue); }

/* ── Totales de factura ───────────────────────────────────── */
.totales-box {
    background: var(--c-surface-2);
    border-radius: var(--radius-sm);
    border: 1px solid var(--c-border);
    padding: 16px;
    max-width: 320px;
    margin-left: auto;
}
.total-row {
    display: flex;
    justify-content: space-between;
    padding: 5px 0;
    font-size: .875rem;
}
.total-row.total-final {
    border-top: 2px solid var(--c-border);
    margin-top: 8px;
    padding-top: 10px;
    font-family: var(--font-num);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--c-blue-dark);
}

/* ── Cashflow semáforo ────────────────────────────────────── */
.cf-ok   { background: var(--c-success-bg); }
.cf-warn { background: var(--c-warning-bg); }
.cf-neg  { background: var(--c-danger-bg); }

/* ── Login ────────────────────────────────────────────────── */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #EBF3FB 0%, #F4F6FA 50%, #EDF9F3 100%);
}
.login-card {
    background: var(--c-surface);
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(107,159,212,.15);
    padding: 40px;
    width: 100%;
    max-width: 400px;
}
.login-title {
    font-family: var(--font-num);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--c-blue-dark);
    margin-bottom: 4px;
}
.login-subtitle { font-size: .85rem; color: var(--c-text-2); margin-bottom: 28px; }

/* ── Print / PDF ─────────────────────────────────────────── */
@media print {
    .sidebar, .page-header, .btn, .header-actions { display: none !important; }
    .main-content { margin-left: 0 !important; }
    .page-body { padding: 0 !important; }
    table { font-size: 11px; }
}

/* ── Utilidades ──────────────────────────────────────────── */
.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: 8px !important; }
.mb-2 { margin-bottom: 16px !important; }
.mb-3 { margin-bottom: 24px !important; }
.mt-2 { margin-top: 16px !important; }
.mt-3 { margin-top: 24px !important; }
.gap-2 { gap: 16px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-end { display: flex; justify-content: flex-end; align-items: center; }
.flex-center { display: flex; justify-content: center; align-items: center; }
.w-100 { width: 100%; }
.text-muted { color: var(--c-text-2); }
.text-small { font-size: .8rem; }
.text-danger { color: var(--c-danger); }
.text-success { color: var(--c-success); }
.fw-bold { font-weight: 700; }
.hidden { display: none !important; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); transition: transform .25s; }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .form-grid-2, .form-grid-3, .form-grid-4 { grid-template-columns: 1fr; }
    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .page-body { padding: 16px; }
}
