/* ==========================================================================
   Licensing Core — admin theme
   RTL-first. All colour lives in tokens so branding can be swapped from the
   settings page (--brand is injected inline by the layout).
   ========================================================================== */

:root {
    --brand: #4f46e5;
    --brand-soft: color-mix(in srgb, var(--brand) 12%, white);
    --brand-strong: color-mix(in srgb, var(--brand) 82%, black);

    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --sidebar-bg: #0f172a;
    --sidebar-fg: #cbd5e1;
    --sidebar-fg-active: #ffffff;
    --sidebar-hover: rgba(255, 255, 255, .07);

    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;

    --ok: #059669;
    --ok-soft: #d1fae5;
    --warn: #d97706;
    --warn-soft: #fef3c7;
    --danger: #dc2626;
    --danger-soft: #fee2e2;
    --info: #0284c7;
    --info-soft: #e0f2fe;
    --neutral: #475569;
    --neutral-soft: #e2e8f0;

    --radius: 12px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
    --shadow: 0 4px 16px rgba(15, 23, 42, .07);
    --shadow-lg: 0 12px 32px rgba(15, 23, 42, .12);

    --sidebar-w: 264px;
    --header-h: 64px;

    --font: "Cairo", "Segoe UI", Tahoma, "Noto Sans Arabic", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0; font-weight: 700; line-height: 1.3; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }

/* ── App shell ────────────────────────────────────────────────────────── */

.app {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    grid-template-rows: auto 1fr auto;
    grid-template-areas:
        "sidebar header"
        "sidebar main"
        "sidebar footer";
    min-height: 100vh;
}

/* ── Sidebar ──────────────────────────────────────────────────────────── */

.sidebar {
    grid-area: sidebar;
    background: var(--sidebar-bg);
    color: var(--sidebar-fg);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 30;
}

.sidebar__brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
    min-height: var(--header-h);
}

.sidebar__logo {
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    border-radius: 11px;
    background: linear-gradient(135deg, var(--brand), color-mix(in srgb, var(--brand) 55%, #22d3ee));
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 800;
    font-size: 15px;
    letter-spacing: .5px;
    box-shadow: 0 4px 14px color-mix(in srgb, var(--brand) 45%, transparent);
}

.sidebar__title { font-size: 15px; font-weight: 700; color: #fff; }
.sidebar__tagline { font-size: 11px; color: #64748b; }

.sidebar__nav { padding: 14px 12px; flex: 1; }

.sidebar__group-label {
    font-size: 11px;
    font-weight: 700;
    color: #475569;
    letter-spacing: .6px;
    padding: 14px 12px 6px;
    text-transform: uppercase;
}

.sidebar__link {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--sidebar-fg);
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 2px;
    transition: background .15s, color .15s;
}

.sidebar__link:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }

.sidebar__link--active {
    background: var(--brand);
    color: var(--sidebar-fg-active);
    font-weight: 600;
    box-shadow: 0 4px 12px color-mix(in srgb, var(--brand) 40%, transparent);
}
.sidebar__link--active:hover { background: var(--brand); }

.sidebar__icon { width: 18px; height: 18px; flex: 0 0 18px; stroke-width: 1.9; }

.sidebar__badge {
    margin-inline-start: auto;
    background: rgba(255, 255, 255, .12);
    color: #e2e8f0;
    border-radius: 999px;
    padding: 1px 8px;
    font-size: 11px;
    font-weight: 700;
}
.sidebar__link--active .sidebar__badge { background: rgba(255, 255, 255, .25); color: #fff; }

.sidebar__foot {
    padding: 14px 20px;
    border-top: 1px solid rgba(255, 255, 255, .08);
    font-size: 11px;
    color: #475569;
}

/* ── Header ───────────────────────────────────────────────────────────── */

.header {
    grid-area: header;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    height: var(--header-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 20;
}

.header__left { display: flex; align-items: center; gap: 14px; min-width: 0; }
.header__page-title { font-size: 16px; font-weight: 700; }
.header__breadcrumb { font-size: 12px; color: var(--text-muted); }

.header__right { display: flex; align-items: center; gap: 10px; }

.header__user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 5px 12px 5px 5px;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--border);
}

.avatar {
    width: 32px; height: 32px; flex: 0 0 32px;
    border-radius: 50%;
    background: var(--brand);
    color: #fff;
    display: grid; place-items: center;
    font-weight: 700; font-size: 13px;
}

.header__user-name { font-size: 13px; font-weight: 600; }
.header__user-role { font-size: 11px; color: var(--text-muted); }

.sidebar-toggle {
    display: none;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--radius-sm);
    padding: 7px 9px;
    cursor: pointer;
}

/* ── Main + footer ────────────────────────────────────────────────────── */

.main { grid-area: main; padding: 24px; min-width: 0; }

.footer {
    grid-area: footer;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    font-size: 12px;
    color: var(--text-muted);
}
.footer__links { display: flex; gap: 16px; flex-wrap: wrap; }

/* ── Page head ────────────────────────────────────────────────────────── */

.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}
.page-head__text { min-width: 0; }
.page-head__title { font-size: 22px; font-weight: 800; }
.page-head__subtitle { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.page-head__actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Cards ────────────────────────────────────────────────────────────── */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    margin-bottom: 18px;
    overflow: hidden;
}
.card__head {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.card__body { padding: 20px; }
.card__body--flush { padding: 0; }

/* ── Stat cards ───────────────────────────────────────────────────────── */

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: flex-start;
    gap: 14px;
    transition: transform .15s, box-shadow .15s;
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow); }

