/* =====================================================================
 * Wiki app shell — layout primitives shared across the four Blazor apps
 * (AdminPortal, Governance, HelperPwa, UserProfile). Marketing has its own
 * CSS (see Wiki.Marketing/wwwroot/css/app.css) — different design profile.
 *
 * Every rule reads from tokens.css custom properties so a single token edit
 * propagates everywhere. AA contrast minimum on every pair.
 * ===================================================================== */

@import url('tokens.css');

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }

body {
    background: var(--wk-bg);
    color: var(--wk-ink);
    font: var(--wk-fs)/1.55 var(--wk-font);
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--wk-accent); text-decoration: none; }
a:hover, a:focus { text-decoration: underline; color: var(--wk-accent-hover); }
a:focus-visible { outline: none; box-shadow: var(--wk-focus-ring); border-radius: var(--wk-radius-sm); }

h1 { font-size: var(--wk-fs-h1); line-height: 1.2; margin: 0 0 0.75rem; color: var(--wk-ink-strong); }
/* FocusOnNavigate (App.razor) moves focus to the page h1 for screen-reader
   announce; the UA focus ring on a non-interactive heading is visual noise. */
h1:focus { outline: none; }
h2 { font-size: var(--wk-fs-h2); margin: 1.5rem 0 0.75rem; }
h3 { font-size: var(--wk-fs-h3); margin: 1.25rem 0 0.5rem; }
p  { margin: 0 0 0.75rem; }

code, pre { font-family: var(--wk-font-mono); font-size: var(--wk-fs-sm); }
pre { background: var(--wk-surface-2); padding: 0.75rem; border-radius: var(--wk-radius); overflow: auto; }

/* ---- App shell -------------------------------------------------------- */

.wk-app {
    display: grid;
    grid-template-columns: var(--wk-nav-w) 1fr;
    min-height: 100vh;
}

