/* ============================================================
   XLXBK DNS — Apple-inspired Design System
   Inspired by macOS System Preferences & iOS Settings
   ============================================================ */

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

/* ── Design Tokens ── */
:root {
  /* Apple Blue */
  --primary: #007AFF;
  --primary-hover: #0066d6;
  --primary-dark: #0055b3;
  --primary-light: rgba(0, 122, 255, .08);
  --primary-glow: rgba(0, 122, 255, .18);

  /* Surfaces — Clean, warm whites */
  --bg-base: #f5f5f7;
  --bg-surface: #ffffff;
  --bg-card: #ffffff;
  --bg-input: #f5f5f7;
  --bg-elevated: #e8e8ed;
  --bg-hover: rgba(0, 0, 0, .03);
  --bg-sidebar: rgba(246, 246, 248, .82);

  /* Borders */
  --border: rgba(0, 0, 0, .08);
  --border-light: rgba(0, 0, 0, .06);
  --border-active: rgba(0, 122, 255, .4);

  /* Text — Apple grays */
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-muted: #aeaeb2;
  --text-inverse: #ffffff;

  /* Semantic */
  --success: #34c759;
  --success-bg: rgba(52, 199, 89, .08);
  --success-border: rgba(52, 199, 89, .20);
  --error: #ff3b30;
  --error-bg: rgba(255, 59, 48, .08);
  --error-border: rgba(255, 59, 48, .20);
  --warn: #ff9500;
  --warn-bg: rgba(255, 149, 0, .08);
  --warn-border: rgba(255, 149, 0, .20);
  --info: #007AFF;
  --info-bg: rgba(0, 122, 255, .08);
  --info-border: rgba(0, 122, 255, .20);

  /* Layout */
  --sidebar-width: 260px;
  --sidebar-collapsed: 68px;
  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 20px;

  /* Shadows — Soft, layered like macOS */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .04);
  --shadow: 0 2px 8px rgba(0, 0, 0, .06), 0 0 1px rgba(0, 0, 0, .08);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, .08), 0 0 1px rgba(0, 0, 0, .06);
  --shadow-card: 0 1px 3px rgba(0, 0, 0, .05), 0 0 0 .5px rgba(0, 0, 0, .04);

  /* Motion */
  --ease: cubic-bezier(.25, .1, .25, 1);
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
  --transition-fast: .15s var(--ease);
  --transition: .25s var(--ease);
  --transition-slow: .35s var(--ease-out);
}

/* ── Base ── */
html, body {
  height: 100%; overflow: hidden;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text',
               'Helvetica Neue', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg-base);
  color: var(--text);
  line-height: 1.47;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-size: 14px;
  letter-spacing: -.01em;
}

/* ── Page States ── */
.page { position: relative; z-index: 1; height: 100%; }
.page.hidden { display: none !important; }
.hidden { display: none !important; }

/* ============================================================
   AUTH PAGE — Minimal, centered, Apple-style
   ============================================================ */
#authPage {
  display: flex; align-items: center; justify-content: center;
  height: 100%; padding: 24px;
  background: var(--bg-base);
}

.auth-container {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 48px 40px 40px;
  max-width: 400px; width: 100%;
  box-shadow: var(--shadow-lg);
  border: .5px solid var(--border-light);
}

.auth-brand { text-align: center; margin-bottom: 36px; }
.auth-logo {
  width: 64px; height: 64px;
  background: linear-gradient(135deg, var(--primary), #5856d6);
  border-radius: 16px;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; margin-bottom: 18px;
  box-shadow: 0 6px 20px rgba(0, 122, 255, .25);
}
.auth-brand h1 {
  font-size: 24px; font-weight: 700;
  letter-spacing: -.5px; color: var(--text);
}
.auth-brand p {
  color: var(--text-muted); font-size: 14px; margin-top: 6px; font-weight: 400;
  letter-spacing: 2px;
}

.auth-switch {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  margin-bottom: 20px;
  padding: 4px;
  background: var(--bg-input);
  border-radius: 12px;
}

.auth-switch-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.auth-switch-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, .65);
}

