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

/* ============================================================
   DESIGN TOKENS
   ============================================================ */
:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-glow: rgba(99,102,241,0.35);
    --accent: #818cf8;
    --success: #10b981;
    --danger: #f43f5e;
    --warning: #f59e0b;
    --bg-main: #f1f5f9;
    --bg-card: #ffffff;
    --bg-sidebar: #1e1b4b;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --shadow: 0 4px 24px -4px rgba(15,23,42,0.10);
    --shadow-lg: 0 12px 40px -8px rgba(15,23,42,0.18);
    --radius: 1rem;
    --radius-sm: 0.625rem;
    --sidebar-text: rgba(255,255,255,0.75);
    --sidebar-active-bg: rgba(99,102,241,0.25);
    --sidebar-active-text: #ffffff;
    --sidebar-hover-bg: rgba(255,255,255,0.08);
    --font: 'Outfit', sans-serif;
}

[data-theme='dark'] {
    --bg-main: #0b0f1a;
    --bg-card: rgba(22,28,48,0.80);
    --bg-sidebar: #080c18;
    --text-main: #e2e8f0;
    --text-muted: #94a3b8;
    --border: rgba(99,102,241,0.14);
    --shadow: 0 4px 24px -4px rgba(0,0,0,0.45);
    --shadow-lg: 0 16px 48px -12px rgba(0,0,0,0.65);
    --sidebar-active-bg: rgba(99,102,241,0.30);
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { margin:0; padding:0; box-sizing:border-box; }

html { scroll-behavior: smooth; }

body {
    font-family: var(--font);
    background-color: var(--bg-main);
    color: var(--text-main);
    transition: background-color 0.35s, color 0.35s;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
    width: 260px;
    height: 100vh;
    position: fixed;
    left: 0; top: 0;
    background: var(--bg-sidebar);
    border-right: 1px solid rgba(99,102,241,0.12);
    padding: 1.5rem 1rem;
    z-index: 50;
    transition: transform 0.3s ease;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(99,102,241,0.3); border-radius: 99px; }

.sidebar nav { flex: 1; }

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.875rem;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: var(--radius-sm);
    margin-bottom: 0.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s cubic-bezier(0.4,0,0.2,1);
    cursor: pointer;
    border: none;
    width: 100%;
    text-align: left;
    background: transparent;
}

.sidebar-link:hover {
    background: var(--sidebar-hover-bg);
    color: #fff;
    transform: translateX(3px);
}

.sidebar-link.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
    box-shadow: inset 2px 0 0 var(--primary);
}

.sidebar-link i {
    width: 18px;
    text-align: center;
    opacity: 0.85;
    flex-shrink: 0;
}

/* Mobile sidebar */
@media (max-width: 1024px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,0.4); }
    main, .main-content { margin-left: 0 !important; }
    .sidebar-overlay {
        display: none; position: fixed; inset: 0;
        background: rgba(0,0,0,0.55); z-index: 40;
        opacity: 0; transition: opacity 0.3s;
    }
    .sidebar-overlay.show { display: block; opacity: 1; }
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main-content {
    margin-left: 260px;
    flex: 1;
    padding: 2rem;
    min-height: 100vh;
    transition: margin-left 0.3s;
}

@media (max-width: 640px) {
    .main-content, main { padding: 1rem !important; }
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    transition: transform 0.22s cubic-bezier(0.4,0,0.2,1), box-shadow 0.22s;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}

.glass {
    background: rgba(255,255,255,0.65);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255,255,255,0.25);
}

[data-theme='dark'] .glass {
    background: rgba(15,19,36,0.75);
    border: 1px solid rgba(99,102,241,0.15);
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn-primary {
    background: linear-gradient(135deg, var(--primary), #7c3aed);
    color: #fff;
    padding: 0.6rem 1.375rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    box-shadow: 0 4px 14px -4px var(--primary-glow);
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}
.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 20px -6px var(--primary-glow);
    filter: brightness(1.08);
}
.btn-primary:active { transform: scale(0.97); }

.btn-secondary {
    background: transparent;
    color: var(--text-muted);
    padding: 0.6rem 1.375rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    border: 1px solid var(--border);
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}
.btn-secondary:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: rgba(99,102,241,0.06);
}

.btn-danger {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: #fff;
    padding: 0.6rem 1.375rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}
.btn-danger:hover { filter: brightness(1.1); transform: translateY(-1px); }

.btn-sm { padding: 0.35rem 0.875rem; font-size: 0.8rem; }

/* ============================================================
   FORM CONTROLS
   ============================================================ */
input, select, textarea {
    color: var(--text-main);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
}

input::placeholder, textarea::placeholder { color: var(--text-muted); opacity: 0.7; }

