/* ============================================================
   Design tokens
   ============================================================ */
:root {
  --bg: #f0f4fb;
  --panel: #ffffff;
  --panel-2: #edf2ff;
  --panel-3: #e2eaf8;
  --text: #0f1e33;
  --muted: #5c6e8a;
  --border: #d8e3f0;
  --primary: #2952e3;
  --primary-2: #1e3fb8;
  --warn: #c9303f;
  --ok: #1b8a58;
  --info: #1a6db8;
  --sidebar-w: 240px;
  --topbar-h: 54px;
  --shadow: 0 4px 18px rgba(14, 30, 60, 0.08);
  --radius: 12px;
}

body.dark {
  --bg: #0d1520;
  --panel: #172030;
  --panel-2: #1e2a3e;
  --panel-3: #243249;
  --text: #e8f0ff;
  --muted: #98aec9;
  --border: #2a3a55;
  --primary: #5b82ff;
  --primary-2: #4267d4;
  --warn: #ff5c6a;
  --ok: #4ecf96;
  --info: #58b0ff;
  --shadow: 0 4px 18px rgba(0, 0, 0, 0.45);
}

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

html {
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  overflow-x: hidden;
}

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

/* ============================================================
   App shell: fixed sidebar + fixed topbar + scrollable content
   ============================================================ */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 100;
  transition: transform 0.25s ease;
}

