/* ═══════════════════════════════════════════════════════════════════════
   Aibot panel — shared shell and components
   Dark-first, teal accent, hairline surfaces. Self-contained: no icon font,
   no external CSS. Page-specific rules live in their own stylesheet.
   ═══════════════════════════════════════════════════════════════════════ */

:root {
    color-scheme: dark;

    --canvas:        #0a0b0d;
    --canvas-glow:   radial-gradient(1200px 600px at 15% -10%, rgba(35, 213, 171, .07), transparent 60%),
                     radial-gradient(900px 500px at 100% 0%, rgba(139, 124, 255, .05), transparent 55%);
    --surface:       #101216;
    --surface-2:     #15181d;
    --surface-3:     #1b1f25;
    --surface-in:    #0c0e11;
    --line:          #22272e;
    --line-soft:     #191d22;

    --text:          #e9edf1;
    --text-2:        #9aa4ae;
    --text-3:        #626c76;

    --accent:        #23d5ab;
    --accent-text:   #062b23;
    --accent-soft:   rgba(35, 213, 171, .12);
    --accent-line:   rgba(35, 213, 171, .34);

    --ok:            #34d399;
    --ok-soft:       rgba(52, 211, 153, .13);
    --warn:          #fbbf24;
    --warn-soft:     rgba(251, 191, 36, .13);
    --danger:        #f87171;
    --danger-soft:   rgba(248, 113, 113, .13);
    --info:          #60a5fa;
    --info-soft:     rgba(96, 165, 250, .13);

    --radius:        14px;
    --radius-sm:     9px;
    --radius-xs:     6px;
    --shadow:        0 1px 2px rgba(0, 0, 0, .5), 0 12px 32px -12px rgba(0, 0, 0, .7);
    --shadow-lift:   0 2px 6px rgba(0, 0, 0, .45), 0 28px 60px -20px rgba(0, 0, 0, .85);

    --ui:   ui-sans-serif, -apple-system, "Segoe UI", Inter, Roboto, "Helvetica Neue", sans-serif;
    --mono: ui-monospace, "JetBrains Mono", "Cascadia Mono", "SF Mono", Consolas, monospace;

    --sidebar:      238px;
    --sidebar-thin: 68px;
    --topbar-h:     66px;
}

[data-theme="light"] {
    color-scheme: light;

    --canvas:      #f4f6f7;
    --canvas-glow: radial-gradient(1100px 560px at 12% -12%, rgba(35, 213, 171, .13), transparent 60%),
                   radial-gradient(900px 500px at 100% 0%, rgba(139, 124, 255, .10), transparent 55%);
    --surface:     #ffffff;
    --surface-2:   #f7f9fa;
    --surface-3:   #eef1f3;
    --surface-in:  #ffffff;
    --line:        #e0e5e9;
    --line-soft:   #eaeef1;

    --text:        #10151a;
    --text-2:      #5b666f;
    --text-3:      #8b959e;

    --accent:      #0d9b7e;
    --accent-text: #ffffff;
    --accent-soft: rgba(13, 155, 126, .10);
    --accent-line: rgba(13, 155, 126, .32);

    --ok:          #0f9c6c;
    --ok-soft:     rgba(15, 156, 108, .11);
    --warn:        #b47708;
    --warn-soft:   rgba(180, 119, 8, .12);
    --danger:      #d34848;
    --danger-soft: rgba(211, 72, 72, .11);
    --info:        #2b74d8;
    --info-soft:   rgba(43, 116, 216, .11);

    --shadow:      0 1px 2px rgba(16, 24, 32, .06), 0 10px 26px -14px rgba(16, 24, 32, .22);
    --shadow-lift: 0 2px 6px rgba(16, 24, 32, .08), 0 28px 60px -24px rgba(16, 24, 32, .30);
}

/* ── Base ─────────────────────────────────────────────────────────────── */

* { box-sizing: border-box; }
html, body { min-height: 100%; }

body {
    margin: 0;
    font-family: var(--ui);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: var(--canvas);
    background-image: var(--canvas-glow);
    background-attachment: fixed;
    -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }

/* Layout rules below use display:flex/grid, which would otherwise beat the
   hidden attribute the page toggles from script. */
[hidden] { display: none !important; }

::selection { background: var(--accent-soft); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--line);
    border: 3px solid transparent;
    border-radius: 8px;
    background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-3); background-clip: content-box; }

