/* ============================================================================
   Pre-D Authorisation Tracker — design system
   Style: Minimalism & Swiss (grid-based, high-contrast, functional)
   Palette: slate primary + status-green accent   Type: Fira Sans / Fira Code
   Light default, full dark-mode support via prefers-color-scheme.
   Generated with the ui-ux-pro-max skill (design-system/predtracker/MASTER.md).
   ========================================================================== */

/* ---- Tokens ------------------------------------------------------------- */
:root {
    /* Brand / neutrals (light) */
    --primary: #1e293b;        /* slate-800 (nav text on light bar) */
    --primary-600: #334155;    /* slate-700 */
    --on-primary: #ffffff;
    --accent: #0d57be;         /* PDA royal blue (CTA / brand) */
    --accent-600: #0a4599;     /* darker blue */
    --on-accent: #ffffff;
    --brand: #0d57be;          /* logo mark */
    --logo-word: #16233f;      /* logo wordmark (navy) */

    --bg: #f8fafc;             /* slate-50  */
    --surface: #ffffff;
    --surface-2: #f1f5f9;      /* slate-100 */
    --text: #0f172a;           /* slate-900 */
    --muted: #64748b;          /* slate-500 */
    --border: #e2e8f0;         /* slate-200 */
    --border-strong: #cbd5e1;  /* slate-300 */
    --ring: #0d57be;

    /* Status */
    --s-new-bg:#e0e7ff;   --s-new-fg:#3730a3;   --s-new-dot:#4f46e5;
    --s-prog-bg:#fef3c7;  --s-prog-fg:#92400e;  --s-prog-dot:#d97706;
    --s-pend-bg:#f3e8ff;  --s-pend-fg:#6b21a8;  --s-pend-dot:#9333ea;
    --s-done-bg:#dcfce7;  --s-done-fg:#166534;  --s-done-dot:#16a34a;
    --s-rej-bg:#fee2e2;   --s-rej-fg:#991b1b;   --s-rej-dot:#dc2626;

    --danger:#dc2626;
    --shadow-sm: 0 1px 2px rgba(15,23,42,.06);
    --shadow: 0 1px 3px rgba(15,23,42,.08), 0 1px 2px rgba(15,23,42,.04);
    --shadow-md: 0 4px 12px rgba(15,23,42,.08);
    --radius: 12px;
    --radius-sm: 8px;

    /* Spacing scale (standard density) */
    --sp-1:4px; --sp-2:8px; --sp-3:12px; --sp-4:16px; --sp-5:24px; --sp-6:32px; --sp-8:48px;

    --font-sans: "Fira Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-mono: "Fira Code", ui-monospace, "Cascadia Code", "Consolas", monospace;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --primary:#e2e8f0; --primary-600:#cbd5e1; --on-primary:#0f172a;
        --accent:#4b9bff; --accent-600:#2f7be0; --on-accent:#ffffff;
        --brand:#4b9bff; --logo-word:#e8eefc;
        --bg:#0f172a; --surface:#1b2336; --surface-2:#243049;
        --text:#f8fafc; --muted:#94a3b8; --border:#334155; --border-strong:#475569;
        --ring:#4b9bff;
        --s-new-bg:#312e81;  --s-new-fg:#c7d2fe;  --s-new-dot:#818cf8;
        --s-prog-bg:#78350f; --s-prog-fg:#fde68a; --s-prog-dot:#fbbf24;
        --s-pend-bg:#581c87; --s-pend-fg:#e9d5ff; --s-pend-dot:#c084fc;
        --s-done-bg:#14532d; --s-done-fg:#bbf7d0; --s-done-dot:#4ade80;
        --s-rej-bg:#7f1d1d;  --s-rej-fg:#fecaca;  --s-rej-dot:#f87171;
        --shadow-sm:0 1px 2px rgba(0,0,0,.3);
        --shadow:0 1px 3px rgba(0,0,0,.35);
        --shadow-md:0 6px 18px rgba(0,0,0,.45);
    }
}

/* ---- Base --------------------------------------------------------------- */
*,*::before,*::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}
h1,h2,h3 { line-height: 1.2; letter-spacing: -0.01em; margin: 0 0 var(--sp-3); }
h1 { font-size: 1.6rem; font-weight: 700; }
h2 { font-size: 1.2rem; font-weight: 600; }
a { color: var(--accent-600); text-decoration: none; }
a:hover { text-decoration: underline; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }

:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; border-radius: 4px; }

/* ---- App shell / top bar ----------------------------------------------- */
.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; justify-content: space-between;
    gap: var(--sp-4);
    background: var(--surface); color: var(--text);
    padding: var(--sp-3) var(--sp-5);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}
.topbar .brand { display: flex; align-items: center; flex: none; }
.topbar .brand:hover { text-decoration: none; }

/* Logo (inline SVG, theme-aware) */
.logo { display: block; height: auto; width: auto; max-width: 100%; object-fit: contain; }
.topbar .logo { height: 30px; }
.auth-head .logo { height: 46px; }
.lg-mark { fill: var(--brand); }
.lg-mark-stroke { stroke: var(--brand); }
.lg-word { fill: var(--logo-word); }
.lg-sub  { fill: var(--brand); }
.lg-divider { stroke: var(--border-strong); }

.nav { display: flex; align-items: center; gap: var(--sp-2); }
.nav a {
    color: var(--muted);
    padding: var(--sp-2) var(--sp-3); border-radius: var(--radius-sm);
    font-size: .92rem; font-weight: 500; display: inline-flex; align-items: center; gap: var(--sp-2);
    transition: background .2s ease, color .2s ease;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.cta { background: var(--accent); color: var(--on-accent); }
.nav a.cta:hover { background: var(--accent-600); color: var(--on-accent); }
.nav svg { width: 16px; height: 16px; }

.user-chip { display: flex; align-items: center; gap: var(--sp-3); }
.avatar {
    display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%;
    background: var(--accent); color: var(--on-accent);
    font-size: .8rem; font-weight: 700; flex: none;
}
.avatar.lg { width: 40px; height: 40px; font-size: .9rem; }
.user-meta { display: flex; flex-direction: column; line-height: 1.15; }
.user-meta .name { font-size: .88rem; font-weight: 600; color: var(--text); }
.user-meta .role { font-size: .72rem; color: var(--muted); }
.icon-link { color: var(--muted); display: inline-grid; place-items: center; padding: var(--sp-2); border-radius: var(--radius-sm); }
.icon-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.icon-link svg { width: 18px; height: 18px; }

.container { max-width: min(1680px, 96vw); margin: 0 auto; padding: var(--sp-6) var(--sp-5) var(--sp-8); }
.container-wide { max-width: min(1680px, 96vw); }

/* ---- Buttons ------------------------------------------------------------ */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
    font-family: inherit; font-size: .95rem; font-weight: 600; line-height: 1;
    padding: .68rem 1.05rem; border-radius: var(--radius-sm);
    border: 1px solid transparent; cursor: pointer;
    transition: background .2s ease, border-color .2s ease, color .2s ease, box-shadow .2s ease;
    min-height: 44px;
}
.btn svg { width: 18px; height: 18px; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-600); text-decoration: none; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-2); text-decoration: none; }
.btn-sm { min-height: 36px; padding: .45rem .75rem; font-size: .875rem; }
.btn-block { width: 100%; }

/* ---- Cards -------------------------------------------------------------- */
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.card-pad { padding: var(--sp-5); }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4); flex-wrap: wrap; margin-bottom: var(--sp-5); }
.page-head h1 { margin: 0; }
.back { display: inline-flex; align-items: center; gap: var(--sp-2); font-weight: 500; margin-bottom: var(--sp-4); color: var(--muted); }
.back svg { width: 16px; height: 16px; }

/* ---- Stat cards (pre-D dashboard) -------------------------------------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--sp-3); margin-bottom: var(--sp-5); }
.stat {
    display: flex; flex-direction: column; gap: var(--sp-2);
    padding: var(--sp-4); border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--surface); box-shadow: var(--shadow-sm);
    transition: border-color .2s ease, box-shadow .2s ease, transform .2s ease;
}
a.stat:hover { text-decoration: none; border-color: var(--border-strong); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.stat.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.stat .n { font-size: 1.8rem; font-weight: 700; letter-spacing: -0.02em; color: var(--text); }
.stat .l { display: inline-flex; align-items: center; gap: var(--sp-2); font-size: .82rem; font-weight: 500; color: var(--muted); }

/* ---- Alerts ------------------------------------------------------------- */
.alert { display: flex; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-radius: var(--radius-sm); margin: var(--sp-4) 0; font-size: .92rem; border: 1px solid transparent; }
.alert svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.alert.error { background: var(--s-rej-bg); color: var(--s-rej-fg); border-color: color-mix(in srgb, var(--s-rej-dot) 40%, transparent); }
.alert.info  { background: var(--s-new-bg); color: var(--s-new-fg); border-color: color-mix(in srgb, var(--s-new-dot) 40%, transparent); }

