/* ============================================================
   Bunny Stream — admin design system
   RTL-first. Light + dark. No build step: plain CSS, tokens only.
   ============================================================ */

/* ---------- Tokens ---------- */
:root {
    /* Surfaces: warm paper, the colour of a printed worksheet */
    --paper:       #FAF9F6;
    --surface:     #FFFFFF;
    --surface-2:   #F3F1EC;
    --surface-3:   #EAE7E0;

    /* Text */
    --ink:         #16181D;
    --ink-2:       #565D6B;
    --ink-3:       #6F7683;

    /* Lines */
    --rule:        #E6E3DC;
    --rule-strong: #D5D1C8;

    /* Brand: a print red, deeper and steadier than a screen red */
    --brand:       #D8382A;
    --brand-hover: #BE2F22;
    --brand-on:    #FFFFFF;
    --brand-soft:  rgba(216, 56, 42, 0.10);
    --brand-line:  rgba(216, 56, 42, 0.28);

    /* Status */
    --ok:          #1B7F5A;
    --ok-soft:     rgba(27, 127, 90, 0.12);
    --warn:        #A8630A;
    --warn-soft:   rgba(168, 99, 10, 0.13);
    --bad:         #B3261E;
    --bad-soft:    rgba(179, 38, 30, 0.11);
    --info:        #1F5FA8;
    --info-soft:   rgba(31, 95, 168, 0.11);

    --shadow-sm:   0 1px 2px rgba(20, 22, 26, 0.06);
    --shadow:      0 2px 8px rgba(20, 22, 26, 0.07);
    --shadow-lg:   0 12px 32px rgba(20, 22, 26, 0.14);

    --r-sm: 6px;
    --r:    10px;
    --r-lg: 14px;

    --font-display: "Readex Pro", "IBM Plex Sans Arabic", system-ui, sans-serif;
    --font-body:    "IBM Plex Sans Arabic", system-ui, "Segoe UI", sans-serif;
    --font-mono:    "IBM Plex Mono", ui-monospace, "Cascadia Mono", monospace;

    --sidebar-w: 264px;
    --topbar-h: 60px;
}

:root[data-theme="dark"] {
    --paper:       #0E1014;
    --surface:     #161A21;
    --surface-2:   #1D222B;
    --surface-3:   #262C36;

    --ink:         #E8EAED;
    --ink-2:       #A2AAB8;
    --ink-3:       #737C8B;

    --rule:        #262C36;
    --rule-strong: #333B47;

    --brand:       #FF5A47;
    --brand-hover: #FF7060;
    --brand-on:    #1A0B09;
    --brand-soft:  rgba(255, 90, 71, 0.14);
    --brand-line:  rgba(255, 90, 71, 0.32);

    --ok:          #3FBF88;
    --ok-soft:     rgba(63, 191, 136, 0.14);
    --warn:        #E0A33C;
    --warn-soft:   rgba(224, 163, 60, 0.14);
    --bad:         #F2695C;
    --bad-soft:    rgba(242, 105, 92, 0.14);
    --info:        #6BA6E8;
    --info-soft:   rgba(107, 166, 232, 0.14);

    --shadow-sm:   0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow:      0 2px 10px rgba(0, 0, 0, 0.45);
    --shadow-lg:   0 16px 40px rgba(0, 0, 0, 0.55);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
    font-family: var(--font-display);
    font-weight: 600;
    line-height: 1.25;
    margin: 0;
    letter-spacing: -0.01em;
}

a { color: inherit; }

/* Numerals, sizes, durations and ids read as data, not prose */
.num, .mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

::selection { background: var(--brand-soft); }

:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
    border-radius: var(--r-sm);
}

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.app-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.app-content {
    flex: 1;
    width: 100%;
    max-width: 1360px;
    padding: 28px 32px 64px;
}

@media (max-width: 900px) {
    .app-content { padding: 20px 16px 56px; }
}

/* ---------- Page header ---------- */
.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}

.page-eyebrow {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.08em;
    color: var(--ink-3);
    margin-bottom: 6px;
}

.page-title { font-size: clamp(1.35rem, 2.2vw, 1.75rem); }

.page-sub { color: var(--ink-2); font-size: 14px; margin-top: 4px; }

.page-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Cards ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-sm);
}

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--rule);
}

.card-title { font-size: 1rem; font-weight: 600; }

.card-note { font-size: 13px; color: var(--ink-3); }

.card-body { padding: 20px; }
.card-body.flush { padding: 0; }

/* ---------- Stats ---------- */
/* Separate bordered cards rather than a seamless 1px-gap row: an incomplete
   last row in the seamless version leaves the divider colour showing as an
   empty grey block. */
.stat-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(170px, 100%), 1fr));
    gap: 12px;
}

