:root {
  color-scheme: light dark;

  &:has(> head > meta[name="color-scheme"][content="dark"]) {
    color-scheme: dark;
  }
  &:has(> head > meta[name="color-scheme"][content="light"]) {
    color-scheme: light;
  }

  --bg-page: light-dark(#f6f8fb, #0b101b);
  --bg-surface: light-dark(#ffffff, #131a29);
  --bg-subtle: light-dark(#f1f5f9, #1b2436);
  --bg-hover: light-dark(#f8fafc, #1e293b);

  --text-primary: light-dark(#0f172a, #f1f5f9);
  --text-secondary: light-dark(#475569, #94a3b8);
  --text-muted: light-dark(#64748b, #64748b);

  --border-color: light-dark(#e2e8f0, #253147);
  --border-strong: light-dark(#cbd5e1, #334155);

  --accent: light-dark(#2563eb, #3b82f6);
  --accent-hover: light-dark(#1d4ed8, #60a5fa);
  --accent-soft: light-dark(rgba(37, 99, 235, 0.1), rgba(59, 130, 246, 0.16));

  --success: light-dark(#15803d, #22c55e);
  --success-soft: light-dark(#dcfce7, rgba(34, 197, 94, 0.15));

  --danger: light-dark(#dc2626, #ef4444);
  --danger-hover: light-dark(#b91c1c, #f87171);
  --danger-soft: light-dark(#fef2f2, rgba(239, 68, 68, 0.14));

  --warning: light-dark(#b45309, #f59e0b);
  --warning-soft: light-dark(#fef3c7, rgba(245, 158, 11, 0.15));

  --shadow-sm: light-dark(0 1px 2px rgba(15, 23, 42, 0.05), 0 1px 2px rgba(0, 0, 0, 0.35));
  --shadow-md: light-dark(0 8px 24px rgba(15, 23, 42, 0.08), 0 10px 28px rgba(0, 0, 0, 0.45));
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
}

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

body {
  margin: 0;
  font-family: "IBM Plex Sans Arabic", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-page);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.visually-hidden:where(:not(:focus-within, :active)) {
  position: absolute !important;
  clip-path: inset(50%) !important;
  overflow: hidden !important;
  width: 1px !important;
  height: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  border: 0 !important;
  white-space: nowrap !important;
}

.container {
  width: min(1160px, 100% - 2rem);
  margin-inline: auto;
}

/* Theme toggle icon visibility */
.theme-icon-dark,
.theme-label-dark {
  display: none;
}

@media (prefers-color-scheme: dark) {
  :root:not(:has(> head > meta[name="color-scheme"][content="light"])) {
    .theme-icon-light,
    .theme-label-light {
      display: none;
    }
    .theme-icon-dark,
    .theme-label-dark {
      display: inline;
    }
  }
}

:root:has(> head > meta[name="color-scheme"][content="dark"]) {
  .theme-icon-light,
  .theme-label-light {
    display: none;
  }
  .theme-icon-dark,
  .theme-label-dark {
    display: inline;
  }
}

/* Header */
.app-header {
  position: sticky;
  inset-block-start: 0;
  z-index: 20;
  background: var(--bg-surface);
  border-block-end: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
}

.header-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-block: 0.875rem;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  background: var(--accent-soft);
  color: var(--accent);
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.brand-name {
  font-weight: 700;
  font-size: 1.05rem;
}

.domain-pill {
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  background: var(--bg-subtle);
  color: var(--accent);
  border: 1px solid var(--border-color);
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.inline-form {
  margin: 0;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  font: inherit;
  font-weight: 600;
  font-size: 0.925rem;
  min-height: 44px;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

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

.btn:focus-visible,
input:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.btn-sm {
  min-height: 38px;
  padding: 0.35rem 0.85rem;
  font-size: 0.875rem;
}

.btn-xs {
  min-height: 32px;
  padding: 0.2rem 0.6rem;
  font-size: 0.8rem;
}

.btn-icon {
  width: 40px;
  min-height: 40px;
  padding: 0;
}

.btn-block {
  width: 100%;
  min-height: 48px;
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-outline {
  background: var(--bg-surface);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.btn-outline:hover:not(:disabled) {
  background: var(--bg-subtle);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-subtle);
  color: var(--text-primary);
}

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

.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
}

.btn-link {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
}

.btn-link:hover {
  text-decoration: underline;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Main content */
.main-content {
  padding-block: 1.75rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem 1.35rem;
  box-shadow: var(--shadow-sm);
}

.stat-label {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  margin-block: 0.35rem 0.2rem;
  letter-spacing: -0.02em;
}

.stat-meta {
  font-size: 0.825rem;
  color: var(--text-muted);
}

/* Toolbar & Tabs */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.tabs {
  display: inline-flex;
  background: var(--bg-subtle);
  padding: 0.25rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.tab-btn {
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: transparent;
  border: 0;
  border-radius: 6px;
  padding: 0.45rem 1rem;
  min-height: 38px;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.tab-btn.is-active {
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.search-box input {
  min-width: 240px;
  min-height: 44px;
  padding: 0.5rem 0.875rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  color: var(--text-primary);
  font: inherit;
  font-size: max(1rem, 1em);
}

/* Responsive Table */
.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.table-wrapper {
  overflow: auto;
  max-inline-size: 100%;
  max-block-size: min(640px, 75vh);
  container-type: inline-size;
}

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  text-align: start;
}

.data-table thead {
  position: sticky;
  inset-block-start: 0;
  z-index: 2;
  background: var(--bg-subtle);
}

.data-table th,
.data-table td {
  padding: 0.95rem 1.15rem;
  border-block-end: 1px solid var(--border-color);
  vertical-align: middle;
}

.data-table thead th {
  font-size: 0.825rem;
  font-weight: 700;
  color: var(--text-secondary);
  white-space: nowrap;
}

.data-table tbody th {
  position: sticky;
  inset-inline-start: 0;
  background: var(--bg-surface);
  font-weight: 600;
  z-index: 1;
}

.data-table tbody tr:hover td,
.data-table tbody tr:hover th {
  background: var(--bg-hover);
}

.data-table tbody tr:last-child td,
.data-table tbody tr:last-child th {
  border-block-end: 0;
}

.empty-cell {
  text-align: center;
  padding: 2.5rem 1rem !important;
  color: var(--text-secondary);
}

.email-cell {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.email-text {
  font-weight: 600;
  unicode-bidi: plaintext;
}

/* Storage bar */
.usage-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-width: 140px;
}

.usage-nums {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.progress-track {
  width: 100%;
  height: 7px;
  border-radius: 999px;
  background: var(--bg-subtle);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
}

.progress-fill.is-warn {
  background: var(--warning);
}

.progress-fill.is-danger {
  background: var(--danger);
}

/* Badges */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--success-soft);
  color: var(--success);
}

.status-pill.is-suspended {
  background: var(--danger-soft);
  color: var(--danger);
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

/* Container query stacked cards on narrow containers */
@container (width < 680px) {
  .data-table,
  .data-table thead,
  .data-table tbody,
  .data-table tr,
  .data-table th,
  .data-table td {
    display: block;
  }

  .data-table thead {
    display: none;
  }

  .data-table tbody tr {
    margin: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    overflow: hidden;
  }

  .data-table tbody th {
    position: sticky;
    inset-block-start: 0;
    z-index: 2;
    background: var(--bg-subtle);
    border-block-end: 1px solid var(--border-color);
  }

  .data-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
  }

  .data-table td::before {
    content: attr(data-label) ":";
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-secondary);
  }

  .data-table td.empty-cell {
    display: block;
  }

  .data-table td.empty-cell::before {
    content: none;
  }
}

/* Native Dialogs */
dialog {
  margin: auto;
  padding: 0;
  width: min(500px, calc(100% - 2rem));
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-md);
}

dialog[open] {
  display: flex;
  flex-direction: column;
}

dialog:modal {
  overscroll-behavior: contain;
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  overflow: hidden;
  overscroll-behavior: contain;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.15rem 1.35rem;
  border-block-end: 1px solid var(--border-color);
}

.dialog-header h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
}

dialog form,
.settings-body {
  padding: 1.35rem;
}

.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.65rem;
  margin-block-start: 0.75rem;
}

/* Forms & Validation */
.stack-form {
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.field label {
  font-weight: 600;
  font-size: 0.925rem;
}

.req {
  color: var(--danger);
}

.hint {
  font-size: 0.825rem;
  color: var(--text-secondary);
}

.field input[type="text"],
.field input[type="email"],
.field input[type="password"],
.field input[type="number"] {
  width: 100%;
  min-height: 48px;
  padding: 0.65rem 0.85rem;
  font: inherit;
  font-size: max(1rem, 1em);
  color: var(--text-primary);
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.input-group {
  display: flex;
  align-items: stretch;
}

.input-group input {
  border-start-end-radius: 0;
  border-end-end-radius: 0;
}

.input-addon {
  display: inline-flex;
  align-items: center;
  padding-inline: 0.85rem;
  background: var(--bg-subtle);
  border: 1px solid var(--border-strong);
  border-inline-start: 0;
  border-start-end-radius: var(--radius-sm);
  border-end-end-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
}

.password-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.password-wrap input {
  padding-inline-end: 4.5rem;
}

.btn-toggle-pw {
  position: absolute;
  inset-inline-end: 0.45rem;
  min-height: 36px;
  padding: 0.25rem 0.65rem;
  border: 0;
  border-radius: 6px;
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.825rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-toggle-pw:hover {
  color: var(--text-primary);
}

.error-msg {
  display: none;
  color: var(--danger);
  font-size: 0.85rem;
  font-weight: 500;
}

:is(input:user-invalid, input.user-invalid-fallback) {
  border-color: var(--danger);
  background-color: var(--danger-soft);
}

.field:has(:is(input:user-invalid, input.user-invalid-fallback)) .error-msg {
  display: block;
}

input:user-valid {
  border-color: var(--success);
}

.target-badge {
  margin: 0;
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  font-weight: 700;
  text-align: center;
}

.target-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.confirm-text {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

/* Key-value settings list */
.kv-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-block: 1rem;
}

.kv-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  background: var(--bg-subtle);
  border-radius: var(--radius-sm);
}

.kv-key {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-weight: 600;
}

.kv-val {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-weight: 600;
}

/* Alerts & Toasts */
.alert {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.925rem;
  font-weight: 500;
}

.alert-error {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent);
}

.toast-region {
  position: fixed;
  inset-block-end: 1.25rem;
  inset-inline-start: 1.25rem;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: min(380px, calc(100vw - 2.5rem));
}

.toast {
  padding: 0.85rem 1.1rem;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-md);
  font-weight: 600;
  font-size: 0.9rem;
}

.toast.is-success {
  border-inline-start: 4px solid var(--success);
}

.toast.is-error {
  border-inline-start: 4px solid var(--danger);
}

/* Auth Page */
.auth-page {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.auth-topbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem 1.5rem;
}

.btn-danger-text {
  color: var(--danger);
}

.input-group input {
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}

.input-addon {
  display: inline-flex;
  align-items: center;
  padding-inline: 0.85rem;
  background: var(--bg-subtle);
  border: 1px solid var(--border-strong);
  border-left: 0;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
}

.panel-padded {
  padding: 1.35rem;
}

.section-title {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
  font-weight: 700;
}

.dns-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.85rem;
}

.dns-card {
  padding: 0.95rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.dns-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.dns-detail {
  font-size: 0.78rem;
  color: var(--text-secondary);
  word-break: break-all;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 500;
  cursor: pointer;
}

.check-row input {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--accent);
}

.field textarea {
  width: 100%;
  padding: 0.65rem 0.85rem;
  font: inherit;
  font-size: max(1rem, 1em);
  color: var(--text-primary);
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  resize: vertical;
}

.log-box {
  margin: 0;
  padding: 1rem;
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  line-height: 1.5;
  max-height: 360px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.auth-container {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.auth-card {
  width: min(440px, 100%);
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.auth-brand {
  display: flex;
  align-items: flex-start;
  gap: 0.9rem;
}

.auth-brand h1 {
  margin: 0 0 0.25rem;
  font-size: 1.3rem;
}

.auth-subtitle {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-secondary);
}
