/* Forms Hub dashboard */
:root {
  --bg: #f6f7f9; --panel: #fff; --ink: #111827; --ink-2: #4b5563; --ink-3: #6b7280; --line: #e5e7eb; --line-2: #eef0f3;
  --brand: #4f46e5; --brand-ink: #fff; --brand-soft: #eef2ff; --side: #0f172a; --side-ink: #cbd5e1; --side-active: #1e293b;
  --ok: #047857; --ok-soft: #d1fae5; --warn: #b45309; --warn-soft: #fef3c7; --bad: #b91c1c; --bad-soft: #fee2e2; --info: #1d4ed8; --info-soft: #dbeafe;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { font: 14px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 650; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }

/* layout */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.side .logo { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 16px; padding: 4px 10px 18px; }
.side .logo span.mark { width: 28px; height: 28px; border-radius: 8px; background: linear-gradient(135deg, #6366f1, #22d3ee); display: grid; place-items: center; font-size: 14px; }
.side a.nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border-radius: 8px; color: var(--side-ink); font-weight: 500; }
.side a.nav:hover { background: var(--side-active); text-decoration: none; color: #fff; }
.side a.nav.active { background: var(--side-active); color: #fff; }
.side .pill { background: #334155; color: #fff; border-radius: 999px; font-size: 11px; padding: 0 7px; }
.side .pill.hot { background: var(--brand); }
.side .grow { flex: 1; }
.side .who { border-top: 1px solid #1e293b; padding: 12px 10px 0; font-size: 12px; }
.side .who button { background: none; border: 0; color: var(--side-ink); padding: 0; cursor: pointer; font: inherit; text-decoration: underline; }
.main { min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 20px 28px 0; }
.crumbs { color: var(--ink-3); font-size: 13px; margin-bottom: 4px; }
.crumbs a { color: var(--ink-3); }
.content { padding: 20px 28px 48px; display: grid; gap: 20px; }

/* panels */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card > .head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card > .body { padding: 18px; }
.card > .body.flush { padding: 0; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.side-right { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
.stat { padding: 16px 18px; }
.stat .n { font-size: 26px; font-weight: 700; }
.stat .l { color: var(--ink-3); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stat.hot .n { color: var(--brand); }
.stat.bad .n { color: var(--bad); }

/* buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 7px 12px; border-radius: 8px; font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f9fafb; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* badges */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--line-2); color: var(--ink-2); }
.badge.new, .badge.pending, .badge.sending { background: var(--info-soft); color: var(--info); }
.badge.read { background: var(--line-2); color: var(--ink-2); }
.badge.in_progress, .badge.warn, .badge.test { background: var(--warn-soft); color: var(--warn); }
.badge.closed, .badge.sent, .badge.ok, .badge.live, .badge.set { background: var(--ok-soft); color: var(--ok); }
.badge.failed, .badge.bad, .badge.missing, .badge.off { background: var(--bad-soft); color: var(--bad); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: currentColor; }

/* tables */
table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { text-align: start; padding: 10px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.list th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); font-weight: 600; background: #fafbfc; }
table.list tr:last-child td { border-bottom: 0; }
table.list tr.unread td { font-weight: 600; }
table.list tr.clickable:hover td { background: #fafaff; cursor: pointer; }
table.kv { width: 100%; border-collapse: collapse; }
table.kv th { width: 34%; text-align: start; vertical-align: top; padding: 12px 16px; color: var(--ink-2); font-weight: 600; border-bottom: 1px solid var(--line-2); }
table.kv th small { display: block; font-weight: 400; color: var(--ink-3); font-family: var(--mono); font-size: 11px; }
table.kv td { padding: 12px 16px; border-bottom: 1px solid var(--line-2); white-space: pre-wrap; word-break: break-word; }
.empty { padding: 36px; text-align: center; color: var(--ink-3); }

/* forms */
label { font-weight: 600; font-size: 13px; }
.field { display: grid; gap: 6px; align-content: start; }
.field .help { color: var(--ink-3); font-size: 12px; font-weight: 400; }
.field .errorlist, ul.errorlist { margin: 0; padding: 0; list-style: none; color: var(--bad); font-size: 12.5px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; border: 1px solid #d1d5db; border-radius: 8px; padding: 7px 10px; font: inherit; background: #fff; color: var(--ink);
}
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], select { height: 40px; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #c7d2fe; border-color: var(--brand); }
input[disabled], select[disabled], textarea[disabled] { background: #f3f4f6; color: var(--ink-3); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: 16px; height: 16px; }
.form-grid { display: grid; gap: 14px; }
.form-grid.two { grid-template-columns: 1fr 1fr; }
.filters { display: grid; grid-template-columns: 2fr repeat(3, 1fr) 1fr 1fr auto; gap: 10px; align-items: end; }

/* messages */
.flash { padding: 10px 14px; border-radius: 8px; border: 1px solid; font-weight: 500; }
.flash.success { background: var(--ok-soft); border-color: #a7f3d0; color: var(--ok); }
.flash.error { background: var(--bad-soft); border-color: #fecaca; color: var(--bad); }
.flash.warning { background: var(--warn-soft); border-color: #fde68a; color: var(--warn); }
.flash.info { background: var(--info-soft); border-color: #bfdbfe; color: var(--info); }
.callout { padding: 12px 14px; border-radius: 8px; background: var(--brand-soft); color: #3730a3; font-size: 13px; }
.callout.warn { background: var(--warn-soft); color: var(--warn); }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 0 28px; padding-top: 14px; }
.tabs a { padding: 9px 14px; color: var(--ink-2); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--brand); border-color: var(--brand); }
.tabs a:hover { text-decoration: none; color: var(--ink); }

/* field builder */
fieldset.bare { border: 0; padding: 0; margin: 0; min-width: 0; }
.card > .head .sub { margin: 2px 0 0; }
.fields { display: grid; gap: 10px; }
.frow { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); transition: border-color .15s, box-shadow .15s; }
.frow.open { border-color: #c7d2fe; box-shadow: 0 0 0 3px var(--brand-soft); }
.frow.has-errors { border-color: #fca5a5; box-shadow: 0 0 0 3px var(--bad-soft); }
.frow .fhead { display: flex; align-items: center; gap: 10px; padding: 8px 12px 8px 8px; min-height: 52px; }
.frow .grip { display: flex; flex-direction: column; gap: 2px; flex: none; }
.frow .grip button { border: 1px solid transparent; background: none; border-radius: 6px; width: 26px; height: 18px; line-height: 1; cursor: pointer; color: var(--ink-3); font-size: 12px; padding: 0; }
.frow .grip button:hover { background: var(--line-2); color: var(--ink); }
.frow:first-child .grip [data-move=up], .frow:last-child .grip [data-move=down] { opacity: .25; pointer-events: none; }
.frow .fsummary { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; background: none; border: 0; padding: 4px 0; font: inherit; color: inherit; text-align: start; cursor: pointer; }
.frow .ficon { flex: none; width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); font-weight: 700; font-size: 13px; }
.frow[data-type=text] .ficon::before { content: "Aa"; }
.frow[data-type=email] .ficon::before { content: "@"; }
.frow[data-type=tel] .ficon::before { content: "#"; }
.frow[data-type=textarea] .ficon::before { content: "¶"; }
.frow[data-type=select] .ficon::before { content: "≡"; }
.frow[data-type=checkbox] .ficon::before { content: "✓"; }
.frow[data-type=file] .ficon::before { content: "⇪"; }
.frow .ftitle { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.frow .ftitle strong, .frow .ftitle code { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.frow .ftitle code { color: var(--ink-3); font-size: 12px; }
.frow .fmeta { display: flex; gap: 6px; flex: none; }
.frow .chev { flex: none; width: 8px; height: 8px; border-right: 2px solid var(--ink-3); border-bottom: 2px solid var(--ink-3); transform: rotate(45deg); margin: 0 6px -4px; transition: transform .15s; }
.frow.open .chev { transform: rotate(-135deg); margin-bottom: 2px; }
.frow .fremove { flex: none; display: inline-flex; align-items: center; padding: 5px 10px; border-radius: 8px; border: 1px solid var(--line); font-size: 12.5px; font-weight: 550; color: var(--ink-2); cursor: pointer; }
.frow .fremove:hover { border-color: #fecaca; color: var(--bad); background: var(--bad-soft); }
.frow .fremove input { position: absolute; opacity: 0; pointer-events: none; }
.frow .fremove:has(input:focus-visible) { outline: 2px solid #c7d2fe; }
.frow .fbody { display: none; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 14px 16px; padding: 14px 16px 16px; border-top: 1px solid var(--line-2); }
.frow.open .fbody { display: grid; }
.frow .fbody > div { min-width: 0; }
.frow .fbody .field { align-content: start; }
.frow .c-label { grid-column: span 5; }
.frow .c-key { grid-column: span 4; }
.frow .c-type { grid-column: span 3; }
.frow .c-ph { grid-column: 1 / span 5; }
.frow .c-len { grid-column: span 4; }
.frow .c-req { grid-column: 10 / span 3; }
.frow .c-opts { grid-column: 1 / -1; }
.frow[data-type=select] .c-req, .frow[data-type=checkbox] .c-req, .frow[data-type=file] .c-req { grid-column: 1 / span 4; }
.frow .opts { display: none; }
.frow[data-type=select] .opts { display: block; }
.frow[data-type=select] .len, .frow[data-type=checkbox] .len, .frow[data-type=checkbox] .ph, .frow[data-type=select] .ph,
.frow[data-type=file] .len, .frow[data-type=file] .ph { display: none; }
.frow .flabel { font-weight: 600; font-size: 13px; }
.toggle { display: flex; align-items: center; gap: 10px; height: 40px; padding: 0 12px; border: 1px solid #d1d5db; border-radius: 8px; font-weight: 500; cursor: pointer; background: #fff; }
.frow .fdeleted { display: none; padding: 0 16px 12px 52px; color: var(--bad); font-size: 12.5px; }
.frow.deleted { background: #fafafa; border-style: dashed; box-shadow: none; border-color: var(--line); }
.frow.deleted .fdeleted { display: block; }
.frow.deleted .fbody, .frow.deleted .chev, .frow.deleted .grip { visibility: hidden; }
.frow.deleted .fbody { display: none; }
.frow.deleted .ftitle, .frow.deleted .ficon, .frow.deleted .fmeta { opacity: .45; }
.frow.deleted .ftitle strong { text-decoration: line-through; }
.frow.deleted .fremove { color: var(--brand); border-color: #c7d2fe; background: var(--brand-soft); }
.add-field { display: block; width: 100%; margin-top: 12px; padding: 12px; border: 1.5px dashed #c7d2fe; border-radius: 10px; background: #fafaff; color: var(--brand); font: inherit; font-weight: 600; cursor: pointer; }
.add-field:hover { background: var(--brand-soft); border-color: var(--brand); }
.fields-empty { border: 1px dashed var(--line); border-radius: 10px; padding: 28px; }
.copyline { display: flex; align-items: center; gap: 8px; }
.copyline code { flex: 1; min-width: 0; background: #f3f4f6; padding: 7px 10px; border-radius: 8px; overflow-wrap: anywhere; font-size: 12px; }
.savebar { position: sticky; bottom: 16px; z-index: 5; margin-top: 20px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 12px 10px 18px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 24px rgba(16,24,40,.12); }
@media (min-width: 1101px) { .savebar { width: calc(100% - 356px); } }
.savebar .dot { color: var(--ok); margin-inline-end: 8px; vertical-align: 1px; }
.savebar.dirty { border-color: #c7d2fe; }
.savebar.dirty .dot { color: var(--warn); }
.savebar.dirty [data-save-state] { font-weight: 600; }

/* code */
.code { position: relative; }
.code pre { margin: 0; background: #0b1020; color: #e2e8f0; padding: 14px 16px; border-radius: 8px; overflow: auto; max-height: 440px; line-height: 1.55; }
.code .copy { position: absolute; top: 8px; right: 8px; background: #1e293b; color: #e2e8f0; border: 1px solid #334155; }
.code .copy:hover { background: #334155; }
.steps { counter-reset: step; display: grid; gap: 18px; }
.step { display: grid; grid-template-columns: 30px 1fr; gap: 12px; }
.step::before { counter-increment: step; content: counter(step); width: 26px; height: 26px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.step h3 { margin-bottom: 6px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { background: #fff; border: 0; padding: 6px 12px; font: inherit; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.seg button.on { background: var(--brand-soft); color: var(--brand); }
.kvline { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line-2); }
.kvline > :first-child { grid-column: 1 / -1; font-size: 12px; }
.kvline.row { grid-template-columns: auto 1fr auto; }
.kvline.row > :first-child { grid-column: auto; }
.kvline:last-child { border-bottom: 0; }
.kvline code { background: #f3f4f6; padding: 3px 7px; border-radius: 6px; overflow-wrap: anywhere; }

/* pagination */
.pager { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line-2); }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(circle at 20% 10%, #e0e7ff, transparent 40%), var(--bg); }
.login .card { width: 100%; max-width: 380px; }

@media (max-width: 1100px) { .grid.cols-4 { grid-template-columns: repeat(2, 1fr); } .grid.side-right { grid-template-columns: 1fr; } .filters { grid-template-columns: 1fr 1fr; } }
@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; } .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; } .side .grow, .side .who { display: none; }
  .content, .topbar { padding-left: 16px; padding-right: 16px; } .tabs { margin: 0 16px; }
  .grid.cols-2, .grid.cols-3, .form-grid.two { grid-template-columns: 1fr; }
  .frow .fbody > div { grid-column: 1 / -1 !important; }
  .frow .fmeta .badge[data-preview=type] { display: none; }
  .frow .fremove { padding: 5px 8px; }
  .savebar .hide-sm { display: none; }
  table.list .hide-sm { display: none; }
}

/* permission matrix */
table.list.perms { border: 1px solid var(--line-2); border-radius: 8px; }
table.list.perms th:not(:first-child), table.list.perms td:not(:first-child) { text-align: center; }
table.list.perms th:last-child, table.list.perms td:last-child { text-align: start; }
table.list.perms.off { opacity: .45; pointer-events: none; }
table.list.perms input[type=checkbox] { width: 16px; height: 16px; }

/* languages */
.lang-tag { display: inline-block; padding: 0 5px; border-radius: 4px; background: var(--line-2); color: var(--ink-2); font-size: 10.5px; font-weight: 700; letter-spacing: .03em; }
.langbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 18px; border-bottom: 1px solid var(--line); background: #fafbfc; }
.badge.missing-tr { background: var(--line-2); color: var(--ink-3); font-weight: 600; }
.builder[data-lang]:not([data-lang=""]) .frow.open { border-color: #a5b4fc; }

/* form sections: title + one-line description, separated by a rule */
.form-section { display: grid; gap: 14px; }
.form-section + .form-section { border-top: 1px solid var(--line-2); padding-top: 20px; }
.form-section > .section-head h3 { font-size: 14px; }
.form-section > .section-head p { margin: 2px 0 0; color: var(--ink-3); font-size: 12.5px; }
.form-foot { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; border-top: 1px solid var(--line-2); padding-top: 18px; }
.form-foot .grow { flex: 1; }

/* on/off rows: title + help on one side, switch on the other */
.switches { display: grid; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 14px; cursor: pointer; font-weight: 400; background: #fff; }
.switch-row + .switch-row { border-top: 1px solid var(--line-2); }
.switch-row:hover { background: #fafbfc; }
.switch-row strong { display: block; font-weight: 600; font-size: 13.5px; }
.switch-row .help { color: var(--ink-3); font-size: 12px; }
.switch-row input, .toggle input { appearance: none; margin: 0; flex: none; width: 34px; height: 20px; border-radius: 999px; background: #d1d5db; position: relative; cursor: pointer; transition: background .15s; }
.switch-row input::after, .toggle input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: transform .15s; }
.switch-row input:checked, .toggle input:checked { background: var(--brand); }
.switch-row input:checked::after, .toggle input:checked::after { transform: translateX(14px); }
.switch-row input:focus-visible, .toggle input:focus-visible { outline: 2px solid #c7d2fe; outline-offset: 2px; }
.switch-row input[disabled] { opacity: .5; cursor: not-allowed; }
.switch-row .errorlist { margin-top: 4px; }

/* key/value side panel */
.kv-list { display: grid; gap: 14px; }
.kv-list > div { display: grid; gap: 4px; }
.kv-list .k { color: var(--ink-3); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
td.row-actions { text-align: end; white-space: nowrap; }
td.row-actions .actions { justify-content: flex-end; flex-wrap: nowrap; }
/* keys, hostnames and origins in monospace (also avoids "1x00" rendering as "1×00") */
input.mono, textarea.mono { font-family: var(--mono); font-size: 13px; font-variant-ligatures: none; }

/* wide tables scroll inside their card instead of widening the page on phones */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-wrap > table { min-width: 100%; }
table.list.perms td:last-child .check { white-space: nowrap; }
.frow .ftitle strong, table.list td strong { overflow-wrap: anywhere; }
@media (max-width: 800px) {
  table.list th, table.list td { padding: 10px; }
  .topbar { flex-wrap: wrap; }
}
.content > *, .grid > * { min-width: 0; }
.card > .head { flex-wrap: wrap; }
