:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --surface-muted: #f8fafc;
  --sidebar: #ffffff;
  --text: #172033;
  --heading: #0d1424;
  --muted: #667085;
  --faint: #98a2b3;
  --border: #dfe4ec;
  --border-strong: #c8d0dc;
  --primary: #0875e1;
  --primary-hover: #0563bf;
  --primary-soft: #eaf4ff;
  --danger: #c9364b;
  --danger-soft: #fff0f2;
  --success: #12805c;
  --success-soft: #eaf8f2;
  --warning: #b45309;
  --shadow: 0 1px 2px rgb(16 24 40 / 4%), 0 5px 18px rgb(16 24 40 / 5%);
  --focus: 0 0 0 3px rgb(8 117 225 / 18%);
  --row-hover: #f7faff;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d1420;
    --surface: #151f2e;
    --surface-raised: #192536;
    --surface-muted: #111a28;
    --sidebar: #101927;
    --text: #e7edf6;
    --heading: #f6f8fc;
    --muted: #9cabc0;
    --faint: #6f8098;
    --border: #2a394d;
    --border-strong: #3a4c64;
    --primary: #4295eb;
    --primary-hover: #63a9f0;
    --primary-soft: #162e49;
    --danger: #ff7586;
    --danger-soft: #3a2029;
    --success: #55d2a3;
    --success-soft: #16352e;
    --warning: #f6ad55;
    --shadow: 0 1px 2px rgb(0 0 0 / 20%), 0 8px 28px rgb(0 0 0 / 16%);
    --focus: 0 0 0 3px rgb(66 149 235 / 22%);
    --row-hover: #19283c;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1420;
  --surface: #151f2e;
  --surface-raised: #192536;
  --surface-muted: #111a28;
  --sidebar: #101927;
  --text: #e7edf6;
  --heading: #f6f8fc;
  --muted: #9cabc0;
  --faint: #6f8098;
  --border: #2a394d;
  --border-strong: #3a4c64;
  --primary: #4295eb;
  --primary-hover: #63a9f0;
  --primary-soft: #162e49;
  --danger: #ff7586;
  --danger-soft: #3a2029;
  --success: #55d2a3;
  --success-soft: #16352e;
  --warning: #f6ad55;
  --shadow: 0 1px 2px rgb(0 0 0 / 20%), 0 8px 28px rgb(0 0 0 / 16%);
  --focus: 0 0 0 3px rgb(66 149 235 / 22%);
  --row-hover: #19283c;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); font: 14px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif; }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
.hidden { display: none !important; }