.stat {
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-sm);
    padding: 16px 18px;
}

.stat-label {
    font-size: 12.5px;
    color: var(--ink-2);
    display: flex;
    align-items: center;
    gap: 7px;
}

.stat-value {
    font-family: var(--font-display);
    font-size: 1.7rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    margin-top: 6px;
    font-variant-numeric: tabular-nums;
}

.stat-unit { font-size: 0.8rem; color: var(--ink-3); font-weight: 500; margin-inline-start: 4px; }

.stat-foot { font-size: 12px; color: var(--ink-3); margin-top: 4px; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 16px;
    border-radius: var(--r);
    border: 1px solid var(--rule-strong);
    background: var(--surface);
    color: var(--ink);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
    transition: background .13s ease, border-color .13s ease, color .13s ease;
}

.btn:hover { background: var(--surface-2); border-color: var(--ink-3); }

.btn-primary {
    background: var(--brand);
    border-color: var(--brand);
    color: var(--brand-on);
}
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }

.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }

.btn-danger { color: var(--bad); border-color: transparent; background: transparent; }
.btn-danger:hover { background: var(--bad-soft); border-color: var(--bad-soft); }

.btn-sm { padding: 6px 11px; font-size: 13px; border-radius: var(--r-sm); }

.btn-icon { padding: 8px; width: 36px; height: 36px; }

/* ---------- Badges ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 12.5px;
    font-weight: 500;
    white-space: nowrap;
}

.badge::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    flex: none;
}

.badge-ok    { background: var(--ok-soft);   color: var(--ok); }
.badge-warn  { background: var(--warn-soft); color: var(--warn); }
.badge-bad   { background: var(--bad-soft);  color: var(--bad); }
.badge-muted { background: var(--surface-2); color: var(--ink-2); }
.badge-info  { background: var(--info-soft); color: var(--info); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }

table.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

table.table th {
    text-align: start;
    font-weight: 600;
    font-size: 12.5px;
    color: var(--ink-2);
    padding: 11px 20px;
    border-bottom: 1px solid var(--rule);
    background: var(--surface-2);
    white-space: nowrap;
}

table.table td {
    padding: 13px 20px;
    border-bottom: 1px solid var(--rule);
    vertical-align: middle;
}

table.table tbody tr:last-child td { border-bottom: 0; }
table.table tbody tr { transition: background .12s ease; }
table.table tbody tr:hover { background: var(--surface-2); }

.cell-title { font-weight: 500; }
.cell-muted { color: var(--ink-2); }

.truncate {
    display: block;
    max-width: 340px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---------- Forms ---------- */
.input, .select, textarea.input {
    width: 100%;
    padding: 9px 12px;
    border-radius: var(--r);
    border: 1px solid var(--rule-strong);
    background: var(--surface);
    color: var(--ink);
    font-family: inherit;
    font-size: 14px;
    transition: border-color .13s ease, box-shadow .13s ease;
}

.input::placeholder { color: var(--ink-3); }

.input:focus, .select:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-soft);
}

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; color: var(--ink-2); }
.field .hint { font-size: 12.5px; color: var(--ink-3); margin-top: 5px; }

.search { position: relative; display: flex; align-items: center; }
.search i {
    position: absolute;
    inset-inline-start: 12px;
    color: var(--ink-3);
    font-size: 13px;
    pointer-events: none;
}
.search .input { padding-inline-start: 34px; }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: 56px 24px; }
.empty-icon { font-size: 30px; color: var(--ink-3); margin-bottom: 12px; }
.empty-title { font-family: var(--font-display); font-size: 1.05rem; font-weight: 600; }
.empty-text { color: var(--ink-2); font-size: 14px; margin: 6px auto 18px; max-width: 42ch; }

/* ---------- Flash messages ---------- */
.success, .flash {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 11px 16px;
    border-radius: var(--r);
    background: var(--ok-soft);
    color: var(--ok);
    border: 1px solid transparent;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 18px;
}
.flash-bad { background: var(--bad-soft); color: var(--bad); }

/* ---------- Meter ---------- */
.meter {
    height: 6px;
    border-radius: 999px;
    background: var(--surface-3);
    overflow: hidden;
}
.meter > span {
    display: block;
    height: 100%;
    border-radius: 999px;
    background: var(--brand);
    transition: width .5s ease;
}
.meter.is-warn > span { background: var(--warn); }
.meter.is-bad  > span { background: var(--bad); }

/* ---------- Utility ---------- */
/* minmax(0,1fr): without it the single column sizes to its widest child's
   min-content, so the library strip drags the whole page wider than the screen
   instead of scrolling inside its own box. */
