/* shared by the webmail and the admin panel */
/* ---------- tokens ---------- */
:root {
  --bg: #f6f8fc;
  --surface: #ffffff;
  --surface-2: #f2f6fc;
  --surface-3: #eaf1fb;
  --text: #1f1f1f;
  --text-2: #444746;
  --muted: #5f6368;
  --border: #e0e3e7;
  --border-2: #c4c7c5;
  --hover: rgba(31, 31, 31, .06);
  --press: rgba(31, 31, 31, .12);
  --accent: #0b57d0;
  --accent-text: #ffffff;
  --accent-soft: #d3e3fd;
  --compose: #c2e7ff;
  --compose-text: #001d35;
  --nav-active: #d3e3fd;
  --row-read: #f2f6fc;
  --row-unread: #ffffff;
  --row-selected: #c2dbff;
  --row-shadow: inset 1px 0 0 #dadce0, inset -1px 0 0 #dadce0, 0 1px 2px 0 rgba(60, 64, 67, .3), 0 1px 3px 1px rgba(60, 64, 67, .15);
  --star: #f4b400;
  --danger: #b3261e;
  --chip: #e8eaed;
  --shadow-1: 0 1px 2px rgba(60, 64, 67, .3), 0 1px 3px 1px rgba(60, 64, 67, .15);
  --shadow-3: 0 4px 8px 3px rgba(60, 64, 67, .15), 0 1px 3px rgba(60, 64, 67, .3);
  --compose-head: #f2f6fc;
  --toast: #303030;
  --toast-text: #f2f2f2;
  --focus: #0b57d0;
  --radius: 16px;
  --row-h: 40px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111214;
    --surface: #1d1e21;
    --surface-2: #232428;
    --surface-3: #2a2c31;
    --text: #e3e3e3;
    --text-2: #c7c7c7;
    --muted: #a8abaf;
    --border: #34363b;
    --border-2: #4a4d52;
    --hover: rgba(227, 227, 227, .07);
    --press: rgba(227, 227, 227, .14);
    --accent: #a8c7fa;
    --accent-text: #062e6f;
    --accent-soft: #1f3a5f;
    --compose: #004a77;
    --compose-text: #c2e7ff;
    --nav-active: #004a77;
    --row-read: #1d1e21;
    --row-unread: #26282c;
    --row-selected: #1f3a5f;
    --row-shadow: inset 1px 0 0 #4a4d52, inset -1px 0 0 #4a4d52, 0 1px 3px rgba(0, 0, 0, .6);
    --chip: #34363b;
    --shadow-1: 0 1px 3px rgba(0, 0, 0, .6);
    --shadow-3: 0 6px 16px rgba(0, 0, 0, .6);
    --compose-head: #2a2c31;
    --toast: #e3e3e3;
    --toast-text: #1f1f1f;
    --danger: #f2b8b5;
    --focus: #a8c7fa;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #111214;
  --surface: #1d1e21;
  --surface-2: #232428;
  --surface-3: #2a2c31;
  --text: #e3e3e3;
  --text-2: #c7c7c7;
  --muted: #a8abaf;
  --border: #34363b;
  --border-2: #4a4d52;
  --hover: rgba(227, 227, 227, .07);
  --press: rgba(227, 227, 227, .14);
  --accent: #a8c7fa;
  --accent-text: #062e6f;
  --accent-soft: #1f3a5f;
  --compose: #004a77;
  --compose-text: #c2e7ff;
  --nav-active: #004a77;
  --row-read: #1d1e21;
  --row-unread: #26282c;
  --row-selected: #1f3a5f;
  --row-shadow: inset 1px 0 0 #4a4d52, inset -1px 0 0 #4a4d52, 0 1px 3px rgba(0, 0, 0, .6);
  --chip: #34363b;
  --shadow-1: 0 1px 3px rgba(0, 0, 0, .6);
  --shadow-3: 0 6px 16px rgba(0, 0, 0, .6);
  --compose-head: #2a2c31;
  --toast: #e3e3e3;
  --toast-text: #1f1f1f;
  --danger: #f2b8b5;
  --focus: #a8c7fa;
  color-scheme: dark;
}

:root[data-density="compact"] { --row-h: 32px; }

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.43 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
[hidden] { display: none !important; }
kbd {
  font: 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  padding: 3px 6px;
  border: 1px solid var(--border-2);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: var(--surface-2);
}
.muted { color: var(--muted); }
.small { font-size: 12px; }
.spacer { flex: 1; }
.noscript { padding: 40px; text-align: center; }

.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon.tiny { width: 14px; height: 14px; }

