:root {
    font: 15px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: #182230;
    background: #f8fafc;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --border: #e4e9f0;
    --muted: #667085;
    --surface: #ffffff;
    --danger: #dc2626;
}

* { box-sizing: border-box; }
body { display: flex; flex-direction: column; min-width: 320px; min-height: 100vh; margin: 0; overflow-x: hidden; background: #f8fafc; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

.topbar { position: sticky; top: 0; z-index: 10; border-bottom: 1px solid rgba(255,255,255,.08); background: linear-gradient(90deg, #0f172a, #172033); color: #fff; box-shadow: 0 1px 3px rgba(15,23,42,.18); }
.bar { display: flex; align-items: center; gap: 2rem; width: min(1440px, 100%); min-height: 68px; margin: auto; padding: 0 max(2rem, env(safe-area-inset-right)) 0 max(2rem, env(safe-area-inset-left)); }
.brand { display: flex; align-items: center; gap: .75rem; min-width: max-content; color: #fff; }
.brand:hover { color: #fff; }
.brand-mark { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 11px; background: linear-gradient(145deg, #60a5fa, #2563eb); color: #fff; font-size: 21px; font-weight: 800; box-shadow: 0 8px 22px rgba(37,99,235,.35); }
.brand b { display: block; font-size: 17px; letter-spacing: -.02em; }
.brand small { display: block; max-width: 180px; overflow: hidden; color: #98a2b3; font-size: 11px; font-weight: 500; text-overflow: ellipsis; }
nav { display: flex; align-items: center; gap: .25rem; }
nav a { padding: .5rem .7rem; border-radius: 7px; color: #d0d5dd; font-size: 14px; font-weight: 600; }
nav a:hover { background: #1d2939; color: #fff; }
.menu-toggle, .mobile-logout { display: none; }
.user { display: flex; align-items: center; gap: .75rem; margin-left: auto; color: #d0d5dd; font-size: 13px; }
.user a { padding: .45rem .7rem; border: 1px solid #344054; border-radius: 7px; color: #fff; }
.user a:hover { border-color: #475467; background: #1d2939; }

.workspace { flex: 1; width: min(1320px, 100%); margin: auto; padding: 2.25rem max(2rem, env(safe-area-inset-right)) max(4rem, env(safe-area-inset-bottom)) max(2rem, env(safe-area-inset-left)); }
.page > h1:first-child { margin-top: 0; }
h1 { margin: 0 0 1.5rem; color: #0f172a; font-size: clamp(1.7rem, 3vw, 2.15rem); line-height: 1.2; letter-spacing: -.035em; }
h2 { margin: 2.25rem 0 1rem; color: #101828; font-size: 1.15rem; letter-spacing: -.015em; }
p { color: #475467; }
.muted { color: var(--muted); }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; }
.page-heading h1 { margin: 0 0 .3rem; }
.page-heading p, .panel > p { margin: 0 0 1rem; }
.summary-card { display: flex; gap: 2rem; margin-bottom: 1.5rem; padding: 1rem 1.25rem; border: 1px solid var(--border); border-radius: 12px; background: #fff; box-shadow: 0 1px 2px rgba(15,23,42,.04); }
.summary-card span { display: grid; gap: .15rem; color: var(--muted); font-size: 12px; font-weight: 650; text-transform: uppercase; }
.summary-card strong { color: #0f172a; font-size: 14px; font-weight: 700; text-transform: none; }

.data-list { margin: 1rem 0 2rem; overflow: hidden; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); box-shadow: 0 1px 2px rgba(16,24,40,.04); }
.data-head, .data-row { display: grid; align-items: center; }
.data-head { background: #f9fafb; color: #667085; font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.data-head span, .data-cell { min-width: 0; padding: .8rem 1rem; overflow-wrap: anywhere; }
.data-row { border-top: 1px solid var(--border); }
.data-row:hover { background: #fafcff; }
.zones-list .data-head, .zones-list .data-row { grid-template-columns: minmax(200px, 3fr) 160px minmax(300px, 3.7fr) minmax(170px, .1fr); }
.sync-list .data-head, .sync-list .data-row { grid-template-columns: 160px 140px minmax(240px, 1fr) 140px; }
.records-list .data-head, .records-list .data-row { grid-template-columns: minmax(140px, 1fr) minmax(260px, 2fr) 100px 180px; }
.servers-list .data-head, .servers-list .data-row { grid-template-columns: 140px 120px minmax(220px, 1.3fr) minmax(180px, 1fr) 100px 180px; }
.accounts-list .data-head, .accounts-list .data-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.credentials-list .data-head, .credentials-list .data-row { grid-template-columns: minmax(160px, 1fr) minmax(220px, 1.5fr) 110px 250px; }
.audit-list .data-head, .audit-list .data-row { grid-template-columns: 180px 120px 160px minmax(160px, 1fr) minmax(220px, 1.4fr); }
.identity-line { display: flex; align-items: center; flex-wrap: wrap; gap: .5rem; }
.identity-line .badge { margin-left: 0; }
.zone-group-create.panel > form { display: grid; grid-template-columns: minmax(180px, 360px) auto; align-items: end; justify-content: start; }
.zone-domain-group { margin: 1.75rem 0; }
.zone-group-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .65rem; }
.zone-group-heading > div { display: flex; align-items: baseline; flex-wrap: wrap; gap: .35rem .75rem; }
.zone-group-heading small { width: 100%; color: var(--primary); font-size: 11px; font-weight: 750; letter-spacing: .05em; text-transform: uppercase; }
.zone-group-heading h2 { margin: 0; }
.zone-group-heading span { color: var(--muted); font-size: 12px; font-weight: 650; }
.zone-group-heading form { display: inline-flex; }
.empty-group { margin: 0; padding: 1rem 1.25rem; border: 1px dashed var(--border); border-radius: 12px; background: #f9fafb; }
.zone-domain-group .data-list { margin: 0; }
.grouping-tabs { display: inline-flex; gap: .25rem; margin-bottom: .5rem; padding: .25rem; border: 1px solid var(--border); border-radius: 10px; background: #fff; }
.grouping-tabs a { padding: .5rem .85rem; border-radius: 7px; color: var(--muted); font-size: 13px; font-weight: 700; }
.grouping-tabs a:hover { background: #f9fafb; color: var(--primary); }
.grouping-tabs a[aria-current="page"] { background: var(--primary); color: #fff; }
.group-assignment { display: grid !important; grid-template-columns: minmax(120px, 1fr) auto; width: 100%; }
.group-membership { display: flex; align-items: center; justify-content: space-between; gap: .5rem; width: 100%; }
.group-name { color: #344054; font-size: 13px; font-weight: 650; }

form { display: grid; gap: 1rem; }
.page > form { width: 100%; padding: 1.25rem; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); box-shadow: 0 1px 2px rgba(16,24,40,.04); }
.data-list form, form.inline { display: inline-flex; align-items: center; gap: .4rem; padding: 0; border: 0; background: transparent; box-shadow: none; }
.panel { margin: 1.5rem 0; padding: 1.25rem; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); box-shadow: 0 1px 2px rgba(16,24,40,.04); }
.panel h2 { margin: 0 0 .35rem; }
section.panel { display: flex; flex-direction: column; }
section.panel > form { display: flex; flex: 1; flex-direction: column; }
section.panel > form > button:last-child { margin-top: auto; }
.section-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem; }
.section-grid .panel { margin: 0; }
.form-grid, .record-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; gap: 1rem; }
.form-grid .full { grid-column: 1 / -1; }
.zone-basics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.soa-advanced { padding-top: .25rem; }
.soa-advanced[open] > summary { margin-bottom: 1rem; }
.record-grid { grid-template-columns: 140px minmax(160px, .8fr) minmax(260px, 2fr) 140px; }
details > summary { width: max-content; color: var(--primary); font-weight: 650; cursor: pointer; }
.import-panel > summary, .settings-panel > summary { font-size: 1.05rem; }
.import-panel[open] > summary, .settings-panel[open] > summary { margin-bottom: 1rem; }
.record-value { max-width: 600px; }
.record-groups { display: grid; gap: 1.25rem; margin: 1rem 0 2rem; }
.record-group { min-width: 0; }
.record-group-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .55rem; }
.record-group-heading h3 { margin: 0; color: #101828; font-size: 1rem; }
.record-group-heading span { color: var(--muted); font-size: 12px; font-weight: 650; }
.record-group .data-list { margin: 0; }
.record-base { display: grid; grid-template-columns: 180px minmax(240px, 1fr) 140px; align-items: start; gap: 1rem; }
.record-fields { padding: 1rem; border: 1px solid var(--border); border-radius: 9px; background: #f9fafb; }
.record-values { display: grid; grid-template-columns: 120px minmax(240px, 1fr); align-items: start; gap: 1rem; }
.record-values.four { grid-template-columns: repeat(4, minmax(120px, 1fr)); }
.form-actions { display: flex; align-items: center; gap: .75rem; }
.credential-operations { display: flex; flex-wrap: wrap; gap: .75rem; padding: 1rem 0; border-top: 1px solid var(--border); }
[hidden] { display: none !important; }
.page > form.delete-zone { display: flex; justify-content: flex-end; margin-top: 2rem; }
label { display: grid; gap: .4rem; color: #344054; font-size: 13px; font-weight: 650; }
label small { color: #98a2b3; font-weight: 500; }
label.check { display: flex; align-items: center; gap: .55rem; width: max-content; }
label.check input[type="checkbox"] { width: 17px; min-height: 17px; margin: 0; accent-color: var(--primary); }
input, textarea, select, button { font: inherit; }
input, textarea, select { width: 100%; min-height: 40px; padding: .55rem .7rem; border: 1px solid #d0d5dd; border-radius: 8px; outline: none; background: #fff; color: #101828; transition: border-color .15s, box-shadow .15s; }
input:focus, textarea:focus, select:focus { border-color: #84adff; box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.data-list input { min-width: 76px; }
input.wide { min-width: 260px; }
.zone-import { max-width: none !important; }
.zone-import textarea { min-height: 320px; resize: vertical; font: 13px/1.55 ui-monospace, SFMono-Regular, Consolas, monospace; }
button, .action-button { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; width: max-content; padding: .55rem .9rem; border: 1px solid var(--primary); border-radius: 8px; background: var(--primary); color: #fff; font-weight: 650; cursor: pointer; transition: background .15s, border-color .15s, transform .05s; }
button:hover, .action-button:hover { border-color: var(--primary-dark); background: var(--primary-dark); color: #fff; }
button:active, .action-button:active { transform: translateY(1px); }
button.secondary, .action-button.secondary { border-color: #d0d5dd; background: #fff; color: #344054; }
button.secondary:hover, .action-button.secondary:hover { border-color: #98a2b3; background: #f9fafb; color: #344054; }
button.danger, button[value="record_delete"] { border-color: #fecaca; background: #fff; color: var(--danger); }
button.danger:hover, button[value="record_delete"]:hover { border-color: var(--danger); background: #fef2f2; }
.row-actions { display: flex; gap: .35rem; }
button.order { min-height: 32px; padding: .3rem .65rem; }
.badge { display: inline-block; margin-left: .4rem; padding: .18rem .5rem; border-radius: 999px; background: #dbeafe; color: #1d4ed8; font-size: 11px; font-weight: 700; }
.badge.enabled { margin-left: 0; background: #dcfce7; color: #15803d; }
.badge.disabled { margin-left: 0; background: #f1f5f9; color: #64748b; }
.status-dot { display: inline-block; width: 8px; height: 8px; margin-right: .45rem; border-radius: 50%; background: #22c55e; box-shadow: 0 0 0 3px #dcfce7; }
.status-dot.offline { background: #ef4444; box-shadow: 0 0 0 3px #fee2e2; }

.record-dialog { width: min(620px, calc(100% - 2rem)); max-height: calc(100dvh - 2rem); padding: 0; border: 0; border-radius: 16px; overflow: auto; background: #fff; color: #182230; box-shadow: 0 24px 80px rgba(16,24,40,.3); }
.record-dialog::backdrop { background: rgba(16,24,40,.62); backdrop-filter: blur(2px); }
.record-dialog form { gap: 1.25rem; padding: 1.5rem; }
.dialog-content { display: grid; gap: 1.25rem; padding: 1.5rem; }
.dialog-title { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; padding-bottom: 1rem; border-bottom: 1px solid var(--border); }
.dialog-title h2 { margin: .1rem 0 0; font-size: 1.35rem; }
.dialog-title small { color: var(--primary); font-weight: 750; text-transform: uppercase; }
button.dialog-close { min-height: 36px; width: 36px; padding: 0; border-color: transparent; border-radius: 50%; background: #f2f4f7; color: #475467; font-size: 24px; line-height: 1; }
button.dialog-close:hover { border-color: #d0d5dd; background: #e4e7ec; }
.edit-record-grid { display: grid; grid-template-columns: 1fr 150px; gap: 1rem; }
.edit-record-grid .full { grid-column: 1 / -1; }
.edit-record-grid textarea { min-height: 90px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .75rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.credential-details { display: grid; gap: .85rem; margin: 0; }
.credential-details div { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 1rem; align-items: start; }
.credential-details dt { color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; }
.credential-details dd { min-width: 0; margin: 0; }
.credential-details code { display: block; padding: .65rem .75rem; }
.dialog-content > .muted { margin: 0; }

.site-footer { display: flex; justify-content: space-between; gap: 1rem; width: min(1320px, 100%); margin: 0 auto; padding: 1.25rem max(2rem, env(safe-area-inset-right)) max(1.25rem, env(safe-area-inset-bottom)) max(2rem, env(safe-area-inset-left)); border-top: 1px solid var(--border); color: var(--muted); font-size: 12px; }
.site-footer a { color: inherit; font-weight: 650; }
.site-footer a:hover { color: var(--primary); }

.notice, .error, .secret { margin: 1rem 0; padding: .85rem 1rem; border: 1px solid #bfdbfe; border-radius: 9px; background: #eff6ff; color: #1e40af; }
.error { border-color: #fecaca; background: #fef2f2; color: #b42318; }
.toast { position: fixed; right: 1.25rem; bottom: 1.25rem; z-index: 100; max-width: min(360px, calc(100vw - 2rem)); margin: 0; padding: .75rem 1rem; border: 1px solid #a6f4c5; border-radius: 9px; background: #ecfdf3; color: #067647; font-weight: 650; box-shadow: 0 10px 30px rgba(15,23,42,.16); opacity: 0; transform: translateY(.5rem); transition: opacity .15s, transform .15s; }
.toast.visible { opacity: 1; transform: translateY(0); }
.toast.error { margin: 0; }
.ok { color: #067647; font-weight: 700; }
.bad, .danger { color: #b42318; font-weight: 700; }
code { padding: .15rem .35rem; border-radius: 5px; background: #f2f4f7; color: #344054; font: 12px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; overflow-wrap: anywhere; }

.auth { min-height: 100vh; background: radial-gradient(circle at 15% 15%, rgba(59,130,246,.18), transparent 34%), linear-gradient(145deg, #0b1220, #182230); }
.auth .site-footer { border-color: rgba(255,255,255,.1); color: #98a2b3; }
.auth .site-footer a:hover { color: #fff; }
.login { display: grid; flex: 1; place-items: center; align-content: center; padding: 2rem 1rem; }
.login-card { width: min(430px, 100%); padding: 2rem; border: 1px solid rgba(255,255,255,.65); border-radius: 18px; background: rgba(255,255,255,.98); box-shadow: 0 24px 70px rgba(0,0,0,.28); }
.login-brand { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.75rem; }
.login-brand .brand-mark { width: 46px; height: 46px; border-radius: 13px; font-size: 25px; }
.login h1 { margin: 0 0 .15rem; font-size: 1.55rem; }
.login p { margin: 0; }
.login button { width: 100%; margin-top: .25rem; }
.login-node { margin-top: 1rem !important; color: #98a2b3 !important; font-size: 12px; }

@media (max-width: 900px) {
    .bar { gap: 1rem; padding: .75rem max(1rem, env(safe-area-inset-right)) .75rem max(1rem, env(safe-area-inset-left)); }
    .workspace { padding: 1.5rem max(1rem, env(safe-area-inset-right)) max(3rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left)); }
    .record-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .zone-basics, .record-base, .record-values.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .section-grid { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
    .topbar { position: sticky; }
    .bar { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; min-height: 64px; }
    .menu-toggle { display: grid; place-content: center; gap: 4px; width: 40px; min-height: 40px; padding: 0; border-color: #344054; background: transparent; }
    .menu-toggle:hover { border-color: #667085; background: #1d2939; }
    .menu-toggle span { display: block; width: 18px; height: 2px; border-radius: 2px; background: #fff; }
    nav { display: none; grid-column: 1 / -1; flex-direction: column; align-items: stretch; gap: .2rem; padding-top: .75rem; border-top: 1px solid #344054; }
    nav.open { display: flex; }
    nav a { width: 100%; padding: .7rem .75rem; }
    nav .mobile-logout { display: block; margin-top: .25rem; border-top: 1px solid #344054; border-radius: 0; color: #fff; }
    .user { display: none; }
}

@media (max-width: 900px) {
    .brand { flex: 1; }
    .data-list { display: grid; gap: .85rem; overflow: visible; border: 0; background: transparent; box-shadow: none; }
    .data-head { display: none; }
    .data-list .data-row { display: grid; grid-template-columns: 1fr; padding: .35rem 1rem; border: 1px solid #e2e8f0; border-radius: 14px; background: #fff; box-shadow: 0 1px 2px rgba(15,23,42,.04), 0 8px 24px rgba(15,23,42,.04); }
    .data-cell { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; padding: .7rem 0; border-bottom: 1px solid #f1f5f9; text-align: right; }
    .data-cell:last-child { border-bottom: 0; }
    .data-cell::before { content: attr(data-label); flex: 0 0 92px; color: #64748b; font-size: 11px; font-weight: 700; letter-spacing: .05em; text-align: left; text-transform: uppercase; }
    .data-cell:first-child { color: #0f172a; font-size: 15px; }
    .data-cell code { max-width: calc(100% - 108px); }
    .data-actions { display: block; padding-top: .85rem; }
    .data-actions::before { display: none; }
    .data-actions .row-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(82px, 1fr)); width: 100%; }
    .data-actions form, .data-actions button, .data-actions .action-button { width: 100%; }
    .identity-line { justify-content: flex-end; }
    .zone-group-create.panel > form { grid-template-columns: 1fr; }
    .zone-group-create.panel > form button { width: 100%; }
    .zone-group-heading { align-items: flex-start; }
    .zone-group-heading form, .zone-group-heading button { width: 100%; }
    .zone-group-heading { display: grid; }
    .group-assignment { grid-template-columns: 1fr; }
    .page > form.delete-zone button { width: 100%; }
    .form-grid, .zone-basics, .record-grid, .record-base, .record-values, .record-values.four { grid-template-columns: 1fr; }
    .panel { padding: 1rem; }
    .record-dialog { width: calc(100% - 1rem); max-height: calc(100dvh - 1rem); border-radius: 12px; }
    .record-dialog form, .dialog-content { padding: 1rem; }
    .edit-record-grid { grid-template-columns: 1fr; }
    .edit-record-grid .full { grid-column: auto; }
    .dialog-actions { display: grid; grid-template-columns: 1fr 1fr; }
    .dialog-actions button { width: 100%; }
    .credential-details div { grid-template-columns: 1fr; gap: .25rem; }
    .form-actions { display: grid; grid-template-columns: 1fr 1fr; }
    .form-actions button { width: 100%; }
    .summary-card { display: grid; gap: .75rem; }
    .credential-operations { display: grid; }
    .credential-operations button { width: 100%; }
    .login-card { padding: 1.4rem; border-radius: 14px; }
    .site-footer { display: grid; justify-items: center; padding-inline: 1rem; text-align: center; }
}
