:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --text: #1b1f24;
  --muted: #667085;
  --primary: #2f6fed;
  --primary-text: #ffffff;
  --danger: #d93a3a;
  --ok-bg: #e3f6ea;   --ok-fg: #1d7a43;
  --warn-bg: #fff3d6; --warn-fg: #8a5a00;
  --proxy-bg: #ffe9d9; --proxy-fg: #b4520c;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 12px rgba(16, 24, 40, .06);
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1f242c;
    --border: #2b313a;
    --text: #e7eaee;
    --muted: #98a2b3;
    --primary: #5b8ef5;
    --danger: #f06767;
    --ok-bg: #12301f;   --ok-fg: #6fd69a;
    --warn-bg: #352a0c; --warn-fg: #f2c25b;
    --proxy-bg: #3a2414; --proxy-fg: #f5a46a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 12px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 17px; margin-bottom: 14px; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.pad { padding: 14px; }
.error { color: var(--danger); margin: 8px 0 0; }

input, select, textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}
textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
select:disabled { opacity: .6; }

label { display: block; margin-bottom: 12px; font-weight: 500; }
label > input, label > select, label > textarea { margin-top: 4px; font-weight: 400; }
label small { display: block; font-weight: 400; margin-top: 3px; }
label.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; }
label.check input { width: auto; margin: 3px 0 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 500;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .6; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn.xs { padding: 3px 8px; font-size: 12.5px; }
.btn.block { width: 100%; }
.danger-text { color: var(--danger); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }

.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; text-transform: capitalize;
  background: var(--surface-2); color: var(--muted);
}
.badge.ok { background: var(--ok-bg); color: var(--ok-fg); }
.badge.warn { background: var(--warn-bg); color: var(--warn-fg); }
.badge.proxied { background: var(--proxy-bg); color: var(--proxy-fg); text-transform: none; }
.badge.muted-badge { text-transform: none; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; padding: 28px; }
.login-card p.muted { margin: 4px 0 20px; }

/* layout */
.topbar {
  height: 54px; padding: 0 16px;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; font-size: 16px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.layout { display: grid; grid-template-columns: 300px 1fr; min-height: calc(100vh - 54px); }

.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sidebar-head h2 { font-size: 15px; }
.count { color: var(--muted); font-weight: 500; }

.zone-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.zone-item {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 10px; border: 0; border-radius: 8px;
  background: transparent; color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.zone-item:hover { background: var(--surface-2); }
.zone-item.active { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--primary); }
.zone-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { padding: 24px; min-width: 0; }
.empty { color: var(--muted); text-align: center; margin-top: 15vh; }

.zone-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.zone-head h2 { font-size: 22px; word-break: break-all; }

.notice { padding: 16px 18px; margin-bottom: 18px; border-left: 4px solid var(--warn-fg); }
.notice p { margin: 6px 0; }
.ns-list { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 6px; }
.ns-list li { display: flex; align-items: center; gap: 8px; }
.ns-list code { background: var(--surface-2); padding: 4px 8px; border-radius: 6px; }

.toolbar { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input { flex: 1 1 220px; width: auto; }
.toolbar select { flex: 0 0 140px; width: auto; }

.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; }
table.records { width: 100%; border-collapse: collapse; }
.records th {
  text-align: left; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em;
  color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.records td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.records tr:last-child td { border-bottom: 0; }
.records td.wrap { word-break: break-all; max-width: 420px; }
.records td.actions { text-align: right; white-space: nowrap; }
.type-tag { font-weight: 700; font-size: 12px; background: var(--surface-2); padding: 2px 7px; border-radius: 5px; }

/* dialogs */
dialog {
  border: 1px solid var(--border); border-radius: 14px; padding: 0;
  background: var(--surface); color: var(--text);
  width: min(480px, calc(100vw - 32px)); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(10, 14, 20, .5); }
.dialog-body { padding: 22px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); z-index: 50;
  max-width: calc(100vw - 32px);
}
.toast.error-toast { background: var(--danger); color: #fff; }

.mobile-only { display: none; }

/* phone */
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; }
  .main { padding: 16px; display: none; }
  body.zone-open .sidebar { display: none; }
  body.zone-open .main { display: block; }
  .mobile-only { display: inline-flex; margin-bottom: 10px; }
  #who { display: none; }

  .records thead { display: none; }
  .records tr { display: block; padding: 10px 12px; border-bottom: 1px solid var(--border); }
  .records td { display: flex; gap: 10px; padding: 3px 0; border: 0; max-width: none; }
  .records td[data-label]::before { content: attr(data-label); flex: 0 0 56px; color: var(--muted); font-size: 12px; font-family: system-ui, sans-serif; }
  .records td.actions { justify-content: flex-end; padding-top: 6px; }
  .records td.pad { display: block; }
}