/* ---------- buttons & inputs ---------- */
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-2);
  transition: background-color .12s;
}
.icon-btn:hover { background: var(--hover); }
.icon-btn:active { background: var(--press); }
.icon-btn:disabled { opacity: .38; pointer-events: none; }
.icon-btn.small { width: 30px; height: 30px; }
.icon-btn.small .icon { width: 17px; height: 17px; }
.icon-btn.narrow { width: 20px; border-radius: 4px; }
.icon-btn.narrow .icon { width: 14px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  padding: 0 20px;
  border: 0;
  border-radius: 18px;
  background: var(--surface-3);
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
  transition: background-color .12s, box-shadow .12s;
}
.btn:hover { box-shadow: var(--shadow-1); }
.btn:disabled { opacity: .6; pointer-events: none; }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.text { background: transparent; color: var(--accent); padding: 0 12px; }
.btn.text:hover { background: var(--hover); box-shadow: none; }
.btn.small { height: 30px; font-size: 13px; }
.btn.outline { background: transparent; border: 1px solid var(--border-2); color: var(--text-2); }
.btn.outline:hover { background: var(--hover); box-shadow: none; }
.btn.wide { width: 100%; }
.danger-text { color: var(--danger) !important; }
.link-btn { border: 0; background: none; padding: 0 4px; color: var(--text-2); }
.link-btn:hover { text-decoration: underline; }

.input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--border-2);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
textarea.input { resize: vertical; min-height: 80px; }
.field-label { display: block; margin-bottom: 14px; font-weight: 500; color: var(--text-2); }
.check-row { display: flex; gap: 10px; align-items: flex-start; margin: 4px 0 14px; }
.check-row small { display: block; color: var(--muted); font-weight: 400; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; cursor: pointer; }

/* ---------- boot / login ---------- */
.boot, .boot-error { height: 100vh; display: grid; place-items: center; text-align: center; }
.boot-spinner {
  width: 36px; height: 36px; border-radius: 50%;
  border: 3px solid var(--accent-soft); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; overflow: auto; }
.login-card {
  width: min(420px, 100%);
  padding: 40px 36px 36px;
  background: var(--surface);
  border-radius: 28px;
  box-shadow: var(--shadow-1);
}
.login-card h1 { margin: 18px 0 4px; font-size: 26px; font-weight: 400; }
.login-card .muted { margin: 0 0 24px; }
.login-logo { display: flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 500; color: var(--text-2); }
.logo-icon { width: 28px; height: 28px; color: var(--accent); stroke-width: 1.6; }
.login-error { min-height: 20px; margin: -4px 0 12px; color: var(--danger); font-size: 13px; }

/* ---------- app layout ---------- */
.app {
  display: grid;
  grid-template-columns: 256px minmax(0, 1fr);
  grid-template-rows: 64px minmax(0, 1fr);
  grid-template-areas: "top top" "nav main";
  height: 100vh;
  height: 100dvh;
}
.nav-collapsed .app { grid-template-columns: 72px minmax(0, 1fr); }

.topbar { grid-area: top; display: flex; align-items: center; gap: 4px; padding: 8px 12px 8px 8px; }
.brand { display: flex; align-items: center; gap: 8px; width: 196px; padding-left: 6px; color: var(--text-2); font-size: 20px; text-decoration: none; white-space: nowrap; }
.brand span { overflow: hidden; text-overflow: ellipsis; }
.avatar {
  display: inline-grid; place-items: center;
  width: 32px; height: 32px; flex: none;
  border-radius: 50%; color: #fff; font-weight: 500; font-size: 15px;
  user-select: none;
}
.avatar-btn { border: 0; margin: 0 4px 0 8px; outline-offset: 3px; }

