:root {
  --cf-orange: #f48120;
  --cf-orange-dim: #e66a00;
  --cf-orange-light: #ff9f4d;
  --bg: #0c1118;
  --bg-elevated: #161f2c;
  --bg-card: #131b26;
  --bg-subtle: #1c2635;
  --border: #253140;
  --border-light: #334155;
  --text: #e8edf4;
  --text-muted: #8b9cb3;
  --text-subtle: #64748b;
  --success: #22c55e;
  --success-bg: rgba(34, 197, 94, 0.1);
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.1);
  --warning: #eab308;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 10px 40px -10px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255,255,255,0.02);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --transition: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 90% 55% at 50% -25%, rgba(244, 129, 32, 0.08), transparent 70%),
    radial-gradient(ellipse 50% 35% at 95% 95%, rgba(59, 130, 246, 0.06), transparent);
  pointer-events: none;
  z-index: 0;
}

#app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
}

.view {
  display: none;
  min-height: 100vh;
}

.view.active {
  display: flex;
}

/* Login */
#login-view {
  align-items: center;
  justify-content: center;
  padding: 2rem;
  min-height: 100vh;
}

.login-card {
  width: 100%;
  max-width: 440px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2.75rem 2.5rem 2.25rem;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.login-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--cf-orange), transparent);
  opacity: 0.3;
}

.brand {
  text-align: center;
  margin-bottom: 2rem;
}

.logo-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 68px;
  height: 68px;
  background: linear-gradient(145deg, var(--bg-elevated), var(--bg-card));
  border: 1px solid var(--border-light);
  border-radius: 16px;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow-sm);
}

.logo {
  width: 42px;
  height: 42px;
  color: var(--cf-orange);
}

.brand h1 {
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.35rem;
}

.brand-subtitle {
  color: var(--text-muted);
  font-size: 0.92rem;
  max-width: 280px;
  margin: 0 auto;
  line-height: 1.45;
}

.login-form {
  margin-bottom: 0.25rem;
}

.form-group {
  margin-bottom: 1.1rem;
}

label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--text-muted);
  letter-spacing: 0.01em;
}

.input-with-icon {
  position: relative;
  display: flex;
  align-items: center;
}

/* .input-icon removed (no longer using padlock icon) */

.input-with-icon input {
  width: 100%;
  padding: 0.75rem 4.2rem 0.75rem 0.85rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.input-with-icon input:focus {
  outline: none;
  border-color: var(--cf-orange);
  box-shadow: 0 0 0 3px rgba(244, 129, 32, 0.1);
}

.input-with-icon input::placeholder {
  color: var(--text-subtle);
}

.password-toggle {
  position: absolute;
  right: 2px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--text-subtle);
  cursor: pointer;
  padding: 0;
  min-width: 44px;
  min-height: 44px;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition), background var(--transition);
  z-index: 10;
  pointer-events: auto;
}

.password-toggle:hover {
  color: var(--text);
  background: var(--bg-elevated);
}

.password-toggle:active {
  background: var(--border);
  transform: translateY(-50%) scale(0.92);
}

.password-toggle svg {
  display: block;
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  pointer-events: none; /* clicks go to the button */
}

.login-btn {
  position: relative;
  height: 48px;
  font-size: 0.96rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  margin-top: 0.35rem;
}

.login-btn .btn-spinner {
  display: inline-flex;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.login-error {
  margin-top: 1rem;
  padding: 0.65rem 0.9rem;
  background: var(--danger-bg);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius-sm);
  color: #fca5a5;
  font-size: 0.875rem;
  line-height: 1.4;
}

.login-footer {
  margin-top: 1.5rem;
  text-align: center;
}

.secure-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--text-subtle);
  background: var(--bg-elevated);
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.secure-badge svg {
  color: var(--success);
}

/* Legacy input base styles kept for modals & other fields */
input[type='text'],
input[type='password'],
input[type='search'],
input[type='number'],
select {
  width: 100%;
  padding: 0.6rem 0.85rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--cf-orange);
  box-shadow: 0 0 0 3px rgba(244, 129, 32, 0.1);
}

