:root {
    --paper: #f4f1ea;
    --paper-2: #ebe6dc;
    --ink: #14171b;
    --ink-2: #2a3038;
    --muted: #68707b;
    --line: #c9c2b5;
    --line-strong: #9e9688;
    --panel: #fffdf8;
    --rail: #171b20;
    --rail-2: #20262e;
    --accent: #0f5f9f;
    --accent-2: #0b7c86;
    --warning: #a56300;
    --danger: #b3261e;
    --ok: #256b3b;
    --shadow: 0 24px 80px rgba(34, 29, 22, 0.12);
    --font: "Aptos", "Segoe UI Variable", "Segoe UI", sans-serif;
    --mono: "Cascadia Mono", "JetBrains Mono", "Consolas", monospace;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    background:
        linear-gradient(90deg, rgba(20, 23, 27, 0.035) 1px, transparent 1px),
        linear-gradient(0deg, rgba(20, 23, 27, 0.025) 1px, transparent 1px),
        linear-gradient(135deg, #f9f6ef 0%, var(--paper) 48%, #e7edf0 100%);
    background-size: 40px 40px, 40px 40px, auto;
    color: var(--ink);
    font-family: var(--font);
}

button,
input,
select {
    font: inherit;
}

button {
    border-radius: 0;
}

.hidden {
    display: none !important;
}

.login-view {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 32px;
}

.login-card {
    width: min(480px, 100%);
    border: 1px solid var(--line-strong);
    background: var(--panel);
    padding: 34px;
    box-shadow: var(--shadow);
}

.login-card h1,
.topbar h1,
.command-panel h2,
.empty-state h2 {
    margin: 0;
    letter-spacing: -0.035em;
}

.login-card h1 {
    font-size: clamp(32px, 5vw, 52px);
    line-height: 0.95;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 292px minmax(0, 1fr);
}

.rail {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 22px;
    padding: 22px;
    border-right: 1px solid #0b0d10;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent 30%),
        var(--rail);
    color: #f5efe4;
}

.brand {
    display: grid;
    grid-template-columns: 46px minmax(0, 1fr);
    gap: 12px;
    align-items: center;
    padding-bottom: 18px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 46px;
    height: 46px;
    border: 1px solid rgba(255, 255, 255, 0.35);
    background: #f5efe4;
    color: var(--rail);
    font-weight: 850;
    letter-spacing: -0.08em;
}

.brand-title {
    font-size: 21px;
    font-weight: 820;
    letter-spacing: -0.04em;
}

.brand-subtitle,
.rail-label,
.rail-search span,
.eyebrow,
.muted,
.cell-secondary,
th,
.topbar-meta,
.counter {
    color: var(--muted);
}

.rail .muted,
.rail-label,
.rail-search span,
.brand-subtitle {
    color: rgba(245, 239, 228, 0.62);
}

.rail-section {
    border: 1px solid rgba(255, 255, 255, 0.14);
    padding: 13px;
    background: rgba(255, 255, 255, 0.035);
}

.rail-value {
    margin-top: 6px;
    overflow: hidden;
    color: #fffdf8;
    font-weight: 760;
    text-overflow: ellipsis;
}

.rail-search {
    display: grid;
    gap: 8px;
}

.rail-search input,
.field input,
.toolbar select,
.toolbar input,
.inspector input,
.inspector select {
    width: 100%;
    min-height: 40px;
    border: 1px solid var(--line-strong);
    border-radius: 0;
    background: #fffdf8;
    color: var(--ink);
    padding: 9px 10px;
}

.rail-search input {
    border-color: rgba(255, 255, 255, 0.2);
    background: #101318;
    color: #fffdf8;
}

input:focus,
select:focus,
button:focus-visible {
    outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent);
    outline-offset: 2px;
}

.nav-list {
    display: grid;
    gap: 6px;
}

.nav-item {
    width: 100%;
    border: 1px solid transparent;
    background: transparent;
    color: rgba(245, 239, 228, 0.72);
    cursor: pointer;
    padding: 11px 12px;
    text-align: left;
}

.nav-item:hover,
.nav-item.active {
    border-color: rgba(255, 255, 255, 0.18);
    background: var(--rail-2);
    color: #fffdf8;
}

.rail-footer {
    display: grid;
    gap: 9px;
    margin-top: auto;
}

.workspace {
    min-width: 0;
    padding: 28px;
}

.topbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 20px;
}

.topbar h1 {
    font-size: clamp(28px, 4vw, 46px);
    line-height: 0.98;
}

.topbar-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    justify-content: flex-end;
    font-size: 13px;
}

.section {
    display: none;
}

.section.active {
    display: grid;
    gap: 18px;
}

.hero-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.55fr) minmax(320px, 0.85fr);
    gap: 18px;
}

.split-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.registry-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(360px, 460px);
    gap: 18px;
    align-items: start;
}

.command-panel,
.inspector {
    border: 1px solid var(--line);
    background: color-mix(in srgb, var(--panel) 92%, white);
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset;
}

.command-panel {
    padding: 18px;
}

.inspector {
    position: sticky;
    top: 18px;
    max-height: calc(100vh - 56px);
    overflow: auto;
    padding: 0;
}

.panel-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
}

.eyebrow {
    margin: 0 0 7px;
    font-size: 11px;
    font-weight: 850;
    letter-spacing: 0.13em;
    text-transform: uppercase;
}

.muted {
    line-height: 1.55;
}

.mono {
    font-family: var(--mono);
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}

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

