/* ─── Reset & tokens ──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    color-scheme: light;

    --accent:       #2563eb;
    --accent-hover: #1d4ed8;
    --accent-light: #eff6ff;

    --bg:           #f8fafc;
    --bg-card:      #ffffff;
    --bg-sidebar:   #1e293b;

    --text:         #0f172a;
    --text-muted:   #64748b;
    --text-sidebar: #cbd5e1;

    --border:       #e2e8f0;
    --border-focus: #93c5fd;

    --success:      #16a34a;
    --success-bg:   #f0fdf4;
    --success-bdr:  #86efac;

    --error:        #dc2626;
    --error-bg:     #fef2f2;
    --error-bdr:    #fca5a5;

    --warn:         #d97706;
    --warn-bg:      #fffbeb;
    --warn-bdr:     #fcd34d;

    --danger:       #dc2626;
    --danger-hover: #b91c1c;

    --radius:       8px;
    --radius-lg:    12px;
    --shadow:       0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md:    0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);

    /* Access-class ramp G < F < E < D < C < B < A < S */
    --access-G-bg: #f1f5f9; --access-G-text: #475569; --access-G-border: #94a3b8;
    --access-F-bg: #f8fafc; --access-F-text: #334155; --access-F-border: #cbd5e1;
    --access-E-bg: #f0fdf4; --access-E-text: #15803d; --access-E-border: #22c55e;
    --access-D-bg: #eff6ff; --access-D-text: #1d4ed8; --access-D-border: #3b82f6;
    --access-C-bg: #f5f3ff; --access-C-text: #6d28d9; --access-C-border: #8b5cf6;
    --access-B-bg: #fff7ed; --access-B-text: #c2410c; --access-B-border: #f97316;
    --access-A-bg: #fefce8; --access-A-text: #a16207; --access-A-border: #eab308;
    --access-S-bg: #fef2f2; --access-S-text: #b91c1c; --access-S-border: #ef4444;
}

@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;

        --accent:       #3b82f6;
        --accent-hover: #60a5fa;
        --accent-light: #1e3a5f;

        --bg:           #0f172a;
        --bg-card:      #1e293b;
        --bg-sidebar:   #0f172a;

        --text:         #f1f5f9;
        --text-muted:   #94a3b8;
        --text-sidebar: #94a3b8;

        --border:       #334155;
        --border-focus: #3b82f6;

        --success-bg:   #052e16;
        --success-bdr:  #166534;
        --error-bg:     #2d0a0a;
        --error-bdr:    #7f1d1d;
        --warn-bg:      #27180a;
        --warn-bdr:     #92400e;

        --access-G-bg: #1e293b; --access-G-text: #cbd5e1; --access-G-border: #64748b;
        --access-F-bg: #1e293b; --access-F-text: #94a3b8; --access-F-border: #475569;
        --access-E-bg: #052e16; --access-E-text: #4ade80; --access-E-border: #22c55e;
        --access-D-bg: #1e3a5f; --access-D-text: #93c5fd; --access-D-border: #3b82f6;
        --access-C-bg: #2e1065; --access-C-text: #c4b5fd; --access-C-border: #8b5cf6;
        --access-B-bg: #27180a; --access-B-text: #fdba74; --access-B-border: #f97316;
        --access-A-bg: #27200a; --access-A-text: #fde047; --access-A-border: #eab308;
        --access-S-bg: #2d0a0a; --access-S-text: #fca5a5; --access-S-border: #ef4444;
    }
}

html { font-size: 16px; -webkit-font-smoothing: antialiased; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { line-height: 1.25; }

/* ─── Layout ──────────────────────────────────────────────── */
.layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 232px;
    flex-shrink: 0;
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 10;
}

.sidebar-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 18px 16px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}

.sidebar-logo {
    max-width: 150px;
    max-height: 44px;
    object-fit: contain;
}

.sidebar-tagline {
    font-size: 11px;
    color: rgba(255,255,255,.4);
    letter-spacing: .05em;
    text-transform: uppercase;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
}