input::placeholder {
  color: var(--text-subtle);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.55rem 1.05rem;
  border: none;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--cf-orange);
  color: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.btn-primary:hover:not(:disabled) {
  background: var(--cf-orange-dim);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(244, 129, 32, 0.35);
}

.btn-primary:disabled {
  opacity: 0.65;
  cursor: not-allowed;
  transform: none;
}

.btn-block {
  width: 100%;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  font-weight: 500;
}

.btn-ghost:hover {
  background: var(--bg-elevated);
  color: var(--text);
  border-color: var(--border-light);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  background: #dc2626;
}

.btn-sm {
  padding: 0.32rem 0.7rem;
  font-size: 0.78rem;
  font-weight: 600;
}

.btn-icon-header {
  padding: 0.45rem;
  border: 1px solid var(--border);
}

/* Icon buttons for table rows */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
  font-size: 0.9rem;
}

.icon-btn:hover {
  background: var(--bg-elevated);
  color: var(--text);
  border-color: var(--border-light);
}

.icon-btn.danger:hover {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: rgba(239,68,68,0.3);
}

.copy-btn {
  opacity: 0.6;
  margin-left: 6px;
}

.copy-btn:hover {
  opacity: 1;
}

.record-actions {
  display: flex;
  gap: 0.2rem;
}

