@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600;700&display=swap');

/* ==========================================================
   DESIGN TOKENS
   ========================================================== */
:root {
    color-scheme: light;

    --bg:            #ffffff;
    --bg-subtle:     #fafafa;
    --bg-muted:      #f4f4f5;
    --surface:       #ffffff;
    --surface-hover: #fafafa;
    --overlay:       rgba(9, 9, 11, 0.45);

    --border:        #e4e4e7;
    --border-strong: #d4d4d8;

    --text-primary:   #09090b;
    --text-secondary: #52525b;
    --text-muted:     #a1a1aa;

    --accent:        #5b5fe8;
    --accent-hover:  #4c50d4;
    --accent-fg:     #ffffff;
    --accent-subtle: rgba(91, 95, 232, 0.10);
    --accent-ring:   rgba(91, 95, 232, 0.35);

    --hadir:         #16a34a;
    --hadir-bg:      rgba(22, 163, 74, 0.10);
    --izin:          #d97706;
    --izin-bg:       rgba(217, 119, 6, 0.10);
    --sakit:         #dc2626;
    --sakit-bg:      rgba(220, 38, 38, 0.10);
    --alfa:          #71717a;
    --alfa-bg:       rgba(113, 113, 122, 0.10);

    --font-sans: 'Inter', ui-sans-serif, system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, 'Courier New', monospace;

    --radius-sm: 6px;
    --radius:    10px;
    --radius-lg: 14px;

    --shadow-sm: 0 1px 2px rgba(9, 9, 11, 0.04);
    --shadow-md: 0 4px 16px -4px rgba(9, 9, 11, 0.08);
    --shadow-pop: 0 12px 32px -8px rgba(9, 9, 11, 0.16);
}

[data-theme="dark"] {
    color-scheme: dark;

    --bg:            #0a0a0b;
    --bg-subtle:     #101012;
    --bg-muted:      #18181b;
    --surface:       #131316;
    --surface-hover: #19191d;
    --overlay:       rgba(0, 0, 0, 0.6);

    --border:        #232327;
    --border-strong: #303036;

    --text-primary:   #f4f4f5;
    --text-secondary: #a1a1aa;
    --text-muted:     #6b6b72;

    --accent:        #7b7ff0;
    --accent-hover:  #9194f5;
    --accent-fg:     #0a0a0b;
    --accent-subtle: rgba(123, 127, 240, 0.14);
    --accent-ring:   rgba(123, 127, 240, 0.35);

    --hadir:         #4ade80;
    --hadir-bg:      rgba(74, 222, 128, 0.12);
    --izin:          #fbbf24;
    --izin-bg:       rgba(251, 191, 36, 0.12);
    --sakit:         #f87171;
    --sakit-bg:      rgba(248, 113, 113, 0.12);
    --alfa:          #a1a1aa;
    --alfa-bg:       rgba(161, 161, 170, 0.12);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px -4px rgba(0, 0, 0, 0.5);
    --shadow-pop: 0 16px 40px -8px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
    background: var(--bg);
    font-family: var(--font-sans);
    font-size: 13.5px;
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    transition: background 0.2s ease, color 0.2s ease;
}

body { overflow: hidden; }

::selection { background: var(--accent-subtle); color: var(--accent); }

button { font-family: inherit; }

svg.icon {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
}

/* ==========================================================
   LAYOUT
   ========================================================== */
.layout {
    display: grid;
    grid-template-rows: 60px auto 1fr;
    grid-template-columns: 1fr 1fr 360px;
    height: 100vh;
    gap: 0;
    background: var(--bg);
}

/* ── Topbar ── */
.topbar {
    grid-column: 1 / -1;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 100;
}

.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }

.brand {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    min-width: 0;
}

.brand-mark {
    width: 26px;
    height: 26px;
    border-radius: 7px;
    background: var(--accent);
    color: var(--accent-fg);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.brand-mark svg { width: 15px; height: 15px; }

.topbar-title {
    font-size: 14.5px;
    font-weight: 700;
    letter-spacing: -0.2px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-sub {
    font-size: 11.5px;
    color: var(--text-muted);
    margin-left: 10px;
    font-weight: 500;
    padding-left: 10px;
    border-left: 1px solid var(--border);
    white-space: nowrap;
}

.topbar-right { display: flex; align-items: center; gap: 10px; }

.btn-download {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: var(--accent-fg);
    font-size: 12.5px;
    font-weight: 600;
    text-decoration: none;
    border: 1px solid var(--accent);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
    white-space: nowrap;
}
.btn-download svg { width: 15px; height: 15px; }
.btn-download:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-download:active { transform: translateY(1px); }

.live-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 600;
    color: var(--hadir);
    background: var(--hadir-bg);
    padding: 5px 10px 5px 8px;
    border-radius: 999px;
    font-family: var(--font-mono);
    letter-spacing: 0.2px;
}

.live-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--hadir);
    position: relative;
}
.live-dot::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: var(--hadir);
    animation: live-ping 1.8s cubic-bezier(0,0,0.2,1) infinite;
}
@keyframes live-ping {
    0% { transform: scale(1); opacity: 0.7; }
    75%, 100% { transform: scale(2.6); opacity: 0; }
}

