:root {
    color-scheme: dark;
    --bg: #0a0c10;
    --panel: #11151b;
    --panel-2: #171c24;
    --line: #29313d;
    --muted: #8f9baa;
    --text: #edf2f7;
    --accent: #86efac;
    --accent-strong: #22c55e;
    --danger: #fb7185;
    font-family: Inter, system-ui, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.topbar { height: 68px; padding: 0 32px; border-bottom: 1px solid var(--line); background: rgba(10, 12, 16, .88); backdrop-filter: blur(16px); display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 10; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 700; }
.brand img { width: 30px; height: 30px; object-fit: contain; }
.admin-pill { padding: 3px 8px; border: 1px solid #315541; border-radius: 999px; color: var(--accent); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
.top-actions, .catalog-actions, .tabs { display: flex; align-items: center; gap: 8px; }

.shell { width: min(1320px, calc(100% - 40px)); margin: 0 auto; padding: 50px 0 80px; }
.hero { display: flex; justify-content: space-between; gap: 32px; align-items: end; margin-bottom: 28px; }
.eyebrow { margin: 0 0 8px; color: var(--accent); font-size: 12px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
h1 { margin: 0; font-size: clamp(34px, 5vw, 58px); letter-spacing: -.055em; }
h2 { margin: 0; font-size: 23px; letter-spacing: -.025em; }
.hero-copy { max-width: 700px; margin: 14px 0 0; color: var(--muted); line-height: 1.65; }
.revision-box { min-width: 190px; padding: 15px 17px; border: 1px solid var(--line); border-radius: 14px; background: rgba(17, 21, 27, .75); display: grid; gap: 6px; }
.revision-box span:first-child { color: var(--muted); font-size: 12px; }
.revision-box code { color: var(--accent); }
.clean-state, .dirty-state { font-size: 12px; }
.clean-state { color: var(--muted); }
.dirty-state { color: #fde68a; }

.notice { display: none; padding: 13px 16px; margin-bottom: 18px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.notice.visible { display: block; }
.notice.success { border-color: #24643d; color: var(--accent); }
.notice.error { border-color: #7f293b; color: #fda4af; }

.summary-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.summary-grid article { padding: 18px 20px; border: 1px solid var(--line); border-radius: 14px; background: rgba(23, 28, 36, .94); }
.summary-grid span { display: block; margin-bottom: 8px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .07em; }
.summary-grid strong { font-size: 28px; }

.workspace { border: 1px solid var(--line); border-radius: 18px; overflow: hidden; background: rgba(17, 21, 27, .9); box-shadow: 0 26px 70px rgba(0, 0, 0, .28); }
.workspace-head { padding: 16px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 14px; }
.tab { padding: 9px 13px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); cursor: pointer; }
.tab.active { color: var(--text); background: #232a34; }
.ghost-button, .primary-button, .secondary-button, .icon-button { border-radius: 9px; cursor: pointer; transition: border-color .15s, background .15s, opacity .15s; }
.ghost-button { padding: 9px 13px; border: 1px solid var(--line); background: transparent; color: var(--text); text-decoration: none; }
.ghost-button:hover { border-color: #4a586a; background: #1b212a; }
.primary-button { padding: 10px 15px; border: 1px solid var(--accent-strong); background: var(--accent-strong); color: #06120a; font-weight: 700; }
.primary-button:disabled { opacity: .38; cursor: not-allowed; }
.secondary-button { padding: 10px 15px; border: 1px solid #315541; background: #12281a; color: var(--accent); font-weight: 600; }
.icon-button { width: 38px; height: 38px; border: 1px solid var(--line); background: transparent; color: var(--muted); font-size: 24px; }

.filters { padding: 16px 18px; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: minmax(220px, 1fr) 220px minmax(max-content, 1fr); gap: 10px; }
.filters input, .filters select { width: 100%; height: 42px; border: 1px solid var(--line); border-radius: 9px; background: #0d1116; color: var(--text); padding: 0 12px; outline: none; }
.filters input:focus, .filters select:focus, .form-grid input:focus, .form-grid select:focus, .form-grid textarea:focus { border-color: #3e8f5c; box-shadow: 0 0 0 3px rgba(34, 197, 94, .1); }
.filter-actions { grid-column: 3; display: flex; justify-content: flex-end; gap: 10px; }

.catalog-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 12px; padding: 18px; }
.catalog-card { min-width: 0; padding: 17px; border: 1px solid var(--line); border-radius: 13px; background: var(--panel-2); }
.card-head { display: flex; align-items: start; justify-content: space-between; gap: 10px; }
.card-title { min-width: 0; }
.card-title h3 { margin: 0 0 5px; font-size: 16px; overflow-wrap: anywhere; }
.card-title code { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.badge { flex: none; padding: 4px 8px; border-radius: 999px; background: #233029; color: var(--accent); font-size: 11px; }
.badge.disabled, .badge.deprecated { background: #34232a; color: #fda4af; }
.card-meta { display: grid; gap: 7px; margin: 17px 0; color: var(--muted); font-size: 13px; }
.card-meta div { display: flex; justify-content: space-between; gap: 16px; }
.card-meta span:last-child { color: #ccd5df; text-align: right; overflow-wrap: anywhere; }
.card-actions { display: flex; gap: 8px; padding-top: 13px; border-top: 1px solid var(--line); }
.card-actions button { flex: 1; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: transparent; color: var(--text); cursor: pointer; }
.card-actions .delete-action { flex: 0 0 auto; color: var(--danger); }
.empty-state { padding: 70px 24px; color: var(--muted); text-align: center; }

.catalog-grid.table-view { display: block; padding: 0; }
.catalog-table-wrap { overflow-x: auto; padding: 0 18px 18px; }
.catalog-table { width: 100%; min-width: 900px; border-collapse: collapse; font-size: 13px; }
.catalog-table th { padding: 15px 12px 11px; border-bottom: 1px solid #3a4553; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .08em; text-align: left; text-transform: uppercase; white-space: nowrap; }
.catalog-table td { padding: 15px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.catalog-table tbody tr { transition: background .15s; }
.catalog-table tbody tr:hover { background: rgba(35, 42, 52, .48); }
.table-entity-cell { min-width: 180px; }
.table-entity-name { display: block; margin-bottom: 5px; color: var(--text); font-size: 14px; }
.table-entity-key, .table-code { color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }
.table-code { display: block; max-width: 220px; }
.table-list { min-width: 150px; color: #ccd5df; overflow-wrap: anywhere; }
.console-link { color: var(--accent); text-decoration: none; border-bottom: 1px solid rgba(134, 239, 172, .35); overflow-wrap: anywhere; }
.console-link:hover { border-bottom-color: var(--accent); }
.table-multimodal { min-width: 190px; color: #ccd5df; }
.table-status .badge { display: inline-block; }
.table-actions { display: flex; gap: 7px; }
.table-actions button { padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: transparent; color: var(--text); cursor: pointer; white-space: nowrap; }
.table-actions .delete-action { color: var(--danger); }

.editor-dialog { width: min(760px, calc(100% - 28px)); max-height: calc(100vh - 40px); padding: 0; border: 1px solid var(--line); border-radius: 18px; background: #11151b; color: var(--text); box-shadow: 0 30px 90px #000; }
.editor-dialog::backdrop { background: rgba(0, 0, 0, .72); backdrop-filter: blur(4px); }
.editor-dialog form { padding: 22px; }
.compact-dialog { width: min(560px, calc(100% - 28px)); }
.delete-model-name { font-weight: 600; overflow-wrap: anywhere; }
.danger-button { color: var(--danger); border-color: var(--danger); }
#deleteModelImpact { line-height: 1.6; }
.dialog-head { display: flex; justify-content: space-between; align-items: start; margin-bottom: 22px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid.single-column { grid-template-columns: 1fr; }
.form-grid label { display: grid; gap: 7px; color: #cdd5df; font-size: 13px; font-weight: 600; }
.form-grid label.wide { grid-column: 1 / -1; }
.form-grid input, .form-grid select, .form-grid textarea { width: 100%; border: 1px solid var(--line); border-radius: 9px; background: #0b0f14; color: var(--text); padding: 10px 11px; outline: none; }
.form-grid textarea { resize: vertical; line-height: 1.5; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.form-grid small { color: var(--muted); font-weight: 400; line-height: 1.4; }
.modality-fieldset { min-width: 0; margin: 0; padding: 14px; border: 1px solid var(--line); border-radius: 11px; }
.modality-fieldset legend { padding: 0 7px; color: #cdd5df; font-size: 13px; font-weight: 600; }
.modality-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modality-grid label { display: grid; gap: 7px; color: #cdd5df; font-size: 13px; font-weight: 600; }
.modality-fieldset > small { display: block; margin-top: 11px; }
.modality-fieldset code { color: #ccd5df; }
.form-grid label.check { display: flex; align-items: center; gap: 9px; }
.form-grid label.check input { width: 17px; height: 17px; accent-color: var(--accent-strong); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--line); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 820px) {
    .topbar { padding: 0 18px; }
    .shell { width: min(100% - 24px, 1320px); padding-top: 30px; }
    .hero { align-items: start; flex-direction: column; }
    .revision-box { width: 100%; }
    .summary-grid { grid-template-columns: 1fr 1fr; }
    .workspace-head { align-items: stretch; flex-direction: column; }
    .catalog-actions { justify-content: flex-end; }
    .filters { grid-template-columns: 1fr; }
    .filter-actions { grid-column: auto; }
    .form-grid { grid-template-columns: 1fr; }
    .form-grid label.wide { grid-column: auto; }
    .modality-grid { grid-template-columns: 1fr; }
}

@media (max-width: 500px) {
    .top-actions .ghost-button:first-child { display: none; }
    .summary-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .summary-grid article { padding: 14px; }
    .catalog-actions { display: grid; grid-template-columns: 1fr 1fr 1.4fr; }
    .catalog-actions button { padding-inline: 8px; }
    .catalog-grid { grid-template-columns: 1fr; padding: 12px; }
    .catalog-table-wrap { padding: 0 12px 12px; }
    .filter-actions { justify-content: stretch; }
    .filter-actions button { flex: 1; }
}