/* Dashboard */
#dashboard-view {
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.35rem;
  border-bottom: 1px solid var(--border);
  background: rgba(12, 17, 24, 0.92);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand-inline {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.logo-sm {
  width: 22px;
  height: 22px;
  color: var(--cf-orange);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.topbar-left h1 {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.badge {
  font-size: 0.72rem;
  padding: 0.15rem 0.55rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
  font-weight: 600;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.global-search {
  position: relative;
  display: flex;
  align-items: center;
}

.global-search .search-icon {
  position: absolute;
  left: 11px;
  color: var(--text-subtle);
  pointer-events: none;
}

#zone-search {
  width: 240px;
  padding-left: 2.1rem !important;
  font-size: 0.85rem;
  background: var(--bg);
}

.layout {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* Stats */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
  padding: 1rem 1.35rem 0.35rem;
  border-bottom: 1px solid var(--border);
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1.05rem;
  transition: transform var(--transition), border-color var(--transition);
}

.stat-card:hover {
  border-color: var(--border-light);
}

.stat-card-muted {
  opacity: 0.85;
}

.stat-value {
  font-size: 1.45rem;
  font-weight: 700;
  line-height: 1.1;
  margin-bottom: 0.1rem;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 0.73rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Sidebar */
.sidebar {
  width: 272px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  padding: 0.85rem 0.7rem 1rem;
  overflow-y: auto;
  max-height: calc(100vh - 120px);
  background: var(--bg);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0.65rem 0.45rem;
}

.sidebar-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.sidebar-count {
  font-size: 0.72rem;
  color: var(--text-subtle);
  background: var(--bg-elevated);
  padding: 0 0.4rem;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.zone-search-wrap {
  padding: 0 0.5rem 0.6rem;
}

.zone-search-wrap input {
  font-size: 0.82rem;
  padding: 0.48rem 0.7rem;
}

.zone-list {
  list-style: none;
  padding: 0 0.35rem;
}

.zone-item {
  display: flex;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 0.55rem 0.7rem;
  margin-bottom: 0.2rem;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: all var(--transition);
  gap: 0.55rem;
}

.zone-item:hover {
  background: var(--bg-elevated);
  border-color: var(--border);
}

.zone-item.active {
  background: rgba(244, 129, 32, 0.1);
  border-color: rgba(244, 129, 32, 0.4);
  box-shadow: inset 0 0 0 1px rgba(244, 129, 32, 0.15);
}

.zone-item-left {
  flex: 1;
  min-width: 0;
}

.zone-item-name {
  font-weight: 600;
  font-size: 0.875rem;
  display: block;
  word-break: break-all;
  line-height: 1.25;
}

.zone-item-meta {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-top: 0.12rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.status-dot.active { background: var(--success); }
.status-dot.pending { background: var(--cf-orange); }
.status-dot.inactive { background: var(--text-subtle); }

.zone-item.active .zone-item-name {
  color: #fff;
}

.main-panel {
  flex: 1;
  padding: 1.15rem 1.35rem;
  overflow-y: auto;
  max-height: calc(100vh - 120px);
  min-width: 0;
}

.placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 340px;
  color: var(--text-muted);
  text-align: center;
  padding: 1rem;
}

.placeholder-illustration {
  margin-bottom: 1rem;
  opacity: 0.65;
}

.placeholder-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.3rem;
}

.placeholder-desc {
  max-width: 260px;
  font-size: 0.875rem;
  color: var(--text-subtle);
}

/* Zone header */
.zone-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.95rem;
  flex-wrap: wrap;
}

.zone-header-main {
  min-width: 0;
}

.zone-title-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.zone-header h2 {
  font-size: 1.35rem;
  font-weight: 700;
  word-break: break-all;
  line-height: 1.15;
  margin: 0;
}

.zone-meta {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-top: 0.3rem;
  flex-wrap: wrap;
}

.zone-meta-item {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg-elevated);
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.zone-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

/* Status */
.status-pill {
  display: inline-flex;
  align-items: center;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.12rem 0.55rem;
  border-radius: 999px;
  text-transform: capitalize;
  letter-spacing: 0.02em;
}

.status-pill.active {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid rgba(34, 197, 94, 0.25);
}

.status-pill.pending {
  background: rgba(244, 129, 32, 0.12);
  color: var(--cf-orange);
  border: 1px solid rgba(244, 129, 32, 0.25);
}

.status-pill.inactive {
  background: rgba(148, 163, 184, 0.12);
  color: var(--text-subtle);
}

/* Toolbar & Search */
.dns-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.65rem;
  flex-wrap: wrap;
}

.dns-search {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1;
  max-width: 340px;
}

.dns-search svg {
  position: absolute;
  left: 11px;
  color: var(--text-subtle);
  pointer-events: none;
}

#dns-search {
  padding-left: 2.15rem !important;
  background: var(--bg);
  font-size: 0.875rem;
}

.records-badge {
  font-size: 0.72rem;
  padding: 0.2rem 0.6rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
  font-weight: 600;
  white-space: nowrap;
}

/* Table */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
}

.dns-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.dns-table th,
.dns-table td {
  padding: 0.7rem 0.95rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.dns-table th {
  background: var(--bg-elevated);
  font-weight: 700;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-subtle);
  position: sticky;
  top: 0;
  z-index: 5;
}

.dns-table tr:last-child td {
  border-bottom: none;
}

.dns-table tbody tr {
  transition: background var(--transition);
}

.dns-table tbody tr:hover {
  background: rgba(255,255,255,0.025);
}

.dns-table td {
  font-variant-numeric: tabular-nums;
}

.col-type { width: 78px; }
.col-name { min-width: 110px; }
.col-content { max-width: 320px; }
.col-ttl { width: 68px; }
.col-proxy { width: 88px; }
.col-actions { width: 74px; text-align: right; }

.type-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.68rem;
  font-weight: 800;
  padding: 0.12rem 0.48rem;
  border-radius: 5px;
  letter-spacing: 0.02em;
  min-width: 42px;
}