.auth-switch-btn.active {
  background: #fff;
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* ── Form Controls ── */
.form-group { margin-bottom: 20px; }
.form-group.compact { margin-bottom: 16px; }
.form-group label {
  display: block; font-size: 13px; font-weight: 500;
  color: var(--text-secondary); margin-bottom: 8px;
}

input[type="text"],
input[type="password"],
input[type="number"],
select,
textarea {
  width: 100%; padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text); font-size: 14px; font-family: inherit;
  transition: all var(--transition-fast);
  outline: none;
}
input::placeholder, textarea::placeholder { color: var(--text-muted); }
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
  background: #fff;
}
input:disabled { opacity: .35; cursor: not-allowed; background: var(--bg-input); }
textarea { resize: vertical; min-height: 60px; line-height: 1.6; }

/* Select */
select {
  cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23aeaeb2' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
  padding-right: 32px;
}

.form-row { display: flex; gap: 12px; }
.flex-1 { flex: 1; }
.form-help {
  margin-top: 6px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-muted);
}
.form-help code {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 5px;
  background: rgba(0, 122, 255, .08);
  color: var(--primary);
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
  font-size: 11px;
}

/* Toggle Switch — iOS style */
.toggle-label {
  display: flex !important; align-items: center;
  justify-content: space-between; cursor: pointer;
}
.toggle-label span:first-child { color: var(--text); font-size: 15px; font-weight: 400; }
.toggle-label input { display: none; }
.toggle-switch {
  width: 51px; height: 31px;
  background: var(--bg-elevated); border: none;
  border-radius: 16px; position: relative;
  transition: background var(--transition);
  flex-shrink: 0;
}
.toggle-switch::after {
  content: ''; position: absolute;
  width: 27px; height: 27px;
  background: #fff; border-radius: 50%;
  top: 2px; left: 2px;
  transition: all var(--transition);
  box-shadow: 0 2px 4px rgba(0, 0, 0, .15), 0 0 1px rgba(0, 0, 0, .06);
}
.toggle-label input:checked + .toggle-switch {
  background: var(--success);
}
.toggle-label input:checked + .toggle-switch::after {
  transform: translateX(20px);
}

/* ── Buttons ── */
.btn {
  width: auto; padding: 11px 20px;
  border: none; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 500; font-family: inherit;
  cursor: pointer; transition: all var(--transition-fast);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  position: relative; overflow: hidden;
}
.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:active { background: var(--primary-dark); transform: scale(.98); }
.btn-primary:disabled, .btn-secondary:disabled {
  opacity: .35; cursor: not-allowed; transform: none;
}
.btn-secondary {
  background: var(--bg-elevated); border: none;
  color: var(--text-secondary);
}
.btn-secondary:hover { background: rgba(0, 0, 0, .06); color: var(--text); }
.btn-secondary:active { background: rgba(0, 0, 0, .1); }
.btn-danger {
  background: var(--error); color: #fff;
}
.btn-danger:hover { background: #e0342b; }
.auth-form .btn { width: 100%; }
.btn-sm { padding: 8px 16px; font-size: 13px; width: auto; border-radius: 8px; }

/* Turnstile widget in auth form */
.turnstile-widget {
  display: flex;
  justify-content: center;
  margin: 4px 0 8px;
  min-height: 65px;
}
.turnstile-widget iframe {
  border-radius: 8px;
}
.btn-icon {
  background: transparent; border: none;
  border-radius: 8px; color: var(--text-muted);
  cursor: pointer; padding: 8px; display: flex; align-items: center; justify-content: center;
  transition: all var(--transition-fast);
}
.btn-icon:hover { color: var(--primary); background: var(--primary-light); }

/* ── Toast ── */
.toast {
  position: fixed; top: 24px; right: 24px; z-index: 9999;
  padding: 14px 22px; border-radius: var(--radius);
  font-size: 14px; font-weight: 500;
  transform: translateX(calc(100% + 48px));
  transition: transform .35s var(--ease-spring);
  max-width: 360px;
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(20px) saturate(1.8);
  -webkit-backdrop-filter: blur(20px) saturate(1.8);
}
.toast.show { transform: translateX(0); }
.toast.success {
  background: rgba(255, 255, 255, .92); border: .5px solid var(--success-border);
  color: var(--success);
}
.toast.error {
  background: rgba(255, 255, 255, .92); border: .5px solid var(--error-border);
  color: var(--error);
}

/* ============================================================
   APP LAYOUT — Full viewport, no body scroll
   ============================================================ */
#appPage { height: 100%; display: flex; overflow: hidden; }

/* ── Sidebar — macOS Finder / System Preferences style ── */
.sidebar {
  position: fixed; left: 0; top: 0; bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  backdrop-filter: blur(40px) saturate(1.8);
  -webkit-backdrop-filter: blur(40px) saturate(1.8);
  border-right: .5px solid var(--border);
  display: flex; flex-direction: column;
  z-index: 100;
  transition: width var(--transition-slow);
  flex-shrink: 0;
}
.sidebar.collapsed { width: var(--sidebar-collapsed); }

.sidebar-header {
  display: flex; align-items: center; gap: 12px;
  padding: 20px 18px;
  border-bottom: .5px solid var(--border);
  transition: padding var(--transition-slow);
  position: relative;
}
.sidebar.collapsed .sidebar-header {
  padding: 16px 14px;
  flex-direction: column; gap: 4px; justify-content: center;
}
.sidebar-logo {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--primary), #5856d6);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0, 122, 255, .2);
}
.sidebar-title {
  font-size: 16px; font-weight: 600;
  letter-spacing: -.3px; white-space: nowrap; overflow: hidden;
  color: var(--text);
  transition: opacity var(--transition-fast), width var(--transition-slow);
}
.sidebar.collapsed .sidebar-title {
  opacity: 0; width: 0; overflow: hidden; margin: 0; padding: 0;
}
.sidebar-toggle {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; padding: 6px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 6px; transition: all var(--transition-fast);
  margin-left: auto; flex-shrink: 0;
}
.sidebar-toggle:hover { color: var(--text); background: var(--bg-hover); }
.sidebar.collapsed .sidebar-toggle { margin-left: 0; width: 36px; }
.sidebar.collapsed .sidebar-toggle svg { transform: rotate(180deg); }