.icon { width: 1em; height: 1em; flex: none; fill: none; stroke: currentColor; stroke-width: 1.85; stroke-linecap: round; stroke-linejoin: round; }
.mono { font-family: var(--mono); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

/* ── Shell ────────────────────────────────────────────────────────────── */

.sd-shell {
    display: grid;
    grid-template-columns: var(--sidebar) minmax(0, 1fr);
    min-height: 100vh;
    transition: grid-template-columns .18s ease;
}
:root[data-sidebar="collapsed"] .sd-shell { grid-template-columns: var(--sidebar-thin) minmax(0, 1fr); }

.sd-col { min-width: 0; display: flex; flex-direction: column; }

/* ── Sidebar ──────────────────────────────────────────────────────────── */

.sd-sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-right: 1px solid var(--line-soft);
    overflow: hidden;
    z-index: 45;
}

.sd-sidebar-brand {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 14px 14px;
    border-bottom: 1px solid var(--line-soft);
    min-height: var(--topbar-h);
}
.sd-brand-mark {
    width: 36px; height: 36px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: 10px;
    font-size: 18px;
    color: var(--accent);
    background: var(--accent-soft);
    border: 1px solid var(--accent-line);
    overflow: hidden;
}
.sd-brand-mark img { width: 26px; height: 26px; object-fit: contain; display: block; }
.sd-wordmark { display: block; height: 15px; width: auto; max-width: 132px; object-fit: contain; }
.sd-sidebar-brand-text { display: flex; flex-direction: column; min-width: 0; }
.sd-sidebar-brand-text b { font-size: 14px; font-weight: 650; letter-spacing: -.01em; }
.sd-sidebar-brand-text small { font-size: 10.5px; color: var(--text-3); }

.sd-nav { flex: 1; overflow-y: auto; padding: 12px 9px; display: flex; flex-direction: column; gap: 16px; }
.sd-nav-section { display: flex; flex-direction: column; gap: 2px; }
.sd-nav-label {
    padding: 0 8px 5px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--text-3);
}

.sd-nav-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 550;
    color: var(--text-2);
    transition: background .13s, color .13s;
}
.sd-nav-item .icon { font-size: 17px; }
.sd-nav-item:hover { background: var(--surface-2); color: var(--text); }
.sd-nav-item.is-active {
    background: var(--accent-soft);
    color: var(--text);
    font-weight: 650;
}
.sd-nav-item.is-active::before {
    content: "";
    position: absolute;
    left: -9px; top: 50%;
    transform: translateY(-50%);
    width: 3px; height: 20px;
    border-radius: 0 3px 3px 0;
    background: var(--accent);
}
.sd-nav-item.is-active .icon { color: var(--accent); }
.sd-nav-item.is-disabled { color: var(--text-3); cursor: default; }
.sd-nav-item.is-disabled:hover { background: transparent; color: var(--text-3); }
.sd-nav-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sd-nav-tag {
    font-size: 9.5px;
    font-weight: 700;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: var(--text-3);
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 1px 6px;
}

.sd-sidebar-foot {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 11px 12px;
    border-top: 1px solid var(--line-soft);
}
.sd-user { display: flex; align-items: center; gap: 9px; min-width: 0; flex: 1; }
.sd-avatar {
    width: 30px; height: 30px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: 9px;
    font-size: 11px;
    font-weight: 700;
    color: var(--accent);
    background: var(--accent-soft);
    border: 1px solid var(--accent-line);
}
.sd-user-text { display: flex; flex-direction: column; min-width: 0; }
.sd-logout { display: flex; margin: 0; }
.sd-logout button:hover { color: var(--danger); }
.sd-user-text b { font-size: 12px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sd-user-text small { font-size: 10px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Collapsed rail: icons only */
:root[data-sidebar="collapsed"] .sd-sidebar-brand-text,
:root[data-sidebar="collapsed"] .sd-nav-text,
:root[data-sidebar="collapsed"] .sd-nav-tag,
:root[data-sidebar="collapsed"] .sd-nav-label,
:root[data-sidebar="collapsed"] .sd-user-text { display: none; }
:root[data-sidebar="collapsed"] .sd-sidebar-brand { justify-content: center; padding-left: 8px; padding-right: 8px; }
:root[data-sidebar="collapsed"] .sd-user { flex: none; }
:root[data-sidebar="collapsed"] .sd-nav-item { justify-content: center; padding: 10px 0; }
:root[data-sidebar="collapsed"] .sd-nav { gap: 10px; }
/* Stack the footer so the expand button still has room — hiding it would trap
   the sidebar in the collapsed state. */
:root[data-sidebar="collapsed"] .sd-sidebar-foot {
    flex-direction: column;
    justify-content: center;
    gap: 8px;
    padding: 10px 8px;
}
:root[data-sidebar="collapsed"] .sd-collapse .icon { transform: rotate(180deg); }

.sd-scrim {
    position: fixed;
    inset: 0;
    z-index: 44;
    background: rgba(4, 6, 8, .55);
    opacity: 0;
    visibility: hidden;
    transition: opacity .18s, visibility .18s;
}

/* ── Top bar ──────────────────────────────────────────────────────────── */

.sd-topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: var(--topbar-h);
    padding: 12px 20px;
    background: var(--canvas);
    background: color-mix(in srgb, var(--canvas) 84%, transparent);
    backdrop-filter: blur(14px) saturate(140%);
    border-bottom: 1px solid var(--line-soft);
}
.sd-page-title { min-width: 0; }
.sd-page-title h1 { margin: 0; font-size: 15px; font-weight: 650; letter-spacing: -.01em; white-space: nowrap; }
.sd-page-sub { display: flex; align-items: center; gap: 7px; font-size: 11.5px; color: var(--text-3); }
.sd-page-sub code {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--text-2);
    background: var(--surface-2);
    border: 1px solid var(--line-soft);
    border-radius: 5px;
    padding: 1px 6px;
}
.sd-topbar-spacer { flex: 1; }