.btn {
  min-height: 36px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 7px 13px;
  background: var(--surface);
  color: var(--text);
  font-weight: 550;
  white-space: nowrap;
  transition: border-color .15s, background .15s, color .15s, transform .08s;
}
.btn:hover { border-color: var(--primary); background: var(--primary-soft); }
.btn:active { transform: translateY(1px); }
.btn.primary { border-color: var(--primary); background: var(--primary); color: #fff; }
.btn.primary:hover { border-color: var(--primary-hover); background: var(--primary-hover); }
.btn.danger { border-color: var(--danger); background: var(--danger); color: #fff; }
.btn.danger.subtle { background: var(--danger-soft); color: var(--danger); }
.btn.block { width: 100%; margin-top: 18px; }
.btn.square { width: 36px; padding: 0; font-size: 20px; line-height: 1; }

input, select, textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  padding: 8px 10px;
  outline: 0;
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s, background .15s;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: var(--focus); }
textarea { min-height: 76px; resize: vertical; }
label { display: block; margin: 0 0 6px; color: var(--muted); font-size: 12px; font-weight: 650; }
label span { font-weight: 450; color: var(--faint); }
.field { min-width: 0; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 50% 0, var(--primary-soft), transparent 42%), var(--bg); }
.login-card { width: min(420px, 100%); padding: 34px; border: 1px solid var(--border); border-radius: 16px; background: var(--surface-raised); box-shadow: var(--shadow); }
.login-mark, .brand-mark { display: grid; place-items: center; color: #fff; background: linear-gradient(145deg, #ff9b38, #f06c17); font-weight: 800; }
.login-mark { width: 46px; height: 46px; margin-bottom: 22px; border-radius: 12px; }
.login-card h1 { margin: 0; color: var(--heading); font-size: 25px; letter-spacing: -.02em; }
.login-card > p { margin: 7px 0 24px; color: var(--muted); }
.login-card form label:not(:first-child) { margin-top: 15px; }

.app { display: grid; grid-template-columns: 250px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 16px 12px; border-right: 1px solid var(--border); background: var(--sidebar); }
.brand-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 2px 4px 20px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { flex: 0 0 auto; width: 34px; height: 34px; border-radius: 9px; font-size: 11px; }
.brand strong, .brand small { display: block; }
.brand strong { color: var(--heading); font-size: 15px; }
.brand small { color: var(--muted); font-size: 11px; }
.sidebar-label { padding: 0 10px 8px; color: var(--faint); font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.account-list { display: grid; gap: 5px; overflow: auto; }
.account-item { width: 100%; border: 1px solid transparent; border-radius: 9px; padding: 10px 11px; background: transparent; color: var(--text); text-align: left; }
.account-item:hover { background: var(--surface-muted); }
.account-item.active { border-color: color-mix(in srgb, var(--primary) 35%, var(--border)); background: var(--primary-soft); }
.account-item strong, .account-item small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-item strong { color: var(--heading); font-size: 13px; }
.account-item small { margin-top: 3px; color: var(--muted); font-size: 11px; }
.empty-side { margin: 5px 10px; color: var(--faint); font-size: 12px; }
.sidebar-foot { margin-top: auto; padding: 14px 9px 4px; border-top: 1px solid var(--border); color: var(--muted); font-size: 11px; }
.secure-dot { display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; background: var(--success); }

.main { min-width: 0; padding: 26px clamp(20px, 3vw, 48px) 56px; }
.page-header { max-width: 1540px; margin: 0 auto; display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; }
.eyebrow { margin-bottom: 3px; color: var(--faint); font-size: 11px; font-weight: 750; letter-spacing: .07em; text-transform: uppercase; }
.page-header h1 { margin: 0; color: var(--heading); font-size: clamp(22px, 2vw, 29px); line-height: 1.2; letter-spacing: -.025em; }
.page-header p { margin: 5px 0 0; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
.header-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.theme-control { display: flex; align-items: center; gap: 7px; margin: 0; }
.theme-control > span { color: var(--muted); font-size: 12px; }
.theme-control select { width: auto; min-height: 36px; padding-right: 30px; }
.page-status { max-width: 1540px; margin: 8px auto 0; }
#workspace { max-width: 1540px; margin: 0 auto; }

.surface { border: 1px solid var(--border); border-radius: 11px; background: var(--surface); box-shadow: var(--shadow); }
.zone-bar { display: flex; align-items: end; gap: 12px; margin: 20px 0 0; padding: 15px 16px; }
.zone-picker { flex: 1 1 420px; min-width: 220px; }
.zone-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.tabs { display: flex; gap: 22px; margin-top: 20px; border-bottom: 1px solid var(--border); }
.tab { border: 0; border-bottom: 2px solid transparent; padding: 10px 2px; background: transparent; color: var(--muted); font-weight: 650; }
.tab:hover { color: var(--heading); }
.tab.active { border-bottom-color: var(--primary); color: var(--primary); }
.panel { padding-top: 16px; }
.editor-card, .records-card { padding: 18px 20px; }
.records-card { margin-top: 14px; padding-bottom: 8px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin-bottom: 15px; }
.section-heading h2 { margin: 0; color: var(--heading); font-size: 16px; letter-spacing: -.01em; }
.section-heading p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.count-pill { padding: 3px 9px; border-radius: 999px; background: var(--surface-muted); color: var(--muted); font-size: 12px; }

.dns-form-grid { display: grid; grid-template-columns: 105px minmax(160px, 1fr) minmax(240px, 2fr) 120px auto; gap: 12px; align-items: end; }
.priority-field { grid-column: 4; }
.proxy-toggle { min-height: 38px; display: flex; align-items: center; gap: 8px; margin: 0; padding: 0 6px; color: var(--text); white-space: nowrap; cursor: pointer; }
.proxy-toggle input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.switch { position: relative; display: inline-block; width: 34px; height: 19px; border-radius: 999px; background: var(--border-strong); transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 13px; height: 13px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / 25%); transition: transform .15s; }
.proxy-toggle input:checked + .switch { background: #f6821f; }
.proxy-toggle input:checked + .switch::after { transform: translateX(15px); }
.proxy-toggle input:focus-visible + .switch { box-shadow: var(--focus); }
.form-actions { display: flex; align-items: center; gap: 9px; margin-top: 14px; }
.inline-status { margin: 0 0 0 4px; }
.inline-form { display: flex; align-items: end; gap: 10px; max-width: 720px; }
.grow { flex: 1; }
.rule-grid { display: grid; grid-template-columns: .8fr 1fr 1fr; gap: 12px; }

.table-wrap { width: 100%; overflow: auto; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 12px; }
th, td { padding: 10px 9px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { position: sticky; top: 0; z-index: 1; background: var(--surface); color: var(--muted); font-size: 11px; font-weight: 700; white-space: nowrap; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: var(--row-hover); }
tbody tr:last-child td { border-bottom: 0; }
td code { color: var(--text); font: 12px/1.45 ui-monospace, SFMono-Regular, Consolas, monospace; overflow-wrap: anywhere; }
td .button-row { display: flex; gap: 6px; }
td button { min-height: 30px; border: 1px solid var(--border-strong); border-radius: 6px; padding: 4px 9px; background: var(--surface); color: var(--text); font-size: 11px; }
td button:hover { border-color: var(--primary); color: var(--primary); }
td button.danger { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); background: var(--danger-soft); color: var(--danger); }
.badge { display: inline-block; min-width: 32px; padding: 3px 7px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); font-weight: 700; text-align: center; }
.hint { color: var(--muted); font-size: 11px; }
.empty { margin: 0; padding: 26px 10px; color: var(--muted); text-align: center; }

.status { min-height: 20px; color: var(--muted); font-size: 12px; }
.status.error { color: var(--danger); }
.status.success { color: var(--success); }

.backdrop { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 20px; background: rgb(10 16 26 / 58%); backdrop-filter: blur(3px); }
.modal { width: min(560px, 100%); max-height: 90vh; overflow: auto; padding: 24px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface-raised); box-shadow: 0 24px 80px rgb(0 0 0 / 25%); }
.modal.compact { width: min(500px, 100%); }
.modal header { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 20px; }
.modal header h2 { margin: 0; color: var(--heading); font-size: 19px; }
.modal header p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.modal .field + .field { margin-top: 14px; }
.close { width: 32px; height: 32px; border: 0; border-radius: 7px; padding: 0; background: transparent; color: var(--muted); font-size: 22px; }
.close:hover { background: var(--surface-muted); color: var(--heading); }
.security-note { display: flex; align-items: flex-start; gap: 10px; margin-top: 16px; padding: 11px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-muted); }
.security-note.success { border-color: color-mix(in srgb, var(--success) 30%, var(--border)); background: var(--success-soft); }
.security-note span { flex: 0 0 auto; }
.security-note p { margin: 0; color: var(--muted); font-size: 12px; }
.secret { display: block; padding: 11px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface-muted); color: var(--heading); font: 12px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; overflow-wrap: anywhere; }