.nav-section-label {
    margin: 14px 12px 4px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: rgba(255,255,255,.3);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius);
    color: var(--text-sidebar);
    font-size: 14px;
    text-decoration: none;
    transition: background .15s, color .15s;
}
.nav-item svg { flex-shrink: 0; }
.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; text-decoration: none; }
.nav-item.active { background: rgba(59,130,246,.25); color: #93c5fd; }

.sidebar-settings {
    padding: 8px;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px;
    border-top: 1px solid rgba(255,255,255,.08);
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 13px; font-weight: 500; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-login { font-size: 11px; color: var(--text-sidebar); }

.logout-btn {
    color: var(--text-sidebar);
    opacity: .6;
    transition: opacity .15s;
    display: flex;
}
.logout-btn:hover { opacity: 1; text-decoration: none; }

.content {
    flex: 1;
    margin-left: 232px;
    padding: 32px;
    max-width: 1320px;
}

@media (max-width: 900px) {
    .sidebar { position: static; width: 100%; }
    .content { margin-left: 0; max-width: 100%; padding: 20px; }
    .layout { flex-direction: column; }
}

/* ─── Page header ─────────────────────────────────────────── */
.page-header,
.section-headline {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.section-headline h1,
.page-header h1 {
    margin: 0;
    font-size: 30px;
    line-height: 1.15;
}

.section-headline p {
    max-width: 780px;
    margin: 10px 0 0;
    color: var(--text-muted);
    font-size: 15px;
    line-height: 1.55;
}

.header-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.hero-badge {
    display: inline-flex;
    width: fit-content;
    margin-bottom: 12px;
    padding: 5px 12px;
    border-radius: 999px;
    background: var(--accent-light);
    color: var(--accent);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .02em;
    text-transform: uppercase;
}

/* ─── Cards / panels ──────────────────────────────────────── */
.panel,
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 22px 24px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.console-shell,
.compact-shell {
    display: grid;
    gap: 20px;
}

.panel h2,
.form-panel h2 {
    margin: 0 0 16px;
    font-size: 16px;
    font-weight: 600;
}

/* Console home hero */
.console-hero {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 280px;
    gap: 28px;
    align-items: center;
}

.console-hero h1 {
    margin: 0;
    font-size: 36px;
    line-height: 1.1;
}

.console-hero p {
    max-width: 720px;
    margin: 14px 0 0;
    color: var(--text-muted);
    font-size: 16px;
    line-height: 1.55;
}

.console-logo-wrap {
    display: grid;
    place-items: center;
    min-height: 150px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
}

.console-logo {
    max-width: 220px;
    max-height: 110px;
    object-fit: contain;
}

.console-note {
    padding: 14px 16px;
    border: 1px solid var(--border-focus);
    border-radius: var(--radius);
    background: var(--accent-light);
    color: var(--text);
    line-height: 1.55;
    font-size: 14px;
}

.console-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}

.console-card {
    display: block;
    min-height: 170px;
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--bg-card);
    box-shadow: var(--shadow);
    text-decoration: none;
    transition: transform .12s, box-shadow .12s, border-color .12s;
}
.console-card:hover {
    text-decoration: none;
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--border-focus);
}

.console-card span {
    display: inline-flex;
    margin-bottom: 12px;
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
}

.console-card h2 {
    margin: 0 0 8px;
    font-size: 19px;
}

.console-card p {
    margin: 0;
    color: var(--text-muted);
    font-size: 14px;
    line-height: 1.5;
}

@media (max-width: 900px) {
    .console-hero,
    .console-grid {
        grid-template-columns: 1fr;
    }
    .console-hero h1 { font-size: 28px; }
}

/* ─── Stat tiles ──────────────────────────────────────────── */
.metric-grid,
.two-column-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
}

.two-column-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.metric-card {
    display: grid;
    gap: 4px;
    padding: 18px 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--bg-card);
    box-shadow: var(--shadow);
    text-decoration: none;
}
.metric-card:hover { text-decoration: none; border-color: var(--border-focus); }

.metric-card span {
    font-size: 30px;
    font-weight: 700;
    line-height: 1;
    color: var(--accent);
}

.metric-card strong {
    font-size: 14px;
    font-weight: 600;
    margin-top: 4px;
}

.metric-card small,
.row-link span,
.empty-text {
    color: var(--text-muted);
    font-size: 13px;
}

.muted-card span { color: var(--text-muted); }

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

.row-link {
    display: grid;
    gap: 4px;
    padding: 12px 14px;
    border-radius: var(--radius);
    text-decoration: none;
    transition: background .12s;
}
.row-link:hover { background: var(--bg); text-decoration: none; }
.row-link strong { font-size: 14px; }