.sd-stat-row { display: flex; gap: 8px; }
.sd-stat {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px 6px 10px;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--line-soft);
    font-size: 11.5px;
    color: var(--text-2);
    white-space: nowrap;
}
.sd-stat b { color: var(--text); font-weight: 650; font-variant-numeric: tabular-nums; }
.sd-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--text-3); }

/* Status colours shared by dots, badges and cards */
.st-0 { background: var(--warn); }
.st-1 { background: var(--ok); }
.st-2 { background: var(--warn); }
.st-3 { background: var(--info); }
.st-4 { background: var(--danger); }
.st-unknown { background: var(--text-3); }

/* ── Buttons ──────────────────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 8px 13px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    background: var(--surface-2);
    color: var(--text);
    font-size: 12.5px;
    font-weight: 550;
    white-space: nowrap;
    transition: background .14s ease, border-color .14s ease, color .14s ease, transform .12s ease, opacity .14s;
}
.btn:hover { background: var(--surface-3); border-color: var(--text-3); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn[disabled] { opacity: .42; pointer-events: none; }
.btn .icon { font-size: 13px; }

.btn-primary {
    background: var(--accent);
    border-color: transparent;
    color: var(--accent-text);
    font-weight: 650;
}
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 86%, #fff); border-color: transparent; }

.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--line-soft); color: var(--text); }

.btn-danger { color: var(--danger); border-color: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 34%, transparent); background: var(--danger-soft); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 22%, transparent); border-color: var(--danger); }

.btn-accent-soft { color: var(--accent); border-color: var(--accent-line); background: var(--accent-soft); }
.btn-accent-soft:hover { background: color-mix(in srgb, var(--accent) 20%, transparent); }

.btn-sm { padding: 5px 9px; font-size: 11.5px; gap: 5px; border-radius: var(--radius-xs); }
.btn-icon { padding: 7px; width: 32px; height: 32px; }
.btn-icon.btn-sm { width: 27px; height: 27px; padding: 0; }

/* Declared after .btn so it wins on source order (same specificity). */
.btn.sd-burger { display: none; }

/* ── Fields ───────────────────────────────────────────────────────────── */

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label {
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: .07em;
    text-transform: uppercase;
    color: var(--text-3);
}
.field-hint { font-size: 11.5px; color: var(--text-3); }
.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }

.input, .textarea, .select {
    width: 100%;
    padding: 8px 11px;
    background: var(--surface-in);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 13px;
    outline: none;
    transition: border-color .14s, box-shadow .14s, background .14s;
}
.input:focus, .textarea:focus, .select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.textarea { resize: vertical; min-height: 72px; font-family: var(--mono); font-size: 12.5px; line-height: 1.55; }

.select {
    appearance: none;
    padding-right: 30px;
    background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%), linear-gradient(135deg, var(--text-2) 50%, transparent 50%);
    background-position: calc(100% - 15px) 52%, calc(100% - 10px) 52%;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
    cursor: pointer;
}

