/* ============================================================
   Bitbas6x HS Manager — admin dashboard
   Layout follows the agreed wireframes; colours map onto the
   existing Bitbas6x palette so the whole product reads as one thing.
   ============================================================ */

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

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Inter', 'Segoe UI', Arial, sans-serif; }

:root {
    /* Surfaces */
    --bg:              #f4f6fa;
    --surface-1:       #ffffff;   /* cards, panels */
    --surface-2:       #ffffff;   /* raised cards (router cards) */
    --surface-muted:   #fafbfd;   /* read-only / de-emphasised blocks */

    /* Text */
    --text:            #1a2233;
    --text-secondary:  #5a6675;
    --text-muted:      #8a94a3;
    --text-accent:     #0072cc;

    /* Lines */
    --border:          #e3e8ef;
    --border-accent:   #0094ff;
    --border-danger:   #e8b4ae;

    /* Accent + status (mapped from the existing Bitbas6x admin palette) */
    --fill-accent:     #0094ff;
    --accent-deep:     #0a2080;

    --text-success:    #1a7f37;
    --bg-success:      #e9f7ee;
    --text-danger:     #c0392b;
    --bg-danger:       #fdecea;
    --text-warning:    #b45309;
    --bg-warning:      #fff8e1;

    --radius:          12px;
    --font-mono:       ui-monospace, 'Cascadia Mono', 'Segoe UI Mono', Consolas, monospace;
}

body { background: var(--bg); color: var(--text); min-height: 100vh; font-size: 14px; }

/* ── Top bar ── */
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 24px 14px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-1);
    margin-bottom: 20px;
}
.topbar-left { display: flex; align-items: center; gap: 20px; }
.topbar img { height: 26px; }
.brandname { font-size: 15px; font-weight: 600; }
.topbar nav { display: flex; gap: 18px; }
.topbar nav a { font-size: 13px; color: var(--text-secondary); text-decoration: none; padding-bottom: 2px; }
.topbar nav a:hover { color: var(--text-accent); }
.topbar nav a.active { color: var(--text-accent); border-bottom: 2px solid var(--fill-accent); }

.container { max-width: 1000px; margin: 0 auto; padding: 0 20px 60px; }

/* ── Page header (breadcrumb + title) ── */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; padding: 4px 4px 12px; gap: 16px; }
.crumb { font-size: 12px; color: var(--text-secondary); text-decoration: none; display: block; }
.crumb:hover { color: var(--text-accent); }
.page-title { font-size: 18px; font-weight: 600; margin-top: 4px; }
.page-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ── Metric cards ── */
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 18px; }
.metric { background: var(--surface-1); border-radius: var(--radius); padding: 1rem; }
.metric-label { font-size: 13px; color: var(--text-secondary); margin-bottom: 4px; }
.metric-value { font-size: 24px; font-weight: 600; }
.metric-value.danger { color: var(--text-danger); }
.metric-sub { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ── Router cards ── */
.router-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
.router-card {
    background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 1rem 1.25rem; text-decoration: none; color: inherit; display: block;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.router-card:hover { border-color: var(--border-accent); box-shadow: 0 4px 16px rgba(0,148,255,0.10); }
.router-card.is-offline { border-color: var(--border-danger); }
.router-card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.router-card-name { font-size: 15px; font-weight: 600; }
.router-card table { width: 100%; font-size: 13px; }
.router-card table td { padding: 3px 0; }
.router-card table td:first-child { color: var(--text-secondary); }
.router-card table td:last-child { text-align: right; }
.router-card table td.danger { color: var(--text-danger); }
.router-card table td.warn { color: var(--text-warning); }
.router-open { font-size: 12px; color: var(--text-accent); margin-top: 10px; }

/* ── Pills / badges ── */
.pill { font-size: 12px; padding: 3px 10px; border-radius: 20px; white-space: nowrap; display: inline-block; }
.pill-success { background: var(--bg-success); color: var(--text-success); }
.pill-danger  { background: var(--bg-danger);  color: var(--text-danger); }
.pill-warning { background: var(--bg-warning); color: var(--text-warning); }
.pill-muted   { background: #eef1f5;           color: var(--text-secondary); }
.pill-accent  { background: #e6f4ff;           color: var(--text-accent); }
.pill-sm { font-size: 11px; padding: 2px 8px; border-radius: 10px; }

/* ── Tabs ── */
.tabs { display: flex; gap: 18px; border-bottom: 1px solid var(--border); margin-bottom: 16px; padding: 0 4px; }
.tabs a { font-size: 13px; color: var(--text-secondary); text-decoration: none; padding-bottom: 8px; }
.tabs a:hover { color: var(--text-accent); }
.tabs a.active { color: var(--text-accent); border-bottom: 2px solid var(--fill-accent); }

/* ── Section headers ── */
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 0 0 10px; gap: 12px; }
.section-label { font-size: 13px; color: var(--text-secondary); }
.section-note { font-size: 12px; color: var(--text-muted); margin: 0 0 10px; }

/* ── List cards (packages, vouchers, generic rows) ── */
.list { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface-1); margin-bottom: 18px; }
.list.muted { background: var(--surface-muted); }
.list-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); gap: 12px; }
.list-row:last-child { border-bottom: none; }
.list-row-title { font-size: 14px; font-weight: 600; margin: 0; }
.list-row-meta { font-size: 12px; color: var(--text-secondary); margin: 3px 0 0; }
.list-row-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
.list-empty { padding: 16px; font-size: 13px; color: var(--text-muted); }

