:root {
    --primary: #0f172a;
    --primary-light: #1e293b;
    --accent: #3b82f6;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --background: #f8fafc;
    --surface: #ffffff;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --sidebar-w: 260px;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--background);
    color: var(--text);
    line-height: 1.5;
}

/* ===== NAVIGATION ===== */
.mobile-nav {
    display: none;
    padding: 1rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    font-weight: 700;
    font-size: 1.25rem;
    text-decoration: none;
    color: var(--primary);
}
.nav-brand span { color: var(--accent); }

#menu-toggle {
    background: none;
    border: none;
    color: var(--primary);
    cursor: pointer;
    padding: 0.25rem;
}

/* Sidebar overlay for mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
}
.sidebar-overlay.active { display: block; }

/* ===== LAYOUT ===== */
.app-container {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-w);
    background: var(--primary);
    color: white;
    padding: 2rem 1.5rem;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
    z-index: 1000;
}

.sidebar-header { margin-bottom: 2rem; }
.sidebar-header .nav-brand { color: white; }

.nav-links {
    list-style: none;
    flex: 1;
}
.nav-links li { margin-bottom: 0.35rem; }
.nav-links a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 1rem;
    color: #cbd5e1;
    text-decoration: none;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
    font-size: 0.9rem;
}
.nav-links a:hover, .nav-links a.active {
    background: var(--primary-light);
    color: white;
}
.nav-links a.active { border-left: 3px solid var(--accent); }

.content {
    flex: 1;
    margin-left: var(--sidebar-w);
    padding: 2rem 3rem;
    max-width: calc(100vw - var(--sidebar-w));
}

/* ===== DOLAR BOX ===== */
.dolar-box-sidebar {
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.09);
    border-radius: var(--radius-sm);
    padding: 0.7rem 0.875rem;
    margin-top: 0.75rem;
}
.dolar-box-label {
    font-size: 0.67rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    margin-bottom: 0.55rem;
}
.dolar-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.32rem 0;
}
.dolar-item + .dolar-item {
    border-top: 1px solid rgba(255,255,255,0.07);
}
.dolar-item-name {
    font-size: 0.78rem;
    font-weight: 600;
    color: white;
    min-width: 48px;
}
.dolar-item-vals {
    display: flex;
    gap: 0.7rem;
    align-items: center;
}
.dolar-compra { font-size: 0.73rem; color: #f87171; }
.dolar-venta  { font-size: 0.76rem; font-weight: 700; color: #34d399; }

/* ===== CARDS & STATS ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2.5rem;
}

.stat-card {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    transition: transform 0.3s ease;
    cursor: default;
}
.stat-card:hover { transform: translateY(-3px); }

.stat-label {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    display: block;
}
.stat-value { font-size: 1.5rem; font-weight: 700; }
.stat-value.up   { color: var(--success); }
.stat-value.down { color: var(--danger); }

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    border: none;
    font-family: inherit;
    font-size: 0.9rem;
    white-space: nowrap;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }
.btn:hover { transform: translateY(-1px); box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1); }

/* ===== FORMS ===== */
.card-form {
    background: var(--surface);
    padding: 2rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow);
    max-width: 640px;
    width: 100%;
}

.form-group { margin-bottom: 1.5rem; }

label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.875rem;
}

input, select, textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: white;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* 2-column grid helper — se vuelve 1 columna en mobile */
.grid-2col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

/* ===== TABLES ===== */
.table-container {
    background: var(--surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow);
    overflow: hidden;
    margin-top: 1rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 560px;
}

th {
    background: #f1f5f9;
    text-align: left;
    padding: 0.875rem 1rem;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    white-space: nowrap;
}

td {
    padding: 0.875rem 1rem;
    border-top: 1px solid var(--border);
    vertical-align: middle;
}