.stack   { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; }
.row     { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.muted   { color: var(--ink-2); }
.dim     { color: var(--ink-3); }
.small   { font-size: 13px; }
.grow    { flex: 1; min-width: 0; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); gap: 20px; }

/* Grid and flex children default to min-width:auto, which lets wide content
   (the library strip, a table) push the whole page sideways instead of
   scrolling inside its own box. */
.stack > *, .grid-2 > *, .card, .card-body, .table-wrap { min-width: 0; }

/* ---------- Motion ---------- */
@keyframes rise {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: none; }
}
.rise { animation: rise .28s ease both; }
.rise-2 { animation-delay: .05s; }
.rise-3 { animation-delay: .1s; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .001ms !important;
        transition-duration: .001ms !important;
    }
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--rule-strong); border-radius: 999px; border: 3px solid var(--paper); }
::-webkit-scrollbar-thumb:hover { background: var(--ink-3); }

/* ============================================================
   Shared page patterns
   Class names kept as the existing pages already use them, so markup
   does not need to change - only the styling moves onto the tokens.
   ============================================================ */

/* ---------- Page container & header ---------- */
.container,
.analytics-container,
.reports-container,
.report-detail-container,
.form-container { max-width: 100%; margin: 0; padding: 0; }

.header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}
.header h1, .header h2 {
    font-family: var(--font-display);
    font-size: clamp(1.35rem, 2.2vw, 1.75rem);
    font-weight: 600;
    letter-spacing: -0.01em;
    margin: 0;
}
.header p, .header .note { color: var(--ink-2); font-size: 14px; margin: 4px 0 0; }
.header-actions, .header-top { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ---------- Secondary button (pages define .btn as primary) ---------- */
.btn-secondary {
    background: var(--surface);
    color: var(--ink);
    border-color: var(--rule-strong);
}
.btn-secondary:hover { background: var(--surface-2); border-color: var(--ink-3); }

.btn-group { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Forms ---------- */
.form-card, .settings-card {
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-sm);
    padding: 24px;
    margin-bottom: 20px;
}

.form-group { margin-bottom: 18px; }

.form-label, .form-group > label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--ink-2);
    margin-bottom: 6px;
}

.form-control {
    width: 100%;
    padding: 9px 12px;
    border-radius: var(--r);
    border: 1px solid var(--rule-strong);
    background: var(--surface);
    color: var(--ink);
    font-family: inherit;
    font-size: 14px;
    transition: border-color .13s ease, box-shadow .13s ease;
}
.form-control::placeholder { color: var(--ink-3); }
.form-control:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-soft);
}
textarea.form-control { min-height: 96px; resize: vertical; line-height: 1.6; }
select.form-control { cursor: pointer; }

.form-help { font-size: 12.5px; color: var(--ink-3); margin-top: 5px; }

.form-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    padding-top: 18px;
    border-top: 1px solid var(--rule);
    margin-top: 22px;
}

.error, .error-message {
    color: var(--bad);
    font-size: 12.5px;
    margin-top: 5px;
}

.input-group { margin-bottom: 18px; }
.input-with-suffix { position: relative; display: flex; align-items: center; }
.input-with-suffix .form-control { padding-inline-end: 62px; }
.input-suffix {
    position: absolute;
    inset-inline-end: 12px;
    font-size: 12.5px;
    color: var(--ink-3);
    pointer-events: none;
}

/* ---------- Sections ---------- */
.settings-section { margin-bottom: 26px; }

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}
.section-title {
    font-family: var(--font-display);
    font-size: 1.05rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 9px;
}
.section-title .icon, .section-title i { color: var(--ink-3); font-size: 15px; }
.section-description { color: var(--ink-2); font-size: 13.5px; margin: 4px 0 0; }

/* ---------- Alerts & info boxes ---------- */
.alert {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 16px;
    border-radius: var(--r);
    font-size: 14px;
    margin-bottom: 18px;
}
.alert-icon { flex: none; margin-top: 2px; }
.alert-success { background: var(--ok-soft); color: var(--ok); }
.alert-error   { background: var(--bad-soft); color: var(--bad); }

.info-box {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
    border: 1px solid var(--rule);
    border-radius: var(--r);
    background: var(--surface-2);
    margin-bottom: 18px;
}
.info-box-icon {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    background: var(--info-soft);
    color: var(--info);
    flex: none;
}
.info-box-content { flex: 1; min-width: 0; }
.info-box-title { font-weight: 600; font-size: 14px; margin-bottom: 3px; }
.info-box-text { color: var(--ink-2); font-size: 13px; line-height: 1.65; }

