:root {
  --ink: #161a26;
  --muted: #5d6578;
  --navy: #1a2033;
  --navy-2: #252d47;
  --navy-line: #323b5a;
  --on-navy: #e8ebf5;
  --on-navy-muted: #9aa3bd;
  --fog: #eceef3;
  --paper: #ffffff;
  --line: #d6d9e3;
  --gold: #e3a72f;
  --focus: #3552d6;
  --danger: #b83a28;
  --ok: #23805a;
  --field: #ffffff;
  --field-line: #bcc1cf;
  --head: #f7f8fb;
  --switch-off: #bfc4d3;
  --switch-on: #1a2033;
  --btn-bg: #1a2033;
  --btn-fg: #ffffff;
  --btn-hover: #252d47;
  --danger-text: #b83a28;
  --danger-line: #e2b9b2;
  --danger-hover: #fbeeec;
  --tag-ok-bg: #dff2e8;
  --tag-ok: #23805a;
  --tag-todo-bg: #fbecc9;
  --tag-todo: #7a5300;
  --tag-off-bg: #e6e8ee;
  --toast-bg: #161a26;
  --toast-fg: #ffffff;
  --chip-bg: #eceef3;
  color-scheme: light;
  --display: 'Bricolage Grotesque', 'Hanken Grotesk', system-ui, sans-serif;
  --body: 'Hanken Grotesk', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

:root[data-theme="dark"] {
  --ink: #e8ebf5;
  --muted: #9aa3bd;
  --fog: #11141d;
  --paper: #1a1f2e;
  --line: #2b3250;
  --navy: #0b0d15;
  --navy-2: #1a2033;
  --navy-line: #262d47;
  --focus: #8ea2ff;
  --danger: #ff8b7a;
  --field: #131726;
  --field-line: #3a4366;
  --head: #20263a;
  --switch-off: #434b68;
  --switch-on: #5f73e0;
  --btn-bg: #e8ebf5;
  --btn-fg: #11141d;
  --btn-hover: #ffffff;
  --danger-text: #ff8b7a;
  --danger-line: #5a2e2a;
  --danger-hover: #2b1b1b;
  --tag-ok-bg: #17352b;
  --tag-ok: #6fd0a3;
  --tag-todo-bg: #3b2f12;
  --tag-todo: #f0c565;
  --tag-off-bg: #272d42;
  --toast-bg: #e8ebf5;
  --toast-fg: #11141d;
  --chip-bg: #232a40;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--fog);
  color: var(--ink);
  font: 400 15px/1.5 var(--body);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
h1, h2, h3 { font-family: var(--display); margin: 0; letter-spacing: -0.01em; }

.shell { display: grid; grid-template-columns: 280px minmax(0, 1fr); min-height: 100vh; }

.side {
  background: var(--navy);
  color: var(--on-navy);
  padding: 16px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; font: 700 20px/1 var(--display); }
.brand i { width: 12px; height: 12px; background: var(--gold); transform: rotate(45deg); border-radius: 2px; display: block; }

.switcher { position: relative; }
.switcher > button {
  width: 100%; display: flex; align-items: center; gap: 10px; text-align: left;
  background: var(--navy-2); border: 1px solid var(--navy-line); color: inherit;
  border-radius: 10px; padding: 9px 10px;
}
.switcher .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.switcher .chev { color: var(--on-navy-muted); font-size: 12px; }
.menu {
  position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 6px);
  background: var(--navy-2); border: 1px solid var(--navy-line); border-radius: 10px;
  padding: 6px; max-height: 320px; overflow: auto; box-shadow: 0 12px 28px rgba(8, 10, 20, .4);
}
.menu button {
  width: 100%; display: flex; align-items: center; gap: 10px; background: none; border: 0; color: inherit;
  padding: 8px; border-radius: 8px; text-align: left;
}
.menu button:hover, .menu button[aria-current="true"] { background: var(--navy); }
.avatar {
  width: 28px; height: 28px; border-radius: 8px; flex: none; background: var(--navy-line);
  display: grid; place-items: center; font: 700 12px var(--display); color: var(--on-navy); overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label { color: var(--on-navy-muted); font-size: 13px; padding: 8px 10px 2px; }
nav a {
  display: block; padding: 5px 10px 5px 12px; border-radius: 8px; color: var(--on-navy);
  text-decoration: none; border-left: 3px solid transparent; position: relative;
}
nav a:hover { background: var(--navy-2); }
nav a[aria-current="page"] { background: var(--navy-2); border-left-color: var(--gold); font-weight: 600; }
nav a .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--gold); margin-left: 8px; vertical-align: middle; }