#clock {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    letter-spacing: 0.2px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-secondary);
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.15s ease;
}
.theme-toggle:hover { background: var(--surface-hover); color: var(--text-primary); border-color: var(--border-strong); }
.theme-toggle svg { width: 16px; height: 16px; }
.theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* ── Stats bar (replaces sidebar) ── */
.stats-bar {
    grid-column: 1 / -1;
    grid-row: 2 / 3;
    display: flex;
    gap: 10px;
    padding: 14px 16px 0;
    overflow-x: auto;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(120px, 1fr));
    gap: 10px;
    flex: 1 1 auto;
    min-width: 0;
}

.stat-card {
    position: relative;
    border-radius: var(--radius);
    padding: 12px 13px;
    background: var(--surface);
    border: 1px solid var(--border);
    transition: border-color 0.15s ease, background 0.15s ease;
}
.stat-card:hover { border-color: var(--border-strong); background: var(--surface-hover); }

.stat-label {
    display: flex;
    align-items: center;
    gap: 5px;
    color: var(--text-muted);
    font-size: 10.5px;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}
.stat-label svg { width: 12px; height: 12px; }

.stat-num {
    font-family: var(--font-mono);
    font-size: 24px;
    font-weight: 700;
    line-height: 1;
    letter-spacing: -0.5px;
    font-variant-numeric: tabular-nums;
}

.stat-num.hadir { color: var(--hadir); }
.stat-num.izin  { color: var(--izin); }
.stat-num.sakit { color: var(--sakit); }
.stat-num.alfa  { color: var(--alfa); }

.info-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(110px, 1fr));
    gap: 10px;
    flex: 0 0 auto;
}