/* Stacked row variant, for vouchers (code above, meta below, actions under) */
.vrow { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.vrow:last-child { border-bottom: none; }
.vrow-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.vrow-code { font-size: 14px; font-weight: 600; margin: 0; font-family: var(--font-mono); letter-spacing: 0.5px; }
.vrow-pills { display: flex; gap: 6px; flex-wrap: wrap; }
.vrow-meta { font-size: 12px; color: var(--text-secondary); margin: 0 0 8px; }
.vrow-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Buttons ── */
.btn {
    display: inline-block; background: linear-gradient(135deg, var(--accent-deep), #1a3dcc);
    color: #fff !important; border: none; border-radius: 8px; padding: 8px 16px;
    font-size: 13px; font-weight: 600; cursor: pointer; text-decoration: none !important;
    transition: box-shadow 0.15s;
}
.btn:hover { box-shadow: 0 4px 14px rgba(10,32,128,0.22); }

.btn-sm {
    font-size: 12px; padding: 4px 12px; border-radius: 7px;
    background: var(--surface-1); border: 1px solid var(--border); color: var(--text);
    cursor: pointer; text-decoration: none; display: inline-block;
}
.btn-sm:hover { border-color: var(--border-accent); color: var(--text-accent); }
.btn-sm.danger { color: var(--text-danger); }
.btn-sm.danger:hover { border-color: var(--border-danger); }
.btn-sm.primary { border-color: var(--border-accent); color: var(--text-accent); font-weight: 600; }

.link { color: var(--text-accent); text-decoration: none; font-size: 13px; font-weight: 600; }
.link:hover { text-decoration: underline; }

/* ── Filter bar ── */
.filters { background: var(--surface-1); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 20px; }
.filters-label { font-size: 12px; color: var(--text-secondary); margin: 0 0 10px; }
.filters-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.filters input, .filters select {
    font-size: 13px; height: 34px; padding: 0 10px;
    border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--text);
}
.filters input:focus, .filters select:focus { outline: none; border-color: var(--border-accent); }

/* ── Funnel ── */
.funnel { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 8px; background: var(--surface-1); }
.funnel-step { padding: 16px; text-align: center; border-right: 1px solid var(--border); }
.funnel-step:last-child { border-right: none; }
.funnel-label { font-size: 12px; color: var(--text-secondary); margin: 0 0 6px; }
.funnel-value { font-size: 22px; font-weight: 600; margin: 0; }
.funnel-value.mismatch { color: var(--text-danger); }
.funnel-pct { font-size: 11px; color: var(--text-muted); margin: 2px 0 0; }

/* ── Forms ── */
.form label { display: block; margin-top: 16px; font-weight: 600; font-size: 13px; }
.form input, .form select { width: 100%; padding: 10px 12px; margin-top: 6px; font-size: 14px; border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--text); }
.form input:focus, .form select:focus { outline: none; border-color: var(--border-accent); box-shadow: 0 0 0 3px rgba(0,148,255,0.15); }
.form input:disabled { background: #eef1f5; color: var(--text-muted); cursor: not-allowed; }
.form .note { color: var(--text-muted); font-size: 12px; margin-top: 4px; }
.form button { margin-top: 22px; }

/* ── Alerts ── */
.alert { padding: 12px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; }
.alert-error { background: var(--bg-danger); border: 1px solid #f3c4be; color: var(--text-danger); }
.alert-warn  { background: var(--bg-warning); border: 1px solid #f0d999; color: var(--text-warning); }
.alert-info  { background: #eaf5ff; border: 1px solid #b8dfff; color: var(--text-accent); }

/* ── Simple two-column table (revenue by package etc.) ── */
.kv-list { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface-1); }
.kv-row { display: flex; justify-content: space-between; padding: 10px 16px; border-bottom: 1px solid var(--border); font-size: 13px; }
.kv-row:last-child { border-bottom: none; }
.kv-row span:last-child { color: var(--text-secondary); }

code { background: #eef1f5; padding: 2px 6px; border-radius: 4px; font-size: 12px; font-family: var(--font-mono); }

@media (max-width: 640px) {
    /* Top bar: stack brand row above the Add Router button, full width */
    .topbar { flex-wrap: wrap; gap: 10px; padding: 10px 14px; }
    .topbar-left { flex-wrap: wrap; row-gap: 6px; }
    .topbar .btn { width: 100%; text-align: center; }

    /* Tabs: horizontal scroll instead of wrapping into a cramped 2-line mess —
       the standard mobile pattern for a tab bar that has too many items to
       fit, rather than trying to force 5 tabs into a narrow screen. */
    .tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 2px;
    }
    .tabs a { flex-shrink: 0; }

    /* Page header: breadcrumb/title and the status pill stack instead of
       fighting for the same row */
    .page-head { flex-direction: column; align-items: flex-start; gap: 8px; }

    .metrics { grid-template-columns: repeat(2, 1fr); }
    .funnel { grid-template-columns: repeat(2, 1fr); }
    .funnel-step:nth-child(2) { border-right: none; }

    .list-row { flex-direction: column; align-items: flex-start; }
    .list-row-actions { width: 100%; }

    /* Voucher rows are the densest content in the whole UI (code, several
       pills, meta text, action buttons) and had NO mobile handling at all
       before this — pills wrap naturally already, but actions need to be
       full-width, tappable targets rather than cramped inline buttons. */
    .vrow-head { flex-wrap: wrap; gap: 6px; }
    .vrow-actions { flex-direction: column; align-items: stretch; }
    .vrow-actions form { width: 100%; }
    .vrow-actions .btn-sm { width: 100%; text-align: center; padding: 10px; }

    /* Any inline "input + button" row (filters, rename, delete confirmation)
       stacks and goes full-width — relying on inline flex:1 sizing alone
       doesn't behave predictably once the container becomes a column, so
       this is explicit rather than assumed. */
    .filters-row { flex-direction: column; align-items: stretch; }
    .filters-row input, .filters-row select, .filters-row .btn, .filters-row .link {
        width: 100%;
        text-align: center;
    }

    .router-card table { font-size: 13px; }
}


/* ============================================================
   DARK THEME — opt-in via .dark on <html>. Light stays the
   default (unchanged above) so nothing looks different for
   anyone until they deliberately toggle it.
   ============================================================ */
.dark {
    --bg:              #07111f;
    --surface-1:       #101f3d;
    --surface-2:       #14243f;
    --surface-muted:   #0a1628;

    --text:            #ffffff;
    --text-secondary:  rgba(255,255,255,0.65);
    --text-muted:      rgba(255,255,255,0.50);
    --text-accent:     #36b4ff;

    --border:          rgba(255,255,255,0.12);
    --border-accent:   #0094ff;
    --border-danger:   rgba(255,110,100,0.45);

    --fill-accent:     #0094ff;
    --accent-deep:     #0a2080;

    --text-success:    #4ade80;
    --bg-success:      rgba(74,222,128,0.12);
    --text-danger:     #ff8a80;
    --bg-danger:       rgba(255,80,80,0.14);
    --text-warning:    #fbbf24;
    --bg-warning:      rgba(251,191,36,0.12);
}

.dark body { background: radial-gradient(circle at 50% -10%, #143d78 0%, transparent 45%), var(--bg); }

/* A few spots in the light styles above hardcode a color instead of using
   a variable — harmless in light mode, but they'd stay wrong-looking in
   dark mode if left alone. Corrected here rather than touched above, so
   the diff against the working light theme stays minimal and obvious. */
.dark .pill-muted   { background: rgba(255,255,255,0.08); }
.dark .pill-accent   { background: rgba(0,148,255,0.15); }
.dark .filters input, .dark .filters select,
.dark .form input, .dark .form select { background: var(--surface-muted); }
.dark .form input:disabled { background: rgba(255,255,255,0.05); }
.dark code { background: rgba(255,255,255,0.08); }
.dark .alert-error { border-color: rgba(255,110,100,0.35); }
.dark .alert-warn   { border-color: rgba(251,191,36,0.35); }
.dark .alert-info   { background: rgba(0,148,255,0.10); border-color: rgba(0,148,255,0.30); }

/* ── Theme toggle — small pill in the topbar, present on every page ── */
.theme-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
}
.theme-toggle:hover { border-color: var(--border-accent); color: var(--text-accent); }
.theme-toggle svg { width: 14px; height: 14px; }
.theme-toggle .i-moon { display: none; }
.dark .theme-toggle .i-sun  { display: none; }
.dark .theme-toggle .i-moon { display: block; }