/* Sidebar Nav */
.sidebar-nav { flex: 1; overflow-y: auto; padding: 8px 0; }
.nav-section { margin-bottom: 2px; }
.nav-section-title {
  font-size: 11px; font-weight: 600;
  color: var(--text-muted); text-transform: uppercase;
  letter-spacing: .5px; padding: 16px 18px 6px;
  white-space: nowrap; overflow: hidden;
  transition: opacity var(--transition-fast), height var(--transition-slow);
}
.sidebar.collapsed .nav-section-title {
  opacity: 0; height: 0; padding: 0; overflow: hidden;
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: calc(100% - 16px); margin: 1px 8px;
  padding: 7px 12px;
  background: none; border: none;
  color: var(--text-secondary); cursor: pointer;
  font-size: 13px; font-weight: 400; font-family: inherit;
  transition: all var(--transition-fast);
  text-align: left; position: relative; white-space: nowrap;
  border-radius: 8px;
}
.sidebar.collapsed .nav-item { padding: 9px 0; justify-content: center; width: calc(100% - 12px); margin: 1px 6px; }
.nav-item:hover { color: var(--text); background: rgba(0, 0, 0, .04); }
.nav-item.active {
  color: var(--primary); background: var(--primary-light);
  font-weight: 500;
}
.nav-item svg { flex-shrink: 0; opacity: .5; transition: opacity var(--transition-fast); }
.nav-item:hover svg { opacity: .7; }
.nav-item.active svg { opacity: 1; }
.nav-item span {
  overflow: hidden; transition: opacity var(--transition-fast), width var(--transition-slow);
}
.sidebar.collapsed .nav-item span { opacity: 0; width: 0; }

