:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e4e7ec;
  --border-strong: #d0d5dd;
  --text: #111827;
  --text-secondary: #4b5563;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff6ff;
  --ok: #16a34a;
  --ok-bg: #f0fdf4;
  --warn: #d97706;
  --warn-bg: #fffbeb;
  --err: #dc2626;
  --err-bg: #fef2f2;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --sidebar-w: 240px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f14;
    --surface: #121820;
    --surface-2: #1a222d;
    --border: #243041;
    --border-strong: #334155;
    --text: #eef2f7;
    --text-secondary: #cbd5e1;
    --muted: #94a3b8;
    --accent: #3b82f6;
    --accent-hover: #60a5fa;
    --accent-soft: #172554;
    --ok: #22c55e;
    --ok-bg: #052e16;
    --warn: #f59e0b;
    --warn-bg: #451a03;
    --err: #f87171;
    --err-bg: #450a0a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  }
}

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

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Layout */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.5rem 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 2rem;
  padding: 0 0.5rem;
}

.brand-badge {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.brand-badge svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand h1 {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
}

.brand small {
  color: var(--muted);
  display: block;
  font-size: 0.75rem;
  margin-top: 0.1rem;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  flex: 1;
}

.nav a {
  color: var(--text-secondary);
  padding: 0.55rem 0.7rem;
  border-radius: var(--radius-sm);
  display: flex;
  gap: 0.65rem;
  align-items: center;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.12s ease, color 0.12s ease;
}

.nav a:hover {
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}

.nav a.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.nav .icon {
  width: 1.15rem;
  height: 1.15rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0.9;
}

.nav .icon svg {
  width: 1.15rem;
  height: 1.15rem;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 1.5rem;
}

.main {
  padding: 2rem 2.5rem 3rem;
  width: 100%;
  max-width: none;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.75rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.topbar h2 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 0.65rem;
  margin-bottom: 0.65rem;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  min-width: 0;
}

.sidebar-user-icon {
  width: 1.25rem;
  height: 1.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--muted);
}

.sidebar-user-icon svg {
  width: 1.15rem;
  height: 1.15rem;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sidebar-user-email {
  font-size: 0.78rem;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.topbar .btn svg {
  flex-shrink: 0;
}

/* Cards & panels */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.2rem;
  box-shadow: var(--shadow);
}

.card .label {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 500;
}

.card .value {
  font-size: 1.65rem;
  font-weight: 650;
  margin-top: 0.3rem;
  letter-spacing: -0.02em;
  color: var(--text);
}

.card .sub {
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 0.3rem;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.35rem 1.4rem;
  margin-top: 1.25rem;
  box-shadow: var(--shadow);
}

.panel h3 {
  margin: 0 0 1.1rem;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* Status badges with dots */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.2;
}

.badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  background: currentColor;
}

.badge.ok {
  background: var(--ok-bg);
  color: var(--ok);
}

.badge.bad {
  background: var(--err-bg);
  color: var(--err);
}

.badge.warn {
  background: var(--warn-bg);
  color: var(--warn);
}

/* Tables */
.table-wrap { overflow: visible; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  text-align: left;
  padding: 0.75rem 0.65rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

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

tbody tr:hover td { background: var(--surface-2); }

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.85rem;
  align-items: end;
}

label {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.3rem;
  font-weight: 500;
}

input, select, textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.7rem;
  font: inherit;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

.btn {
  appearance: none;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.95rem;
  font: inherit;
  font-weight: 560;
  font-size: 0.875rem;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  transition: background 0.12s ease, filter 0.12s ease;
}

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

.btn.secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
}

.btn.secondary:hover {
  background: var(--surface-2);
  filter: none;
}

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

.btn.danger:hover { filter: brightness(1.05); }

.btn.sm {
  padding: 0.3rem 0.55rem;
  font-size: 0.78rem;
}

/* Flash */
.flash {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 0.85rem;
  border: 1px solid var(--border);
  font-size: 0.9rem;
}

.flash.success {
  background: var(--ok-bg);
  border-color: color-mix(in srgb, var(--ok) 35%, var(--border));
  color: var(--ok);
}

.flash.error {
  background: var(--err-bg);
  border-color: color-mix(in srgb, var(--err) 35%, var(--border));
  color: var(--err);
}

.flash.warning {
  background: var(--warn-bg);
  border-color: color-mix(in srgb, var(--warn) 35%, var(--border));
  color: var(--warn);
}