/* ---------- sidebar ---------- */
.sidebar { grid-area: nav; overflow-y: auto; padding: 0 0 16px; scrollbar-width: thin; }
.nav-list { display: flex; flex-direction: column; padding-right: 16px; }
.nav-item {
  position: relative;
  display: flex; align-items: center; gap: 16px;
  height: 32px; padding: 0 12px 0 26px;
  border-radius: 0 16px 16px 0;
  color: var(--text-2); text-decoration: none;
  white-space: nowrap;
}
.nav-item:hover { background: var(--hover); }
.nav-item.active { background: var(--nav-active); color: var(--text); font-weight: 600; }
.nav-item.bold { font-weight: 700; color: var(--text); }
.nav-item.disabled { opacity: .55; cursor: default; }
.nav-item.drop { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
.nav-item .icon { width: 19px; height: 19px; }
.nav-label { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.nav-count { font-size: 12px; font-weight: 600; }
.nav-more { display: none; margin-right: -8px; }
.nav-item:hover .nav-more { display: inline-grid; }
.nav-item:hover .nav-count:has(+ .nav-more) { display: none; }
.nav-section { display: flex; align-items: center; justify-content: space-between; margin: 14px 0 4px; padding: 0 4px 0 26px; font-size: 15px; font-weight: 500; color: var(--text-2); }
.nav-collapsed .compose-btn { width: 56px; padding: 0; justify-content: center; }
.nav-collapsed .compose-btn span,
.nav-collapsed .nav-label,
.nav-collapsed .nav-count,
.nav-collapsed .nav-section span,
.nav-collapsed .nav-more { display: none; }
.nav-collapsed .nav-item { width: 56px; margin-left: 8px; padding: 0; justify-content: center; border-radius: 16px; }
.nav-collapsed .nav-section { justify-content: center; padding: 0; }
.nav-collapsed .nav-list { padding-right: 0; }
.nav-scrim { display: none; }

/* ---------- content panel ---------- */
.content { grid-area: main; min-width: 0; padding: 0 16px 16px 0; }
.panel {
  position: relative;
  height: 100%;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
}
.loading-bar { position: absolute; inset: 0 0 auto; height: 3px; z-index: 2; overflow: hidden; pointer-events: none; }
.loading-bar.on::after {
  content: ""; position: absolute; top: 0; left: -40%; width: 40%; height: 100%;
  background: var(--accent); border-radius: 2px;
  animation: loading 1s cubic-bezier(.4, 0, .2, 1) infinite;
}
@keyframes loading { to { left: 100%; } }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 48px; padding: 4px 8px 4px 12px; flex: none; }
.tb-left, .tb-right { display: flex; align-items: center; gap: 2px; min-width: 0; }
.tb-left { flex: 1 1 auto; overflow: hidden; }
.tb-right { flex: none; }
.tb-sep { width: 1px; height: 20px; margin: 0 6px; background: var(--border); }

/* ---------- menus, dialogs, toasts ---------- */
.menu { position: fixed; z-index: 100; min-width: 200px; max-height: 70vh; overflow-y: auto; padding: 8px 0; border-radius: 8px; background: var(--surface); box-shadow: var(--shadow-3); }
.menu-item { display: flex; align-items: center; gap: 14px; width: 100%; height: 36px; padding: 0 16px; border: 0; background: none; text-align: left; white-space: nowrap; }
.menu-item:hover:not(:disabled), .menu-item:focus-visible { background: var(--hover); outline: none; }
.menu-item:disabled { color: var(--muted); cursor: default; }
.menu-item span { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.menu-item.danger { color: var(--danger); }
.menu-item .icon { width: 18px; height: 18px; color: var(--muted); }
.icon-space { width: 18px; flex: none; }
.menu-sep { height: 1px; margin: 6px 0; background: var(--border); }

.backdrop { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 16px; background: rgba(0, 0, 0, .4); }
.dialog { width: min(420px, 100%); max-height: calc(100vh - 32px); overflow: auto; padding: 24px; border-radius: 28px; background: var(--surface); box-shadow: var(--shadow-3); }
.dialog.wide { width: min(560px, 100%); }
.dialog-title { margin: 0 0 16px; font-size: 22px; font-weight: 400; }
.dialog-body p { margin: 0 0 8px; color: var(--text-2); }
.dialog-error:empty { display: none; }
.dialog-error { margin-top: 12px; color: var(--danger); font-size: 13px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

.toasts { position: fixed; left: 24px; bottom: 24px; z-index: 110; display: flex; flex-direction: column; gap: 8px; }
.toast { display: flex; align-items: center; gap: 12px; min-width: 288px; max-width: min(560px, calc(100vw - 48px)); padding: 6px 6px 6px 16px; border-radius: 6px; background: var(--toast); color: var(--toast-text); box-shadow: var(--shadow-3); }
.toast.error { background: var(--danger); color: #fff; }
.toast-text { flex: 1; padding: 8px 0; }
.toast-action { border: 0; background: none; padding: 8px 10px; border-radius: 4px; color: #a8c7fa; font-weight: 600; }
:root[data-theme="dark"] .toast-action { color: #0b57d0; }
.toast .icon-btn { color: inherit; }
@media (max-width: 800px) {
  .app, .nav-collapsed .app { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "main"; }
  .brand { width: auto; }
  .brand span { display: none; }
  .sidebar {
    position: fixed; z-index: 60; top: 0; bottom: 0; left: 0; width: 280px;
    padding-top: 12px; background: var(--surface);
    transform: translateX(-100%); transition: transform .2s cubic-bezier(.2, 0, 0, 1);
  }
  .nav-open .sidebar { transform: none; box-shadow: var(--shadow-3); }
  .nav-open .nav-scrim { display: block; position: fixed; inset: 0; z-index: 55; background: rgba(0, 0, 0, .35); }
  .content { padding: 0; }
  .panel { border-radius: 0; }
  .toasts { left: 12px; right: 12px; bottom: 12px; }
  .toast { min-width: 0; }
  .toolbar { padding-left: 4px; }
  .toolbar .tb-sep { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