/* Sidebar Footer */
.sidebar-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  border-top: .5px solid var(--border);
  transition: padding var(--transition-slow);
}
.sidebar.collapsed .sidebar-footer { padding: 12px; justify-content: center; }
.sidebar-user-wrap {
  display: flex; align-items: center; gap: 10px;
  overflow: hidden;
}
.sidebar-user-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 1px;
}
.sidebar-avatar {
  width: 30px; height: 30px;
  background: linear-gradient(135deg, #007AFF, #5856d6);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 12px; font-weight: 600;
  flex-shrink: 0;
}
.sidebar-user {
  font-size: 13px; color: var(--text-secondary); font-weight: 400;
  white-space: nowrap; overflow: hidden;
  transition: opacity var(--transition-fast), width var(--transition-slow);
}
.sidebar-role {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  transition: opacity var(--transition-fast), width var(--transition-slow);
}
.sidebar.collapsed .sidebar-user { opacity: 0; width: 0; overflow: hidden; }
.sidebar.collapsed .sidebar-role { opacity: 0; width: 0; overflow: hidden; }

/* ── Main Content — fills remaining space, scrolls internally ── */
.main-content {
  flex: 1; margin-left: var(--sidebar-width);
  padding: 20px 32px;
  height: 100%;
  overflow-y: auto; overflow-x: hidden;
  position: relative; z-index: 1;
  transition: margin-left var(--transition-slow);
}
/* Non-log pages: normal scrolling */
.tab-content.active:not(.log-page) {
  animation: fadeIn .2s var(--ease-out);
  height: 100%;
}
.sidebar.collapsed ~ .main-content, .main-content.sidebar-collapsed {
  margin-left: var(--sidebar-collapsed);
}
/* When a log page is active, disable main-content scroll — log-viewer scrolls instead */
.main-content.log-active {
  overflow-y: hidden;
}

/* ── Page Header — Apple Large Title style ── */
.page-header {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 10px; flex-wrap: wrap; gap: 12px;
  padding-bottom: 0;
}
.page-title {
  font-size: 28px; font-weight: 700; letter-spacing: -.5px;
  color: var(--text);
}
.page-actions { display: flex; align-items: center; gap: 8px; }

/* ── Tab Content ── */
.tab-content { display: none; }
.tab-content.active { display: block; }
.tab-content.hidden { display: none !important; }

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

/* ============================================================
   DASHBOARD — Stat Cards
   ============================================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px; margin-bottom: 20px;
}
.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-card);
  border: .5px solid var(--border-light);
  transition: all var(--transition-fast);
}
.stat-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, .06), 0 0 0 .5px rgba(0, 0, 0, .06);
}

.stat-card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.stat-card-label {
  font-size: 12px; font-weight: 500; color: var(--text-muted);
  letter-spacing: .01em;
}
.stat-card-icon {
  width: 34px; height: 34px;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.stat-card-icon svg { width: 17px; height: 17px; }

.stat-card-icon.icon-domain { background: rgba(0, 122, 255, .08); color: var(--primary); }
.stat-card-icon.icon-doh { background: rgba(52, 199, 89, .08); color: var(--success); }
.stat-card-icon.icon-dot { background: rgba(88, 86, 214, .08); color: #5856d6; }
.stat-card-icon.icon-adblock { background: rgba(255, 149, 0, .08); color: var(--warn); }
.stat-card-icon.icon-filter { background: rgba(0, 122, 255, .08); color: var(--primary); }
.stat-card-icon.icon-geoip { background: rgba(52, 199, 89, .08); color: var(--success); }
.stat-card-icon.icon-ssl { background: rgba(88, 86, 214, .08); color: #5856d6; }

.stat-card-value {
  font-size: 14px; font-weight: 600; color: var(--text);
  word-break: break-all; line-height: 1.4;
}

/* ── Info Cards — macOS System Preferences style ── */
.info-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 0;
  margin-bottom: 12px;
  box-shadow: var(--shadow-card);
  border: .5px solid var(--border-light);
}

.card-header {
  font-size: 13px; font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: .01em; margin-bottom: 0;
  padding: 12px 20px 0;
  display: flex; align-items: center; gap: 8px;
}
.card-header-info {
  font-size: 12px; color: var(--text-muted);
  font-weight: 400; letter-spacing: 0;
}

/* macOS-style grouped rows */
.info-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 20px;
  min-height: 44px;
}
.info-row + .info-row { border-top: .5px solid var(--border-light); }
.info-row .label { color: var(--text); font-size: 14px; font-weight: 400; }
.info-row .value {
  font-size: 14px; font-weight: 400; max-width: 60%; text-align: right;
  word-break: break-all; color: var(--text-secondary);
}
.value-small { font-size: 13px !important; color: var(--primary) !important; font-weight: 400 !important; }

/* Form rows inside cards — Apple Web style */
.info-card .form-group { margin-bottom: 0; padding: 4px 20px 12px; }
.info-card .form-group + .form-group { padding-top: 0; }
.info-card .form-group label { margin-bottom: 4px; padding: 4px 0 0; }
.info-card .form-group input,
.info-card .form-group textarea,
.info-card .form-group select {
  background: var(--bg-input);
  border: 1px solid transparent;
}
.info-card .form-group input:focus,
.info-card .form-group textarea:focus,
.info-card .form-group select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
  background: #fff;
}
.info-card .form-group.compact { margin-bottom: 0; }
.info-card .card-header + .form-group { padding-top: 4px; }
.info-card .card-header + .info-row { margin-top: 2px; }