.brand {
  font-weight: 700;
  font-size: 15px;
  padding: 16px 14px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.nav-section-title {
  font-size: 10.5px;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.06em;
  padding: 14px 14px 4px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border-radius: 8px;
  margin: 1px 8px;
  font-size: 13.5px;
  color: var(--text);
  transition: background 0.15s ease;
}
.nav-link:hover { background: var(--panel-2); text-decoration: none; }
.nav-link.active { background: var(--primary); color: #fff; }

.sidebar .footer-actions {
  margin-top: auto;
  padding: 12px 10px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

/* ---- Main column (offset by sidebar + topbar) ---- */
.main-col {
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  flex: 1;
  min-width: 0;
}

/* ---- Topbar ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 90;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  height: var(--topbar-h);
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.topbar-title {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar .right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* ---- Content area ---- */
main.content {
  padding: 22px 22px 40px;
  overflow-y: auto;
  flex: 1;
}

/* ============================================================
   Auth pages (login / register — no sidebar)
   ============================================================ */
.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 22px;
  background: linear-gradient(140deg, var(--panel-3) 0%, var(--bg) 60%);
}

.auth-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 30px 28px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
}

.auth-card h1 { font-size: 22px; margin-bottom: 6px; }

/* ============================================================
   User chip & role pills
   ============================================================ */
.user-chip { font-size: 13px; color: var(--muted); }

.role-pill {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--panel-2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.role-pill.admin   { background: var(--primary); color: #fff; }
.role-pill.manager { background: var(--info);    color: #fff; }

/* ============================================================
   Cards, forms, typography
   ============================================================ */
.page-title    { font-size: 21px; font-weight: 700; margin-bottom: 4px; }
.page-subtitle { font-size: 13px; color: var(--muted); margin-bottom: 18px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card h3 { font-size: 15px; margin-bottom: 12px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }

.form-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field label { font-size: 12.5px; color: var(--muted); }

.muted { color: var(--muted); font-size: 13px; }

/* ============================================================
   Inputs
   ============================================================ */
input, textarea, select {
  width: 100%;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.18s;
  font-family: inherit;
}
input:focus, textarea:focus, select:focus { border-color: var(--primary); }
textarea { resize: vertical; }

/* ============================================================
   Buttons
   ============================================================ */
button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 0;
  border-radius: 10px;
  padding: 9px 14px;
  cursor: pointer;
  font-size: 13.5px;
  font-family: inherit;
  background: var(--panel-2);
  color: var(--text);
  transition: filter 0.15s, background 0.15s;
  white-space: nowrap;
}
button:hover, .btn:hover { filter: brightness(0.92); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-2); filter: none; }
.btn-warn  { background: var(--warn);  color: #fff; }
.btn-ok    { background: var(--ok);    color: #fff; }
.btn-ghost { background: transparent; border: 1px solid var(--border); }
a.btn-ghost { text-decoration: none; color: inherit; }

/* Inbox / mail list */
.mail-card-focused {
  outline: 2px solid var(--primary);
  outline-offset: 3px;
  border-radius: 12px;
}

/* ============================================================
   Status pills
   ============================================================ */
.status-pill {
  display: inline-block;
  font-size: 11.5px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  white-space: nowrap;
}
.status-pill.configured    { background: var(--ok);   color: #fff; }
.status-pill.configuring   { background: var(--info); color: #fff; }
.status-pill.error         { background: var(--warn); color: #fff; }
.status-pill.not_configured { background: var(--panel-3); color: var(--muted); }
.status-pill.active   { background: var(--ok);   color: #fff; }
.status-pill.inactive { background: var(--warn); color: #fff; }
.status-pill.failed   { background: var(--warn); color: #fff; }

/* ============================================================
   Table
   ============================================================ */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); }
th { background: var(--panel-2); font-weight: 600; white-space: nowrap; }
tr:last-child td { border-bottom: none; }

/* ============================================================
   Mail rows
   ============================================================ */
.mail-row {
  padding: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 10px;
  margin-bottom: 8px;
  transition: background 0.15s;
}
.mail-row:hover { background: var(--panel-2); }
.mail-row .subject { font-weight: 600; font-size: 14px; }
.mail-row .preview { color: var(--muted); font-size: 12.5px; }

/* ============================================================
   Log / code blocks
   ============================================================ */
.log-line {
  font-family: "Courier New", Courier, monospace;
  font-size: 12px;
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
  white-space: pre-wrap;
  word-break: break-all;
}
.log-line.error { color: var(--warn); }

.dns-block {
  font-family: "Courier New", Courier, monospace;
  background: var(--panel-2);
  padding: 12px;
  border-radius: 10px;
  font-size: 12.5px;
  white-space: pre-wrap;
  word-break: break-all;
  border: 1px dashed var(--border);
}

.kbd {
  font-family: "Courier New", monospace;
  background: var(--panel-2);
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 12px;
}

/* ============================================================
   Toast notifications
   ============================================================ */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  padding: 12px 16px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 13.5px;
  z-index: 200;
  animation: slideUp 0.2s ease;
}
.toast.error { border-left-color: var(--warn); color: var(--warn); }
.toast.ok    { border-left-color: var(--ok);   color: var(--ok);   }

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

/* ============================================================
   Mobile sidebar overlay
   ============================================================ */
.mobile-menu-btn {
  display: none;
  border: 0;
  background: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text);
  padding: 0 4px;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 99;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 800px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-overlay.open {
    display: block;
  }
  .main-col {
    margin-left: 0;
  }
  .mobile-menu-btn {
    display: inline-flex;
  }
  .grid-2, .grid-3 {
    grid-template-columns: 1fr;
  }
  main.content {
    padding: 16px 14px 32px;
  }
}

/* ---- Lucide icon sizing ---- */
.icon-sm { width: 16px; height: 16px; stroke-width: 2; flex-shrink: 0; }
.icon-md { width: 22px; height: 22px; stroke-width: 2; flex-shrink: 0; }
.nav-ic { width: 18px; height: 18px; stroke-width: 2; flex-shrink: 0; }
.brand-ic { width: 20px; height: 20px; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
}
.nav-link .nav-txt { flex: 1; min-width: 0; }
.nav-badge {
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--warn);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.sidebar .footer-actions {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.sidebar .footer-actions .btn { flex: 1 1 auto; min-width: 0; justify-content: center; }

/* ---- Buttons: extended ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn:hover { filter: brightness(0.95); }
.btn:active { transform: translateY(1px); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; border-radius: 8px; }
.btn-block { width: 100%; }

.mailbox-toolbar { margin-bottom: 18px; }
.mailbox-toolbar-inner {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: flex-end;
}
.mailbox-toolbar .field-grow { flex: 1 1 220px; min-width: 160px; }
.mailbox-toolbar .field-date { flex: 0 1 150px; min-width: 130px; }
.mailbox-toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex: 1 1 100%;
}
@media (min-width: 700px) {
  .mailbox-toolbar-actions { flex: 0 0 auto; align-self: flex-end; }
}

.mail-unread {
  border-left: 4px solid var(--primary);
  background: linear-gradient(90deg, rgba(41, 82, 227, 0.06), transparent);
}

/* Inbox/mailbox list preview vs full HTML body */
.mail-body-slot {
  min-height: 0;
  margin-top: 10px;
}

.mail-body-preview {
  white-space: normal;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.45;
  color: var(--muted);
  font-size: 13px;
  word-break: break-word;
}

.mail-body-html {
  line-height: 1.55;
  font-size: 14px;
  color: var(--text);
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--panel-2);
  border: 1px solid var(--border);
  overflow-x: auto;
  overflow-wrap: break-word;
  max-width: 100%;
}

/* HTML mail is designed for a light canvas (Gmail-style). Isolate it so
   sender colors never inherit the app theme. */
.mail-body-html.mail-body-paper {
  padding: 0;
  background: #ffffff;
  color: #202124;
  color-scheme: light;
  overflow: hidden;
}

.mail-body-frame {
  display: block;
  width: 100%;
  border: 0;
  background: #ffffff;
  color-scheme: light;
  min-height: 96px;
}

.mail-body-html.mail-body-plain {
  color: var(--text);
}

.mail-body-html img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
}

.mail-body-html a {
  color: var(--primary);
  word-break: break-word;
}

.mail-body-html table {
  border-collapse: collapse;
  max-width: 100%;
}

.mail-body-html .mail-body-fallback {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

.mail-body-html .mail-body-plain-rich {
  font-size: 14px;
  line-height: 1.6;
}

.mail-body-plain-rich a {
  word-break: break-word;
}

.mail-inbox-thread-nav { margin-bottom: 14px; }
.mail-inbox-thread-nav-inner { flex-wrap: wrap; gap: 10px; }
.mail-nav-spacer { opacity: 0.4; cursor: default; pointer-events: none; user-select: none; }
.mail-nav-unread-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  margin-left: 4px;
  vertical-align: middle;
}

.mail-actions { flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.attach-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.table-dense table { font-size: 12.5px; }
.table-dense th, .table-dense td { padding: 6px 10px; }
.input-inline {
  width: 100%;
  max-width: 200px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  font-family: inherit;
}
.input-inline.input-grow { max-width: min(100%, 260px); min-width: 140px; }
.mono { font-family: ui-monospace, monospace; font-size: 12px; }
.nowrap { white-space: nowrap; }

/* ---- Login / 3D motion ---- */
.login-body {
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}
.login-scene {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  perspective: 1200px;
  overflow: hidden;
}
.login-orbit {
  position: absolute;
  width: 140vmax;
  height: 140vmax;
  left: 50%;
  top: 40%;
  transform: translate(-50%, -50%) rotateX(72deg) rotateZ(0deg);
  background: radial-gradient(ellipse at center, rgba(41, 82, 227, 0.18), transparent 55%);
  animation: orbit-drift 22s linear infinite;
  border-radius: 50%;
}
.login-glow {
  position: absolute;
  width: 400px;
  height: 400px;
  right: -80px;
  top: -80px;
  background: radial-gradient(circle, rgba(41, 82, 227, 0.35), transparent 70%);
  filter: blur(40px);
  animation: glow-pulse 8s ease-in-out infinite alternate;
}
@keyframes orbit-drift {
  to { transform: translate(-50%, -50%) rotateX(72deg) rotateZ(360deg); }
}
@keyframes glow-pulse {
  from { opacity: 0.7; transform: scale(1); }
  to   { opacity: 1;   transform: scale(1.08); }
}
.login-shell {
  position: relative;
  z-index: 1;
}
.login-card {
  max-width: 420px;
  margin: 0 auto;
  transform-style: preserve-3d;
  animation: card-float 6s ease-in-out infinite alternate;
  box-shadow: var(--shadow), 0 24px 60px rgba(15, 30, 60, 0.15);
}
@keyframes card-float {
  from { transform: translateY(0) rotateX(0deg); }
  to   { transform: translateY(-6px) rotateX(2deg); }
}
.login-brand h1 { font-size: 1.55rem; margin-top: 8px; }
.login-tagline { color: var(--muted); font-size: 0.95rem; margin-top: 4px; }
.login-ssb {
  font-size: 0.82rem;
  color: var(--muted);
  margin: 16px 0 8px;
  line-height: 1.45;
  text-align: center;
}
.login-logo-wrap {
  width: 56px;
  height: 56px;
  margin: 0 auto;
  border-radius: 14px;
  background: linear-gradient(145deg, var(--primary), var(--primary-2));
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 12px 28px rgba(41, 82, 227, 0.35);
  transform: rotateY(-12deg);
}
.login-logo-icon { width: 28px; height: 28px; color: #fff; stroke-width: 2; }

@media (prefers-reduced-motion: reduce) {
  .login-orbit, .login-glow, .login-card { animation: none; }
}