.search { position: relative; display: flex; align-items: center; }
.search > .icon {
    position: absolute;
    left: 11px;
    font-size: 14px;
    color: var(--text-3);
    pointer-events: none;
}
.search .input { padding-left: 32px; }
.search-clear {
    position: absolute;
    right: 6px;
    display: none;
    place-items: center;
    width: 22px; height: 22px;
    border: 0; border-radius: 5px;
    background: transparent;
    color: var(--text-3);
}
.search-clear:hover { background: var(--surface-3); color: var(--text); }
.search.has-value .search-clear { display: grid; }

kbd {
    font-family: var(--ui);
    font-size: 10px;
    font-weight: 600;
    color: var(--text-3);
    background: var(--surface-3);
    border: 1px solid var(--line);
    border-bottom-width: 2px;
    border-radius: 5px;
    padding: 1px 5px;
}

.switch { position: relative; flex: none; width: 38px; height: 21px; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch span {
    position: absolute; inset: 0;
    background: var(--surface-3);
    border: 1px solid var(--line);
    border-radius: 999px;
    transition: background .16s, border-color .16s;
    pointer-events: none;
}
.switch span::after {
    content: "";
    position: absolute;
    top: 2px; left: 2px;
    width: 15px; height: 15px;
    border-radius: 50%;
    background: var(--text-3);
    transition: transform .16s ease, background .16s;
}
.switch input:checked + span { background: var(--accent); border-color: transparent; }
.switch input:checked + span::after { transform: translateX(17px); background: #fff; }
.switch input:focus-visible + span { box-shadow: 0 0 0 3px var(--accent-soft); }
.switch input:disabled + span { opacity: .5; }


/* ── Per-row actions menu ─────────────────────────────────────────────────
   Used by any table with a per-row Actions button. .panel clips its overflow,
   so a menu positioned inside a row would be cut off on the last rows — it is
   rendered at the end of <body> and placed from the button's rect instead,
   hence position: fixed. Driven by SD.rowMenu() in app.js. */

.row-menu-btn[aria-expanded="true"] { background: var(--surface-3); color: var(--text); }

.row-menu {
    position: fixed;
    z-index: 60;
    min-width: 152px;
    padding: 4px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
}
.row-menu button {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    padding: 7px 9px;
    border: 0;
    border-radius: var(--radius-xs);
    background: transparent;
    color: var(--text-2);
    font: inherit;
    font-size: 12.5px;
    text-align: left;
    cursor: pointer;
    transition: background .12s, color .12s;
}
.row-menu button:hover,
.row-menu button:focus-visible { background: var(--surface-2); color: var(--text); outline: none; }
.row-menu button .icon { font-size: 14px; color: var(--text-3); }
.row-menu button:hover .icon { color: inherit; }
.row-menu button.is-danger { color: var(--danger); }
.row-menu button.is-danger:hover,
.row-menu button.is-danger:focus-visible { background: var(--danger-soft); color: var(--danger); }
.row-menu button.is-danger .icon { color: currentColor; }
.row-menu-sep { height: 1px; margin: 4px 2px; background: var(--line-soft); }

/* ── Panels ───────────────────────────────────────────────────────────── */

.panel {
    background: var(--surface);
    border: 1px solid var(--line-soft);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.panel-head {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line-soft);
}
.panel-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--text-2);
}
.panel-title .icon { color: var(--accent); font-size: 14px; }
.panel-head-spacer { flex: 1; }

.pill {
    font-size: 11px;
    font-weight: 650;
    font-variant-numeric: tabular-nums;
    color: var(--accent);
    background: var(--accent-soft);
    border: 1px solid var(--accent-line);
    border-radius: 999px;
    padding: 2px 9px;
    white-space: nowrap;
}
.pill-quiet { color: var(--text-2); background: var(--surface-2); border-color: var(--line); }
.pill-danger { color: var(--danger); background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 32%, transparent); }

/* Tab strip — page sections (Settings) and any future segmented control. */
.tabs {
    display: flex;
    gap: 6px;
    padding: 11px 13px;
    border-bottom: 1px solid var(--line-soft);
    overflow-x: auto;
    scrollbar-width: thin;
}
.tab {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 13px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--surface-2);
    color: var(--text-2);
    font-size: 12.5px;
    font-weight: 550;
    white-space: nowrap;
    transition: background .13s, color .13s, border-color .13s;
}
.tab:hover { color: var(--text); border-color: var(--text-3); }
.tab[aria-selected="true"] {
    background: var(--accent);
    border-color: transparent;
    color: var(--accent-text);
    font-weight: 650;
}
.tab .icon { font-size: 14px; }

