/* KNM Gateway dashboard — sits on top of Bootstrap 5 + KNM.RazorComponents.
   Bootstrap supplies the form-control / card / navbar / modal classes;
   this file only adds dark-mode tokens + a few page-shell tweaks. */

/* FOUC prevention overlay — shown until the KNM loader fires window.load and adds .loaded.
   Lives in site.css (loaded in <head>) so it applies before the body paints. */
#knm-loading {
    position: fixed; inset: 0; z-index: 9999;
    background: var(--bs-body-bg, #fff);
    display: flex; align-items: center; justify-content: center;
    transition: opacity .3s ease;
}
#knm-loading.loaded { opacity: 0; pointer-events: none; }
.knm-loading-spinner {
    width: 40px; height: 40px;
    border: 3px solid var(--bs-border-color, #e9ecef);
    border-top-color: var(--bs-primary, #0d6efd);
    border-radius: 50%;
    animation: knm-spin .6s linear infinite;
}
@keyframes knm-spin { to { transform: rotate(360deg); } }

/* Default = dark theme tokens (matches html data-bs-theme="dark" / "system"-resolved-dark). */
:root,
html[data-bs-theme="dark"] {
    --bg:    #0e1116;
    --panel: #161b22;
    --line:  #2a3140;
    --fg:    #e6edf3;
    --muted: #8d96a0;
    --acc:   #4ea1ff;
    --err:   #ff6b6b;
}

/* Light theme tokens — kicked in by App.razor cookie resolver or system pref. */
html[data-bs-theme="light"] {
    --bg:    #ffffff;
    --panel: #f5f7fa;
    --line:  #dee2e6;
    --fg:    #1f2329;
    --muted: #6c757d;
    --acc:   #0d6efd;
    --err:   #dc3545;
}

html, body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    background: var(--bg) !important;
    color: var(--fg);
}

/* Sticky footer — body flex column so <main> grows to push <footer> to the bottom even
   when page content is short (login screen, 404, dashboards with little data). */
body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}
body > main { flex: 1 0 auto; }
body > footer { flex-shrink: 0; }

/* Navbar — link colour MUST follow theme too, otherwise light bg + light text = invisible. */
.knm-topbar { background: var(--panel); border-bottom: 1px solid var(--line); }
.knm-topbar .navbar-brand { color: var(--fg); }
.knm-topbar .nav-link { color: var(--fg); }
.knm-topbar .nav-link:hover { color: var(--acc); }
.knm-topbar .nav-link.active { background: rgba(78, 161, 255, 0.15); border-radius: 6px; color: var(--acc); }

a { color: var(--acc); text-decoration: none; }
a:hover { text-decoration: underline; }

code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem; color: var(--acc); }

.layout { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
    display: flex; align-items: center; gap: 1.5rem;
    padding: 0.75rem 1.5rem; background: var(--panel);
    border-bottom: 1px solid var(--line);
}
.brand   { font-weight: 600; font-size: 1.05rem; }
.nav     { display: flex; gap: 1rem; flex: 1; }
.user    { color: var(--muted); }
.logout  { color: var(--muted); }

.content { padding: 1.5rem; }

/* Blank layout (login etc.) — single-screen flex shell. The body's global flex-column
   keeps MainLayout's footer pinned; on the Blank layout we override it locally so the
   shell sizes to the viewport (100dvh) and the card + footer fit inside one screen,
   no scrollbar. The branded backdrop lives on .blank-main only — the footer keeps the
   neutral knm-app-footer background. */
body:has(.blank-shell) { display: block; min-height: auto; }

.blank-shell {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
}
.blank-shell > .blank-main {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: radial-gradient(ellipse at top, rgba(78, 161, 255, 0.08), transparent 50%),
                radial-gradient(ellipse at bottom right, rgba(0, 184, 148, 0.05), transparent 50%);
}
.blank-langbar { position: fixed; top: 1rem; right: 1rem; z-index: 1050; display: flex; gap: .5rem; align-items: center; }

.knm-app-footer {
    border-top: 1px solid var(--line);
    background: var(--panel);
    padding: .5rem 0;
    /* No margin-top: the body flex-column already keeps it pinned to the bottom via
       main { flex: 1 }. A margin here would only show when content is already long
       enough to push the footer past the viewport — i.e. never useful. */
}

.error-page {
    text-align: center;
    padding: 3rem 1.5rem;
    max-width: 480px;
}
.error-page__icon {
    font-size: 4rem;
    color: var(--acc);
    margin-bottom: 1rem;
    display: block;
}

h1 { margin: 0 0 0.5rem; font-size: 1.5rem; }
.sub { color: var(--muted); margin: 0 0 1.5rem; }
.muted { color: var(--muted); }

table.grid { width: 100%; border-collapse: collapse; }
table.grid th, table.grid td { padding: 0.55rem 0.75rem; text-align: left;
    border-bottom: 1px solid var(--line); }
table.grid th { background: var(--panel); font-weight: 600; color: var(--muted);
    text-transform: uppercase; font-size: 0.75rem; letter-spacing: 0.05em; }