/* Override for form-row inside info-card */
.info-card .form-row { padding: 4px 20px 14px; gap: 12px; }
.info-card .form-row .form-group { padding: 0; }
.info-card .form-row .form-group:first-child { border-right: none; }

/* Override for compact form groups in info-cards */
.info-card > .form-group.compact { padding: 2px 20px 12px; }
/* Toggle labels self-manage padding; cancel the extra bottom from parent form-group */
.info-card > .form-group.compact .toggle-label { margin: 0 -20px -12px; padding: 10px 20px; }

/* Toggle inside card */
.info-card .toggle-label { padding: 10px 20px; margin-bottom: 0; }
.info-card > .form-group.compact + .form-group.compact .toggle-label { border-top: .5px solid var(--border-light); }
.info-card .card-header + .form-group .toggle-label { margin-top: 0; }

/* Buttons inside cards (like changePwdBtn) */
.info-card > .btn { margin: 4px 20px 14px; }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 6px;
  font-size: 12px; font-weight: 500;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-danger { background: var(--error-bg); color: var(--error); }

.actions { display: flex; gap: 12px; margin-top: 20px; }
.actions .btn { flex: none; max-width: 200px; min-width: 120px; }

/* ============================================================
   DEVICE SETUP
   ============================================================ */
.setup-desc {
  font-size: 14px; color: var(--text-secondary);
  line-height: 1.6; margin-bottom: 16px; padding: 10px 20px 0;
}
.setup-section { margin-bottom: 14px; padding: 0 20px; }
.setup-label {
  font-size: 12px; font-weight: 500; color: var(--text-muted);
  margin-bottom: 6px;
}
.setup-protocol-cards { display: flex; gap: 10px; flex-wrap: wrap; }
.protocol-card {
  flex: 1; min-width: 220px;
  background: var(--bg-input); border: 1px solid transparent;
  border-radius: var(--radius-sm); padding: 14px;
  display: flex; align-items: center; gap: 12px;
  transition: all var(--transition-fast);
}
.protocol-card:hover { border-color: var(--primary); background: var(--primary-light); }
.protocol-icon {
  width: 44px; height: 44px;
  background: var(--primary-light); border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  color: var(--primary); flex-shrink: 0;
}
.protocol-info { flex: 1; min-width: 0; }
.protocol-name { font-size: 14px; font-weight: 600; margin-bottom: 2px; color: var(--text); }
.protocol-detail { font-size: 12px; color: var(--text-muted); word-break: break-all; font-family: 'SF Mono', 'Menlo', 'Consolas', monospace; }
.protocol-card .btn { flex-shrink: 0; text-decoration: none; white-space: nowrap; }
.mobileconfig-link { cursor: pointer; }

/* Data Update page — compact form layout */
.info-card textarea { width: 100%; }

.setup-copy-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-input); border: 1px solid transparent;
  border-radius: var(--radius-sm); padding: 10px 14px;
  transition: all var(--transition-fast);
}
.setup-copy-row:hover { border-color: var(--primary); }
.setup-copy-row code {
  flex: 1; font-size: 13px;
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
  color: var(--primary); word-break: break-all; background: none;
}
.copy-btn { flex-shrink: 0; }

/* ============================================================
   CUSTOM RULES
   ============================================================ */
.custom-rules-hint {
  font-size: 13px; color: var(--text-secondary);
  margin-bottom: 10px; line-height: 1.7; padding: 0 20px;
}
.custom-rules-hint code {
  background: var(--bg-input); padding: 2px 7px;
  border-radius: 5px; font-size: 12px;
  font-family: 'SF Mono', 'Menlo', monospace;
  color: var(--primary);
}
.custom-rules-actions { display: flex; gap: 10px; margin-top: 14px; padding: 0 20px 14px; flex-wrap: wrap; }

/* Domain Check */
.check-domain-row {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  padding: 10px 20px;
}
.check-domain-row .filter-input { flex: 1; min-width: 160px; }
.check-result { margin-top: 0; }
.check-result.hidden { display: none; }
.check-loading {
  text-align: center; color: var(--text-muted);
  font-size: 14px; padding: 16px;
}
.check-blocked, .check-whitelist, .check-pass, .check-error {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 20px;
}
.check-blocked { background: var(--error-bg); }
.check-whitelist { background: var(--success-bg); }
.check-pass { background: var(--info-bg); }
.check-error { background: var(--error-bg); color: var(--error); font-size: 14px; }