@media (max-width: 1120px) {
  .dns-form-grid { grid-template-columns: 100px minmax(150px, 1fr) minmax(220px, 1.5fr) 110px; }
  .proxy-toggle { grid-column: 1 / 3; }
  .priority-field { grid-column: 4; }
  .zone-bar { align-items: stretch; flex-direction: column; }
}

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .sidebar-label, .sidebar-foot { display: none; }
  .brand-row { padding-bottom: 12px; }
  .account-list { display: flex; padding-bottom: 3px; overflow-x: auto; }
  .account-item { flex: 0 0 210px; }
  .main { padding: 20px 14px 44px; }
  .page-header { flex-direction: column; gap: 14px; }
  .header-actions { justify-content: flex-start; }
  .dns-form-grid, .rule-grid { grid-template-columns: 1fr 1fr; }
  .content-field { grid-column: 1 / -1; }
  .priority-field { grid-column: auto; }
  .proxy-toggle { grid-column: auto; }
}

@media (max-width: 560px) {
  .login-card { padding: 25px 20px; }
  .header-actions { width: 100%; }
  .theme-control { width: 100%; }
  .theme-control select { flex: 1; }
  .zone-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .dns-form-grid, .rule-grid { grid-template-columns: 1fr; }
  .content-field, .proxy-toggle { grid-column: auto; }
  .inline-form { align-items: stretch; flex-direction: column; }
  .inline-form .btn { width: 100%; }
  .editor-card, .records-card { padding: 15px; }
  .modal { padding: 20px 16px; }
}