/* ---- Filters ------------------------------------------------------------ */
.filters { display: flex; align-items: center; gap: var(--sp-2); margin-bottom: var(--sp-4); }
.filters label { margin: 0; font-size: .85rem; color: var(--muted); font-weight: 500; }

/* ---- Table -------------------------------------------------------------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); }
.grid { width: 100%; border-collapse: collapse; font-size: .9rem; }
.grid thead th { position: sticky; top: 0; background: var(--surface-2); text-align: left; font-weight: 600; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border); }
.grid td { padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
.grid tbody tr { transition: background .15s ease; }
.grid tbody tr:hover { background: var(--surface-2); }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid .num { font-family: var(--font-mono); color: var(--muted); }
.truncate { max-width: 260px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-link { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; }
.row-link svg { width: 15px; height: 15px; }
.empty { display: flex; flex-direction: column; align-items: center; gap: var(--sp-3); padding: var(--sp-8) var(--sp-4); color: var(--muted); text-align: center; }
.empty svg { width: 40px; height: 40px; opacity: .5; }

/* ---- Status badge ------------------------------------------------------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.lg { font-size: .9rem; padding: 6px 14px; }
.badge.s-New        { background: var(--s-new-bg);  color: var(--s-new-fg);  }
.badge.s-InProgress { background: var(--s-prog-bg); color: var(--s-prog-fg); }
.badge.s-PendingInfo{ background: var(--s-pend-bg); color: var(--s-pend-fg); }
.badge.s-Completed  { background: var(--s-done-bg); color: var(--s-done-fg); }
.badge.s-Rejected   { background: var(--s-rej-bg);  color: var(--s-rej-fg);  }

/* ---- Status stepper ----------------------------------------------------- */
.stepper { display: flex; align-items: center; gap: 0; margin: var(--sp-4) 0 var(--sp-5); flex-wrap: wrap; }
.step { display: flex; align-items: center; gap: var(--sp-2); color: var(--muted); font-size: .85rem; font-weight: 500; }
.step .dot { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--border-strong); display: grid; place-items: center; background: var(--surface); flex: none; }
.step .dot svg { width: 12px; height: 12px; }
.step.done { color: var(--accent-600); }
.step.done .dot { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.step.current { color: var(--text); font-weight: 700; }
.step.current .dot { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.step-line { width: 34px; height: 2px; background: var(--border-strong); margin: 0 6px; }
.step-line.done { background: var(--accent); }
.stepper.rejected { color: var(--s-rej-fg); }

/* ---- Detail definition grid -------------------------------------------- */
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: var(--sp-4) var(--sp-5); }
.detail-grid .field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.detail-grid .field.full { grid-column: 1 / -1; }
.detail-grid dt, .detail-grid .k { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.detail-grid .v { font-size: .98rem; color: var(--text); word-break: break-word; }

/* ---- Status update bar (pre-D) ----------------------------------------- */
.statusbar { display: flex; align-items: flex-end; gap: var(--sp-3); flex-wrap: wrap; margin-top: var(--sp-4); }
.statusbar .field { display: flex; flex-direction: column; gap: 4px; }
.statusbar label { margin: 0; font-size: .8rem; color: var(--muted); font-weight: 600; }
.statusbar select { width: auto; min-width: 190px; }

/* ---- Comment thread ----------------------------------------------------- */
.thread { display: flex; flex-direction: column; gap: var(--sp-4); margin: var(--sp-4) 0 var(--sp-5); }
.comment { display: flex; gap: var(--sp-3); max-width: 88%; }
.comment.onshore { align-self: flex-end; flex-direction: row-reverse; }
.comment .bubble { border: 1px solid var(--border); border-radius: var(--radius); padding: var(--sp-3) var(--sp-4); background: var(--surface); box-shadow: var(--shadow-sm); }
.comment.pred .bubble { border-left: 3px solid var(--s-new-dot); }
.comment.onshore .bubble { border-left: 3px solid var(--accent); background: var(--surface-2); }
.comment .meta { font-size: .74rem; color: var(--muted); margin-bottom: 4px; }
.comment .meta strong { color: var(--text); font-weight: 600; }
.comment .text { white-space: pre-wrap; font-size: .95rem; }
.comment .avatar { background: var(--s-new-dot); }
.comment.onshore .avatar { background: var(--accent); color: var(--on-accent); }

/* ---- Forms -------------------------------------------------------------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: var(--sp-4) var(--sp-5); }
.form-grid .full { grid-column: 1 / -1; }
.field-label { display: block; margin-bottom: 6px; font-weight: 600; font-size: .88rem; color: var(--text); }
.hint { font-size: .8rem; color: var(--muted); margin-top: 4px; }
input, select, textarea {
    width: 100%; font-family: inherit; font-size: .95rem; color: var(--text);
    background: var(--surface); border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm); padding: .62rem .75rem;
    transition: border-color .2s ease, box-shadow .2s ease;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
textarea { resize: vertical; min-height: 84px; }
input::placeholder, textarea::placeholder { color: color-mix(in srgb, var(--muted) 80%, transparent); }
.form-actions { margin-top: var(--sp-5); display: flex; gap: var(--sp-3); }

/* ---- Comment composer --------------------------------------------------- */
.composer { display: flex; flex-direction: column; gap: var(--sp-3); }
.composer .form-actions { margin: 0; justify-content: flex-end; }

/* ---- Auth --------------------------------------------------------------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: var(--sp-5);
    background:
        radial-gradient(1200px 500px at 50% -10%, color-mix(in srgb, var(--accent) 12%, transparent), transparent),
        var(--bg);
}
.auth-card { width: 100%; max-width: 400px; }
.auth-head { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--sp-3); margin-bottom: var(--sp-5); }
.auth-head .brand-mark { width: 48px; height: 48px; border-radius: 14px; }
.auth-head .brand-mark svg { width: 28px; height: 28px; }
.auth-head h1 { font-size: 1.35rem; margin: 0; }
.auth-card form + form { margin-top: var(--sp-4); padding-top: var(--sp-4); border-top: 1px solid var(--border); }
.auth-card .btn { margin-top: var(--sp-4); }
.code-input { font-family: var(--font-mono); font-size: 1.4rem; letter-spacing: .5em; text-align: center; padding-left: .5em; }

/* ---- Footer ------------------------------------------------------------- */
.footer { text-align: center; color: var(--muted); font-size: .8rem; padding: var(--sp-6) var(--sp-5); }

/* ---- Admin -------------------------------------------------------------- */
.admin-tabs { display: flex; gap: var(--sp-2); border-bottom: 1px solid var(--border); margin-bottom: var(--sp-5); }
.admin-tabs a { padding: var(--sp-2) var(--sp-3); color: var(--muted); font-weight: 500; font-size: .92rem; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.admin-tabs a:hover { color: var(--text); text-decoration: none; }
.admin-tabs a.active { color: var(--accent-600); border-bottom-color: var(--accent); }

.inline-form { display: flex; gap: var(--sp-4); align-items: flex-end; flex-wrap: wrap; }
.inline-form .field { display: flex; flex-direction: column; gap: 6px; }
.inline-form .field.grow { flex: 1; min-width: 200px; }
.inline-form .field-label { margin: 0; }
.inline-form button { margin: 0; }

.switch-inline { display: inline-flex; align-items: center; gap: var(--sp-2); font-weight: 500; font-size: .92rem; margin: 0; cursor: pointer; }
.switch-inline input { width: auto; }

.switch-row { display: flex; align-items: center; gap: var(--sp-4); flex-wrap: wrap; }
.switch { position: relative; display: inline-block; width: 46px; height: 26px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; inset: 0; background: var(--border-strong); border-radius: 999px; transition: background .2s ease; }
.switch .slider::before { content: ""; position: absolute; height: 20px; width: 20px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform .2s ease; box-shadow: var(--shadow-sm); }
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(20px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--ring); outline-offset: 2px; }
.switch-row > div { flex: 1; min-width: 200px; }

/* ---- Responsive --------------------------------------------------------- */
@media (max-width: 720px) {
    .topbar { padding: var(--sp-3) var(--sp-4); flex-wrap: wrap; }
    .user-meta { display: none; }
    .container { padding: var(--sp-5) var(--sp-4) var(--sp-6); }
    .detail-grid, .form-grid { grid-template-columns: 1fr; }
    .comment { max-width: 100%; }
    .truncate { max-width: 150px; }
}

/* ---- Reduced motion ----------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    * { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
