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

[hidden] {
  display: none !important;
}

:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-subtle: #f9faf7;
  --text: #17201a;
  --muted: #687167;
  --line: #dfe5dc;
  --line-strong: #cbd5c7;
  --primary: #1f6f4a;
  --primary-dark: #155738;
  --primary-soft: #e7f4ec;
  --accent: #345c7c;
  --danger: #af3029;
  --danger-soft: #fdecea;
  --warning: #8a5b00;
  --warning-soft: #fff4d8;
  --success: #17653b;
  --success-soft: #e6f6ed;
  --neutral-soft: #edf0ea;
  --shadow: 0 1px 2px rgba(23, 32, 26, 0.06), 0 12px 32px rgba(23, 32, 26, 0.08);
  --radius: 8px;
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    linear-gradient(135deg, rgba(31, 111, 74, 0.08), transparent 32rem),
    radial-gradient(circle at 100% 0%, rgba(52, 92, 124, 0.11), transparent 28rem),
    var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 18px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(18px);
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--text);
  color: #ffffff;
  font-weight: 800;
  font-size: 13px;
}

.brand-name,
.brand-subtitle,
.eyebrow,
.page-description,
.panel-header p,
.field span,
.muted,
.sidebar-label {
  margin: 0;
}

.brand-name {
  font-weight: 800;
  letter-spacing: 0;
}

.brand-subtitle {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.nav-list {
  display: grid;
  gap: 4px;
}

.nav-item {
  color: var(--muted);
  text-decoration: none;
  font-weight: 650;
  font-size: 14px;
  padding: 10px 12px;
  border-radius: 7px;
}

.nav-item:hover,
.nav-item.active {
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-subtle);
}

.sidebar-label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
}

.domain-pill {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 750;
}

.main {
  width: min(1380px, 100%);
  padding: 24px 32px 32px;
  display: grid;
  gap: 14px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.eyebrow {
  color: var(--primary);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  margin-top: 4px;
  font-size: clamp(30px, 4vw, 44px);
  line-height: 1.05;
}

h2 {
  font-size: 16px;
}

.page-description {
  margin-top: 8px;
  color: var(--muted);
  font-size: 15px;
}

.header-actions {
  display: flex;
  gap: 10px;
}

.status-banner {
  margin: 0;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 650;
  border: 1px solid;
}

.status-banner.success {
  color: var(--success);
  background: var(--success-soft);
  border-color: #b8e3c9;
}

.status-banner.error {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: #f3b8b3;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 0;
}

.page-content {
  min-height: 420px;
}

.app-page {
  display: none;
}

.app-page.active {
  display: grid;
  gap: 18px;
}

.page-section-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-end;
  padding-top: 8px;
}

.page-section-header h2 {
  font-size: 24px;
}

.page-section-header p {
  margin: 7px 0 0;
  color: var(--muted);
}

