:root {
  --navy: #0E1A2B;
  --navy-2: #172840;
  --green: #2D7A4F;
  --green-hover: #2A6650;
  --sand: #D9C7A3;
  --grey: #F5F7F9;
  --line: #E3E8ED;
  --text: #1A1A1A;
  --muted: #6B7280;
  --red: #B42318;
  --amber: #B54708;
  --shadow: 0 1px 2px rgba(14, 26, 43, .06), 0 4px 16px rgba(14, 26, 43, .06);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Instrument Sans", system-ui, -apple-system, sans-serif;
  color: var(--text); background: var(--grey); line-height: 1.5; font-size: 15px;
}
h1, h2, h3 { line-height: 1.2; margin: 0; font-weight: 700; }
h1 { font-size: 24px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
a { color: var(--green); }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { padding: 48px; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff;
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 14px; white-space: nowrap;
}
.btn:hover { border-color: #c9d1d9; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-hover); }
.btn.danger { color: var(--red); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: rgba(14, 26, 43, .06); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

/* Sign-in */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: linear-gradient(135deg, var(--navy) 0%, #152D42 55%, #245c44 100%); }
.login { background: #fff; border-radius: 16px; padding: 32px; width: 100%; max-width: 400px; box-shadow: var(--shadow); }
.login .brand { margin-bottom: 20px; }
.login p { margin: 6px 0 20px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { width: 36px; height: 36px; border-radius: 8px; background: #fff; }
.wordmark { font-family: Montserrat, sans-serif; font-weight: 800; font-size: 18px; letter-spacing: -.01em; }
.wordmark span { font-weight: 500; }
.login-status { margin-top: 14px; display: grid; gap: 6px; }
.login-status div { font-size: 13px; padding: 8px 10px; border-radius: 8px; background: var(--grey); }
.login-status .bad { background: #FEF3F2; color: var(--red); }
.login-status .ok { background: #ECFDF3; color: #067647; }

/* Shell */
.shell { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.side { background: var(--navy); color: #fff; padding: 20px 14px; display: flex; flex-direction: column; gap: 18px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side .brand { padding: 0 6px; }
.side h4 { margin: 0 0 6px; padding: 0 8px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--sand); font-weight: 600; }
.nav { display: grid; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 8px; color: #dfe6ee; text-decoration: none; padding: 8px 10px; border-radius: 8px; font-weight: 500; }
.nav a:hover { background: rgba(255, 255, 255, .07); }
.nav a.on { background: rgba(255, 255, 255, .12); color: #fff; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #6B7280; flex: none; }
.dot.on { background: #4FA374; }
.dot.err { background: #F97066; }
.side .spacer { flex: 1; }
.conn { display: grid; gap: 6px; font-size: 13px; }
.conn-row { display: flex; align-items: center; gap: 8px; padding: 4px 8px; color: #dfe6ee; }
.conn-row button { margin-left: auto; background: none; border: 0; color: var(--sand); cursor: pointer; text-decoration: underline; font-size: 12px; padding: 0; }
.side .who { padding: 8px; font-size: 12px; color: #9fb0c3; word-break: break-all; }
.side .btn { background: transparent; color: #fff; border-color: rgba(255, 255, 255, .25); justify-content: center; }

.main { padding: 28px 32px 64px; min-width: 0; }
.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .grow { flex: 1; min-width: 200px; }
.page-head p { margin: 4px 0 0; }
.banner { background: #FFFAEB; border: 1px solid #FEDF89; color: var(--amber); padding: 10px 14px; border-radius: 10px; margin-bottom: 16px; font-size: 14px; }

/* Cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; }
.card { background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 18px; }
a.card { text-decoration: none; color: inherit; display: block; transition: transform .12s, box-shadow .12s; }
a.card:hover { transform: translateY(-2px); box-shadow: 0 6px 24px rgba(14, 26, 43, .12); }
.card-top { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.swatch { width: 14px; height: 14px; border-radius: 4px; border: 1px solid rgba(0, 0, 0, .1); flex: none; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 14px; }
.stat { background: var(--grey); border-radius: 8px; padding: 8px; text-align: center; }
.stat b { display: block; font-size: 18px; }
.stat span { font-size: 11px; color: var(--muted); }
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--grey); color: var(--muted); white-space: nowrap; }
.pill.green { background: #ECFDF3; color: #067647; }
.pill.red { background: #FEF3F2; color: var(--red); }
.pill.sand { background: #F6EFDF; color: #6b5a2e; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs a { padding: 10px 14px; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.on { color: var(--navy); border-bottom-color: var(--green); }
.tabs a .count { font-weight: 500; font-size: 12px; margin-left: 4px; }

/* Toolbar + table */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input[type=search], .toolbar select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.toolbar input[type=search] { flex: 1; min-width: 180px; max-width: 340px; }
.toolbar .grow { flex: 1; }
.table-wrap { background: #fff; border: 1px solid var(--line); border-radius: 12px; overflow-x: auto; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--line); background: #fff; white-space: nowrap; }
td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr.row { cursor: pointer; }
tbody tr.row:hover { background: #FAFBFC; }
tr.group td { background: var(--grey); font-weight: 700; font-size: 13px; padding: 8px 14px; color: var(--navy); }
tr.off td:not(.keep) { opacity: .5; }
td .sub { display: block; color: var(--muted); font-size: 13px; max-width: 520px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.num, th.num { text-align: right; white-space: nowrap; }
td.tight { white-space: nowrap; width: 1%; }
.empty { padding: 36px; text-align: center; color: var(--muted); }

/* Switch */
.switch { position: relative; width: 36px; height: 20px; border-radius: 999px; background: #CBD2D9; border: 0; cursor: pointer; padding: 0; flex: none; vertical-align: middle; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left .12s; }
.switch[aria-checked=true] { background: var(--green); }
.switch[aria-checked=true]::after { left: 18px; }

/* Forms */
.form { display: grid; gap: 14px; }
.form .two { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field label, .field .lbl { display: block; font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 3px; }
.field input[type=text], .field input[type=email], .field input[type=password], .field input[type=url], .field input[type=number],
.field input[type=date], .field select, .field textarea {
  width: 100%; padding: 9px 10px; border: 1px solid #cfd6dd; border-radius: 8px; background: #fff;
}
.field textarea { min-height: 90px; resize: vertical; line-height: 1.5; }
.field textarea.tall { min-height: 300px; }
.field textarea.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.counter { float: right; font-weight: 400; color: var(--muted); font-size: 12px; }
.section { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 20px; box-shadow: var(--shadow); margin-bottom: 16px; max-width: 860px; }
.section h2 { margin-bottom: 14px; }
.actions { display: flex; gap: 10px; align-items: center; }
.colour { display: flex; gap: 8px; align-items: center; }
.colour input[type=color] { width: 40px; height: 38px; padding: 2px; border: 1px solid #cfd6dd; border-radius: 8px; background: #fff; flex: none; }
.domains { display: grid; gap: 6px; margin-bottom: 12px; }
.domain { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--grey); border-radius: 8px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.domain button { margin-left: auto; }
.inline-add { display: flex; gap: 8px; }
.inline-add input { flex: 1; padding: 9px 10px; border: 1px solid #cfd6dd; border-radius: 8px; }

/* Rates grid */
.rates input { width: 84px; padding: 6px 8px; border: 1px solid #cfd6dd; border-radius: 6px; text-align: right; }
.rates input.changed { border-color: var(--green); background: #ECFDF3; }
.rates td { vertical-align: middle; }

/* Drawer */
dialog.drawer { border: 0; padding: 0; margin: 0 0 0 auto; height: 100vh; max-height: 100vh; width: min(640px, 100vw); max-width: 100vw; background: #fff; box-shadow: -8px 0 40px rgba(14, 26, 43, .2); }
dialog.drawer::backdrop, dialog.confirm::backdrop { background: rgba(14, 26, 43, .45); }
.drawer form { display: flex; flex-direction: column; height: 100%; }
.drawer-head { display: flex; align-items: center; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { flex: 1; }
.drawer-body { padding: 20px 22px; overflow-y: auto; flex: 1; }
.drawer-foot { display: flex; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--line); background: #fff; }
.drawer-foot .grow { flex: 1; }
.meta { font-size: 12px; color: var(--muted); margin-top: 16px; }
dialog.confirm { border: 0; border-radius: 14px; padding: 24px; max-width: 420px; box-shadow: var(--shadow); }
dialog.confirm p { margin: 8px 0 20px; color: var(--muted); }
dialog.confirm .actions { justify-content: flex-end; }

/* Toasts */
#toasts { position: fixed; right: 20px; bottom: 20px; display: grid; gap: 8px; z-index: 1000; }
.toast { background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); font-size: 14px; max-width: 380px; }
.toast.err { background: var(--red); }

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; }
  .side .spacer { display: none; }
  .main { padding: 20px 16px 48px; }
  .form .two { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}

.field textarea.auto { min-height: 0; }
.field textarea.changed { border-color: var(--green); background: #ECFDF3; }