.wk-app__nav {
    background: var(--wk-surface-1);
    border-right: 1px solid var(--wk-border);
    padding: 1.25rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

/* Brand lockup — family spec: both words 800 at ~1.05rem, hub link hovers to
   accent, ▸ separator accent-coloured at .85em (set inline where used). */
.wk-app__brand {
    font-weight: 800;
    font-size: 1.05rem;
    letter-spacing: 0.01em;
    color: var(--wk-ink-strong);
    padding: 0 0.5rem 1rem;
    border-bottom: 1px solid var(--wk-border-soft);
}

.wk-app__brand a { color: inherit; text-decoration: none; }
.wk-app__brand a:hover, .wk-app__brand a:focus { color: var(--wk-accent); text-decoration: none; }

.wk-app__nav nav {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.wk-app__nav nav a {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.55rem 0.6rem;
    border-left: 3px solid transparent;   /* reserved so .active doesn't shift text */
    border-radius: var(--wk-radius-sm);
    color: var(--wk-ink);
    min-height: 40px;
}

.wk-app__nav nav a:hover { background: var(--wk-surface-2); text-decoration: none; color: var(--wk-ink); }
.wk-app__nav nav a.active {
    background: var(--wk-accent-tint);
    border-left-color: var(--wk-accent);
    color: var(--wk-ink-strong);
    font-weight: 600;
}

.wk-app__main {
    padding: 1.5rem 2rem 3rem;
    max-width: var(--wk-maxw);
    width: 100%;
}

.wk-app__header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 1rem;
    gap: 1rem;
    flex-wrap: wrap;
}

.wk-app__title { margin: 0; }

@media (max-width: 720px) {
    .wk-app { grid-template-columns: 1fr; }
    .wk-app__nav {
        position: relative;
        height: auto;
        flex-direction: row;
        flex-wrap: wrap;
        overflow-x: auto;
    }
    .wk-app__main { padding: 1rem; }
}

/* ---- Tiles ------------------------------------------------------------ */

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

.wk-tile {
    background: var(--wk-surface-1);
    border: 1px solid var(--wk-border);
    border-radius: var(--wk-radius-lg);
    padding: 1rem 1.1rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    box-shadow: var(--wk-shadow-1);
    min-height: 130px;
}

.wk-tile__label {
    color: var(--wk-ink-muted);
    font-size: var(--wk-fs-sm);
    letter-spacing: 0.01em;
    text-transform: uppercase;
}

.wk-tile__value {
    color: var(--wk-ink-strong);
    font-size: 2rem;
    font-weight: 600;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

.wk-tile__sub {
    color: var(--wk-ink-muted);
    font-size: var(--wk-fs-sm);
}

.wk-tile.is-stale { opacity: 0.55; }
.wk-tile.is-error { border-color: var(--wk-danger); }
.wk-tile.is-error .wk-tile__sub { color: var(--wk-danger); }

.wk-spark {
    margin-top: auto;
    width: 100%;
    height: 36px;
}

/* ---- Forms ------------------------------------------------------------ */

.wk-form-row {
    display: grid;
    grid-template-columns: minmax(180px, 28%) 1fr;
    gap: 0.5rem 1rem;
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--wk-border-soft);
    align-items: start;
}

.wk-form-row__label { color: var(--wk-ink); font-weight: 500; padding-top: 0.35rem; }
.wk-form-row__desc  { color: var(--wk-ink-muted); font-size: var(--wk-fs-sm); margin-top: 0.2rem; }
.wk-form-row__error { color: var(--wk-danger); font-size: var(--wk-fs-sm); margin-top: 0.2rem; }

.wk-form-row input[type=text],
.wk-form-row input[type=number],
.wk-form-row input[type=password],
.wk-form-row input[type=tel],
.wk-form-row select,
.wk-form-row textarea {
    width: 100%;
    min-height: var(--wk-hit);
    padding: 0.5rem 0.7rem;
    background: var(--wk-bg);
    color: var(--wk-ink);
    border: 1px solid var(--wk-border);
    border-radius: var(--wk-radius-sm);
    font: inherit;
}

.wk-form-row input:focus-visible,
.wk-form-row select:focus-visible,
.wk-form-row textarea:focus-visible {
    outline: none;
    box-shadow: var(--wk-focus-ring);
    border-color: var(--wk-accent);
}

.wk-form-row input[readonly] { opacity: 0.7; cursor: not-allowed; }

.wk-input-unit {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}
.wk-input-unit > input { flex: 1; }
.wk-input-unit > .unit { color: var(--wk-ink-muted); font-size: var(--wk-fs-sm); }

/* ---- Buttons ---------------------------------------------------------- */

.wk-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    min-height: var(--wk-hit);
    padding: 0.5rem 1rem;
    border-radius: var(--wk-radius);
    border: 1px solid var(--wk-border);
    background: var(--wk-surface-2);
    color: var(--wk-ink);
    font: inherit;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
}

.wk-btn:hover  { background: var(--wk-surface-3); }
.wk-btn:focus-visible { outline: none; box-shadow: var(--wk-focus-ring); border-color: var(--wk-accent); }
.wk-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Primary = family spec: accent bg + WHITE ink in both themes (light theme's
   deeper #CC3415 accent keeps the pair AA), hover swaps to --wk-accent-hover
   (colour swap, not a brightness filter), active nudges down 1px. */
.wk-btn--primary { background: var(--wk-orange); border-color: var(--wk-orange); color: var(--wk-orange-ink); }
.wk-btn--primary:hover { background: var(--wk-accent-hover, var(--ml-accent-hover)); border-color: var(--wk-accent-hover, var(--ml-accent-hover)); }
.wk-btn--primary:active { transform: translateY(1px); }
.wk-btn--primary:disabled { background: var(--wk-orange); border-color: var(--wk-orange); color: var(--wk-orange-ink); opacity: 0.65; }

.wk-btn--danger { background: var(--wk-danger); border-color: var(--wk-danger); color: var(--wk-danger-ink); }

/* ---- Badges (EditClass colouring + general status) ------------------- */

.wk-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: var(--wk-fs-xs);
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    border: 1px solid transparent;
}