table.grid td.muted { color: var(--muted); text-align: center; }

/* Login card wrapper — width-constrained box; the .blank-main shell already
   handles centring + backdrop. */
.login-card-wrap { width: 100%; max-width: 420px; }
.login-brand {
    display: inline-flex; align-items: center; justify-content: center;
    width: 64px; height: 64px; margin-bottom: 1rem;
    background: linear-gradient(135deg, var(--acc), #4f8df9);
    border-radius: 16px; font-size: 2rem; color: #fff;
}
.login-brand i { line-height: 1; }

/* Nav links — active state */
.nav a, .nav .active {
    color: var(--muted); padding: 0.35rem 0.65rem; border-radius: 4px;
    text-decoration: none; display: inline-flex; align-items: center; gap: 0.35rem;
}
.nav a:hover { color: var(--fg); background: rgba(78, 161, 255, 0.08); }
.nav a.active { color: var(--fg); background: rgba(78, 161, 255, 0.15); }

/* Page header bar */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.page-header h1 { margin: 0; }

/* Profile (Berruto-style) — sidebar nav + content panel */
.profile-shell .profile-nav-card { position: sticky; top: 1rem; }
.profile-nav { gap: 0.25rem; }
.profile-nav .nav-link {
    background: transparent; border: 0; color: var(--fg);
    text-align: left; padding: 0.55rem 0.85rem; border-radius: 0.5rem;
    transition: background 0.15s ease;
}
.profile-nav .nav-link:hover { background: rgba(78, 161, 255, 0.10); }
.profile-nav .nav-link.active { background: rgba(78, 161, 255, 0.20); color: var(--fg); font-weight: 500; }
.profile-nav .nav-link i { font-size: 1.05rem; opacity: 0.85; }

.device-icon { font-size: 1.5rem; opacity: 0.7; line-height: 1; }

/* Profile → Security — Berruto image-7 pattern: label / status / action per row */
.security-row {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: 1rem;
    padding: 0.85rem 0;
    border-bottom: 1px solid var(--line);
}
.security-row:last-child { border-bottom: 0; }
.security-row__label  { font-weight: 500; color: var(--fg); }
.security-row__status { color: var(--bs-secondary-color); font-size: 0.92rem; }
.security-row__action { min-width: 100px; text-align: right; }
.security-passkey-list { margin: 0 -1rem 0 -1rem; border-top: 1px dashed var(--line); }

/* KNMAuditFooter — local override block removed in 0.5.12 after upgrade to
   KNM.RazorComponents 1.9.0 (issue #104). The component now auto-applies a
   dense layout when its rendered width drops below 720 px via CSS container
   queries; no parent selector / parameter is required from the consumer. */

/* Modal action row */
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1rem; }

/* Pager (Audit) */
.pager { display: flex; gap: 0.5rem; justify-content: center; margin-top: 1rem; }

/* Token reveal block */
.token-block textarea {
    width: 100%; min-height: 6rem; padding: 0.75rem;
    background: var(--bg); color: var(--fg);
    border: 1px solid var(--line); border-radius: 4px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.8rem;
    word-break: break-all; resize: vertical;
}

/* Legacy "vanilla form" reset for old pages — kept commented out.
   These selectors are too broad: they steam-roll KNMInput's RadioButtonList / Switch / Checkbox
   inner <input>, KNMSelect's <select>, etc. Configurations + Tokens now use Bootstrap form-* /
   KNM components, so this fallback is unnecessary. Re-enable scoped to ".row > .col-* > input"
   if a future vanilla form needs it. */
/*
.row .col-12 label, .row .col-md-3 label, .row .col-md-6 label { display: block; margin-bottom: 0.5rem; }
.row label > span { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.25rem; }
.row input, .row select, .row textarea {
    width: 100%; padding: 0.45rem 0.65rem;
    background: var(--bg); color: var(--fg);
    border: 1px solid var(--line); border-radius: 4px; font-size: 0.9rem;
}
.row input:focus, .row select:focus { outline: none; border-color: var(--acc); }
.row.g-3 > * { padding: 0.5rem; }
*/

/* Grid path column wraps */
table.grid td.path { max-width: 24rem; word-break: break-all; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.8rem; }

/* Brand asset editor — square-ish thumbnail with the uploaded image fitted; transparent
   checkered background helps spotting alpha logos. */
.brand-asset-editor .brand-asset-preview {
    min-height: 110px;
    background-color: var(--panel);
    background-image:
        linear-gradient(45deg, rgba(127, 127, 127, .12) 25%, transparent 25%),
        linear-gradient(-45deg, rgba(127, 127, 127, .12) 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, rgba(127, 127, 127, .12) 75%),
        linear-gradient(-45deg, transparent 75%, rgba(127, 127, 127, .12) 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
    border-radius: 6px;
}
.brand-asset-editor .brand-asset-preview img {
    max-height: 90px;
    max-width: 100%;
    object-fit: contain;
}