.check-status-icon {
  width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; flex-shrink: 0;
}
.check-status-icon.blocked { background: rgba(255, 59, 48, .12); color: var(--error); }
.check-status-icon.whitelist { background: rgba(52, 199, 89, .12); color: var(--success); }
.check-status-icon.pass { background: rgba(0, 122, 255, .12); color: var(--info); }
.check-info { flex: 1; min-width: 0; }
.check-status-text { font-size: 14px; font-weight: 600; }
.check-status-text.blocked { color: var(--error); }
.check-status-text.whitelist { color: var(--success); }
.check-status-text.pass { color: var(--info); }
.check-rule { font-size: 12px; color: var(--text-secondary); margin-top: 2px; word-break: break-all; }
.check-rule code {
  background: var(--bg-input); padding: 2px 7px;
  border-radius: 5px; font-size: 12px;
  font-family: 'SF Mono', 'Menlo', monospace;
  color: var(--primary);
}

/* ============================================================
   USER MANAGEMENT
   ============================================================ */
.user-select-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px 16px;
  flex-wrap: wrap;
}

.user-select-dropdown {
  min-width: 200px;
  max-width: 320px;
}

.user-select-actions {
  display: flex;
  gap: 8px;
}

.user-select-info {
  padding: 0 20px 12px;
}

.user-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 20px 16px;
}

.user-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  background: rgba(0, 122, 255, .08);
  color: var(--primary);
}

.user-pill.success {
  background: var(--success-bg);
  color: var(--success);
}

.user-pill.danger {
  background: var(--error-bg);
  color: var(--error);
}

.user-select-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}


.panel-empty {
  padding: 24px 20px 20px;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.6;
}

.form-help-block {
  padding: 0 20px 12px;
}

.user-editor-actions {
  padding: 0 20px 14px;
  margin-top: 0;
}

/* ============================================================
   LOG VIEWER
   ============================================================ */
.log-info { font-size: 12px; color: var(--text-muted); font-weight: 400; white-space: nowrap; }
.log-viewer {
  background: var(--bg-card); border: .5px solid var(--border-light);
  border-radius: var(--radius); padding: 4px 0;
  overflow-y: auto; overflow-x: hidden;
  font-size: 12px; line-height: 1.6;
  box-shadow: var(--shadow-card);
}
.log-line {
  padding: 2px 16px;
  word-break: break-all;
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
  font-size: 12px; transition: background var(--transition-fast);
}
.log-line:hover { background: rgba(0, 0, 0, .02); }
.log-line.log-error { color: var(--error); }
.log-line.log-warn { color: var(--warn); }
.log-empty {
  text-align: center; padding: 60px 20px;
  color: var(--text-muted); font-size: 14px; font-weight: 400;
}

/* Log pages fill viewport, no global scroll */
.tab-content.log-page.active {
  display: flex; flex-direction: column;
  height: 100%;
  overflow: hidden;
}
.tab-content.log-page.active .page-header {
  flex-shrink: 0; margin-bottom: 8px;
}
.tab-content.log-page.active .log-toolbar { flex-shrink: 0; }
.tab-content.log-page.active .log-viewer { flex: 1; min-height: 0; }

/* DNS Log Toolbar — compact inline */
.log-toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 0 8px; flex-shrink: 0;
}
.log-toolbar .filter-select {
  width: auto; min-width: 80px; flex-shrink: 0;
}
.log-toolbar .filter-input {
  flex: 1; min-width: 120px;
}
.filter-input {
  flex: 1; min-width: 120px; padding: 7px 10px;
  background: var(--bg-input); border: 1px solid transparent;
  border-radius: 8px; color: var(--text);
  font-size: 13px; font-family: inherit;
  outline: none; transition: all var(--transition-fast);
}
.filter-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.filter-select {
  padding: 7px 26px 7px 10px;
  background: var(--bg-input); border: 1px solid transparent;
  border-radius: 8px; color: var(--text);
  font-size: 13px; font-family: inherit;
  cursor: pointer; outline: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' fill='%23aeaeb2' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
  transition: all var(--transition-fast);
}
.filter-select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.filter-lines-inline { width: 80px; flex-shrink: 0; }
#mobileconfigUser { max-width: 200px; }
#checkDomainUser { max-width: 160px; }