.metric {
    min-height: 104px;
    border: 1px solid var(--line);
    background: #fbf8f1;
    padding: 13px;
}

.metric-label {
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.metric-value {
    margin-top: 12px;
    font-size: clamp(24px, 3vw, 34px);
    font-weight: 860;
    letter-spacing: -0.045em;
}

.metric-note {
    margin-top: 8px;
    color: var(--muted);
    font-size: 13px;
}

.focus-list,
.feature-matrix,
.action-stack,
.stack {
    display: grid;
    gap: 10px;
}

.focus-item,
.feature-row,
.operation-result {
    border-left: 4px solid var(--line-strong);
    background: #fbf8f1;
    padding: 12px;
}

.focus-item.ok {
    border-left-color: var(--ok);
}

.focus-item.warn {
    border-left-color: var(--warning);
}

.focus-item.danger {
    border-left-color: var(--danger);
}

.feature-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 12px;
}

.toolbar label {
    display: grid;
    min-width: 180px;
    gap: 6px;
    color: var(--muted);
    font-size: 13px;
}

.table-wrap {
    overflow: auto;
    border: 1px solid var(--line);
    background: #fffdf8;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 11px 12px;
    border-bottom: 1px solid #e2dbcf;
    text-align: left;
    vertical-align: top;
}

th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #ede7dc;
    font-size: 11px;
    font-weight: 850;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

td {
    font-size: 14px;
}

tr[data-chat-id],
tr[data-row-click] {
    cursor: pointer;
}

tr[data-chat-id]:hover,
tr[data-row-click]:hover {
    background: #f7f1e7;
}

tr.selected {
    background: #eef5f4;
    box-shadow: inset 4px 0 0 var(--accent-2);
}

.cell-primary {
    font-weight: 780;
}

.cell-secondary {
    margin-top: 4px;
    font-size: 12px;
    line-height: 1.45;
}

.status,
.counter,
.rect-badge {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    border: 1px solid var(--line-strong);
    background: #fffdf8;
    padding: 5px 8px;
    font-size: 12px;
    font-weight: 780;
    white-space: nowrap;
}

.status.ok,
.rect-badge.ok {
    border-color: color-mix(in srgb, var(--ok) 60%, var(--line));
    color: var(--ok);
}

.status.warn,
.rect-badge.warn {
    border-color: color-mix(in srgb, var(--warning) 60%, var(--line));
    color: var(--warning);
}

.status.danger,
.rect-badge.danger {
    border-color: color-mix(in srgb, var(--danger) 60%, var(--line));
    color: var(--danger);
}

.button {
    border: 1px solid var(--line-strong);
    background: #fffdf8;
    color: var(--ink);
    cursor: pointer;
    min-height: 38px;
    padding: 9px 12px;
    font-weight: 780;
}

.button:hover {
    transform: translateY(-1px);
}

.button.primary {
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
}

.button.secondary {
    border-color: var(--ink-2);
    background: var(--ink-2);
    color: #fffdf8;
}

.button.ghost {
    background: transparent;
    color: inherit;
}

.button.danger {
    border-color: var(--danger);
    background: #fff7f4;
    color: var(--danger);
}

.button.small {
    min-height: 30px;
    padding: 6px 8px;
    font-size: 12px;
}

.action-row {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}

.table-link {
    color: var(--accent);
    font-weight: 800;
    text-decoration: none;
}

.table-link:hover {
    text-decoration: underline;
}

.notice,
.toast {
    border: 1px solid var(--line-strong);
    background: #fff9e9;
    color: #6b3f00;
    padding: 12px 14px;
}

.notice {
    margin-bottom: 16px;
}

.toast {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 20;
    max-width: min(460px, calc(100vw - 44px));
    background: var(--ink);
    color: #fffdf8;
}

.field {
    display: grid;
    gap: 7px;
}

.field span {
    color: var(--muted);
    font-size: 13px;
}

.inspector-block {
    padding: 16px;
    border-bottom: 1px solid var(--line);
}

.inspector-block h3 {
    margin: 0 0 10px;
    font-size: 16px;
}

.inspector-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.check-line {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 36px;
}

.check-line input {
    width: auto;
}

.empty-state {
    padding: 22px;
}

.mini-list {
    display: grid;
    gap: 8px;
}

.mini-row {
    border: 1px solid #e2dbcf;
    background: #fbf8f1;
    padding: 10px;
}

.permissions-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
}

.permission-row {
    border: 1px solid #e2dbcf;
    padding: 10px;
    background: #fffdf8;
}

.permission-controls {
    display: grid;
    grid-template-columns: minmax(120px, 0.9fr) repeat(4, minmax(70px, 1fr)) auto;
    gap: 8px;
    align-items: center;
    margin-top: 8px;
}

.coverage-list {
    margin: 0;
    padding-left: 18px;
    color: var(--ink-2);
    line-height: 1.65;
}

@media (max-width: 1280px) {
    .metric-grid,
    .metric-grid.compact {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .hero-grid,
    .split-grid,
    .registry-layout {
        grid-template-columns: 1fr;
    }

    .inspector {
        position: static;
        max-height: none;
    }
}

@media (max-width: 860px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .rail {
        position: static;
        height: auto;
    }

    .workspace {
        padding: 18px;
    }

    .topbar {
        display: grid;
    }

    .metric-grid,
    .metric-grid.compact,
    .inspector-grid,
    .permission-controls {
        grid-template-columns: 1fr;
    }
}