.me { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 12px 8px 0; border-top: 1px solid var(--navy-line); }
.me span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me .avatar { flex: none; }
.link-btn { background: none; border: 0; padding: 4px 0; color: var(--on-navy-muted); text-decoration: underline; text-underline-offset: 3px; }
.link-btn:hover { color: var(--on-navy); }

.main { padding: 36px clamp(16px, 4vw, 56px) 140px; min-width: 0; }
.page { max-width: 860px; }
.page > header { margin-bottom: 8px; }
.page h1 { font-size: clamp(26px, 3.2vw, 34px); line-height: 1.1; font-weight: 700; }
.page .blurb { color: var(--muted); margin: 8px 0 0; max-width: 60ch; }
.page-actions { margin-top: 14px; }
.text-btn { background: none; border: 0; padding: 0; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.text-btn:hover { color: var(--ink); }

.group { margin-top: 30px; }
.group > h2 { font-size: 17px; font-weight: 700; padding-bottom: 6px; border-bottom: 2px solid var(--ink); }
.rows { background: var(--paper); border-radius: 12px; padding: 0 20px; margin-top: 14px; border: 1px solid var(--line); }
.group > h2 + .rows { margin-top: 0; border-top-left-radius: 0; border-top-right-radius: 0; border-top: 0; }

.row {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(180px, 340px); gap: 8px 28px;
  padding: 16px 0; border-top: 1px solid var(--line); align-items: start;
}
.row:first-child { border-top: 0; }
.row.wide { grid-template-columns: minmax(0, 1fr); }
.row.dim .ctl { opacity: .45; }
.row label, .row .lbl { font-weight: 600; display: block; }
.row .help { color: var(--muted); font-size: 14px; margin-top: 2px; max-width: 56ch; }
.ctl { min-width: 0; display: flex; align-items: center; gap: 10px; }
.row.wide .ctl { display: block; }
.unit { color: var(--muted); font-size: 14px; white-space: nowrap; }
.changed .lbl::after { content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--gold); margin-left: 8px; vertical-align: middle; }

input[type=text], input[type=number], input[type=search], select, textarea {
  width: 100%; background: var(--field); border: 1px solid var(--field-line); border-radius: 8px; padding: 8px 10px; min-height: 38px;
}
input[type=number] { width: 120px; }
input[type=color] { width: 44px; height: 38px; padding: 2px; border: 1px solid var(--field-line); border-radius: 8px; background: var(--field); }
textarea { resize: vertical; min-height: 84px; line-height: 1.45; }
textarea.mono { font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace; font-size: 13.5px; min-height: 150px; }
.count { color: var(--muted); font-size: 13px; margin-top: 4px; }

.switch {
  position: relative; width: 42px; height: 24px; border-radius: 12px; border: 0; padding: 0; flex: none;
  background: var(--switch-off); transition: background .15s;
}
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch[aria-checked="true"] { background: var(--switch-on); }
.switch[aria-checked="true"]::after { transform: translateX(18px); }
.switch-text { color: var(--muted); font-size: 14px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--chip-bg); border: 1px solid var(--line); border-radius: 999px; padding: 3px 4px 3px 10px; font-size: 14px; }
.chip button { border: 0; background: none; width: 20px; height: 20px; border-radius: 50%; line-height: 1; color: var(--muted); }
.chip button:hover { background: var(--line); color: var(--ink); }
.row .multi { width: 100%; }
.empty-note { color: var(--muted); font-size: 14px; }

