:root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --line: #dfe4e8;
    --line-strong: #cbd3da;
    --text: #17212b;
    --muted: #66727e;
    --primary: #1457d9;
    --primary-dark: #0f43aa;
    --success: #137a49;
    --danger: #ba2d36;
    --shadow: 0 8px 30px rgba(21, 38, 58, .08);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; }
button, input { font: inherit; }
a { color: inherit; }

.topbar {
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    background: #111b27;
    color: #fff;
}
.brand { display: flex; align-items: center; gap: 11px; color: #fff; text-decoration: none; letter-spacing: .02em; }
.brand b { color: #91b5ff; }
.brand-mark {
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    border-radius: 13px;
    background: var(--primary);
    color: #fff;
    font-size: 24px;
    font-weight: 800;
    box-shadow: 0 8px 18px rgba(20, 87, 217, .25);
}
.brand-mark-small { width: 34px; height: 34px; border-radius: 9px; font-size: 17px; box-shadow: none; }

.tabs {
    display: flex;
    gap: 6px;
    padding: 0 28px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}
.tabs a { padding: 17px 18px 14px; border-bottom: 3px solid transparent; color: var(--muted); font-weight: 650; text-decoration: none; }
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }

.page-shell { width: min(1600px, calc(100% - 48px)); margin: 0 auto; padding: 32px 0 56px; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 22px; }
.page-heading h1 { margin: 3px 0 7px; font-size: clamp(26px, 3vw, 38px); letter-spacing: -.035em; }
.page-heading p { margin: 0; color: var(--muted); }
.eyebrow { color: var(--primary) !important; font-size: 11px; font-weight: 800; letter-spacing: .14em; }
.record-count { display: flex; flex-direction: column; align-items: flex-end; }
.record-count strong { font-size: 26px; }
.record-count span { color: var(--muted); font-size: 12px; }

.toolbar { display: flex; align-items: center; gap: 9px; margin-bottom: 15px; }
.search { min-width: min(420px, 55vw); display: flex; align-items: center; gap: 8px; padding: 0 12px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 8px; }
.search span { font-size: 22px; color: var(--muted); transform: rotate(-20deg); }
.search input { width: 100%; padding: 10px 0; border: 0; outline: 0; background: transparent; }

.button { display: inline-flex; align-items: center; justify-content: center; min-height: 38px; padding: 8px 14px; border: 1px solid var(--line-strong); border-radius: 7px; background: var(--surface); color: var(--text); font-weight: 650; text-decoration: none; cursor: pointer; }
.button:hover { border-color: #a9b4be; background: #f9fafb; }
.button:disabled { cursor: wait; opacity: .6; }
.button-primary { border-color: var(--primary); background: var(--primary); color: #fff; }
.button-primary:hover { border-color: var(--primary-dark); background: var(--primary-dark); }
.button-ghost { background: transparent; color: inherit; }
.topbar .button-ghost { border-color: #3b4856; color: #dce5ee; }
.button-save { min-height: 32px; padding: 5px 10px; color: var(--primary); border-color: #b9cdf6; background: #f4f7ff; }

.grid-card { overflow: hidden; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); box-shadow: var(--shadow); }
.table-scroll { overflow: auto; max-height: calc(100vh - 290px); }
.data-grid { width: 100%; border-collapse: separate; border-spacing: 0; min-width: 980px; }
.data-grid th { position: sticky; top: 0; z-index: 3; padding: 11px 12px; border-bottom: 1px solid var(--line-strong); background: #f7f9fb; color: #4b5865; font-size: 11px; text-align: left; text-transform: uppercase; letter-spacing: .055em; white-space: nowrap; }
.data-grid td { padding: 9px 12px; border-bottom: 1px solid #ebeff2; vertical-align: middle; }
.data-grid tr:last-child td { border-bottom: 0; }
.data-grid tbody tr:hover td { background: #fbfcfd; }
.data-grid small { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; font-weight: 400; }
.data-grid .hidden-by-tree { display: none; }
.number-cell { text-align: right; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.muted { color: var(--muted); }
.actions-cell { width: 78px; text-align: right; }
.inline-edit { margin: 0; }

.cell-input { width: 100%; min-width: 130px; padding: 7px 8px; border: 1px solid transparent; border-radius: 5px; background: transparent; color: var(--text); outline: none; }
.cell-input:hover { border-color: var(--line); background: #fff; }
.cell-input:focus { border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px rgba(20, 87, 217, .12); }
.number-input { min-width: 86px; max-width: 110px; text-align: right; font-variant-numeric: tabular-nums; }
.wide-input { min-width: 260px; }

.switch { position: relative; display: inline-block; width: 38px; height: 22px; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: #bbc4cc; cursor: pointer; transition: .18s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: .18s; }
.switch input:checked + span { background: var(--success); }
.switch-danger input:checked + span { background: var(--danger); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 3px solid rgba(20, 87, 217, .25); }

.tree-name { display: flex; align-items: flex-start; gap: 7px; min-width: 310px; }
.tree-depth-1 { padding-left: 18px; }
.tree-depth-2 { padding-left: 36px; }
.tree-depth-3 { padding-left: 54px; }
.tree-depth-4 { padding-left: 72px; }
.tree-depth-5 { padding-left: 90px; }
.tree-depth-6 { padding-left: 108px; }
.tree-depth-7 { padding-left: 126px; }
.tree-depth-8 { padding-left: 144px; }
.tree-depth-9 { padding-left: 162px; }
.tree-depth-10 { padding-left: 180px; }
.tree-depth-11 { padding-left: 198px; }
.tree-depth-12 { padding-left: 216px; }
.tree-toggle { flex: 0 0 20px; width: 20px; height: 20px; padding: 0; border: 1px solid var(--line-strong); border-radius: 4px; background: #fff; color: var(--muted); cursor: pointer; }
.tree-leaf { flex: 0 0 20px; height: 20px; position: relative; }
.tree-leaf::before { content: ""; position: absolute; left: 8px; top: 8px; width: 4px; height: 4px; border-radius: 50%; background: #a6b0ba; }
.category-grid th:first-child { min-width: 390px; }

.pill, .status { display: inline-flex; padding: 4px 8px; border-radius: 999px; background: #f0f2f4; color: #4b5865; font-size: 11px; font-weight: 700; }
.pill-blue { background: #edf3ff; color: #2159b9; }
.status-on { background: #e7f7ef; color: #087142; }
.code-label { max-width: 440px; overflow: hidden; text-overflow: ellipsis; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; white-space: nowrap; }
details summary { color: var(--primary); cursor: pointer; font-weight: 650; white-space: nowrap; }
.rule-details { min-width: 360px; padding: 10px 0 3px; }
.rule-details h4 { margin: 8px 0 4px; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.rule-details code { display: block; margin: 3px 0; padding: 5px 7px; border-radius: 4px; background: #f3f5f7; color: #273747; white-space: normal; overflow-wrap: anywhere; }

.alert, .info-strip { margin-bottom: 14px; padding: 11px 14px; border: 1px solid #c9dafb; border-radius: 8px; background: #f0f5ff; color: #244d91; }
.alert-error { border-color: #f0c1c4; background: #fff0f1; color: #9b2028; }
.alert-success { border-color: #bfe5d1; background: #eefaf4; color: #12623e; }
.info-strip { color: #43515f; border-color: var(--line); background: #f9fafb; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 20; max-width: 420px; padding: 12px 16px; border-radius: 8px; background: #182430; color: #fff; box-shadow: 0 12px 36px rgba(0,0,0,.22); opacity: 0; transform: translateY(10px); pointer-events: none; transition: .2s; }
.toast.visible { opacity: 1; transform: translateY(0); }
.toast.error { background: #9b2028; }

.pagination { display: flex; align-items: center; justify-content: center; gap: 20px; margin-top: 18px; color: var(--muted); }
.pagination a { color: var(--primary); font-weight: 650; text-decoration: none; }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at top, #e8efff, var(--bg) 48%); }
.login-card { width: min(430px, 100%); padding: 40px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: 0 24px 70px rgba(31, 55, 82, .15); }
.login-card h1 { margin: 16px 0 7px; font-size: 31px; letter-spacing: -.035em; }
.login-card .muted { margin: 0 0 25px; }
.login-form { display: grid; gap: 15px; }
.login-form label { display: grid; gap: 6px; color: #43515f; font-weight: 650; }
.login-form input { width: 100%; padding: 11px 12px; border: 1px solid var(--line-strong); border-radius: 7px; outline: 0; }
.login-form input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(20, 87, 217, .12); }

@media (max-width: 760px) {
    .topbar { padding: 0 16px; }
    .tabs { padding: 0 8px; overflow-x: auto; }
    .tabs a { padding-inline: 12px; white-space: nowrap; }
    .page-shell { width: calc(100% - 24px); padding-top: 22px; }
    .page-heading { align-items: flex-start; }
    .record-count { display: none; }
    .toolbar { flex-wrap: wrap; }
    .search { min-width: 100%; }
    .table-scroll { max-height: none; }
    .login-card { padding: 28px; }
}

.editor-scope { border: 0; padding: 0; margin: 0; min-width: 0; }
.environment-strip { display: flex; justify-content: space-between; gap: 16px; }
.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; }
:focus-visible { outline: 3px solid #1457d9; outline-offset: 3px; }
fieldset.readonly .button-save { display: none; }
fieldset.readonly .cell-input { color: #43515f; }
@media (max-width: 760px) { .environment-strip { flex-direction: column; } }

.data-grid .inherited-block { color: #9b2028; font-weight: 650; }

.manufacturer-detail { margin-top: 20px; padding: 24px; }
.manufacturer-detail h2 { margin-top: 0; }
.detail-fields { border: 1px solid var(--line); border-radius: 9px; margin: 0 0 20px; padding: 18px; min-width: 0; }
.detail-fields legend { font-weight: 700; padding: 0 7px; }
.detail-fields label { display: grid; gap: 6px; margin-bottom: 14px; font-weight: 600; }
.detail-fields input, .detail-fields textarea, .detail-fields select { font: inherit; font-weight: 400; width: 100%; border: 1px solid var(--line-strong); border-radius: 6px; padding: 10px; background: #fff; }
.detail-fields textarea { resize: vertical; }
.detail-fields:disabled input, .detail-fields:disabled textarea, .detail-fields:disabled select { color: var(--text); background: #f4f6f8; opacity: 1; }
.gpsr-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.original-data { margin-top: 20px; }
.original-data pre { overflow-wrap: anywhere; white-space: pre-wrap; padding: 15px; background: var(--bg); }
.autosave-state { font-size: 12px; color: var(--muted); display: inline-block; max-width: 260px; margin: 8px 0; }
.autosave-state[data-state="saved"] { color: var(--success); }
.autosave-state[data-state="error"] { color: var(--danger); }
.js-autosave-form.autosave-ready > button[type="submit"] { display: none; }
@media (max-width: 760px) { .gpsr-columns { grid-template-columns: 1fr; gap: 0; } .manufacturer-detail { padding: 16px; } }