tr { transition: background 0.15s ease; }
tr:hover td { background-color: #f8fafc; }

/* ===== BADGES ===== */
.badge {
    padding: 0.25rem 0.65rem;
    border-radius: 9999px;
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
}
.badge-proceso   { background: #dbeafe; color: #1e40af; }
.badge-terminado { background: #fef3c7; color: #92400e; }
.badge-completado{ background: #dcfce7; color: #166534; }
.badge-pendiente { background: #fee2e2; color: #991b1b; }

/* ===== DOLAR PILL (mobile nav) ===== */
.dolar-pill {
    display: flex;
    align-items: center;
    background: #f1f5f9;
    padding: 0.25rem 0.6rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    gap: 0.4rem;
}
.pill-label { color: var(--text-muted); font-weight: 500; }
.pill-value  { color: var(--success); font-weight: 700; }

/* ===== MODAL ===== */
.modal {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.modal.active { display: flex; }

.modal-content {
    background: white;
    padding: 2rem;
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 500px;
    box-shadow: var(--shadow-lg);
    position: relative;
    animation: modalIn 0.2s ease-out;
}
@keyframes modalIn {
    from { transform: scale(0.95); opacity: 0; }
    to   { transform: scale(1); opacity: 1; }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}
.close-modal {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0.25rem;
    transition: color 0.2s;
}
.close-modal:hover { color: var(--danger); }

/* ===== AUTOCOMPLETE ===== */
.select-with-action { display: flex; gap: 0.5rem; }
.search-input-container { position: relative; flex: 1; }

#client-results {
    position: absolute;
    top: 100%; left: 0;
    width: 100%;
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    z-index: 10;
    max-height: 200px;
    overflow-y: auto;
    display: none;
}
.client-item {
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}
.client-item:last-child { border-bottom: none; }
.client-item:hover { background: #f8fafc; }

/* ===== TOAST ===== */
#toast-container {
    position: fixed;
    top: 20px; right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.toast {
    background: white;
    padding: 1rem 1.5rem;
    border-radius: 8px;
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    gap: 12px;
    border-left: 4px solid var(--accent);
    transform: translateX(120%);
    transition: transform 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    min-width: 260px;
    max-width: 380px;
}
.toast.active { transform: translateX(0); }
.toast-success { border-left-color: #10b981; }
.toast-error   { border-left-color: #ef4444; }
.toast-warning { border-left-color: #f59e0b; }

/* ===== COMMAND PALETTE ===== */
#cmd-palette {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 9000;
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding-top: 10vh;
    backdrop-filter: blur(4px);
}
#cmd-palette.active { display: flex; }

.cmd-content {
    background: white;
    width: 100%;
    max-width: 600px;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
    animation: cmdIn 0.2s ease-out;
    margin: 0 1rem;
}
@keyframes cmdIn {
    from { transform: scale(0.95); opacity: 0; }
    to   { transform: scale(1); opacity: 1; }
}
.cmd-search {
    width: 100%;
    border: none;
    padding: 1.25rem 1.5rem;
    font-size: 1.125rem;
    outline: none;
    border-bottom: 1px solid #f1f5f9;
}
.cmd-results {
    max-height: 400px;
    overflow-y: auto;
    padding: 0.5rem;
}
.cmd-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0.875rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    color: inherit;
}
.cmd-item:hover { background: #f1f5f9; transform: translateX(4px); }
.cmd-item-info { flex: 1; min-width: 0; }
.cmd-item-title { font-weight: 600; font-size: 0.9375rem; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cmd-item-sub   { font-size: 0.75rem; color: #94a3b8; }
.cmd-type {
    font-size: 0.625rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: #f1f5f9;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 700;
    color: #64748b;
    white-space: nowrap;
}

/* ===== RESPONSIVE — 900px ===== */
@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-100%);
        z-index: 1000;
    }
    .sidebar.active { transform: translateX(0); }

    .content {
        margin-left: 0;
        padding: 1.5rem 1rem;
        max-width: 100vw;
    }

    .mobile-nav { display: flex; }

    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
        gap: 1rem;
    }

    .card-form {
        max-width: 100%;
        padding: 1.5rem;
    }

    .modal-content { padding: 1.5rem; }

    .btn { padding: 0.6rem 1rem; font-size: 0.875rem; }
}

/* ===== RESPONSIVE — 640px ===== */
@media (max-width: 640px) {
    .content { padding: 1rem 0.75rem; }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 0.75rem;
    }

    .stat-card { padding: 1rem; }
    .stat-value { font-size: 1.25rem; }

    /* Grids de 2 columnas → 1 columna */
    .grid-2col { grid-template-columns: 1fr; }

    /* Header de páginas */
    .page-header-row {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.75rem;
    }
    .page-header-row .btn { width: 100%; justify-content: center; }

    /* Filtros apilados */
    .filters-row {
        flex-direction: column;
    }
    .filters-row input,
    .filters-row select { width: 100%; }

    /* Tabla: scroll horizontal en móvil */
    .table-container { border-radius: var(--radius-sm); }
    table { min-width: 480px; }
    th, td { padding: 0.65rem 0.75rem; font-size: 0.85rem; }

    .card-form { padding: 1.25rem; }
    .modal-content { padding: 1.25rem; margin: 0; border-radius: var(--radius-md); }

    /* Toast más pequeño */
    .toast { min-width: auto; max-width: calc(100vw - 2rem); right: 1rem; }

    /* Cmd palette padding */
    #cmd-palette { padding-top: 5vh; }
}

/* ===== RESPONSIVE — 480px ===== */
@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .nav-brand  { font-size: 1.1rem; }
    .dolar-pill { font-size: 0.7rem; padding: 0.15rem 0.4rem; }
    .mobile-nav { padding: 0.875rem 1rem; }
}