.info-mini {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 10px 14px;
    border: 1px solid var(--border);
    min-width: 130px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.info-mini-label {
    font-size: 10px;
    color: var(--text-muted);
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}
.info-mini-val {
    font-family: var(--font-mono);
    font-size: 17px;
    font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

/* WiFi panel grid (own panel now, not sidebar) */
.wifi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 8px;
    padding: 14px 18px;
}

.wifi-card-mini {
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 9px 11px 9px 14px;
    transition: all 0.15s ease;
    position: relative;
}

.wifi-card-mini::before {
    content: '';
    position: absolute;
    left: 8px; top: 50%;
    width: 5px; height: 5px;
    transform: translateY(-50%);
    border-radius: 50%;
    background: var(--hadir);
    box-shadow: 0 0 0 2.5px var(--hadir-bg);
}

.wifi-card-mini:hover { border-color: var(--border-strong); background: var(--surface-hover); }

.wifi-ssid-mini  { font-weight: 600; font-size: 12px; color: var(--text-primary); margin-bottom: 2px; }
.wifi-bssid-mini { font-size: 10.5px; color: var(--text-muted); font-family: var(--font-mono); }

.empty-mini { font-size: 11.5px; color: var(--text-muted); padding: 10px 18px; }

/* ── Main content ── */
.main { display: contents; }

.panel-absensi {
    grid-column: 1 / 2;
    grid-row: 3 / 4;
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin: 16px 8px 16px 16px;
    box-shadow: var(--shadow-sm);
}

.panel-rekap {
    grid-column: 2 / 3;
    grid-row: 3 / 4;
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin: 16px 8px;
    box-shadow: var(--shadow-sm);
}

.right-panels {
    grid-column: 3 / 4;
    grid-row: 3 / 4;
    display: grid;
    grid-template-rows: 1fr 1fr;
    gap: 12px;
    padding: 16px 16px 16px 8px;
    overflow: hidden;
}

.panel {
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
    box-shadow: var(--shadow-sm);
}

.panel-head {
    padding: 13px 18px;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    letter-spacing: -0.1px;
}
.panel-head svg { width: 15px; height: 15px; color: var(--text-muted); }

.panel-body { flex: 1; overflow-y: auto; overflow-x: auto; padding: 0; min-height: 0; }

.panel-body table { width: 100%; border-collapse: collapse; font-size: 12.5px; }

.panel-body table thead th {
    position: sticky;
    top: 0;
    background: var(--bg-subtle);
    padding: 9px 18px;
    text-align: left;
    font-size: 10.5px;
    color: var(--text-muted);
    font-weight: 600;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.panel-body table tbody td {
    padding: 10px 18px;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
    white-space: nowrap;
}

.panel-body table tbody tr:last-child td { border-bottom: none; }

.panel-body table tbody tr:hover td {
    background: var(--surface-hover);
    color: var(--text-primary);
}

.cell-strong { font-weight: 600; color: var(--text-primary) !important; }
.cell-mono   { font-family: var(--font-mono); font-size: 11.5px; }

.panel-search {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    position: relative;
}
.panel-search svg {
    position: absolute;
    left: 24px;
    top: 50%;
    transform: translateY(-50%);
    width: 14px;
    height: 14px;
    color: var(--text-muted);
    pointer-events: none;
}

.panel-search input {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 7px 12px 7px 30px;
    font-size: 12.5px;
    outline: none;
    background: var(--bg-subtle);
    color: var(--text-primary);
    font-family: var(--font-sans);
    transition: all 0.15s;
}

.panel-search input::placeholder { color: var(--text-muted); }

.panel-search input:focus {
    border-color: var(--accent);
    background: var(--surface);
    box-shadow: 0 0 0 3px var(--accent-ring);
}

/* Status badges */
.badge-status {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.1px;
}
.badge-status::before {
    content: '';
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: currentColor;
}

.badge-hadir { background: var(--hadir-bg); color: var(--hadir); }
.badge-izin  { background: var(--izin-bg); color: var(--izin); }
.badge-sakit { background: var(--sakit-bg); color: var(--sakit); }
.badge-alfa  { background: var(--alfa-bg); color: var(--alfa); }

/* Scrollbars */
.panel-body::-webkit-scrollbar { width: 6px; height: 6px; }
.panel-body::-webkit-scrollbar-track { background: transparent; }
.panel-body::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 3px;
}
.panel-body::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    .panel, .panel-absensi, .stat-card, .info-mini, .wifi-card-mini, .live-dot::after { animation: none !important; transition: none !important; }
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 1400px) {
    .layout { grid-template-columns: 1fr 1fr 320px; }
    .stat-grid { grid-template-columns: repeat(4, minmax(100px, 1fr)); }
}

@media (max-width: 1100px) {
    html, body { overflow-y: auto; }
    .layout {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: 60px auto auto auto;
        height: auto;
        min-height: 100vh;
    }
    .stats-bar { flex-wrap: wrap; }
    .panel-absensi { grid-column: 1 / 2; grid-row: 3 / 4; margin: 12px 6px 12px 12px; max-height: 420px; }
    .panel-rekap { grid-column: 2 / 3; grid-row: 3 / 4; margin: 12px 12px 12px 6px; max-height: 420px; }
    .right-panels {
        grid-column: 1 / -1;
        grid-row: 4 / 5;
        grid-template-rows: none;
        grid-template-columns: repeat(2, 1fr);
        padding: 0 12px 12px;
    }
}

@media (max-width: 860px) {
    html, body { overflow-y: auto; }

    .topbar { padding: 0 14px; }
    .topbar-sub { display: none; }

    .stats-bar { flex-direction: column; padding: 12px 12px 0; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .info-row { grid-template-columns: repeat(2, 1fr); }

    .layout { grid-template-columns: 1fr; }
    .panel-absensi { grid-column: 1 / -1; margin: 12px; max-height: 380px; }
    .panel-rekap { grid-column: 1 / -1; margin: 0 12px 12px; max-height: 380px; }
    .right-panels {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    .panel { max-height: 320px; }
}

@media (max-width: 480px) {
    .layout { font-size: 12.5px; }
    .topbar-title { font-size: 13px; }
    .stat-num { font-size: 20px; }
    .brand-mark { width: 24px; height: 24px; }
    #clock { display: none; }
    .live-pill span.live-label { display: none; }
    .btn-download span { display: none; }
    .btn-download { padding: 7px 9px; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .panel-head { font-size: 12.5px; padding: 11px 14px; }
    .panel-body table thead th, .panel-body table tbody td { padding: 8px 12px; }
}