:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #a5b4fc;
    --teal: #0d9488;
    --teal-light: #14b8a6;
    --violet: #8b5cf6;
    --pink: #ec4899;
    --amber: #f59e0b;
    --orange: #f97316;
    --green: #10b981;
    --red: #ef4444;
    --sky: #0ea5e9;
    --bg: #eef2ff;
    --card: #ffffff;
    --text: #1e293b;
    --muted: #64748b;
    --border: #e2e8f0;
    --gradient: linear-gradient(135deg, #6366f1, #8b5cf6 50%, #ec4899);
}

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

.hidden { display: none !important; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: linear-gradient(180deg, #eef2ff 0%, #f8fafc 100%);
    color: var(--text);
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 230px;
    background: linear-gradient(180deg, #312e81 0%, #4338ca 40%, #6d28d9 100%);
    color: #fff;
    padding: 20px 0;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    box-shadow: 4px 0 18px rgba(49, 46, 129, .25);
}

.sidebar .brand {
    padding: 0 20px 20px;
    font-size: 1.3rem;
    font-weight: 800;
    border-bottom: 1px solid rgba(255,255,255,.15);
    margin-bottom: 10px;
    letter-spacing: .5px;
}

.sidebar .brand span {
    background: linear-gradient(90deg, #fbbf24, #f97316);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    color: #c7d2fe;
    text-decoration: none;
    font-size: .95rem;
    border-radius: 0 24px 24px 0;
    margin-right: 10px;
    transition: all .18s;
    font-weight: 500;
}

.sidebar nav a .ico { font-size: 1.1rem; }

.sidebar nav a:hover { background: rgba(255,255,255,.12); color: #fff; transform: translateX(4px); }
.sidebar nav a.active {
    background: linear-gradient(90deg, #fbbf24, #f97316);
    color: #312e81;
    font-weight: 700;
    box-shadow: 0 4px 12px rgba(251,191,36,.4);
}

.main {
    margin-left: 230px;
    flex: 1;
    padding: 28px 32px;
}

.page { display: none; }
.page.active { display: block; animation: fadeIn .25s ease; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

h1 {
    font-size: 1.55rem;
    margin-bottom: 22px;
    background: var(--gradient);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    display: inline-block;
}

.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 16px;
    margin-bottom: 25px;
}

.card {
    background: var(--card);
    border: none;
    border-radius: 16px;
    padding: 20px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 6px 18px rgba(99,102,241,.12);
    transition: transform .2s, box-shadow .2s;
}

.card::after {
    content: '';
    position: absolute;
    top: -30px;
    right: -30px;
    width: 90px;
    height: 90px;
    border-radius: 50%;
    opacity: .18;
}

.card:hover { transform: translateY(-3px); box-shadow: 0 12px 24px rgba(99,102,241,.2); }
.card.green::after { background: var(--green); }
.card.blue::after { background: var(--sky); }
.card.violet::after { background: var(--violet); }
.card.pink::after { background: var(--pink); }
.card.amber::after { background: var(--amber); }
.card.red::after { background: var(--red); }

.card .label { color: var(--muted); font-size: .82rem; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.card .value { font-size: 1.75rem; font-weight: 800; margin-top: 6px; }
.card.green .value { color: var(--green); }
.card.blue .value { color: var(--sky); }
.card.violet .value { color: var(--violet); }
.card.pink .value { color: var(--pink); }
.card.amber .value { color: var(--amber); }
.card.red .value { color: var(--red); }

.panel {
    background: var(--card);
    border: none;
    border-radius: 16px;
    padding: 22px;
    margin-bottom: 25px;
    box-shadow: 0 6px 18px rgba(99,102,241,.1);
}

.panel h2 {
    font-size: 1.05rem;
    margin-bottom: 16px;
    color: #4338ca;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}

.panel h2 .dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    display: inline-block;
}

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; color: var(--muted); font-weight: 700; padding: 10px 8px; border-bottom: 2px solid #e0e7ff; font-size: .78rem; text-transform: uppercase; letter-spacing: .4px; }
td { padding: 10px 8px; border-bottom: 1px solid var(--border); }
tr:hover td { background: #f5f3ff; }
tbody tr:last-child td { border-bottom: none; }

.badge { padding: 4px 12px; border-radius: 20px; font-size: .74rem; font-weight: 700; }
.badge.pendiente { background: #fef3c7; color: #d97706; }
.badge.confirmada { background: #dbeafe; color: #2563eb; }
.badge.completada { background: #d1fae5; color: #059669; }
.badge.cancelada { background: #fee2e2; color: #dc2626; }
.badge.pagada { background: #d1fae5; color: #059669; }
.badge.anulada { background: #fee2e2; color: #dc2626; }

.btn {
    background: var(--gradient);
    color: #fff;
    border: none;
    padding: 9px 16px;
    border-radius: 10px;
    cursor: pointer;
    font-size: .9rem;
    font-weight: 600;
    transition: all .18s;
    box-shadow: 0 4px 12px rgba(99,102,241,.3);
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 8px 18px rgba(99,102,241,.4); filter: brightness(1.05); }
.btn.sm { padding: 5px 10px; font-size: .78rem; box-shadow: none; }
.btn.ghost { background: #eef2ff; color: #4338ca; box-shadow: none; }
.btn.ghost:hover { background: #e0e7ff; filter: none; }
.btn.danger { background: linear-gradient(135deg, #f87171, #ef4444); box-shadow: 0 4px 10px rgba(239,68,68,.3); }
.btn.danger:hover { filter: brightness(1.05); }
.btn.green { background: linear-gradient(135deg, #34d399, #10b981); box-shadow: 0 4px 10px rgba(16,185,129,.3); }
.btn.amber { background: linear-gradient(135deg, #fbbf24, #f59e0b); box-shadow: 0 4px 10px rgba(245,158,11,.3); color: #78350f; }

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; gap: 10px; flex-wrap: wrap; }
.toolbar input[type="search"] {
    padding: 10px 14px;
    border: 2px solid #e0e7ff;
    border-radius: 12px;
    min-width: 260px;
    font-size: .9rem;
    outline: none;
    transition: border .2s, box-shadow .2s;
    background: #fff;
}
.toolbar input[type="search"]:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(99,102,241,.15); }

form.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
form.grid label { display: flex; flex-direction: column; font-size: .82rem; color: var(--muted); gap: 5px; font-weight: 600; }
form.grid input, form.grid select, form.grid textarea {
    padding: 9px 12px;
    border: 2px solid #e0e7ff;
    border-radius: 10px;
    font-size: .9rem;
    font-family: inherit;
    color: var(--text);
    background: #fff;
    outline: none;
    transition: border .2s, box-shadow .2s;
}
form.grid input:focus, form.grid select:focus, form.grid textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(99,102,241,.15);
}
form.grid textarea { resize: vertical; min-height: 60px; }

.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(30, 27, 75, .5);
    backdrop-filter: blur(3px);
    z-index: 100;
    justify-content: center;
    align-items: center;
}
.modal.show { display: flex; animation: fadeIn .2s ease; }
.modal-content {
    background: #fff;
    border-radius: 18px;
    padding: 28px;
    width: 540px;
    max-width: 95vw;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 24px 60px rgba(30,27,75,.35);
}
.modal-content h2 {
    margin-bottom: 18px;
    background: var(--gradient);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

.row-actions { display: flex; gap: 6px; align-items: center; }

.muted { color: var(--muted); }
.alert { padding: 10px; border-radius: 8px; margin-bottom: 12px; font-size: .9rem; }
.alert.error { background: #fee2e2; color: #dc2626; }
.alert.success { background: #d1fae5; color: #059669; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 25px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.stock-bajo { color: var(--red); font-weight: 700; }

#toast {
    position: fixed;
    bottom: 25px;
    right: 25px;
    background: linear-gradient(135deg, #312e81, #6d28d9);
    color: #fff;
    padding: 13px 20px;
    border-radius: 12px;
    opacity: 0;
    transition: opacity .25s, transform .25s;
    z-index: 200;
    font-weight: 600;
    box-shadow: 0 10px 24px rgba(49,46,129,.35);
    transform: translateY(10px);
}
#toast.show { opacity: 1; transform: translateY(0); }

/* ============================================================
   LOGIN
   ============================================================ */
.login-screen {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e1b4b 0%, #4338ca 55%, #6d28d9 100%);
    z-index: 500;
    padding: 20px;
}
.login-screen.show { display: flex; animation: fadeIn .35s ease; }

.login-card {
    background: #fff;
    width: 400px;
    max-width: 100%;
    border-radius: 22px;
    padding: 40px 36px;
    box-shadow: 0 30px 70px rgba(20, 10, 60, .5);
    text-align: center;
}

.login-brand { font-size: 1.9rem; font-weight: 800; margin-bottom: 6px; color: #312e81; }
.login-brand i { color: var(--pink); margin-right: 6px; }
.login-brand .grad { background: var(--gradient); -webkit-background-clip: text; background-clip: text; color: transparent; }

.login-card h2 { font-size: 1.3rem; margin-top: 8px; color: var(--text); }
.login-card > .muted { margin: 6px 0 22px; font-size: .9rem; }

#login-form { display: flex; flex-direction: column; gap: 16px; text-align: left; }
#login-form label { font-size: .85rem; color: var(--muted); font-weight: 600; }
.input-ico { position: relative; margin-top: 5px; }
.input-ico i {
    position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
    color: var(--primary); font-size: .95rem;
}
.input-ico input {
    width: 100%; padding: 13px 14px 13px 42px;
    border: 2px solid #e0e7ff; border-radius: 12px; font-size: .95rem; outline: none;
    transition: border .2s, box-shadow .2s;
}
.input-ico input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(99,102,241,.15); }

.login-btn { width: 100%; padding: 13px; font-size: 1rem; border-radius: 12px; }
.login-btn i { margin-right: 6px; }

.login-foot { margin-top: 20px; font-size: .78rem; text-align: center; }
.login-foot i { margin-right: 4px; }

#login-msg { margin-bottom: 0; }

/* ============================================================
   TOPBAR MOVIL
   ============================================================ */
.topbar {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 56px;
    align-items: center;
    justify-content: space-between;
    padding: 0 14px;
    background: linear-gradient(135deg, #312e81, #6d28d9);
    z-index: 60;
    color: #fff;
    box-shadow: 0 4px 16px rgba(30,27,75,.3);
}
.brand-mobile { font-size: 1.15rem; font-weight: 800; }
.brand-mobile .grad { color: #fbbf24; }
.icon-btn {
    background: rgba(255,255,255,.12); border: none; color: #fff;
    width: 40px; height: 40px; border-radius: 10px; cursor: pointer; font-size: 1.1rem;
    display: flex; align-items: center; justify-content: center; transition: background .15s;
}
.icon-btn:hover { background: rgba(255,255,255,.25); }

.sidebar-foot { margin-top: auto; padding: 16px 20px; border-top: 1px solid rgba(255,255,255,.12); }
.logout-link {
    width: 100%; display: flex; align-items: center; gap: 10px;
    background: none; border: none; color: #c7d2fe; cursor: pointer; font-size: .9rem;
    padding: 10px; border-radius: 10px; font-weight: 500; transition: all .15s;
}
.logout-link:hover { background: rgba(239,68,68,.2); color: #fecaca; }

.overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 55; }
.overlay.show { display: block; }

/* ============================================================
   DASHBOARD CHIPS / TEMATICA
   ============================================================ */
.p-nom { font-weight: 700; color: #4338ca; }
.p-ape { color: var(--muted); font-weight: 500; }
.d-nom { color: var(--teal); font-weight: 600; }
.d-ico { margin-right: 6px; color: var(--violet); }
.stock-ico { color: var(--red); margin-right: 6px; }

.chip {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 10px; border-radius: 20px; font-size: .76rem; font-weight: 700;
}
.chip.fecha { background: #eef2ff; color: #4338ca; }
.chip.hora { background: #fff7ed; color: #c2410c; }
.chip.stock { background: #fee2e2; color: #dc2626; }
.chip i { font-size: .7rem; }

/* ============================================================
   RESPONSIVE MOVIL
   ============================================================ */
@media (max-width: 900px) {
    .topbar { display: flex; }
    body { padding-top: 56px; }

    .sidebar {
        transform: translateX(-100%);
        transition: transform .25s ease;
        z-index: 60;
        width: 250px;
        padding-top: 16px;
    }
    .sidebar.show { transform: translateX(0); }

    .main { margin-left: 0; padding: 18px 16px; }

    .cards { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

    .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .table-wrap table { min-width: 620px; }

    .toolbar input[type="search"] { min-width: 100%; flex: 1; }

    h1 { font-size: 1.3rem; }

    .modal-content { padding: 22px 18px; }
}

@media (max-width: 480px) {
    .cards { grid-template-columns: 1fr 1fr; }
    .main { padding: 14px 12px; }
    .toolbar .btn { width: 100%; }
    .login-card { padding: 30px 22px; }
    .modal-actions { flex-wrap: wrap; }
    .modal-actions .btn { flex: 1; }
}