/* Segmented picker (theme, sidebar default …) */
.segment { display: inline-flex; padding: 3px; gap: 3px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.segment button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: 0;
    border-radius: var(--radius-xs);
    background: transparent;
    color: var(--text-2);
    font-size: 12.5px;
    font-weight: 550;
    transition: background .13s, color .13s;
}
.segment button:hover { color: var(--text); background: var(--surface-3); }
.segment button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); font-weight: 650; }

.chip-row { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 9px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: transparent;
    color: var(--text-2);
    font-size: 11px;
    font-weight: 550;
    transition: background .13s, border-color .13s, color .13s;
}
.chip:hover { background: var(--surface-2); color: var(--text); }
.chip[aria-pressed="true"] { color: var(--text); background: var(--surface-3); border-color: var(--text-3); }
.chip .sd-dot { width: 6px; height: 6px; }
.chip-count { font-size: 10px; color: var(--text-3); font-variant-numeric: tabular-nums; }

.tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    max-width: 100%;
    padding: 2px 8px;
    border-radius: 6px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    font-family: var(--mono);
    font-size: 11px;
    color: var(--text-2);
}
.tag b { color: var(--text); font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag-label { color: var(--text-3); }
.tag-on  { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 30%, transparent); background: var(--ok-soft); }
.tag-off { color: var(--text-3); }
.tag-empty { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 30%, transparent); background: var(--warn-soft); }

/* ── Overview page ────────────────────────────────────────────────────── */

.home-area {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 18px 20px 40px;
}

.home-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1px;
    background: var(--line-soft);
}
.home-stat { display: flex; flex-direction: column; gap: 3px; padding: 15px 16px; background: var(--surface); }
.home-stat-label { font-size: 10.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--text-3); }
.home-stat b { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }

.home-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 13px 16px; border-top: 1px solid var(--line-soft); }

/* Fills the width on wide screens instead of leaving a column of dead space. */
.home-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; }
.home-stats { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

.home-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 15px 16px;
    transition: border-color .14s, transform .14s, background .14s;
}
.home-card:hover { border-color: var(--accent-line); transform: translateY(-1px); }
.home-card.is-disabled { opacity: .6; }
.home-card.is-disabled:hover { border-color: var(--line-soft); transform: none; }
.home-card-mark {
    width: 38px; height: 38px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: 11px;
    font-size: 18px;
    color: var(--accent);
    background: var(--accent-soft);
    border: 1px solid var(--accent-line);
}
.home-card-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.home-card-text b { display: flex; align-items: center; gap: 7px; font-size: 13.5px; font-weight: 650; }
.home-card-text small { font-size: 11.5px; color: var(--text-3); }
.home-card-text code { font-family: var(--mono); font-size: 11px; color: var(--text-2); }
.home-card-go { font-size: 16px; color: var(--text-3); margin-left: auto; }

/* ── States ───────────────────────────────────────────────────────────── */

.state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 9px;
    padding: 58px 24px;
    text-align: center;
    color: var(--text-3);
}
.state .icon { font-size: 28px; color: var(--line); }
.state h3 { margin: 0; font-size: 13.5px; font-weight: 600; color: var(--text-2); }
.state p { margin: 0; font-size: 12px; max-width: 420px; }

.skeleton { padding: 13px; display: flex; flex-direction: column; gap: 9px; }
.skeleton-row {
    height: 34px;
    border-radius: var(--radius-xs);
    background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%);
    background-size: 300% 100%;
    animation: shimmer 1.25s ease-in-out infinite;
}
@keyframes shimmer { 0% { background-position: 150% 0; } 100% { background-position: -150% 0; } }

