:root {
    --accent: #1f3a5f;
    --accent-2: #2d5a8e;
    --accent-soft: #eaf0f7;
    --bg: #f4f6f9;
    --surface: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --border: #d9dee6;
    --ok: #15803d;
    --ok-soft: #e8f6ed;
    --error: #b91c1c;
    --error-soft: #fdecec;
    --warn: #a16207;
    --radius: 8px;
    --mono: "Cascadia Code", Consolas, "SFMono-Regular", Menlo, monospace;
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--text);
}

* { box-sizing: border-box; }

/* The hidden attribute must win over component display rules (.empty, .btn, …) — the designer toggles it from JS. */
[hidden] { display: none !important; }

body { margin: 0; background: var(--bg); font-size: 14px; line-height: 1.5; }

a { color: var(--accent-2); }

code, pre, kbd { font-family: var(--mono); font-size: 0.92em; }

code { background: var(--accent-soft); padding: 0 4px; border-radius: 4px; }

pre { background: #0f1b2d; color: #dbe6f5; padding: 12px 14px; border-radius: var(--radius); overflow-x: auto; margin: 8px 0 0; }

pre code { background: none; padding: 0; color: inherit; }

h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 6px; }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.spacer { flex: 1; }
.count { background: var(--accent-soft); color: var(--accent); border-radius: 10px; padding: 0 8px; font-size: 12px; margin-left: 6px; }
.badge { display: inline-block; font-size: 11.5px; padding: 1px 8px; border-radius: 10px; background: #eef1f5; color: var(--muted); white-space: nowrap; }
.badge-standard { background: var(--accent-soft); color: var(--accent); }
.badge-override { background: #fff3d6; color: var(--warn); }
.topbar .tenant { background: rgba(255, 255, 255, 0.14); color: #fff; font-size: 12.5px; padding: 2px 10px; border-radius: 10px; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 18px; height: 48px; padding: 0 18px; background: var(--accent); color: #fff; }
.topbar .brand { color: #fff; text-decoration: none; font-weight: 600; letter-spacing: 0.2px; }
.topbar .brand span { color: #9cc3f0; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a { color: #d6e4f5; text-decoration: none; padding: 6px 10px; border-radius: 6px; }
.topbar nav a:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }
.topbar .user { color: #d6e4f5; font-size: 13px; }
.topbar form { margin: 0; }
.topbar .btn-ghost { color: #fff; border-color: rgba(255, 255, 255, 0.35); }

/* ---------- buttons & inputs ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); font: inherit; font-size: 13px; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: var(--accent-2); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-2); }
.btn-danger { color: var(--error); }
.btn-danger:hover:not(:disabled) { border-color: var(--error); background: var(--error-soft); }
.btn-ghost { background: transparent; }

input, select, textarea { font: inherit; font-size: 13px; height: 32px; padding: 0 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); }
textarea { height: auto; padding: 6px 8px; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(45, 90, 142, 0.25); border-color: var(--accent-2); }
label { display: inline-flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 6px; font-size: 13px; color: var(--text); }
label.check input { height: auto; }

/* ---------- pages ---------- */
.page { max-width: 1100px; margin: 0 auto; padding: 24px 18px 48px; }
.page.narrow { max-width: 560px; padding-top: 64px; }
.page-head { margin-bottom: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; }
.card.center { text-align: center; }
.alert { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.error { background: var(--error-soft); color: var(--error); }

.inline-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; }
.inline-form input[type="file"] { height: auto; padding: 5px 6px; }
.logo-row { display: flex; flex-wrap: wrap; align-items: center; gap: 20px; }
.logo-preview { width: 160px; height: 80px; display: flex; align-items: center; justify-content: center; padding: 8px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
.logo-preview img { max-width: 100%; max-height: 100%; }
.logo-actions { display: flex; flex-direction: column; gap: 10px; flex: 1; min-width: 280px; }
.logo-actions p { margin: 0; }
.logo-actions form { margin: 0; }
.inline-form input { min-width: 260px; }

.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-weight: 600; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--border); padding: 6px 8px; }
table.list td { border-bottom: 1px solid #eef1f5; padding: 8px; vertical-align: middle; }
table.list td.actions { display: flex; gap: 6px; justify-content: flex-end; }
table.list td.actions form { margin: 0; }

.docs .toc { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; }
.docs .toc input[type="search"] { margin-left: auto; min-width: 220px; }
.section-index { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 4px; }
.section-index a { text-decoration: none; }
.ref-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin-top: 12px; min-width: 0; scroll-margin-top: 16px; }
.ref-card > p { margin: 0 0 8px; }
.ref-card:target, .ref-card.current { border-color: var(--accent-2); box-shadow: 0 0 0 3px rgba(45, 90, 142, 0.18); }
.ref-card details { margin-top: 8px; }
.ref-card details summary { cursor: pointer; color: var(--accent-2); font-size: 13px; }
.ref-card pre { font-size: 11.5px; }
table.props td { vertical-align: top; padding: 6px 8px; }
table.props td:first-child, table.props td:nth-child(3) { white-space: nowrap; }
table.props td:nth-child(2) { color: var(--muted); font-size: 12.5px; }
table.props .props-label { display: none; color: var(--muted); font-size: 12px; }
table.props tr.current, table.props tr.current td { background: #fff3c4; }

/* documentation embedded in the designer */
body.embed { background: var(--surface); }
body.embed .page { max-width: none; padding: 0 14px 32px; }
body.embed .page-head { display: none; }
body.embed .docs .toc { position: sticky; top: 0; z-index: 2; margin: 0 -14px 12px; border-radius: 0; border-width: 0 0 1px; padding: 8px 14px; }
body.embed .ref-card { scroll-margin-top: 96px; }

/* Narrow (designer pane, phone): each property as a block — name, type, default on one line, description below. */
@media (max-width: 900px) {
    table.props thead { display: none; }
    table.props, table.props tbody, table.props tr { display: block; }
    table.props tr { padding: 7px 0; border-bottom: 1px solid #eef1f5; }
    table.props td { display: inline; border: 0; padding: 0; }
    table.props td:nth-child(2), table.props td:nth-child(3) { margin-left: 8px; }
    table.props .props-label { display: inline; }
    table.props td:nth-child(4) { display: block; margin-top: 2px; }
}

/* ---------- designer ---------- */
body.designer-page { height: 100vh; overflow: hidden; display: flex; flex-direction: column; }
body.designer-page main { flex: 1; min-height: 0; }
.designer { display: grid; grid-template-columns: minmax(420px, 1fr) minmax(420px, 1fr); height: 100%; }
.pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.editor-pane { border-right: 1px solid var(--border); background: var(--surface); }
.preview-pane { background: #e9edf2; }
.toolbar { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--border); background: var(--surface); flex-wrap: wrap; }
.toolbar.params { align-items: flex-end; }
.toolbar.params input { width: 110px; }
.toolbar.params label.grow { flex: 1; }
.toolbar.params label.grow input { width: 100%; min-width: 140px; }
.doc-name { font-family: var(--mono); font-size: 13px; }
.dirty { color: var(--warn); font-size: 12px; }

.editor { flex: 1; min-height: 0; position: relative; }
.editor textarea { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; border-radius: 0; resize: none; padding: 10px 12px; font-family: var(--mono); font-size: 13px; line-height: 1.5; tab-size: 2; white-space: pre; }
.editor textarea:focus { outline: none; }

.problems { max-height: 30%; overflow: auto; border-top: 1px solid var(--border); background: #fffdf5; font-size: 12.5px; }
.problems div { padding: 5px 12px; border-bottom: 1px solid #f1ecd9; cursor: pointer; }
.problems div:hover { background: #fff6d6; }
.problems .error { color: var(--error); }
.problems .warning { color: var(--warn); }
.problems .pos { color: var(--muted); font-family: var(--mono); margin-right: 6px; }

.tabs .tab { border: 0; background: none; padding: 6px 10px; font: inherit; font-size: 13px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; }
.tabs .tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tab-body { flex: 1; min-height: 0; position: relative; overflow: auto; }
#tab-pdf { overflow: hidden; }
#pdf-frame { width: 100%; height: 100%; border: 0; background: #e9edf2; }
#tab-docs { overflow: hidden; }
#docs-frame { width: 100%; height: 100%; border: 0; background: var(--surface); }
.docs-context { font-family: var(--mono); font-size: 12px; color: var(--muted); max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; color: var(--muted); padding: 24px; }

table.data { border-collapse: collapse; font-size: 12.5px; background: var(--surface); margin: 8px; }
table.data th, table.data td { border: 1px solid var(--border); padding: 4px 8px; white-space: nowrap; max-width: 360px; overflow: hidden; text-overflow: ellipsis; }
table.data th { background: var(--accent-soft); position: sticky; top: 0; text-align: left; }
table.data td.null { color: #b0b7c3; font-style: italic; }
#data-info { padding: 8px 10px 0; }

.status { min-height: 30px; padding: 6px 12px; font-size: 12.5px; border-top: 1px solid var(--border); background: var(--surface); color: var(--muted); }
.status.ok { color: var(--ok); }
.status.error { color: var(--error); }
.status.busy::before { content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 8px; border: 2px solid var(--accent-2); border-right-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1000px) {
    body.designer-page { height: auto; overflow: auto; }
    .designer { grid-template-columns: 1fr; height: auto; }
    .editor-pane { height: 70vh; border-right: 0; }
    .preview-pane { height: 85vh; }
}