.stat-card,
.panel {
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.stat-card {
  min-height: 64px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.stat-copy {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.stat-value {
  flex: 0 0 auto;
  min-width: 44px;
  height: 44px;
  border-radius: 8px;
  display: inline-grid;
  place-items: center;
  background: var(--surface-subtle);
  border: 1px solid var(--line);
  font-size: 26px;
  line-height: 1;
  letter-spacing: 0;
}

.stat-value.compact {
  min-width: 58px;
  width: auto;
  height: 36px;
  padding: 0 12px;
  border-radius: 8px;
  background: var(--success-soft);
  color: var(--success);
  border: 1px solid #b8e3c9;
  font-size: 16px;
  line-height: 1;
}

.stat-value.compact.is-off {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: #f0b6b0;
}

.stat-value.compact.is-drop {
  background: var(--warning-soft);
  color: var(--warning);
  border-color: #efd28f;
}

.stat-meta {
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.section-grid,
.aliases-layout {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.panel {
  padding: 20px;
}

.spacious-panel {
  padding: 24px;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.panel-header p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.split {
  align-items: center;
}

.create-form,
.field {
  display: grid;
  gap: 8px;
}

.create-form {
  gap: 14px;
}

.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.field.grow {
  flex: 1;
  min-width: 240px;
}

input {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #ffffff;
  color: var(--text);
  padding: 0 12px;
  outline: none;
}

input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31, 111, 74, 0.14);
}

.alias-composer {
  min-width: 0;
  display: flex;
  align-items: stretch;
}

.alias-composer input {
  min-width: 0;
  flex: 1 1 auto;
  border-radius: 7px 0 0 7px;
}

.alias-domain {
  flex: 0 0 auto;
  max-width: none;
  height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-left: 0;
  border-radius: 0 7px 7px 0;
  background: var(--surface-subtle);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  white-space: nowrap;
}

.inline-hint {
  margin: 0;
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
}

.button,
.icon-button {
  height: 38px;
  border-radius: 7px;
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 800;
  font-size: 13px;
  white-space: nowrap;
  transition: transform 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}

.button:hover,
.icon-button:hover {
  transform: translateY(-1px);
}

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

.button.primary:hover {
  background: var(--primary-dark);
}

.button.secondary {
  background: var(--surface);
  border-color: var(--line-strong);
  color: var(--text);
}

.button.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
}

.button.danger {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: #f0b6b0;
}

.button.small {
  height: 32px;
  padding: 0 10px;
  font-size: 12px;
}

.inline-form {
  display: flex;
  align-items: end;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 620px;
}

th {
  text-align: left;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  padding: 0 12px 10px;
  border-bottom: 1px solid var(--line);
}

td {
  padding: 13px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  font-size: 14px;
}

tr:last-child td {
  border-bottom: 0;
}

.actions-col {
  text-align: right;
}

.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.alias-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.alias-cell code {
  padding: 5px 8px;
  border-radius: 6px;
  background: var(--neutral-soft);
  color: var(--text);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
}

.icon-button {
  height: 28px;
  padding: 0 9px;
  background: #ffffff;
  border-color: var(--line);
  color: var(--muted);
}

.muted-cell,
.muted {
  color: var(--muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 850;
  border: 1px solid transparent;
}

.badge.success {
  color: var(--success);
  background: var(--success-soft);
  border-color: #b8e3c9;
}

.badge.warning {
  color: var(--warning);
  background: var(--warning-soft);
  border-color: #efd28f;
}

.badge.danger {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: #f0b6b0;
}

.badge.neutral {
  color: var(--muted);
  background: var(--neutral-soft);
  border-color: var(--line);
}

.empty-state {
  min-height: 160px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 6px;
  color: var(--muted);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface-subtle);
  text-align: center;
  padding: 22px;
}

.empty-state strong {
  color: var(--text);
}

.empty-state.compact {
  min-height: 96px;
}

.help-note,
.notice {
  margin: 16px 0 0;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  line-height: 1.5;
}

.help-note {
  background: #eef5f8;
  border: 1px solid #c9dce5;
  color: #24485e;
}

.notice.warning {
  background: var(--warning-soft);
  border: 1px solid #efd28f;
  color: var(--warning);
  margin-bottom: 16px;
}

.notice p {
  margin: 6px 0 0;
}

.action-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.diagnostics-content {
  display: grid;
  gap: 14px;
}

.diagnostics-grid {
  display: grid;
  gap: 8px;
}

.diagnostic-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 11px 12px;
  border-radius: 7px;
  background: var(--surface-subtle);
  border: 1px solid var(--line);
}

.diagnostic-row strong,
.diagnostic-row span {
  display: block;
}

.diagnostic-row span {
  color: var(--muted);
  margin-top: 2px;
  font-size: 12px;
}

.confirm-dialog {
  width: min(390px, calc(100vw - 32px));
  border: 0;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 24px 80px rgba(23, 32, 26, 0.28);
}

.confirm-dialog::backdrop {
  background: rgba(23, 32, 26, 0.38);
  backdrop-filter: blur(3px);
}

#confirm-message {
  margin: 0 0 18px;
  line-height: 1.45;
  font-weight: 700;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    padding: 14px 18px;
    overflow-x: auto;
  }

  .nav-list {
    display: flex;
  }

  .sidebar-footer {
    margin-left: auto;
    margin-top: 0;
    min-width: 180px;
  }

  .main {
    padding: 20px 18px 40px;
  }

  .section-grid,
  .aliases-layout,
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .sidebar {
    align-items: flex-start;
    flex-direction: column;
    gap: 14px;
  }

  .nav-list {
    width: 100%;
    overflow-x: auto;
  }

  .sidebar-footer {
    width: 100%;
    margin-left: 0;
  }

  .page-header {
    flex-direction: column;
  }

  .header-actions,
  .header-actions .button {
    width: 100%;
  }

  .stats-grid,
  .section-grid,
  .aliases-layout {
    grid-template-columns: 1fr;
  }

  .main {
    padding: 18px 12px 36px;
  }

  .panel {
    padding: 16px;
  }

  .panel-header,
  .panel-header.split {
    align-items: flex-start;
    flex-direction: column;
  }

  .inline-form,
  .action-row,
  .row-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .button,
  .icon-button {
    width: 100%;
  }

  .alias-domain {
    max-width: 52%;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

@media (max-width: 420px) {
  .alias-composer {
    display: grid;
  }

  .alias-composer input {
    border-radius: 7px 7px 0 0;
  }

  .alias-domain {
    max-width: none;
    width: 100%;
    border-left: 1px solid var(--line-strong);
    border-top: 0;
    border-radius: 0 0 7px 7px;
    justify-content: flex-start;
  }
}