.spin { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Data workspace ───────────────────────────────────────────────────────
   Rail + table layout shared by Server Data and Global Data. */

.sd-work-area {
    flex: 1;
    display: grid;
    grid-template-columns: 292px minmax(0, 1fr);
    gap: 18px;
    align-items: start;
    padding: 18px 20px 40px;
}

.rail { position: sticky; top: calc(var(--topbar-h) + 18px); display: flex; flex-direction: column; }
.rail-tools {
    padding: 11px 11px 9px;
    display: flex;
    flex-direction: column;
    gap: 9px;
    border-bottom: 1px solid var(--line-soft);
}
.rail-list {
    list-style: none;
    margin: 0;
    padding: 7px;
    max-height: min(56vh, 600px);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.rail-item {
    display: grid;
    grid-template-columns: 9px minmax(0, 1fr) auto;
    align-items: center;
    gap: 9px;
    width: 100%;
    padding: 8px 10px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    text-align: left;
    color: var(--text-2);
    transition: background .13s, color .13s, border-color .13s;
}
.rail-item:hover { background: var(--surface-2); color: var(--text); }
.rail-item[aria-current="true"] {
    background: var(--accent-soft);
    border-color: var(--accent-line);
    color: var(--text);
}
.rail-item-name {
    font-size: 12.5px;
    font-weight: 550;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.rail-item[aria-current="true"] .rail-item-name { font-weight: 650; }
.rail-item-meta { font-size: 10px; color: var(--text-3); white-space: nowrap; }
.rail-empty { padding: 26px 14px; text-align: center; font-size: 12px; color: var(--text-3); }

.work { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

.work-head {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 13px 15px;
}
.work-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.work-title h2 {
    margin: 0;
    font-size: 16px;
    font-weight: 650;
    letter-spacing: -.01em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.work-title-meta { font-size: 11.5px; color: var(--text-3); }

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    background: var(--surface-2);
    border: 1px solid var(--line);
    color: var(--text-2);
}

.data-toolbar {
    display: flex;
    align-items: center;
    gap: 9px;
    flex-wrap: wrap;
    padding: 11px 13px;
    border-bottom: 1px solid var(--line-soft);
}
.data-toolbar .search { flex: 1; min-width: 190px; max-width: 340px; }
.data-toolbar-actions { display: flex; gap: 7px; margin-left: auto; flex-wrap: wrap; }

/* Container (not viewport) sized: the panel narrows with the sidebar and rail,
   so the rows restack based on their own width. */
.rows { display: flex; flex-direction: column; container-type: inline-size; }

.row-head {
    display: grid;
    grid-template-columns: minmax(110px, 240px) minmax(120px, 1fr) auto;
    gap: 12px;
    padding: 8px 15px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--line-soft);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .09em;
    text-transform: uppercase;
    color: var(--text-3);
    position: sticky;
    top: var(--topbar-h);
    z-index: 5;
}
.row-head span:last-child { text-align: right; }

.row {
    display: grid;
    grid-template-columns: minmax(110px, 240px) minmax(120px, 1fr) auto;
    gap: 12px;
    align-items: start;
    padding: 9px 15px;
    border-bottom: 1px solid var(--line-soft);
    border-left: 2px solid transparent;
    transition: background .12s, border-color .12s;
}
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--surface-2); }
.row.is-dirty { border-left-color: var(--warn); background: var(--warn-soft); }
.row.is-saved { border-left-color: var(--ok); }
.row.is-hidden { display: none; }

.row-key {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    padding-top: 6px;
    font-family: var(--mono);
    font-size: 12.5px;
    color: var(--text);
}
.row-key-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-key-copy {
    border: 0;
    background: transparent;
    color: var(--text-3);
    padding: 2px;
    border-radius: 4px;
    opacity: 0;
    transition: opacity .13s, color .13s;
}
.row:hover .row-key-copy { opacity: 1; }
.row-key-copy:hover { color: var(--accent); }

.row-val { min-width: 0; }
.row-val textarea {
    width: 100%;
    resize: none;
    overflow: hidden;
    padding: 6px 9px;
    background: var(--surface-in);
    border: 1px solid var(--line);
    border-radius: var(--radius-xs);
    color: var(--text);
    font-family: var(--mono);
    font-size: 12px;
    line-height: 1.5;
    outline: none;
    transition: border-color .13s, box-shadow .13s;
}
.row-val textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.row-val textarea[readonly] { color: var(--text-2); background: var(--surface-2); cursor: default; }

.row-summary { display: flex; flex-wrap: wrap; gap: 5px; padding-top: 3px; cursor: pointer; }
.row-acts { display: flex; justify-content: flex-end; gap: 5px; padding-top: 2px; }

/* Too tight for three columns — stack key, value and actions instead. */
@container (max-width: 560px) {
    .row { grid-template-columns: minmax(0, 1fr); gap: 7px; }
    .row-head { display: none; }
    .row-key { padding-top: 0; }
    .row-acts { justify-content: flex-start; }
}

@media (max-width: 1080px) {
    .sd-work-area { grid-template-columns: minmax(0, 1fr); }
    .rail { position: static; }
    .rail-list { max-height: 240px; }
}

@media (max-width: 720px) {
    .sd-work-area { padding: 14px 12px 32px; }
    .work-head { padding: 12px; }
}

/* ── Dialogs ──────────────────────────────────────────────────────────── */

.overlay {
    position: fixed;
    inset: 0;
    z-index: 90;
    display: grid;
    place-items: center;
    padding: 22px;
    background: rgba(4, 6, 8, .62);
    backdrop-filter: blur(3px);
    opacity: 0;
    visibility: hidden;
    transition: opacity .16s ease, visibility .16s;
}
.overlay.open { opacity: 1; visibility: visible; }

.dialog {
    width: 100%;
    max-width: 520px;
    max-height: min(86vh, 780px);
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lift);
    transform: translateY(8px) scale(.99);
    transition: transform .18s cubic-bezier(.2, .8, .3, 1);
}
.overlay.open .dialog { transform: none; }
.dialog-lg { max-width: 720px; }