/* Type colors */
.type-badge.A,
.type-badge.AAAA { background: rgba(16, 185, 129, 0.15); color: #34d399; }
.type-badge.CNAME { background: rgba(59, 130, 246, 0.15); color: #60a5fa; }
.type-badge.TXT { background: rgba(234, 179, 8, 0.15); color: #facc15; }
.type-badge.MX { background: rgba(139, 92, 246, 0.15); color: #a78bfa; }
.type-badge.NS { background: rgba(236, 72, 153, 0.15); color: #f472b6; }
.type-badge.PTR,
.type-badge.SRV { background: rgba(148, 163, 184, 0.15); color: #94a3b8; }

.record-content {
  display: flex;
  align-items: center;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
}

.proxy-on {
  color: var(--cf-orange);
  font-weight: 600;
  font-size: 0.8rem;
}

.proxy-off {
  color: var(--text-subtle);
  font-size: 0.8rem;
}

/* Empty / Loading states */
.loading-text,
.empty-text {
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 0.9rem 0;
}

.dns-loading {
  padding: 0.5rem 0;
}

.skeleton-row {
  height: 42px;
  background: linear-gradient(90deg, var(--bg-elevated) 25%, var(--bg-subtle) 50%, var(--bg-elevated) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
}

@keyframes shimmer {
  100% { background-position: -200% 0; }
}

.dns-empty {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem 1rem;
  text-align: center;
  background: var(--bg-card);
}

.dns-empty-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.55rem;
  color: var(--text-muted);
}

.dns-empty-content p {
  margin: 0.1rem 0 0.3rem;
  font-size: 0.9rem;
}

.zones-loading {
  padding: 0.4rem 0.5rem;
}

.skeleton-zone {
  height: 46px;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

/* Error */
.error-msg {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 0.75rem;
  padding: 0.5rem 0.7rem;
  background: var(--danger-bg);
  border-radius: var(--radius-sm);
}

.hidden {
  display: none !important;
}

/* Modal */
.modal {
  border: none;
  border-radius: 16px;
  padding: 0;
  background: var(--bg-card);
  color: var(--text);
  max-width: 460px;
  width: calc(100% - 2rem);
  box-shadow: var(--shadow);

  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(2px);
}

.modal-sm {
  max-width: 360px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.05rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 1rem;
  font-weight: 700;
}

.modal-body {
  padding: 1.25rem;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.85rem 1.25rem;
  border-top: 1px solid var(--border);
}

.modal-zone {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.form-row {
  margin-bottom: 0.9rem;
}

.field-hint {
  display: block;
  font-size: 0.7rem;
  color: var(--text-subtle);
  margin-top: 0.2rem;
}

.checkbox-row label {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  cursor: pointer;
  color: var(--text);
  font-size: 0.9rem;
}

.checkbox-row input {
  width: auto;
  accent-color: var(--cf-orange);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 1.35rem;
  right: 1.35rem;
  padding: 0.7rem 1.1rem 0.7rem 1.15rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 0.875rem;
  z-index: 200;
  animation: slideIn 0.2s ease;
  max-width: 340px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.toast.success { border-color: rgba(34, 197, 94, 0.5); }
.toast.error { border-color: rgba(239, 68, 68, 0.5); }

@keyframes slideIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.mobile-only {
  display: none;
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 199;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
  pointer-events: none;
}

.sidebar-overlay.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* Responsive - Improved mobile experience */
@media (max-width: 860px) {
  .layout {
    flex-direction: column;
  }

  .mobile-only {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Mobile: Sidebar as slide-in drawer (burger menu) */
  .sidebar {
    position: fixed !important;
    top: 0;
    left: 0;
    width: 280px;
    max-width: 82vw;
    height: 100vh;
    max-height: 100vh;
    overflow-y: auto;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 200;
    box-shadow: 4px 0 25px rgba(0, 0, 0, 0.45);
    background: var(--bg);
    border-right: 1px solid var(--border);
    padding: 0.75rem 0.75rem 1.5rem;
    padding-top: 60px; /* push content below the topbar */
    scrollbar-width: thin;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0 0.5rem 0.5rem;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
  }

  .btn-close-mobile {
    display: flex;
    margin-left: auto;
    font-size: 1.6rem;
    line-height: 1;
    padding: 0 0.35rem;
    color: var(--text-muted);
    background: transparent;
    border: none;
  }

  .zone-list {
    display: block;
    padding: 0;
  }

  .zone-item {
    min-width: auto;
    max-width: none;
    width: 100%;
    padding: 0.55rem 0.7rem;
    margin-bottom: 0.2rem;
    border-radius: var(--radius-sm);
    white-space: normal;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.55rem;
  }

  .zone-item-left {
    display: block;
  }

  .zone-item-name {
    font-size: 0.875rem;
    font-weight: 600;
  }

  .zone-item-meta {
    display: flex;
    font-size: 0.68rem;
  }

  .status-dot {
    width: 6px;
    height: 6px;
  }

  .stats-row {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
  }

  .stat-card {
    padding: 0.6rem 0.75rem;
  }

  .stat-value {
    font-size: 1.25rem;
  }

  .topbar {
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0.6rem 0.9rem;
  }

  .topbar-left {
    gap: 0.5rem;
  }

  /* Ensure burger is visible and clickable */
  #mobile-menu-btn {
    padding: 0.25rem;
    margin-right: 0.1rem;
  }

  .global-search input {
    width: 100%;
    min-width: 120px;
    font-size: 0.8rem;
  }

  .topbar-right {
    gap: 0.3rem;
  }

  .btn-icon-header {
    padding: 0.35rem;
  }

  /* Compact logout on mobile - icon only */
  #logout-btn span {
    display: none;
  }

  #logout-btn {
    padding: 0.35rem;
  }

  /* More compact table on mobile */
  .main-panel {
    padding: 0.75rem 0.9rem;
  }

  .table-wrap {
    border-radius: 8px;
  }

  .dns-table {
    font-size: 0.78rem;
  }

  .dns-table th,
  .dns-table td {
    padding: 0.45rem 0.5rem;
  }

  .dns-table th {
    font-size: 0.62rem;
  }

  .record-content {
    max-width: 160px;
  }

  .icon-btn {
    min-width: 34px;
    min-height: 34px;
    width: 34px;
    height: 34px;
  }

  /* Hide less critical column on mid-size mobile to reduce horizontal scroll */
  .col-ttl {
    display: none;
  }

  .records-badge {
    display: none; /* save space */
  }

  /* Make proxy status more compact */
  .proxy-on, .proxy-off {
    font-size: 0.7rem;
  }
}

@media (max-width: 520px) {
  .login-card {
    padding: 1.6rem 1.1rem 1.4rem;
    border-radius: 16px;
  }

  .brand h1 {
    font-size: 1.35rem;
  }

  .password-toggle {
    min-width: 46px;
    min-height: 46px;
    width: 44px;
    height: 44px;
  }

  .stats-row {
    grid-template-columns: 1fr 1fr;
    padding: 0.6rem 0.75rem 0.15rem;
    gap: 0.4rem;
  }

  .zone-header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }

  .zone-actions {
    justify-content: flex-end;
    width: 100%;
  }

  .zone-actions .btn {
    padding: 0.4rem 0.7rem;
    font-size: 0.8rem;
  }

  /* Very small screens: even more compact table */
  .dns-table {
    font-size: 0.72rem;
  }

  .dns-table th,
  .dns-table td {
    padding: 0.35rem 0.4rem;
  }

  .type-badge {
    font-size: 0.62rem;
    padding: 0.08rem 0.35rem;
  }

  /* Make action buttons easier to tap */
  .icon-btn {
    min-width: 38px;
    min-height: 38px;
  }

  .main-panel {
    padding: 0.6rem 0.7rem;
  }

  /* Topbar compact */
  .topbar {
    padding: 0.5rem 0.7rem;
  }

  .brand-inline h1 {
    font-size: 0.95rem;
  }

  .badge {
    font-size: 0.65rem;
    padding: 0.1rem 0.4rem;
  }
}

/* Extra small phones */
@media (max-width: 380px) {
  .stats-row {
    grid-template-columns: 1fr;
  }

  .global-search input {
    font-size: 0.75rem;
  }
}