.btn {
  border: 1px solid var(--btn-bg); background: var(--btn-bg); color: var(--btn-fg); border-radius: 9px; padding: 8px 16px; font-weight: 600;
}
.btn:hover { background: var(--btn-hover); border-color: var(--btn-hover); }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--field-line); }
.btn.ghost:hover { background: var(--fog); border-color: var(--field-line); }
.btn.danger { background: transparent; color: var(--danger-text); border-color: var(--danger-line); }
.btn.danger:hover { background: var(--danger-hover); border-color: var(--danger-line); }
.btn.small { padding: 4px 10px; font-weight: 500; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: default; }

.savebar {
  position: fixed; left: calc(280px + (100vw - 280px) / 2); transform: translateX(-50%); bottom: 22px; z-index: 30;
  width: min(640px, calc(100vw - 32px - 280px)); background: var(--gold); color: #2a1d02; border-radius: 14px;
  padding: 12px 14px 12px 20px; display: flex; align-items: center; gap: 12px;
  box-shadow: 0 14px 34px rgba(26, 32, 51, .28);
  animation: rise .22s ease-out;
}
.savebar p { margin: 0; flex: 1; font-weight: 600; }
.savebar .btn.ghost { border-color: rgba(42, 29, 2, .4); color: #2a1d02; }
.savebar .btn.ghost:hover { background: rgba(42, 29, 2, .1); }
@keyframes rise { from { transform: translate(-50%, 24px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

#toast {
  position: fixed; right: 24px; top: 18px; transform: translateY(-12px); opacity: 0; pointer-events: none;
  background: var(--toast-bg); color: var(--toast-fg); padding: 10px 18px; border-radius: 10px; z-index: 50; transition: opacity .18s, transform .18s;
  max-width: calc(100vw - 48px);
}
#toast.show { opacity: 1; transform: translateY(0); }
#toast.bad { background: var(--danger); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0; margin: 22px 0 0; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; }
.stats div { padding: 14px 18px; border-left: 1px solid var(--line); }
.stats div:first-child { border-left: 0; }
.stats dt { color: var(--muted); font-size: 14px; }
.stats dd { margin: 2px 0 0; font: 700 26px/1.2 var(--display); }

.check { display: flex; align-items: center; gap: 12px; padding: 13px 0; border-top: 1px solid var(--line); }
.check:first-child { border-top: 0; }
.check .what { flex: 1; min-width: 0; }
.check .what b { font-weight: 600; }
.check .what span { display: block; color: var(--muted); font-size: 14px; }
.tag { font-size: 13px; font-weight: 600; padding: 2px 10px; border-radius: 999px; }
.tag.ok { background: var(--tag-ok-bg); color: var(--tag-ok); }
.tag.todo { background: var(--tag-todo-bg); color: var(--tag-todo); }
.tag.off { background: var(--tag-off-bg); color: var(--muted); }

.inline-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 12px; }
.inline-form select, .inline-form input { flex: 1 1 220px; width: auto; }

.table-wrap { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; margin-top: 18px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
th, td { text-align: left; padding: 11px 16px; border-top: 1px solid var(--line); vertical-align: top; }
thead th { border-top: 0; color: var(--muted); font-weight: 500; font-size: 14px; background: var(--head); }
td.reason { min-width: 220px; }
td.when { white-space: nowrap; color: var(--muted); }
.empty { padding: 36px 20px; text-align: center; color: var(--muted); }
.empty b { display: block; color: var(--ink); font: 700 17px var(--display); margin-bottom: 4px; }

.verdict { margin-top: 16px; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 4px 20px; }
.verdict .check .tag { min-width: 92px; text-align: center; }
.metrics { color: var(--muted); font-size: 14px; margin-top: 12px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--navy); color: var(--on-navy); }
.login .box { max-width: 420px; }
.login .brand { padding: 0; margin-bottom: 28px; font-size: 24px; }
.login h1 { font-size: 34px; line-height: 1.1; }
.login p { color: var(--on-navy-muted); margin: 12px 0 26px; }
.login .btn { background: var(--gold); border-color: var(--gold); color: #2a1d02; padding: 11px 22px; text-decoration: none; display: inline-block; }
.login .btn:hover { background: #efb840; border-color: #efb840; }
.plain-page { padding: 60px 24px; max-width: 560px; margin: 0 auto; }
.plain-page code { background: var(--paper); border: 1px solid var(--line); padding: 1px 6px; border-radius: 5px; word-break: break-all; }

.topbar { display: none; }

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .topbar {
    display: flex; align-items: center; gap: 12px; background: var(--navy); color: var(--on-navy);
    padding: 10px 16px; position: sticky; top: 0; z-index: 25;
  }
  .topbar button { background: var(--navy-2); border: 1px solid var(--navy-line); color: inherit; border-radius: 8px; padding: 6px 12px; }
  .side { position: fixed; z-index: 40; inset: 0 auto 0 0; width: min(300px, 86vw); transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .scrim { position: fixed; inset: 0; background: rgba(8, 10, 20, .5); z-index: 35; }
  .savebar { left: 50%; width: calc(100vw - 32px); bottom: 14px; flex-wrap: wrap; }
  .row { grid-template-columns: minmax(0, 1fr); }
  .rows { padding: 0 14px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

.savebar[hidden] { display: none; }

.theme-btn {
  display: flex; align-items: center; gap: 10px; width: 100%; margin-top: auto; background: none; border: 0;
  color: var(--on-navy); padding: 8px 12px; border-radius: 8px; text-align: left;
}
.theme-btn:hover { background: var(--navy-2); }
.theme-btn + .me { margin-top: 0; }
.theme-icon {
  width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; flex: none;
  background: linear-gradient(90deg, currentColor 50%, transparent 50%);
}

/* ticket types editor */
.tt { display: grid; gap: 12px; }
.tt-card { border: 1px solid var(--line); border-radius: 10px; padding: 14px; background: var(--head); }
.tt-head { display: flex; gap: 8px; align-items: center; }
.tt-head .tt-emoji { width: 58px; text-align: center; font-size: 18px; padding: 6px; }
.tt-head .tt-name { flex: 1; min-width: 0; font-weight: 600; }
.tt-tools { display: flex; gap: 6px; flex: none; }
.icon-btn { width: 34px; height: 34px; border: 1px solid var(--field-line); background: var(--field); color: var(--ink); border-radius: 8px; flex: none; }
.icon-btn:hover:not(:disabled) { background: var(--fog); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.tt-field { display: block; margin-top: 12px; }
.tt-field > span { display: block; font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.tt-field > small, .tt-addq small { display: block; color: var(--muted); font-size: 13px; margin-top: 4px; }
.tt-q { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--line); }
.tt-q:first-of-type { border-top: 0; }
.tt-qn { width: 22px; height: 22px; border-radius: 50%; background: var(--chip-bg); display: grid; place-items: center; font-size: 12px; font-weight: 600; flex: none; margin-top: 8px; }
.tt-qfields { flex: 1; min-width: 0; display: grid; gap: 6px; }
.tt-checks { display: flex; gap: 18px; flex-wrap: wrap; font-size: 14px; color: var(--muted); }
.tt-check { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.tt-check input { accent-color: var(--switch-on); width: 16px; height: 16px; }
.tt-addq { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-top: 6px; }
.tt-addq small { margin-top: 0; }
.tt-more { margin-top: 12px; }
.tt-more summary { cursor: pointer; color: var(--muted); font-size: 14px; }
.tt-empty { border: 1px dashed var(--field-line); border-radius: 10px; padding: 18px; text-align: center; color: var(--muted); }
.tt-empty p { margin: 0 0 10px; }
input[type=url] { width: 100%; background: var(--field); border: 1px solid var(--field-line); border-radius: 8px; padding: 8px 10px; min-height: 38px; }
@media (max-width: 860px) { .tt-head { flex-wrap: wrap; } .tt-tools { width: 100%; justify-content: flex-end; } }
.row .tt label { font-weight: 400; }
.row .tt .tt-field > span { font-weight: 600; }