/* DNS Log Entries */
.dns-log-list { display: flex; flex-direction: column; }
.dns-log-entry {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px;
  transition: background var(--transition-fast); cursor: default;
  border-bottom: .5px solid var(--border-light);
}
.dns-log-entry:last-child { border-bottom: none; }
.dns-log-entry:hover { background: rgba(0, 0, 0, .015); }
.dns-log-entry.entry-blocked { background: rgba(255, 59, 48, .02); }
.dns-log-entry.entry-blocked:hover { background: rgba(255, 59, 48, .04); }
.dns-log-entry.entry-rewritten { background: rgba(0, 122, 255, .02); }
.dns-log-entry.entry-rewritten:hover { background: rgba(0, 122, 255, .04); }

.entry-status {
  width: 8px; height: 8px; border-radius: 50%;
  flex-shrink: 0;
}
.entry-status.st-resolve { background: var(--success); }
.entry-status.st-cache { background: var(--info); }
.entry-status.st-blocked { background: var(--error); }
.entry-status.st-blocked-rsp { background: var(--warn); }
.entry-status.st-rewritten { background: #5856d6; }
.entry-status.st-unknown { background: var(--text-muted); }

.entry-body { flex: 1; min-width: 0; }
.entry-main { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.entry-domain { font-size: 13px; font-weight: 500; color: var(--text); word-break: break-all; }
.entry-qtype {
  display: inline-block; padding: 1px 8px; border-radius: 5px;
  font-size: 10px; font-weight: 500;
  background: var(--primary-light); color: var(--primary); flex-shrink: 0;
}
.entry-protocol {
  display: inline-block; padding: 1px 8px; border-radius: 5px;
  font-size: 10px; font-weight: 400;
  background: rgba(0, 0, 0, .03); color: var(--text-muted); flex-shrink: 0;
}
.entry-meta { display: flex; gap: 12px; margin-top: 2px; flex-wrap: wrap; }
.entry-meta-item {
  font-size: 11px; color: var(--text-muted);
  display: flex; align-items: center; gap: 3px;
}
.entry-meta-item svg { width: 11px; height: 11px; opacity: .35; }

.entry-status-text { font-size: 11px; font-weight: 500; }
.entry-status-text.st-resolve { color: var(--success); }
.entry-status-text.st-cache { color: var(--info); }
.entry-status-text.st-blocked { color: var(--error); }
.entry-status-text.st-blocked-rsp { color: var(--warn); }
.entry-status-text.st-rewritten { color: #5856d6; }
.entry-status-text.st-unknown { color: var(--text-muted); }
.entry-filter-tag {
  font-size: 9px; color: var(--warn);
  background: var(--warn-bg); padding: 1px 6px;
  border-radius: 4px; margin-left: 3px; font-weight: 500;
}

.entry-right {
  display: flex; flex-direction: column;
  align-items: flex-end; gap: 2px; flex-shrink: 0;
}
.entry-time { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.entry-latency { font-size: 10px; color: var(--text-muted); white-space: nowrap; }

/* ── Form hint ── */
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

/* ── Spinner ── */
.spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255, 255, 255, .2);
  border-top-color: #fff; border-radius: 50%;
  animation: spin .6s linear infinite; display: none;
}
.btn.loading .spinner { display: block; }
.btn.loading .btn-text, .btn.loading span { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Scrollbar — Thin macOS style ── */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, .12); border-radius: 4px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, .2);
  border: 2px solid transparent;
  background-clip: padding-box;
}

/* ── Mobile Header ── */
.mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 52px;
  background: var(--bg-card);
  border-bottom: .5px solid var(--border);
  z-index: 90;
  align-items: center;
  padding: 0 12px;
  gap: 12px;
  box-shadow: var(--shadow-sm);
}

.hamburger-btn {
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: background var(--transition-fast);
}

.hamburger-btn:hover {
  background: var(--bg-hover);
}

.mobile-header-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -.3px;
}

/* ── Sidebar Backdrop ── */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .4);
  z-index: 99;
  opacity: 0;
  transition: opacity .25s var(--ease);
}

.sidebar-backdrop.active {
  display: block;
  opacity: 1;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1200px) {
  .stats-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}