.stat__icon {
    width: 42px; height: 42px; flex: 0 0 42px;
    border-radius: 11px;
    display: grid; place-items: center;
}
.stat__icon svg { width: 21px; height: 21px; stroke-width: 1.9; }

.stat__label { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.stat__value { font-size: 25px; font-weight: 800; line-height: 1.2; letter-spacing: -.5px; }
.stat__meta { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.stat--brand  .stat__icon { background: var(--brand-soft);  color: var(--brand); }
.stat--ok     .stat__icon { background: var(--ok-soft);     color: var(--ok); }
.stat--warn   .stat__icon { background: var(--warn-soft);   color: var(--warn); }
.stat--danger .stat__icon { background: var(--danger-soft); color: var(--danger); }
.stat--info   .stat__icon { background: var(--info-soft);   color: var(--info); }
.stat--neutral .stat__icon { background: var(--neutral-soft); color: var(--neutral); }

.stat--feature {
    background: linear-gradient(135deg, var(--brand), var(--brand-strong));
    border-color: transparent;
    color: #fff;
}
.stat--feature .stat__label,
.stat--feature .stat__meta { color: rgba(255, 255, 255, .82); }
.stat--feature .stat__icon { background: rgba(255, 255, 255, .18); color: #fff; }

/* ── Filters ──────────────────────────────────────────────────────────── */

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.filters__field { display: flex; flex-direction: column; gap: 4px; min-width: 155px; flex: 1 1 155px; }
.filters__field--wide { flex: 2 1 240px; }
.filters__label { font-size: 11px; font-weight: 700; color: var(--text-muted); }
.filters__actions { display: flex; gap: 8px; align-items: flex-end; }

.active-filters { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; align-items: center; }
.chip {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--brand-soft); color: var(--brand-strong);
    border: 1px solid color-mix(in srgb, var(--brand) 25%, transparent);
    border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 600;
}
.chip a { color: inherit; opacity: .65; font-weight: 700; }
.chip a:hover { opacity: 1; text-decoration: none; }

/* ── Forms ────────────────────────────────────────────────────────────── */

input, select, textarea {
    width: 100%;
    font-family: inherit;
    font-size: 13.5px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 8px 11px;
    transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent);
}
input[type="color"] { padding: 3px; height: 38px; cursor: pointer; }
textarea { min-height: 90px; resize: vertical; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field__label { font-size: 12.5px; font-weight: 600; }
.field__hint { font-size: 11px; color: var(--text-muted); }
.field--full { grid-column: 1 / -1; }

.checkbox { display: flex; align-items: center; gap: 8px; }
.checkbox input { width: auto; margin: 0; }

.form-actions {
    display: flex; gap: 10px; flex-wrap: wrap;
    padding-top: 18px; margin-top: 18px;
    border-top: 1px solid var(--border);
}

/* ── Buttons ──────────────────────────────────────────────────────────── */

.btn {
    display: inline-flex; align-items: center; gap: 7px;
    font-family: inherit; font-size: 13px; font-weight: 600;
    background: var(--brand); color: #fff;
    border: 1px solid transparent; border-radius: var(--radius-sm);
    padding: 8px 14px; cursor: pointer; white-space: nowrap;
    transition: filter .15s, box-shadow .15s;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; color: #fff; }
.btn:active { filter: brightness(.95); }
.btn svg { width: 16px; height: 16px; stroke-width: 2; }

.btn--secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn--secondary:hover { background: var(--surface-2); color: var(--text); }
.btn--danger { background: var(--danger); }
.btn--ghost { background: transparent; color: var(--text-muted); border-color: transparent; }
.btn--ghost:hover { background: var(--surface-2); color: var(--text); }
.btn--sm { padding: 5px 10px; font-size: 12px; }
.btn--block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; filter: none; }

.btn-group { display: inline-flex; gap: 6px; }

/* ── Tables ───────────────────────────────────────────────────────────── */

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }

thead th {
    background: var(--surface-2);
    text-align: start;
    font-size: 11.5px;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: .3px;
    padding: 11px 14px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
thead th a { color: inherit; display: inline-flex; align-items: center; gap: 4px; }

tbody td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.is-selected { background: var(--brand-soft); }

.cell-strong { font-weight: 600; }
.cell-muted { color: var(--text-muted); font-size: 12.5px; }
.cell-mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12px; }
.cell-actions { display: flex; gap: 6px; justify-content: flex-end; }
.col-check { width: 42px; }
.col-check input { width: auto; margin: 0; cursor: pointer; }

/* ── Badges ───────────────────────────────────────────────────────────── */

.badge {
    display: inline-flex; align-items: center; gap: 5px;
    border-radius: 999px; padding: 2px 10px;
    font-size: 11.5px; font-weight: 700; white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge--ok { background: var(--ok-soft); color: #047857; }
.badge--warn { background: var(--warn-soft); color: #b45309; }
.badge--danger { background: var(--danger-soft); color: #b91c1c; }
.badge--info { background: var(--info-soft); color: #0369a1; }
.badge--neutral { background: var(--neutral-soft); color: var(--neutral); }

/* ── Bulk action bar ──────────────────────────────────────────────────── */

.bulk-bar {
    display: none;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 12px 20px;
    background: var(--brand-soft);
    border-bottom: 1px solid color-mix(in srgb, var(--brand) 22%, transparent);
}
.bulk-bar.is-visible { display: flex; }
.bulk-bar__count { font-weight: 700; font-size: 13px; color: var(--brand-strong); }
.bulk-bar__spacer { flex: 1; }
.bulk-bar select { width: auto; min-width: 190px; }

/* ── Alerts ───────────────────────────────────────────────────────────── */

.alert {
    padding: 13px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 13.5px;
    border: 1px solid transparent;
    display: flex; gap: 10px; align-items: flex-start;
}
.alert--success { background: var(--ok-soft); color: #065f46; border-color: #6ee7b7; }
.alert--error { background: var(--danger-soft); color: #991b1b; border-color: #fca5a5; }
.alert--info { background: var(--info-soft); color: #075985; border-color: #7dd3fc; }
.alert--warn { background: var(--warn-soft); color: #92400e; border-color: #fcd34d; }
.alert ul { margin: 6px 0 0; padding-inline-start: 18px; }
.alert svg { width: 18px; height: 18px; flex: 0 0 18px; margin-top: 2px; }

/* ── Empty state ──────────────────────────────────────────────────────── */

.empty { padding: 48px 24px; text-align: center; color: var(--text-muted); }
.empty__icon {
    width: 56px; height: 56px; margin: 0 auto 14px;
    border-radius: 50%; background: var(--surface-2);
    display: grid; place-items: center; color: var(--border-strong);
}
.empty__icon svg { width: 26px; height: 26px; }
.empty__title { font-size: 15px; font-weight: 700; color: var(--text); margin-bottom: 4px; }

/* ── Pagination ───────────────────────────────────────────────────────── */

.pagination-wrap { padding: 14px 20px; border-top: 1px solid var(--border); }
.pagination-wrap nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.pagination-wrap svg { width: 16px; height: 16px; }
.pagination-wrap .hidden { display: none; }
.pagination-wrap span[aria-current="page"] span,
.pagination-wrap a {
    display: inline-grid; place-items: center;
    min-width: 32px; height: 32px; padding: 0 8px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    font-size: 13px; color: var(--text); background: var(--surface);
}
.pagination-wrap a:hover { background: var(--surface-2); text-decoration: none; }
.pagination-wrap span[aria-current="page"] span { background: var(--brand); color: #fff; border-color: var(--brand); font-weight: 700; }
.pagination-wrap p { color: var(--text-muted); font-size: 12.5px; margin: 0; }

/* ── Tabs ─────────────────────────────────────────────────────────────── */

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); padding: 0 20px; flex-wrap: wrap; }
.tab {
    padding: 11px 15px; font-size: 13.5px; font-weight: 600;
    color: var(--text-muted); border-bottom: 2px solid transparent;
    margin-bottom: -1px; cursor: pointer; background: none; border-top: 0; border-inline: 0;
    font-family: inherit; width: auto;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.is-active { color: var(--brand); border-bottom-color: var(--brand); }

/* ── Misc ─────────────────────────────────────────────────────────────── */

.muted { color: var(--text-muted); font-size: 12.5px; }
.stack { display: flex; flex-direction: column; gap: 2px; }
.row-inline { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.divider { height: 1px; background: var(--border); margin: 18px 0; }

.key-value { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; font-size: 13px; }
.key-value dt { color: var(--text-muted); font-weight: 600; }
.key-value dd { margin: 0; }

.copy-field { display: flex; gap: 8px; align-items: center; }
.copy-field input { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }

/* ── Responsive ───────────────────────────────────────────────────────── */

@media (max-width: 1024px) {
    .app { grid-template-columns: 1fr; grid-template-areas: "header" "main" "footer"; }

    .sidebar {
        position: fixed;
        inset-inline-start: 0;
        top: 0;
        width: var(--sidebar-w);
        transform: translateX(100%);
        transition: transform .22s ease;
        box-shadow: var(--shadow-lg);
    }
    html[dir="ltr"] .sidebar { transform: translateX(-100%); }
    .sidebar.is-open { transform: translateX(0); }

    .sidebar-toggle { display: inline-flex; }

    .scrim {
        position: fixed; inset: 0;
        background: rgba(15, 23, 42, .45);
        z-index: 25;
        display: none;
    }
    .scrim.is-open { display: block; }
}

@media (max-width: 640px) {
    .main { padding: 16px; }
    .header { padding: 0 14px; }
    .header__user-name, .header__user-role, .header__breadcrumb { display: none; }
    .header__user { padding: 4px; }
    .stats { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
    .stat { padding: 13px; gap: 10px; }
    .stat__value { font-size: 20px; }
    .stat__icon { width: 34px; height: 34px; flex-basis: 34px; }
    .page-head__title { font-size: 18px; }
    .footer { flex-direction: column; align-items: flex-start; }
}

@media print {
    .sidebar, .header, .footer, .filters, .bulk-bar, .cell-actions, .col-check { display: none !important; }
    .app { grid-template-columns: 1fr; grid-template-areas: "main"; }
    .card { box-shadow: none; border-color: #cbd5e1; }
}

/* ══════════════════════════════════════════════════════════════════════════
   Guided tour
   Shown the first time an admin opens a section. The scrim dims the page, the
   spotlight is a transparent box with an enormous shadow that darkens everything
   around it, and the bubble is positioned by tour.js.
   ══════════════════════════════════════════════════════════════════════════ */

body.tour-open {
    overflow: hidden;
}

.tour {
    position: fixed;
    inset: 0;
    z-index: 1200;
}

.tour__scrim {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, .55);
    backdrop-filter: blur(1.5px);
}

.tour__spot {
    position: fixed;
    border-radius: 12px;
    /* The cut-out: nothing is drawn inside the box, and the shadow paints the dark
       everywhere else, so the element underneath stays fully readable. */
    box-shadow: 0 0 0 9999px rgba(15, 23, 42, .55), 0 0 0 2px var(--brand, #4f46e5);
    transition: top .25s ease, left .25s ease, width .25s ease, height .25s ease;
    pointer-events: none;
}

/* While a step has a target the spotlight paints the dark by itself, so the scrim only
   shows for the centred cards that have nothing to point at. */
.tour__scrim { opacity: 0; }
.tour--centered .tour__scrim { opacity: 1; }

.tour__bubble {
    position: fixed;
    width: min(380px, calc(100vw - 24px));
    background: #fff;
    border-radius: 16px;
    padding: 18px;
    box-shadow: 0 24px 60px rgba(15, 23, 42, .3);
    transition: top .25s ease, left .25s ease;
}

.tour__bubble.is-centered {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(460px, calc(100vw - 24px));
}

.tour__head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.tour__badge {
    font-size: 12px;
    font-weight: 700;
    color: var(--brand, #4f46e5);
    background: var(--brand-soft, #eef2ff);
    border-radius: 999px;
    padding: 3px 10px;
}

.tour__close {
    margin-inline-start: auto;
    border: 0;
    background: transparent;
    color: var(--muted, #6b7280);
    font-size: 14px;
    cursor: pointer;
    line-height: 1;
    padding: 4px;
}

.tour__title {
    margin: 0 0 6px;
    font-size: 16px;
    font-weight: 800;
}

.tour__body {
    margin: 0;
    color: var(--muted, #6b7280);
    font-size: 13.5px;
    line-height: 1.9;
}

.tour__dots {
    display: flex;
    gap: 5px;
    margin: 14px 0 0;
}

.tour__dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--line, #e6e8ef);
}

.tour__dot.is-active {
    width: 18px;
    border-radius: 999px;
    background: var(--brand, #4f46e5);
}

.tour__actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--line, #e6e8ef);
}

.tour__spacer {
    flex: 1;
}

.tour__actions .btn:disabled {
    opacity: .45;
    cursor: default;
}

/* The restart link in Settings. */
.tour-restart {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

/* ══════════════════════════════════════════════════════════════════════════
   Confirm dialog
   Replaces window.confirm, which a browser can suppress silently — leaving a
   destructive button looking like it does nothing at all.
   ══════════════════════════════════════════════════════════════════════════ */

.confirm {
    position: fixed;
    inset: 0;
    z-index: 1300;
    display: grid;
    place-items: center;
}

/* An author display rule beats the browser's [hidden] { display: none }, so say it here
   or the dialog shows itself on every page load. */
.confirm[hidden],
.tour[hidden] {
    display: none !important;
}

.confirm__scrim {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, .5);
}

.confirm__box {
    position: relative;
    width: min(420px, calc(100vw - 32px));
    background: #fff;
    border-radius: 18px;
    padding: 24px;
    text-align: center;
    box-shadow: 0 24px 60px rgba(15, 23, 42, .32);
}

.confirm__icon {
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    margin: 0 auto 14px;
    border-radius: 50%;
    background: #fef3c7;
    color: #b45309;
}

.confirm__icon svg {
    width: 22px;
    height: 22px;
}

.confirm__title {
    margin: 0 0 8px;
    font-size: 17px;
    font-weight: 800;
}

.confirm__text {
    margin: 0;
    color: var(--muted, #6b7280);
    font-size: 13.5px;
    line-height: 1.9;
}

.confirm__actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 20px;
}

.confirm__actions .btn {
    min-width: 120px;
    justify-content: center;
}

/* ── Licence billing choice ── */
.billing-choice {
    margin: 18px 0;
}

.choice-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 10px;
}

.choice {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 14px;
    border: 1px solid var(--line, #e6e8ef);
    border-radius: 12px;
    cursor: pointer;
    background: #fff;
    transition: border-color .15s, box-shadow .15s;
}

.choice:hover {
    border-color: var(--brand, #4f46e5);
}

.choice:has(input:checked) {
    border-color: var(--brand, #4f46e5);
    box-shadow: 0 0 0 3px var(--brand-soft, #eef2ff);
}

/* The panel sizes form inputs to 100% by default, which here would eat the whole card and
   squeeze the label text down to one character per line. */
.choice input[type="radio"] {
    width: auto;
    min-width: 0;
    margin-top: 4px;
    flex: none;
}

.choice > span {
    flex: 1;
    min-width: 0;
}

.choice strong {
    display: block;
    font-size: 14px;
}

.choice small {
    display: block;
    margin-top: 4px;
    color: var(--muted, #6b7280);
    font-size: 12.5px;
    line-height: 1.75;
}

.billing-method {
    display: block;
    margin-top: 16px;
    max-width: 340px;
}

/* ── Type-to-filter dropdowns and date shortcuts on the licence form ── */
.combo-search {
    margin-bottom: 6px;
    font-size: 13px;
}

.quick-dates {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.chip {
    border: 1px solid var(--line, #e6e8ef);
    background: #fff;
    border-radius: 999px;
    padding: 4px 12px;
    font: inherit;
    font-size: 12.5px;
    color: var(--muted, #6b7280);
    cursor: pointer;
    transition: border-color .15s, color .15s;
}

.chip:hover {
    border-color: var(--brand, #4f46e5);
    color: var(--brand, #4f46e5);
}

/* ══════════════════════════════════════════════════════════════════════════
   Form kit
   Every add/edit screen is built from these: named sections, a responsive
   field grid, and an action bar that stays reachable on a long form.
   ══════════════════════════════════════════════════════════════════════════ */

.fsec {
    background: #fff;
    border: 1px solid var(--line, #e6e8ef);
    border-radius: 16px;
    margin-bottom: 16px;
    overflow: hidden;
}

.fsec__head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--line, #e6e8ef);
    background: linear-gradient(180deg, #fbfbfd, #fff);
}

.fsec__icon {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--brand-soft, #eef2ff);
    color: var(--brand, #4f46e5);
    flex: none;
}

.fsec__icon svg {
    width: 18px;
    height: 18px;
}

.fsec__title {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
}

.fsec__subtitle {
    color: var(--muted, #6b7280);
    font-size: 12.5px;
    line-height: 1.7;
}

.fsec__body {
    padding: 20px;
}

/* ── Field grid ── */
.fgrid {
    display: grid;
    gap: 16px;
}

.fgrid--1 { grid-template-columns: 1fr; }
.fgrid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.fgrid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.field--span2 { grid-column: span 2; }
.field--span3 { grid-column: span 3; }

@media (max-width: 900px) {
    .fgrid--2, .fgrid--3 { grid-template-columns: 1fr; }
    .field--span2, .field--span3 { grid-column: span 1; }
}

/* ── Fields ── */
.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.field__label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text, #111827);
}

.field__req {
    color: #ef4444;
    margin-inline-start: 2px;
}

.field__control {
    position: relative;
    display: flex;
    align-items: stretch;
}

.field__control input {
    flex: 1;
    min-width: 0;
}

.field__prefix {
    display: grid;
    place-items: center;
    padding: 0 12px;
    background: #f9fafb;
    border: 1px solid var(--line, #e6e8ef);
    border-inline-end: 0;
    border-start-start-radius: 10px;
    border-end-start-radius: 10px;
    color: var(--muted, #6b7280);
    font-size: 13px;
    white-space: nowrap;
}

.field__control.has-prefix input {
    border-start-start-radius: 0;
    border-end-start-radius: 0;
}

.field__error {
    font-size: 12.5px;
    color: #dc2626;
}

.field--invalid input,
.field--invalid select,
.field--invalid textarea {
    border-color: #fca5a5;
    background: #fef2f2;
}

/* ── Toggle switch ── */
.switch {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    padding: 6px 0;
}

.switch input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.switch__track {
    position: relative;
    width: 42px;
    height: 24px;
    border-radius: 999px;
    background: var(--line, #e6e8ef);
    transition: background .18s;
    flex: none;
}

.switch__thumb {
    position: absolute;
    top: 3px;
    inset-inline-start: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
    transition: transform .18s;
}

.switch input:checked + .switch__track {
    background: var(--brand, #4f46e5);
}

/* RTL: "on" moves the thumb the other way. */
.switch input:checked + .switch__track .switch__thumb {
    transform: translateX(-18px);
}

[dir="ltr"] .switch input:checked + .switch__track .switch__thumb {
    transform: translateX(18px);
}

.switch input:focus-visible + .switch__track {
    box-shadow: 0 0 0 3px var(--brand-soft, #eef2ff);
}

.switch__text {
    font-size: 13px;
    color: var(--muted, #6b7280);
}

/* ── Date field ── */
.date-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.date-field__label {
    font-size: 13px;
    font-weight: 600;
}

.date-field__chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.date-field__read {
    font-size: 12.5px;
    color: var(--muted, #6b7280);
    min-height: 18px;
}

.date-field__read.is-set {
    color: var(--brand, #4f46e5);
    font-weight: 600;
}

.chip--clear {
    color: #b91c1c;
}

.chip--clear:hover {
    border-color: #fca5a5;
    color: #b91c1c;
}

/* ── Sticky action bar ── */
.form-actions {
    position: sticky;
    bottom: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 20px;
    padding: 14px 20px;
    background: rgba(255, 255, 255, .92);
    backdrop-filter: blur(8px);
    border: 1px solid var(--line, #e6e8ef);
    border-radius: 14px;
    box-shadow: 0 -6px 24px rgba(17, 24, 39, .06);
}

.form-actions__spacer {
    flex: 1;
}

/* ── Live total on the subscription form ── */
.total-preview {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 14px 16px;
    border-radius: 12px;
    background: var(--brand-soft, #eef2ff);
    border: 1px solid #c7d2fe;
}

.total-preview__label {
    font-size: 12.5px;
    color: var(--muted, #6b7280);
}

.total-preview__value {
    font-size: 20px;
    font-weight: 800;
    color: var(--brand, #4f46e5);
}

.total-preview__breakdown {
    font-size: 12px;
    color: var(--muted, #6b7280);
}

/* Several toggles side by side, as on the product requirements block. */
.switch-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 4px 16px;
}

.switch-grid .field {
    gap: 0;
}

.switch-grid .field__label {
    font-size: 12.5px;
    font-weight: 500;
    color: var(--muted, #6b7280);
}

/* ── Live arithmetic warning on the money forms ── */
.mismatch {
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 10px;
    background: #fffbeb;
    border: 1px solid #fde68a;
}

.mismatch__text {
    flex: 1;
    font-size: 13px;
    color: #92400e;
}

/* ── Uploaded logo / QR preview ── */
.upload-preview {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 8px;
}

.upload-preview img {
    height: 40px;
    border-radius: 8px;
    border: 1px solid var(--line, #e6e8ef);
}

.upload-preview img.is-tall {
    height: 64px;
}

/* ── Repeating label/value rows (gateway extra fields) ── */
.extra-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 10px;
}

@media (max-width: 700px) {
    .extra-row { grid-template-columns: 1fr; }
}

/* ── Field help: the ⓘ beside a label and the panel it opens ── */
.field__help {
    border: 0;
    background: transparent;
    color: var(--brand, #4f46e5);
    font-size: 13px;
    line-height: 1;
    padding: 0 2px;
    cursor: pointer;
    opacity: .65;
    transition: opacity .15s;
}

.field__help:hover,
.field__help[aria-expanded="true"] {
    opacity: 1;
}

.field__help-body {
    margin: -2px 0 4px;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--brand-soft, #eef2ff);
    border: 1px solid #c7d2fe;
    color: #3730a3;
    font-size: 12.5px;
    font-weight: 400;
    line-height: 1.9;
}

/* The date component's label is a <span> inside a <label>, so normalise the weight. */
.date-field__label .field__help {
    font-weight: 400;
}

/* ── Small state pills (customer subscription state) ── */
.pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.pill b {
    display: grid;
    place-items: center;
    min-width: 17px;
    height: 17px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .7);
    font-size: 11px;
}

.pill--ok { background: #dcfce7; color: #166534; }
.pill--warn { background: #fef3c7; color: #92400e; }
.pill--muted { background: #f1f5f9; color: #64748b; }

/* ── Clinic app serials & clinic control (docs/app-serials.md §11) ── */
.meter { display: inline-block; width: 70px; height: 6px; border-radius: 9px; background: var(--neutral-soft); overflow: hidden; vertical-align: middle; margin-inline-start: 6px; }
.meter > i { display: block; height: 100%; background: var(--brand); }
.meter--full > i { background: var(--warn); }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; direction: ltr; unicode-bidi: isolate; letter-spacing: .03em; }
.serial-box { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; direction: ltr; letter-spacing: .08em; font-size: 18px; text-align: center; padding: 12px 14px; border: 1px dashed var(--brand); border-radius: 10px; background: var(--surface-2); }
.code-box { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; direction: ltr; text-align: left; word-break: break-all; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); font-size: 13px; line-height: 1.7; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; align-items: start; }
.kill-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.kill-toggle { display: flex; gap: 12px; align-items: flex-start; padding: 16px; border: 2px solid var(--border); border-radius: var(--radius); cursor: pointer; background: var(--surface); }
.kill-toggle:has(input:checked) { border-color: var(--danger); background: var(--danger-soft); }
.kill-toggle input { width: 22px; height: 22px; margin-top: 3px; accent-color: var(--danger); flex: none; }
.kill-toggle strong { display: block; font-size: 16px; }
.kill-toggle small { color: var(--text-muted); }
.kill-banner { display: flex; gap: 12px; align-items: center; padding: 14px 16px; border: 2px solid var(--danger); border-radius: var(--radius); background: var(--danger-soft); color: var(--danger); font-weight: 700; margin-bottom: 16px; }
.kill-banner svg { width: 22px; height: 22px; flex: none; }
.timeline { display: grid; gap: 8px; font-size: 13px; }
.timeline > div { display: flex; gap: 10px; align-items: baseline; }
.timeline time { color: var(--text-muted); min-width: 120px; font-variant-numeric: tabular-nums; }
.inline-form { display: inline-flex; gap: 6px; align-items: center; margin: 0; }
details.card > summary { cursor: pointer; padding: 14px 18px; font-weight: 700; list-style: none; }
details.card > summary::-webkit-details-marker { display: none; }

/* A licence section ticked or unticked for you because another one depends on it (js/feature-deps.js). */
.feature-dep-changed { animation: feature-dep-flash 1.6s ease-out; border-radius: 8px; }
@keyframes feature-dep-flash { 0% { background: var(--warn-soft, #fff4d6); box-shadow: 0 0 0 2px var(--warn, #f0b429); } 100% { background: transparent; box-shadow: 0 0 0 0 transparent; } }

/* Licence-form sections that apply to one product kind only (license-kind.js toggles them).
   .alert and .fsec set their own display, which would otherwise beat [hidden]. */
[data-kind-only][hidden] { display: none !important; }
.alert[data-kind-only] { flex-direction: column; gap: 4px; }

/* Tabs joining related lists (Licences / Clinics / Serials, Payments / reviews). */
.section-tabs { padding: 0; margin-bottom: 16px; }
.section-tabs .tab { display: inline-flex; align-items: center; gap: 6px; }
.section-tabs__count {
    font-size: 11.5px; font-weight: 700; line-height: 1; padding: 3px 7px; border-radius: 999px;
    background: var(--surface-2); color: var(--text-muted);
}
.section-tabs .tab.is-active .section-tabs__count { background: var(--brand); color: #fff; }