/* Tinted-background idiom: 12% status tint + status-colour text, no hard outline. */
.wk-badge--safe    { background: color-mix(in srgb, var(--wk-ok) 12%, transparent); color: var(--wk-ok); }
.wk-badge--caution { background: color-mix(in srgb, var(--wk-warn) 12%, transparent); color: var(--wk-warn); }
.wk-badge--locked  { background: color-mix(in srgb, var(--wk-danger) 12%, transparent); color: var(--wk-danger); }
.wk-badge--info    { background: color-mix(in srgb, var(--wk-accent) 12%, transparent); color: var(--wk-accent); }

/* ---- Connection indicator (SignalR up/down) -------------------------- */

.wk-conn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: var(--wk-fs-sm);
    color: var(--wk-ink-muted);
}

.wk-conn::before {
    content: "";
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--wk-ink-muted);
}

.wk-conn.is-connected::before    { background: var(--wk-ok); box-shadow: var(--wk-glow-ok); }
.wk-conn.is-reconnecting::before { background: var(--wk-warn); animation: wk-pulse 1s ease-in-out infinite; }
.wk-conn.is-disconnected::before { background: var(--wk-danger); box-shadow: var(--wk-glow-danger); }

@keyframes wk-pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.3; }
}

/* ---- Overlay (restart watchdog modal) ------------------------------- */

.wk-overlay {
    position: fixed; inset: 0;
    background: var(--wk-overlay);
    display: flex; align-items: center; justify-content: center;
    z-index: 100;
    padding: 1rem;
}

.wk-overlay__card {
    background: var(--wk-surface-1);
    border: 1px solid var(--wk-border);
    border-radius: var(--wk-radius-lg);
    padding: 1.5rem;
    max-width: 32rem;
    width: 100%;
    box-shadow: var(--wk-shadow-2);
}

.wk-overlay__title { margin: 0 0 0.5rem; }
.wk-overlay__meta  { color: var(--wk-ink-muted); font-size: var(--wk-fs-sm); }

/* ---- Banner ---------------------------------------------------------- */

.wk-banner {
    background: var(--wk-surface-1);
    border-left: 4px solid var(--wk-accent);
    padding: 0.75rem 1rem;
    border-radius: var(--wk-radius-sm);
    margin-bottom: 1rem;
}

.wk-banner--warn   { border-left-color: var(--wk-warn); }
.wk-banner--danger { border-left-color: var(--wk-danger); }

/* ---- Table ----------------------------------------------------------- */

.wk-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--wk-fs-sm);
}

.wk-table th, .wk-table td {
    padding: 0.55rem 0.6rem;
    border-bottom: 1px solid var(--wk-border-soft);
    text-align: left;
    vertical-align: top;
}

