:root {
  --canvas: #f8f9fa; --surface: #fff; --surface-soft: #f1f3f4; --text: #202124; --text-muted: #5f6368;
  --border: #dadce0; --border-light: #e8eaed; --primary: #1a73e8; --primary-dark: #185abc; --primary-soft: #e8f0fe;
  --success: #137333; --success-soft: #e6f4ea; --warning: #b06000; --warning-soft: #fef7e0; --danger: #d93025; --danger-soft: #fce8e6;
  --shadow: 0 1px 2px rgba(60,64,67,.12), 0 1px 3px 1px rgba(60,64,67,.08);
  font-family: "Google Sans Text", "Google Sans", Roboto, Arial, sans-serif; color: var(--text); background: var(--canvas);
  font-synthesis: none; color-scheme: light;
}
:root[data-theme="dark"] {
  --canvas: #202124; --surface: #292a2d; --surface-soft: #303134; --text: #e8eaed; --text-muted: #bdc1c6;
  --border: #5f6368; --border-light: #3c4043; --primary: #8ab4f8; --primary-dark: #aecbfa; --primary-soft: #28354d;
  --success: #81c995; --success-soft: #1e3a2a; --warning: #fdd663; --warning-soft: #3d3420; --danger: #f28b82; --danger-soft: #42221f;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--canvas); color: var(--text); font-size: 14px; line-height: 1.45; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
code { font-family: "Roboto Mono", ui-monospace, Menlo, monospace; font-size: 12.5px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.spacer { flex: 1; }
.boot { display: grid; place-items: center; min-height: 100vh; color: var(--text-muted); }

/* Buttons and fields */
.button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--primary); border-radius: 4px; padding: 7px 16px; font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; }
.button:hover { background: var(--primary-soft); }
.button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
:root[data-theme="dark"] .button.primary { color: #202124; }
.button.primary:hover { background: var(--primary-dark); }
.button.danger { color: var(--danger); }
.button.wide { width: 100%; padding: 10px 16px; }
.button:disabled { opacity: .5; cursor: not-allowed; }
.icon-button { border: 0; background: transparent; color: var(--text-muted); font-size: 16px; width: 32px; height: 32px; border-radius: 50%; cursor: pointer; }
.icon-button:hover { background: var(--surface-soft); }
.link { border: 0; background: none; color: var(--primary); cursor: pointer; font: inherit; padding: 2px 4px; }
.link.danger { color: var(--danger); }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
label { display: grid; gap: 4px; font-weight: 500; color: var(--text-muted); font-size: 12.5px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 4px; padding: 8px 10px; min-width: 0; width: 100%; }
textarea { font-family: "Roboto Mono", ui-monospace, monospace; font-size: 12.5px; min-height: 90px; resize: vertical; }
select { width: auto; }
.form-error { color: var(--danger); font-size: 13px; }
.hint { color: var(--text-muted); font-size: 12.5px; font-weight: 400; }

/* Lock screen */
.lock-screen { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--canvas); }
.lock-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border-light); border-radius: 8px; box-shadow: var(--shadow); padding: 32px 28px; display: grid; gap: 16px; text-align: center; }
.lock-card h1 { font-size: 22px; font-weight: 500; }
.lock-copy { color: var(--text-muted); }
.lock-card label { text-align: left; }
.lock-foot { color: var(--text-muted); font-size: 12px; }
.brand-mark { width: 44px; height: 44px; margin: 0 auto; display: grid; place-items: center; border-radius: 12px; background: var(--primary); color: #fff; font-size: 24px; }
.topbar .brand-mark { width: 30px; height: 30px; font-size: 16px; border-radius: 8px; margin: 0; }

/* Shell */
.topbar { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding: 8px 24px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-size: 18px; font-weight: 500; }
.scope { display: flex; align-items: center; gap: 4px; }
.scope select { max-width: 200px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.chip { display: inline-block; padding: 2px 10px; border-radius: 12px; background: var(--surface-soft); color: var(--text-muted); font-size: 12px; }
.chip.ok { background: var(--success-soft); color: var(--success); }
.chip.warn { background: var(--warning-soft); color: var(--warning); }
.notice { margin: 12px 24px 0; padding: 10px 14px; border-radius: 6px; background: var(--warning-soft); color: var(--text); border: 1px solid var(--border-light); }
.page { max-width: 1120px; margin: 0 auto; padding: 24px 24px 80px; }
.page-head h1 { font-size: 24px; font-weight: 400; }
.page-head p { color: var(--text-muted); margin-top: 4px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-top: 20px; overflow-x: auto; }
.tab { border: 0; background: none; padding: 12px 16px; font: inherit; font-weight: 500; color: var(--text-muted); cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; }
.menu summary::-webkit-details-marker { display: none; }
.menu-list { position: absolute; right: 0; top: calc(100% + 4px); min-width: 280px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; box-shadow: var(--shadow); padding: 6px 0; z-index: 10; }
.menu-list button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 9px 16px; font: inherit; color: var(--text); cursor: pointer; }
.menu-list button:hover { background: var(--surface-soft); }

/* Publish bar */
.publish-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 16px; padding: 10px 16px; background: var(--primary-soft); border: 1px solid var(--border-light); border-radius: 6px; position: sticky; top: 56px; z-index: 4; }