.dialog-head {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 15px 17px;
    border-bottom: 1px solid var(--line-soft);
}
.dialog-icon {
    width: 34px; height: 34px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: 10px;
    font-size: 16px;
    background: var(--accent-soft);
    border: 1px solid var(--accent-line);
    color: var(--accent);
}
.dialog-icon.tone-danger { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 32%, transparent); color: var(--danger); }
.dialog-icon.tone-warn   { background: var(--warn-soft);   border-color: color-mix(in srgb, var(--warn) 32%, transparent);   color: var(--warn); }
.dialog-icon.tone-info   { background: var(--info-soft);   border-color: color-mix(in srgb, var(--info) 32%, transparent);   color: var(--info); }
.dialog-icon.tone-ok     { background: var(--ok-soft);     border-color: color-mix(in srgb, var(--ok) 32%, transparent);     color: var(--ok); }
.dialog-titles { min-width: 0; flex: 1; }
.dialog-title { margin: 0; font-size: 14.5px; font-weight: 650; }
.dialog-sub { font-size: 12px; color: var(--text-3); }

.dialog-body { padding: 17px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.dialog-body p { margin: 0; font-size: 13px; color: var(--text-2); line-height: 1.6; }
.dialog-body strong { color: var(--text); }
.dialog-foot {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 13px 17px;
    border-top: 1px solid var(--line-soft);
    background: var(--surface-2);
}

.code-block {
    font-family: var(--mono);
    font-size: 11.5px;
    line-height: 1.6;
    color: var(--text-2);
    background: var(--surface-in);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    max-height: 220px;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

.diff-line {
    display: flex;
    align-items: center;
    gap: 7px;
    font-family: var(--mono);
    font-size: 11.5px;
    padding: 3px 9px;
    border-left: 2px solid var(--line);
    border-radius: 0 4px 4px 0;
    background: var(--surface-2);
    color: var(--text-2);
}
.diff-add { border-left-color: var(--ok); background: var(--ok-soft); color: var(--text); }
.diff-del { border-left-color: var(--danger); background: var(--danger-soft); color: var(--text); }
.diff-group { display: flex; flex-direction: column; gap: 3px; max-height: 240px; overflow-y: auto; }

.entry-rows { display: flex; flex-direction: column; gap: 6px; max-height: 340px; overflow-y: auto; padding-right: 2px; }
.entry-row { display: grid; grid-template-columns: 26px minmax(0, 1fr) 32px; gap: 7px; align-items: center; }
.entry-drag { display: grid; place-items: center; height: 32px; border-radius: var(--radius-xs); color: var(--text-3); cursor: grab; }
.entry-drag:hover { background: var(--surface-2); color: var(--text); }
.entry-row.dragging { opacity: .45; }
.entry-row.drag-over .input { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ── Side sheet ───────────────────────────────────────────────────────── */

.sheet-overlay {
    position: fixed;
    inset: 0;
    z-index: 80;
    background: rgba(4, 6, 8, .55);
    backdrop-filter: blur(2px);
    opacity: 0;
    visibility: hidden;
    transition: opacity .18s, visibility .18s;
}
.sheet-overlay.open { opacity: 1; visibility: visible; }

.sheet {
    position: fixed;
    top: 0; right: 0;
    z-index: 81;
    width: min(560px, 100vw);
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-left: 1px solid var(--line);
    box-shadow: var(--shadow-lift);
    transform: translateX(100%);
    transition: transform .24s cubic-bezier(.2, .8, .25, 1);
}
.sheet.open { transform: none; }

/* A short, fixed-length form (the struct field editor) looks lost pinned to
   the bottom of a full-height drawer — shrink to content instead, capped so
   it still scrolls internally rather than running off the viewport. */
.sheet-compact { height: auto; max-height: 100%; }
.sheet-compact .sheet-body { flex: 0 1 auto; min-height: 0; }
.sheet-head {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 15px 17px;
    border-bottom: 1px solid var(--line-soft);
}
.sheet-body { flex: 1; overflow-y: auto; padding: 17px; display: flex; flex-direction: column; gap: 15px; }
.sheet-foot {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 13px 17px;
    border-top: 1px solid var(--line-soft);
    background: var(--surface-2);
}

/* Autocomplete */
.ac-wrap { position: relative; }
.ac {
    position: absolute;
    top: calc(100% + 5px);
    left: 0; right: 0;
    z-index: 20;
    max-height: 240px;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lift);
    display: none;
    padding: 4px;
}
.ac.open { display: block; }
.ac-item {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 6px 9px;
    border-radius: var(--radius-xs);
    font-family: var(--mono);
    font-size: 12px;
    color: var(--text-2);
    cursor: pointer;
}
.ac-item:hover, .ac-item.active { background: var(--surface-3); color: var(--text); }
.ac-item mark { background: transparent; color: var(--accent); font-weight: 700; }
.ac-empty { padding: 10px; font-size: 12px; color: var(--text-3); text-align: center; }

/* ── Toasts ───────────────────────────────────────────────────────────── */

.toasts {
    position: fixed;
    bottom: 18px; right: 18px;
    z-index: 120;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: min(380px, calc(100vw - 36px));
}
.toast {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    padding: 11px 13px;
    border-radius: var(--radius-sm);
    background: var(--surface);
    border: 1px solid var(--line);
    border-left: 3px solid var(--accent);
    box-shadow: var(--shadow-lift);
    font-size: 12.5px;
    color: var(--text);
    animation: toast-in .2s cubic-bezier(.2, .8, .3, 1);
}
.toast.leaving { animation: toast-out .16s ease forwards; }
.toast .icon { font-size: 15px; margin-top: 1px; color: var(--accent); }
.toast-body { flex: 1; min-width: 0; }
.toast-title { font-weight: 650; }
.toast-msg { color: var(--text-2); font-size: 12px; word-break: break-word; }
.toast-ok    { border-left-color: var(--ok); }
.toast-ok .icon { color: var(--ok); }
.toast-error { border-left-color: var(--danger); }
.toast-error .icon { color: var(--danger); }
.toast-warn  { border-left-color: var(--warn); }
.toast-warn .icon { color: var(--warn); }
.toast-close { border: 0; background: transparent; color: var(--text-3); padding: 2px; border-radius: 4px; }
.toast-close:hover { color: var(--text); background: var(--surface-3); }

@keyframes toast-in  { from { opacity: 0; transform: translateY(10px) scale(.98); } }
@keyframes toast-out { to   { opacity: 0; transform: translateX(14px); } }

/* ── Responsive ───────────────────────────────────────────────────────── */

@media (max-width: 960px) {
    .sd-shell { grid-template-columns: minmax(0, 1fr); }
    :root[data-sidebar="collapsed"] .sd-shell { grid-template-columns: minmax(0, 1fr); }

    .sd-sidebar {
        position: fixed;
        top: 0; left: 0;
        width: var(--sidebar);
        transform: translateX(-100%);
        transition: transform .22s cubic-bezier(.2, .8, .25, 1);
    }
    :root[data-sidebar="open"] .sd-sidebar { transform: none; }
    :root[data-sidebar="open"] .sd-scrim { opacity: 1; visibility: visible; }

    /* The collapsed rail styles must not apply to the mobile drawer. */
    :root[data-sidebar="collapsed"] .sd-sidebar-brand-text,
    :root[data-sidebar="collapsed"] .sd-nav-text,
    :root[data-sidebar="collapsed"] .sd-nav-tag,
    :root[data-sidebar="collapsed"] .sd-nav-label,
    :root[data-sidebar="collapsed"] .sd-user-text { display: revert; }
    :root[data-sidebar="collapsed"] .sd-nav-item { justify-content: flex-start; padding: 9px 10px; }

    .btn.sd-burger { display: inline-flex; }
    .sd-stat-row { display: none; }
}

@media (max-width: 720px) {
    .sd-topbar { padding: 10px 12px; }
}

@media (prefers-reduced-motion: reduce) {
    * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
