:root {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  color: #15222d;
  background: #f5f7f8;
  letter-spacing: 0;
  --accent: #008f98;
  --accent-soft: #dff5f4;
  --surface: #ffffff;
  --surface-secondary: #eef3f4;
  --line: #d8e0e3;
  --muted: #60717b;
  --good: #18825d;
  --warning: #a95f00;
  --critical: #b3261e;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; }
button, input, textarea, select { font: inherit; letter-spacing: 0; }
button, .button-link { min-height: 40px; padding: 0 14px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: inherit; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
button:disabled { cursor: default; opacity: .45; }
button:not(:disabled):hover, .button-link:hover { border-color: var(--accent); }
button.danger { color: var(--critical); }
button.primary { border-color: var(--accent); background: var(--accent); color: white; }

.topbar { position: sticky; z-index: 4; top: 0; display: flex; align-items: center; justify-content: space-between; min-height: 64px; padding: 10px max(18px, env(safe-area-inset-left)); border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(18px); }
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { object-fit: contain; }
.brand strong, .brand span { display: block; }
.brand span { margin-top: 2px; color: var(--muted); font-size: 12px; }
.topbar-actions { display: flex; gap: 8px; }

.section-tabs { position: sticky; z-index: 3; top: 64px; display: flex; gap: 4px; overflow-x: auto; padding: 8px max(18px, calc((100% - 1120px) / 2 + 18px)); border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(18px); }
.section-tabs button { flex: 0 0 auto; min-height: 36px; border-color: transparent; background: transparent; }
.section-tabs button.selected { border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); background: var(--accent-soft); color: #006b72; }

main { width: min(1120px, 100%); margin: 0 auto; padding: 24px 18px 64px; }
.view-section { display: none; padding: 0; }
.view-section.active { display: block; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.compact-heading { margin-top: 30px; }
h1, h2 { margin: 0; font-size: 22px; }
h2 { font-size: 18px; }
.section-heading p { margin: 5px 0 0; color: var(--muted); font-size: 14px; }
.timestamp { color: var(--muted); font-size: 12px; }

.alerts { display: grid; gap: 8px; margin-bottom: 14px; }
.alert { padding: 12px 14px; border-left: 4px solid var(--warning); background: color-mix(in srgb, var(--warning) 9%, var(--surface)); }
.alert.critical { border-color: var(--critical); background: color-mix(in srgb, var(--critical) 8%, var(--surface)); }
.alert strong, .alert span { display: block; }
.alert span { margin-top: 3px; color: var(--muted); font-size: 13px; }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.metric { min-height: 94px; padding: 16px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.metric strong, .metric span { display: block; }
.metric strong { font-size: 24px; }
.metric span { margin-top: 8px; color: var(--muted); font-size: 13px; }

.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.panel { min-width: 0; padding: 16px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.panel-heading { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 15px; }
.panel-heading span { color: var(--muted); font-size: 12px; }
.bar-chart { display: grid; gap: 9px; }
.bar-row { display: grid; grid-template-columns: 82px minmax(0, 1fr) 58px; align-items: center; gap: 8px; font-size: 12px; }
.bar-track { height: 8px; overflow: hidden; border-radius: 4px; background: var(--surface-secondary); }
.bar-fill { height: 100%; border-radius: inherit; background: var(--accent); }
.bar-fill.error { background: var(--critical); }
.bar-value { color: var(--muted); text-align: right; }

.table-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-size: 12px; font-weight: 600; }
tr:last-child td { border-bottom: 0; }
td input[type="number"] { width: 92px; margin: 0; }
td input[type="checkbox"] { width: auto; margin: 0; }
.status { color: var(--good); font-weight: 600; }
.status.off { color: var(--warning); }

form { display: grid; gap: 14px; }
.content-form { grid-template-columns: repeat(3, minmax(0, 1fr)); padding: 16px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.inline-form, .filter-row { grid-template-columns: minmax(140px, .35fr) minmax(220px, 1fr) auto; align-items: end; margin-bottom: 20px; }
.filter-row { grid-template-columns: minmax(200px, 1fr) minmax(150px, .35fr) auto auto; margin-top: 26px; }
.grow { min-width: 0; }
label { color: var(--muted); font-size: 13px; }
input, textarea, select { display: block; width: 100%; min-height: 40px; margin-top: 6px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: inherit; }
textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.wide { grid-column: 1 / -1; }
.toggle { display: flex; align-items: center; gap: 8px; color: inherit; min-height: 40px; }
.toggle input { width: auto; min-height: auto; margin: 0; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; }

.catalog-results { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.catalog-item { display: grid; grid-template-columns: 62px minmax(0, 1fr); gap: 12px; min-height: 86px; padding: 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.catalog-item img, .catalog-placeholder { width: 62px; height: 62px; border-radius: 4px; object-fit: cover; background: var(--surface-secondary); }
.catalog-item strong, .catalog-item span { display: block; }
.catalog-item span { margin-top: 4px; color: var(--muted); font-size: 12px; }
.empty-state { display: block; padding: 28px 0; color: var(--muted); text-align: center; }

.record-list { border-top: 1px solid var(--line); }
.record { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.record-title { font-weight: 600; overflow-wrap: anywhere; }
.record-meta { margin-top: 4px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.record-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.record-actions button { min-height: 34px; padding: 0 10px; font-size: 12px; }
.state-pill { display: inline-block; margin-right: 6px; padding: 2px 7px; border-radius: 9px; background: var(--accent-soft); color: #006b72; font-size: 11px; }
.state-pill.stale { background: color-mix(in srgb, var(--warning) 15%, var(--surface)); color: var(--warning); }
.state-pill.expired, .state-pill.deleted { background: color-mix(in srgb, var(--critical) 12%, var(--surface)); color: var(--critical); }
.load-more { width: 100%; margin-top: 12px; }

dialog { width: min(560px, calc(100% - 32px)); max-height: min(760px, calc(100% - 32px)); overflow: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: inherit; }
dialog::backdrop { background: rgb(0 0 0 / .32); backdrop-filter: blur(3px); }
dialog form { display: block; }
dialog h2 { margin-bottom: 18px; }
dialog p { color: var(--muted); font-size: 13px; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dialog-heading h2 { margin: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
#message { position: fixed; z-index: 8; right: 18px; bottom: 18px; max-width: min(380px, calc(100% - 36px)); padding: 12px 14px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); box-shadow: 0 8px 28px rgb(15 40 50 / .16); opacity: 0; pointer-events: none; transform: translateY(8px); transition: opacity .2s ease, transform .2s ease; }
#message.visible { opacity: 1; transform: translateY(0); }

@media (max-width: 820px) {
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid, .catalog-results { grid-template-columns: 1fr; }
  .content-form, .inline-form, .filter-row { grid-template-columns: 1fr; }
  .wide { grid-column: auto; }
  .topbar-actions .button-link { display: none; }
  .record { grid-template-columns: 1fr; }
  .record-actions { justify-content: flex-start; }
}

@media (max-width: 520px) {
  .topbar { align-items: flex-start; }
  .topbar-actions { flex-direction: column; }
  .topbar-actions button { min-height: 34px; }
  .section-tabs { top: 82px; }
  .bar-row { grid-template-columns: 68px minmax(0, 1fr) 48px; }
}

@media (prefers-color-scheme: dark) {
  :root {
    color: #eef5f5;
    background: #11191d;
    --surface: #182329;
    --surface-secondary: #223138;
    --line: #33434a;
    --muted: #9fb0b7;
    --accent: #42cbd0;
    --accent-soft: #173f43;
    --good: #67d8ab;
    --warning: #ffc36b;
    --critical: #ff8a83;
  }
  .section-tabs button.selected, .state-pill { color: #9ef0f1; }
}