.wk-table th {
    background: var(--wk-surface-1);
    color: var(--wk-ink-muted);
    font-weight: 600;
    font-size: var(--wk-fs-xs);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.wk-table tbody tr:hover { background: var(--wk-surface-2); }

/* ---- Login layout (no nav) ------------------------------------------ */

.wk-login {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.wk-login__card {
    background: var(--wk-surface-1);
    border: 1px solid var(--wk-border);
    border-radius: var(--wk-radius-lg);
    padding: 2rem;
    width: 100%;
    max-width: 28rem;
    box-shadow: var(--wk-shadow-1);
}

/* ---- Skip link (a11y) ----------------------------------------------- */

.wk-skip {
    position: absolute; left: -10000px;
}

.wk-skip:focus {
    left: 1rem; top: 1rem;
    background: var(--wk-ink-strong);
    color: var(--wk-bg);
    padding: 0.5rem 0.75rem;
    border-radius: var(--wk-radius-sm);
    z-index: 200;
}

/* ---- Toast (Phase 6.5 KB Sources page; small stack of dismissible notes) -- */

.wk-toast-stack {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    display: grid;
    gap: 0.5rem;
    z-index: 300;
    max-width: min(28rem, calc(100vw - 2rem));
}

.wk-toast {
    background: var(--wk-surface-1);
    color: var(--wk-ink);
    border: 1px solid var(--wk-border);
    border-left: 4px solid var(--wk-ink-strong);
    border-radius: var(--wk-radius-lg);
    box-shadow: var(--wk-shadow-2);
    padding: 0.6rem 0.8rem;
    font-size: var(--wk-fs-sm);
    line-height: 1.35;
    display: flex;
    gap: 0.6rem;
    align-items: flex-start;
    justify-content: space-between;
}

.wk-toast--ok      { border-left-color: var(--wk-ok); }
.wk-toast--error   { border-left-color: var(--wk-danger); }
.wk-toast--info    { border-left-color: var(--wk-ink-muted); }

.wk-toast__dismiss {
    background: none;
    border: 0;
    color: var(--wk-ink-muted);
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    min-width: 44px;       /* hit target */
    min-height: 44px;
    margin: -0.6rem -0.4rem;   /* keep visible footprint compact */
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.wk-toast__dismiss:focus-visible {
    outline: 2px solid var(--wk-ink-strong);
    outline-offset: 2px;
}

/* ---- Toggle switch (Phase 6.5; accessible checkbox-as-switch) ------------- */

.wk-toggle {
    position: relative;
    display: inline-block;
    width: 2.6rem;
    height: 1.4rem;
    vertical-align: middle;
}

.wk-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.wk-toggle__track {
    position: absolute;
    inset: 0;
    background: var(--wk-surface-2, var(--wk-border));
    border: 1px solid var(--wk-border);
    border-radius: 1rem;
    cursor: pointer;
    transition: background 120ms ease-out;
}

.wk-toggle__track::after {
    content: "";
    position: absolute;
    top: 1px;
    left: 1px;
    width: calc(1.4rem - 4px);
    height: calc(1.4rem - 4px);
    background: var(--wk-ink);
    border-radius: 50%;
    transition: transform 120ms ease-out;
}

.wk-toggle input:checked + .wk-toggle__track {
    background: var(--wk-ok);
}

.wk-toggle input:checked + .wk-toggle__track::after {
    transform: translateX(1.2rem);
    background: var(--wk-bg);
}

.wk-toggle input:focus-visible + .wk-toggle__track {
    outline: 2px solid var(--wk-ink-strong);
    outline-offset: 2px;
}

/* ---- Status pip (Phase 6.5; "queued" indicator for SignalR queued event) -- */

.wk-pip {
    display: inline-block;
    width: 0.55rem;
    height: 0.55rem;
    border-radius: 50%;
    margin-right: 0.35rem;
    vertical-align: middle;
    background: var(--wk-ink-muted);
}

.wk-pip--queued {
    background: var(--wk-warn, var(--wk-ink-strong));
    animation: wk-pip-pulse 1.2s ease-in-out infinite;
}

@keyframes wk-pip-pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.45; }
}

/* ---- Truncated cell (Phase 6.5; URL column with hover-full) --------------- */

.wk-truncate {
    display: inline-block;
    max-width: 22rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
}

@media (max-width: 768px) {
    .wk-truncate { max-width: 14rem; }
}

/* ---- Mobile-stacked table (Phase 6.5; reviewers on phones/tablets) -------- */

.wk-stacked-table { width: 100%; border-collapse: collapse; }

.wk-stacked-table th,
.wk-stacked-table td {
    padding: 0.5rem 0.75rem;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid var(--wk-border);
}

.wk-stacked-table th {
    color: var(--wk-ink-muted);
    font-weight: 600;
    font-size: var(--wk-fs-xs);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.wk-stacked-table tbody tr:hover { background: var(--wk-surface-2); }

@media (max-width: 768px) {
    .wk-stacked-table thead { display: none; }
    .wk-stacked-table,
    .wk-stacked-table tbody,
    .wk-stacked-table tr,
    .wk-stacked-table td { display: block; width: 100%; }
    .wk-stacked-table tr {
        border: 1px solid var(--wk-border);
        border-radius: var(--wk-radius-sm);
        padding: 0.5rem;
        margin-bottom: 0.75rem;
        background: var(--wk-surface-1);
    }
    .wk-stacked-table td {
        border: 0;
        padding: 0.25rem 0;
    }
    .wk-stacked-table td[data-label]::before {
        content: attr(data-label) ": ";
        color: var(--wk-ink-muted);
        font-weight: 500;
        margin-right: 0.4rem;
    }
}

/* ---- OTP 6-box row (shared login pattern; interop in js/login-otp.js) ----- */

.wk-otp {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 0.5rem;
}

.wk-otp-cell {
    min-height: var(--wk-hit);
    padding: 0;
    text-align: center;
    font-family: var(--wk-font-mono);
    font-size: var(--wk-fs-lg);
    font-variant-numeric: tabular-nums;
    background: var(--wk-bg);
    color: var(--wk-ink);
    caret-color: var(--wk-accent);
    border: 1px solid var(--wk-border);
    border-radius: var(--wk-radius-sm);
}

/* :focus (not :focus-visible) — the interop moves focus programmatically and the
   active cell must always be visually obvious. */
.wk-otp-cell:focus {
    outline: none;
    box-shadow: var(--wk-focus-ring);
    border-color: var(--wk-accent);
}

.wk-form-row__hint { color: var(--wk-ink-muted); font-size: var(--wk-fs-sm); margin-top: 0.25rem; }

/* ---- Scrollbars (WebKit/Blink; Firefox keeps its thin default) ------------ */

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--wk-border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--wk-ink-muted); }