@media (max-width: 900px) {
    .metric-grid, .two-column-grid { grid-template-columns: 1fr; }
}

/* ─── Forms ───────────────────────────────────────────────── */
.form-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    align-items: end;
}

.compact-form {
    grid-template-columns: minmax(240px, 2fr) repeat(3, minmax(120px, 1fr));
}

.form-grid label {
    display: grid;
    gap: 6px;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
}

.wide-field { grid-column: 1 / -1; }

.check-field {
    display: flex !important;
    grid-template-columns: none !important;
    flex-direction: row !important;
    align-items: center;
    gap: 8px !important;
    min-height: 40px;
}
.check-field input { width: auto; }

input:not([type="checkbox"]):not([type="radio"]),
textarea,
select {
    width: 100%;
    min-height: 40px;
    padding: 9px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
    background: var(--bg);
    color: var(--text);
    transition: border-color .15s, box-shadow .15s;
    outline: none;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, textarea:focus, select:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}
input[type="checkbox"] { width: auto; min-height: auto; accent-color: var(--accent); }

/* ─── Buttons ─────────────────────────────────────────────── */
button,
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    min-height: 42px;
    padding: 0 18px;
    border: none;
    border-radius: var(--radius);
    background: var(--accent);
    color: #fff;
    font: inherit;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background .15s, opacity .15s;
}
button:hover,
.button:hover { background: var(--accent-hover); text-decoration: none; color: #fff; }
button:disabled { opacity: .55; cursor: not-allowed; }

.button.compact,
button.compact {
    width: auto;
    min-width: 120px;
    min-height: 36px;
    padding: 0 14px;
    font-size: 13px;
}

.button.secondary {
    background: var(--border);
    color: var(--text);
}
.button.secondary:hover { filter: brightness(.94); color: var(--text); }

.danger-button {
    width: auto;
    min-height: 34px;
    padding: 0 14px;
    background: var(--border);
    color: var(--danger);
    font-size: 13px;
    font-weight: 600;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
}
.danger-button:hover { background: var(--border); filter: brightness(.94); color: var(--danger-hover); }

/* ─── Alerts / flash messages ────────────────────────────── */
.messages { display: grid; gap: 10px; margin-bottom: 20px; }

.message,
.alert {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 11px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    line-height: 1.5;
    border: 1px solid var(--border);
    background: var(--bg-card);
}

.message-success,
.alert-success { background: var(--success-bg); border-color: var(--success-bdr); color: var(--success); }

.message-error,
.alert-error { background: var(--error-bg); border-color: var(--error-bdr); color: var(--error); }

.alert-warn { background: var(--warn-bg); border-color: var(--warn-bdr); color: var(--warn); }
.alert-info { background: var(--accent-light); border-color: var(--border-focus); color: var(--text); }

/* ─── Table ───────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table th {
    text-align: left;
    padding: 8px 10px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.data-table td {
    padding: 11px 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--bg); }

.data-table code {
    font-family: Consolas, monospace;
    font-size: 12px;
    color: var(--accent);
}

.compact-inline { display: inline; }

/* ─── Access-class & status badges ───────────────────────── */
.access-badge,
.status-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 30px;
    min-height: 24px;
    padding: 3px 10px;
    border-radius: 999px;
    border: 1px solid transparent;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    white-space: nowrap;
}

.access-G { background: var(--access-G-bg); border-color: var(--access-G-border); color: var(--access-G-text); }
.access-F { background: var(--access-F-bg); border-color: var(--access-F-border); color: var(--access-F-text); }
.access-E { background: var(--access-E-bg); border-color: var(--access-E-border); color: var(--access-E-text); }
.access-D { background: var(--access-D-bg); border-color: var(--access-D-border); color: var(--access-D-text); }
.access-C { background: var(--access-C-bg); border-color: var(--access-C-border); color: var(--access-C-text); }
.access-B { background: var(--access-B-bg); border-color: var(--access-B-border); color: var(--access-B-text); }
.access-A { background: var(--access-A-bg); border-color: var(--access-A-border); color: var(--access-A-text); }
.access-S { background: var(--access-S-bg); border-color: var(--access-S-border); color: var(--access-S-text); }

.access-panel { border-left-width: 4px; }

.access-field {
    position: relative;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-left-width: 4px;
    border-radius: var(--radius);
    background: var(--bg-card);
}