/* Tables */
.toolbar { display: flex; align-items: center; gap: 12px; margin: 16px 0 12px; flex-wrap: wrap; }
.toolbar input[type="search"] { max-width: 320px; }
.card { background: var(--surface); border: 1px solid var(--border-light); border-radius: 8px; box-shadow: var(--shadow); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 500; color: var(--text-muted); font-size: 12.5px; padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--surface-soft); }
td { padding: 12px 16px; border-bottom: 1px solid var(--border-light); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tr.group-row td { background: var(--surface-soft); font-weight: 500; color: var(--text-muted); padding: 8px 16px; }
.param-name { font-family: "Roboto Mono", ui-monospace, monospace; font-weight: 500; }
.param-desc { color: var(--text-muted); font-size: 12.5px; }
.value { font-family: "Roboto Mono", ui-monospace, monospace; font-size: 12.5px; background: var(--surface-soft); padding: 1px 6px; border-radius: 3px; word-break: break-word; }
.cv { display: flex; gap: 8px; align-items: baseline; margin-top: 4px; flex-wrap: wrap; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 10px; background: var(--primary-soft); color: var(--primary); font-size: 12px; }
.row-actions { white-space: nowrap; text-align: right; }
.empty { text-align: center; padding: 56px 16px; color: var(--text-muted); }
.empty h2 { font-weight: 400; color: var(--text); margin-bottom: 8px; }
.empty .button { margin-top: 16px; }
.expr { font-family: "Roboto Mono", ui-monospace, monospace; font-size: 12.5px; color: var(--text-muted); word-break: break-word; }
.status { padding: 1px 8px; border-radius: 10px; font-size: 12px; background: var(--surface-soft); }
.status.active { background: var(--success-soft); color: var(--success); }
.status.paused { background: var(--warning-soft); color: var(--warning); }
.live { color: var(--success); font-weight: 500; }

/* Dialogs */
dialog { border: 0; border-radius: 8px; padding: 0; width: min(720px, calc(100vw - 24px)); max-height: calc(100vh - 32px); background: var(--surface); color: var(--text); box-shadow: 0 8px 28px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(32,33,36,.5); }
dialog form, dialog .dialog-body { display: grid; gap: 16px; padding: 24px; }
dialog h2 { font-size: 20px; font-weight: 400; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.cv-row, .rule-row { display: grid; gap: 8px; align-items: end; }
.cv-row { grid-template-columns: minmax(140px, 1fr) minmax(160px, 2fr) auto; }
.rule-row { grid-template-columns: minmax(130px, 1fr) minmax(120px, 1fr) minmax(130px, 1.4fr) auto; }
.rule-group { border: 1px solid var(--border); border-radius: 6px; padding: 12px; display: grid; gap: 8px; }
.or-label { text-align: center; color: var(--text-muted); font-weight: 500; font-size: 12px; }
.preview { background: var(--surface-soft); border-radius: 6px; padding: 10px 12px; }
.warnings { background: var(--warning-soft); border-radius: 6px; padding: 10px 12px 10px 28px; margin: 0; max-height: 160px; overflow: auto; }
.summary-list { display: grid; gap: 4px; }

/* Misc */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 24px); background: #323232; color: #fff; padding: 10px 18px; border-radius: 4px; opacity: 0; pointer-events: none; transition: .2s; z-index: 50; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.noscript-card { margin: 40px auto; max-width: 480px; padding: 24px; background: var(--surface); border-radius: 8px; }
@media (max-width: 720px) {
  .topbar, .page { padding-left: 12px; padding-right: 12px; }
  .grid2, .cv-row, .rule-row { grid-template-columns: 1fr; }
  th:nth-child(3), td:nth-child(3) { display: none; }
}