[data-theme='dark'] input,
[data-theme='dark'] select,
[data-theme='dark'] textarea {
    background: rgba(255,255,255,0.05);
    color: #e2e8f0;
    border-color: rgba(99,102,241,0.18);
}

[data-theme='dark'] input::placeholder { color: #64748b; }

/* Autofill fix */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
    -webkit-box-shadow: 0 0 0 30px var(--bg-card) inset !important;
    -webkit-text-fill-color: var(--text-main) !important;
}
[data-theme='dark'] input:-webkit-autofill {
    -webkit-box-shadow: 0 0 0 30px #1a2035 inset !important;
}

/* Number spinner */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; }

.hf-num-spinner { display: inline-flex; align-items: stretch; gap: 0.35rem; }
.hf-num-spinner.hf-num-spinner--block { display: flex; width: 100%; }
.hf-num-spinner input { flex: 1 1 auto; min-width: 0; width: 4.75rem; text-align: center; }
.hf-num-spinner.hf-num-spinner--block input { width: 100%; }

.hf-num-btn {
    width: 3.25rem;
    min-height: 3rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-main);
    background: var(--bg-card);
    border: 1px solid var(--border);
    cursor: pointer;
    font-size: 1.2rem;
    font-weight: 700;
    border-radius: var(--radius-sm);
    transition: background 0.15s;
    user-select: none;
}
.hf-num-btn:hover { background: rgba(99,102,241,0.1); border-color: var(--primary); }
.hf-num-btn:active { background: rgba(99,102,241,0.2); }
.hf-num-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ============================================================
   TABLES
   ============================================================ */
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
thead tr { border-bottom: 2px solid var(--border); }
thead th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}
tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: rgba(99,102,241,0.04); }
td { padding: 0.875rem 1rem; color: var(--text-main); }

@media (max-width: 768px) {
    table { display: block; overflow-x: auto; white-space: nowrap; }
}

/* ============================================================
   TOAST
   ============================================================ */
.toast-container { position: fixed; bottom: 2rem; right: 2rem; z-index: 9999; }

.toast {
    background: var(--bg-card);
    color: var(--text-main);
    padding: 0.875rem 1.25rem;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    border-left: 3px solid var(--primary);
    margin-top: 0.625rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 300px;
    backdrop-filter: blur(12px);
    animation: slideIn 0.3s cubic-bezier(0.4,0,0.2,1);
    font-size: 0.875rem;
    font-weight: 500;
}

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes slideIn {
    from { transform: translateX(110%); opacity: 0; }
    to   { transform: translateX(0); opacity: 1; }
}
@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 0 0 0 var(--primary-glow); }
    50%       { box-shadow: 0 0 0 8px transparent; }
}

.animate-fade-in { animation: fadeIn 0.4s cubic-bezier(0.4,0,0.2,1) forwards; }

/* ============================================================
   STATUS BADGES
   ============================================================ */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.25rem 0.75rem;
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}
.badge-success { background: rgba(16,185,129,0.12); color: #059669; border: 1px solid rgba(16,185,129,0.2); }
.badge-warning { background: rgba(245,158,11,0.12); color: #d97706; border: 1px solid rgba(245,158,11,0.2); }
.badge-danger  { background: rgba(244,63,94,0.12);  color: #e11d48; border: 1px solid rgba(244,63,94,0.2); }
.badge-info    { background: rgba(99,102,241,0.12); color: #4f46e5; border: 1px solid rgba(99,102,241,0.2); }

/* ============================================================
   PRINT STYLES
   ============================================================ */
@media print {
    body { background: white !important; color: black !important; }
    aside, main, header, .card, .toast-container, #adminLink { display: none !important; }
    #printContainer { display: block !important; width: 45mm; margin: 0; padding: 0; }
    .label-wrapper {
        width: 45mm; height: 15mm; padding: 1mm;
        display: flex; align-items: center;
        page-break-after: always; overflow: hidden;
    }
    @page { size: 45mm 15mm; margin: 0; }
}

#printContainer { display: none; }

.label-content { display: flex; width: 100%; height: 100%; gap: 2mm; overflow: hidden; position: relative; }
.label-barcode  { width: 12mm; height: 12mm; flex-shrink: 0; }
.label-text     { flex: 1; display: flex; flex-direction: column; justify-content: center; font-size: 7pt; line-height: 1.1; overflow: hidden; color: black; }
.label-lab-number { font-weight: bold; font-size: 12pt; }
.label-patient  { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.label-date     { font-size: 6pt; }
.label-index    { position: absolute; bottom: 1mm; right: 1.5mm; font-size: 14pt; font-weight: 800; color: black; line-height: 1; }