@media (max-width: 768px) {
  .mobile-header { display: flex; }

  .sidebar {
    transform: translateX(-100%);
    transition: transform .3s var(--ease-out), width .3s var(--ease-out);
    z-index: 100;
    box-shadow: none;
  }
  .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.mobile-open.collapsed { width: var(--sidebar-width); }
  .sidebar.mobile-open.collapsed .sidebar-title { opacity: 1; width: auto; overflow: visible; margin: 0; padding: 0; }
  .sidebar.mobile-open.collapsed .nav-item span { opacity: 1; width: auto; }
  .sidebar.mobile-open.collapsed .nav-section-title { opacity: 1; height: auto; padding: 16px 18px 6px; }
  .sidebar.mobile-open.collapsed .sidebar-user { opacity: 1; width: auto; }
  .sidebar.mobile-open.collapsed .sidebar-role { opacity: 1; width: auto; }
  .sidebar.mobile-open.collapsed .sidebar-header { flex-direction: row; gap: 12px; justify-content: flex-start; padding: 20px 18px; }
  .sidebar.mobile-open.collapsed .sidebar-footer { padding: 14px 18px; justify-content: space-between; }
  .sidebar.mobile-open.collapsed .sidebar-user-wrap { display: flex; }
  .sidebar.mobile-open.collapsed .sidebar-toggle { margin-left: auto; }
  .sidebar.mobile-open.collapsed .sidebar-toggle svg { transform: none; }
  .sidebar.mobile-open.collapsed .nav-item { padding: 7px 12px; justify-content: flex-start; width: calc(100% - 16px); margin: 1px 8px; }

  .main-content {
    margin-left: 0;
    padding: 68px 16px 20px;
  }
  .main-content.sidebar-collapsed {
    margin-left: 0;
  }

  .sidebar-toggle { display: none; }

  .stats-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
  .stat-card { padding: 14px; }
  .page-title { font-size: 22px; }

  .form-row { flex-direction: column; gap: 0; }
  .form-row .form-group { width: 100%; }

  .info-row { flex-direction: column; align-items: flex-start; gap: 4px; }
  .info-row .value { max-width: 100%; text-align: left; }

  .auth-container { padding: 36px 24px 32px; }

  .toast { right: 12px; left: 12px; max-width: none; }

  .tab-content.log-page.active { height: 100%; }
  .log-toolbar .filter-select { min-width: 60px; }

  .log-toolbar { flex-wrap: wrap; }
  .log-toolbar .filter-input { min-width: 0; }

  .dns-log-entry { flex-wrap: wrap; gap: 6px; }
  .entry-right { flex-direction: row; align-items: center; gap: 8px; width: 100%; justify-content: flex-end; }

  .actions { flex-wrap: wrap; }
}

@media (max-width: 480px) {
  .main-content { padding: 68px 12px 16px; }

  .auth-container { padding: 28px 18px 24px; border-radius: var(--radius); }
  .auth-logo { width: 52px; height: 52px; border-radius: 14px; margin-bottom: 14px; }
  .auth-brand h1 { font-size: 20px; }
  .auth-brand p { font-size: 13px; }

  .page-title { font-size: 20px; }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-card { padding: 12px; }
  .stat-card-icon { width: 30px; height: 30px; }
  .stat-card-value { font-size: 13px; }

  .protocol-card { min-width: 100%; flex-direction: column; align-items: flex-start; }
  .protocol-card .btn { align-self: flex-end; }
  .auth-switch { margin-bottom: 16px; }

  .setup-copy-row { flex-wrap: wrap; }
  .setup-copy-row code { font-size: 12px; }
  .check-domain-row { padding: 10px 14px; }
  .check-domain-row .filter-input { min-width: 0; }

  .actions .btn { max-width: none; min-width: 0; width: 100%; }

  .user-list { padding: 10px 14px 14px; }
  .user-select-row { padding: 10px 14px 14px; flex-direction: column; align-items: stretch; }
  .user-select-dropdown { max-width: 100%; }

  .info-card .form-row { padding: 4px 14px 14px; }
  .info-card .form-group { padding: 4px 14px 12px; }
  .info-card .card-header { padding: 12px 14px 0; }
  .info-row { padding: 10px 14px; }
  .info-card > .btn { margin: 4px 14px 14px; }
  .info-card .toggle-label { padding: 10px 14px; margin: 0 -14px -12px; padding: 10px 14px; }
  .info-card > .form-group.compact .toggle-label { margin: 0 -14px -12px; padding: 10px 14px; }
}