/* ---- Loading states: spinner + skeleton shimmer --------------------------- */

.wk-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--wk-border);
    border-top-color: var(--wk-accent);
    border-radius: 50%;
    /* Spins only under prefers-reduced-motion: no-preference (see motion block
       below); reduced-motion users get a static accent arc. */
}

.wk-skeleton {
    display: block;
    min-height: 1em;
    border-radius: var(--wk-radius-sm);
    background: var(--wk-surface-2);
    /* Shimmer gradient + animation applied in the motion block below. */
}

@keyframes wk-spin {
    to { transform: rotate(360deg); }
}

@keyframes wk-shimmer {
    from { background-position: 200% 0; }
    to   { background-position: -200% 0; }
}

/* ---- Motion (all transitions/animations are reduced-motion aware) --------- */

@media (prefers-reduced-motion: no-preference) {
    .wk-app__nav nav a,
    .wk-btn,
    .wk-form-row input,
    .wk-form-row select,
    .wk-form-row textarea,
    .wk-otp-cell {
        transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
    }

    .wk-tile,
    .wk-login__card {
        transition: background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
    }

    .wk-overlay,
    .wk-overlay__card,
    .wk-toast {
        transition: opacity 0.3s ease, transform 0.3s ease, background-color 0.3s ease;
    }

    .wk-spinner { animation: wk-spin 0.8s linear infinite; }

    .wk-skeleton {
        background: linear-gradient(90deg,
            var(--wk-surface-2) 25%,
            var(--wk-surface-1) 50%,
            var(--wk-surface-2) 75%);
        background-size: 200% 100%;
        animation: wk-shimmer 1.4s ease infinite;
    }
}

/* Pre-existing pulse/toggle motion declared above predates the no-preference
   wrapper — neutralise it here rather than restructuring those blocks. */
@media (prefers-reduced-motion: reduce) {
    .wk-conn.is-reconnecting::before,
    .wk-pip--queued { animation: none; }

    .wk-toggle__track,
    .wk-toggle__track::after { transition: none; }
}