/* ---------- Toggle switch ---------- */
.toggle-container {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 13px 15px;
    border: 1px solid var(--rule);
    border-radius: var(--r);
    background: var(--surface);
    margin-bottom: 10px;
    transition: border-color .13s ease, background .13s ease;
}
.toggle-container:hover { border-color: var(--rule-strong); background: var(--surface-2); }

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 42px;
    height: 24px;
    flex: none;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--surface-3);
    border-radius: 999px;
    transition: background .18s ease;
}
.toggle-slider:before {
    content: "";
    position: absolute;
    width: 18px;
    height: 18px;
    right: 3px;
    top: 3px;
    background: var(--surface);
    border-radius: 50%;
    box-shadow: var(--shadow-sm);
    transition: transform .18s ease;
}
input:checked + .toggle-slider { background: var(--brand); }
input:checked + .toggle-slider:before { transform: translateX(-18px); }
.toggle-switch input:focus-visible + .toggle-slider { outline: 2px solid var(--brand); outline-offset: 2px; }

.toggle-label { flex: 1; min-width: 0; }
.toggle-title { font-size: 14px; font-weight: 500; }
.toggle-description { font-size: 12.5px; color: var(--ink-3); margin-top: 2px; }

/* ---------- Stat / summary cards ---------- */
.stats-grid, .summary-cards, .main-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(190px, 100%), 1fr));
    gap: 12px;
    margin-bottom: 24px;
}
.stats-grid > .stat-card,
.summary-cards > .summary-card,
.main-stats > .stat-card {
    background: var(--surface);
    padding: 16px 18px;
    border: 1px solid var(--rule);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-sm);
}
.stat-icon, .summary-icon { font-size: 14px; color: var(--ink-3); margin-inline-end: 6px; }
.summary-label { font-size: 12.5px; color: var(--ink-2); }
.summary-value, .stat-card .value {
    font-family: var(--font-display);
    font-size: 1.7rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    margin-top: 6px;
    font-variant-numeric: tabular-nums;
}
.stat-change { font-size: 12px; color: var(--ok); margin-top: 4px; }
.stat-change.negative { color: var(--bad); }

/* ---------- Data tables ---------- */
.data-table, .reports-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: var(--r-lg);
    overflow: hidden;
}
.data-table th, .reports-table th, .table-header {
    text-align: start;
    font-weight: 600;
    font-size: 12.5px;
    color: var(--ink-2);
    padding: 11px 16px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--rule);
    white-space: nowrap;
}
.data-table td, .reports-table td {
    padding: 13px 16px;
    border-bottom: 1px solid var(--rule);
    vertical-align: middle;
}
.data-table tbody tr:last-child td,
.reports-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover,
.reports-table tbody tr:hover { background: var(--surface-2); }

.actions { display: flex; gap: 4px; }
.btn-view, .btn-edit, .btn-delete, .btn-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border: 0;
    border-radius: var(--r-sm);
    background: transparent;
    color: var(--ink-2);
    font-family: inherit;
    font-size: 12.5px;
    text-decoration: none;
    cursor: pointer;
    transition: background .12s ease, color .12s ease;
}
.btn-view:hover, .btn-back:hover { background: var(--surface-2); color: var(--ink); }
.btn-edit:hover { background: var(--info-soft); color: var(--info); }
.btn-delete:hover { background: var(--bad-soft); color: var(--bad); }

/* ---------- Status badges ---------- */
.status-badge, .badge-cost, .chart-badge, .info-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 12.5px;
    font-weight: 500;
    background: var(--surface-2);
    color: var(--ink-2);
    white-space: nowrap;
}
.badge-cost { font-family: var(--font-mono); }

/* ---------- Empty state ---------- */
.empty-state {
    text-align: center;
    padding: 56px 24px;
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: var(--r-lg);
    color: var(--ink-2);
}
.empty-state i { font-size: 30px; color: var(--ink-3); margin-bottom: 12px; display: block; }
.empty-state h3 { font-size: 1.05rem; margin-bottom: 6px; }
.empty-state p { font-size: 14px; margin: 0 auto 18px; max-width: 42ch; }

/* ---------- Pagination ---------- */
.pagination {
    display: flex;
    gap: 6px;
    justify-content: center;
    margin-top: 22px;
    flex-wrap: wrap;
}
.pagination a, .pagination span {
    padding: 7px 12px;
    border: 1px solid var(--rule);
    border-radius: var(--r-sm);
    background: var(--surface);
    color: var(--ink-2);
    text-decoration: none;
    font-size: 13.5px;
}
.pagination a:hover { background: var(--surface-2); color: var(--ink); }
.pagination .active span,
.pagination span.active { background: var(--brand); border-color: var(--brand); color: var(--brand-on); }

/* ---------- Loading ---------- */
.loading-spinner, .spinner {
    width: 22px;
    height: 22px;
    border: 2px solid var(--rule-strong);
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: spin .7s linear infinite;
    margin: 24px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