.access-border-G { border-left-color: var(--access-G-border); }
.access-border-F { border-left-color: var(--access-F-border); }
.access-border-E { border-left-color: var(--access-E-border); }
.access-border-D { border-left-color: var(--access-D-border); }
.access-border-C { border-left-color: var(--access-C-border); }
.access-border-B { border-left-color: var(--access-B-border); }
.access-border-A { border-left-color: var(--access-A-border); }
.access-border-S { border-left-color: var(--access-S-border); }

.js-access-label { display: none; }
body.show-access-labels .js-access-label { display: inline-flex; }

.field-corner-badge {
    position: absolute;
    top: -8px;
    min-width: 20px;
    min-height: 20px;
    padding: 1px 6px;
    font-size: 11px;
    box-shadow: 0 0 0 2px var(--bg-card);
    z-index: 1;
}

.corner-left { left: -8px; }
.corner-right { right: -8px; }

select.access-badge {
    width: auto;
    min-height: 24px;
    padding: 1px 6px;
    border: 1px solid transparent;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    text-align: center;
    text-align-last: center;
    cursor: pointer;
}

select.field-corner-badge {
    min-height: 20px;
}

.field-remove-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-card);
    border-radius: 999px;
    cursor: pointer;
}
.field-remove-mark input {
    position: absolute;
    inset: 0;
    opacity: 0;
    margin: 0;
    cursor: pointer;
}
.field-remove-mark span {
    color: var(--danger);
    font-weight: 700;
    font-size: 13px;
    line-height: 1;
    pointer-events: none;
}
.field-remove-mark input:checked + span { color: #fff; }
.field-remove-mark:has(input:checked) { background: var(--danger); }

.entity-card-top { position: relative; }
.access-panel { position: relative; }

.status-active { background: var(--success-bg); border-color: var(--success-bdr); color: var(--success); }
.status-inactive,
.status-archived { background: var(--bg); border-color: var(--border); color: var(--text-muted); }
.status-deprecated { background: var(--warn-bg); border-color: var(--warn-bdr); color: var(--warn); }

/* ─── Entity / property card layout ──────────────────────── */
.compact-headline h1 { font-size: 28px; }
.compact-headline p { margin-top: 6px; font-size: 14px; }

.history-meta {
    margin: -6px 0 12px;
    color: var(--text-muted);
    font-size: 12px;
}

.entity-card-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 14px;
}
.entity-card-top h2 { margin: 0; font-size: 17px; }

.entity-meta-controls {
    display: grid;
    grid-template-columns: minmax(120px, 150px) auto;
    gap: 8px;
    align-items: end;
}
.entity-meta-controls label {
    display: grid;
    gap: 4px;
    color: var(--text-muted);
    font-size: 12px;
}

.compact-entity-grid {
    grid-template-columns: repeat(4, minmax(150px, 1fr));
    gap: 10px;
}
.compact-entity-grid .wide-field { grid-column: 1 / -1; }
.form-grid.compact-entity-grid textarea { min-height: 64px; }

.runtime-property-list { display: grid; gap: 12px; margin-top: 14px; }
.runtime-property { display: grid; gap: 12px; }
.runtime-property-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    font-size: 14px;
}

.add-property-details { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.add-property-details > summary {
    list-style: none;
    cursor: pointer;
    display: inline-flex;
}
.add-property-details > summary::-webkit-details-marker { display: none; }
.add-property-form { margin-top: 12px; }

/* ─── Auth page ───────────────────────────────────────────── */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.auth-wrap { width: 100%; max-width: 400px; }

.auth-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px;
    box-shadow: var(--shadow-md);
}

.auth-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 8px;
    margin-bottom: 26px;
}

.auth-logo { max-width: 200px; max-height: 60px; object-fit: contain; }
.auth-subtitle { font-size: 13px; color: var(--text-muted); }

.auth-form { display: flex; flex-direction: column; gap: 16px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 500; color: var(--text); }

/* ─── Misc ────────────────────────────────────────────────── */
dl { display: grid; grid-template-columns: 160px 1fr; gap: 10px 20px; }
dt { color: var(--text-muted); font-size: 13px; }
dd { margin: 0; }

@media (max-width: 640px) {
    dl { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
    .section-headline,
    .page-header,
    .form-grid,
    .compact-form,
    .entity-card-top,
    .entity-meta-controls {
        grid-template-columns: 1fr;
        display: grid;
    }
}