/* Login */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: var(--bg);
}

.login-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 2rem 1.85rem;
  box-shadow: var(--shadow);
}

.login-card .login-mark {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  margin-bottom: 1.25rem;
}

.login-card .login-mark svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.login-card h1 {
  margin: 0 0 0.25rem;
  font-size: 1.35rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.login-card > p {
  margin: 0 0 1.5rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
}

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

.progress {
  height: 6px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 0.65rem;
}

.progress > span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}


.note {
  background: var(--surface-2);
  border-left: 3px solid var(--accent);
  padding: 0.85rem 1rem;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin-bottom: 1rem;
  color: var(--muted);
  font-size: 0.875rem;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85em;
  background: var(--surface-2);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

details summary.btn {
  list-style: none;
}

details summary.btn::-webkit-details-marker { display: none; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: relative;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .nav {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .sidebar-footer { margin-top: 1rem; padding-top: 0; }
  .main { padding: 1.25rem 1rem 2rem; }
}

.muted { color: var(--muted, #6b7280); font-size: .875rem; }
.rspamd-summary { margin-bottom: 1rem; }


/* Opslag (single storage card) — compact */
.storage-card {
  box-shadow: none;
  padding: 0.85rem 1rem;
}
.storage-card .label { font-size: 0.75rem; margin-bottom: 0.15rem; }
.storage-card .value { font-size: 1.15rem; line-height: 1.2; }
.storage-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.35rem;
}
.storage-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.25rem 0.9rem;
  margin-top: 0;
  font-size: 0.72rem;
  color: var(--text-secondary);
  text-align: right;
}
.storage-legend .dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-right: 0.3rem;
  vertical-align: 0.08em;
}
.storage-legend .dot-mail { background: var(--accent); }
.storage-legend .dot-other { background: var(--border-strong); }
.storage-legend .dot-free { background: var(--surface-2); border: 1px solid var(--border-strong); }
.progress.stacked { display: flex; height: 12px; margin-top: 0; border-radius: 999px; overflow: hidden; }
.progress.stacked > span { border-radius: 0; flex: none; }
.progress.stacked > .seg-mail { background: var(--accent); }
.progress.stacked > .seg-mail.nonzero { min-width: 2px; }
.progress.stacked > .seg-other { background: var(--border-strong); }


/* Create panel actions */
#create-panel[hidden] { display: none !important; }
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

/* DNS status badges (domains table) */
.dns-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.85rem;
  align-items: center;
}
.dns-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
  background: none;
  border: none;
  padding: 0;
}
.dns-item .dns-name { font-weight: 500; color: var(--text); }
.dns-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--border-strong);
}
.dns-item.ok .dns-dot { background: var(--ok); }
.dns-item.bad .dns-dot { background: var(--err); }
.dns-item.warn .dns-dot { background: var(--warn); }


/* Row kebab menu (domains table) */
.row-menu {
  position: relative;
  display: inline-flex;
}
.row-menu-toggle {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  width: 2rem;
  height: 2rem;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.row-menu-toggle:hover,
.row-menu.is-open .row-menu-toggle {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}
.row-menu-toggle svg { display: block; }
.row-menu-panel {
  position: absolute;
  right: 0;
  top: auto;
  bottom: calc(100% + 0.25rem);
  min-width: 10.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow), 0 8px 24px rgba(16, 24, 40, 0.08);
  padding: 0.3rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}
.row-menu-panel[hidden] { display: none !important; }
.row-menu form { margin: 0; }
.row-menu-item {
  display: block;
  width: 100%;
  box-sizing: border-box;
  text-align: left;
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.45rem 0.65rem;
  border-radius: 4px;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.35;
}
.row-menu-item:hover {
  background: var(--surface-2);
  text-decoration: none;
}
.row-menu-item.danger { color: var(--err); }
.row-menu-item.danger:hover { background: var(--err-bg); }

td.actions, tr:has(.row-menu.is-open) { overflow: visible; position: relative; z-index: 5; }
.panel:has(.row-menu.is-open), .table-wrap:has(.row-menu.is-open) { overflow: visible; }

.panel.tight {
  padding: 0;
  overflow: visible;
}
.panel.tight > .table-wrap { margin: 0; }
.panel.tight table { margin: 0; }
.panel.tight th:first-child,
.panel.tight td:first-child { padding-left: 1rem; }
.panel.tight th:last-child,
.panel.tight td:last-child { padding-right: 1rem; }
