/* mssgs mail — tokens, reset and the small components everything reuses.
   The palette is the mssgs app window: a ladder from the window ground
   (#161a1f) through the reading pane (#2c2d32) to the cards (#323338), with
   the brand green for anything the user acts on. The light theme is the
   website's cream. Both are declared here in full; nothing later redefines a
   colour outside a theme block. */

:root {
  color-scheme: dark;

  --bg: #161a1f;
  --rail: #161a1f;
  --pane: #1e2126;
  --surface: #2c2d32;
  --card: #323338;
  --card-2: #383a40;
  --hover: #414248;
  --line: #393a3f;
  --line-soft: rgba(255, 255, 255, .07);

  --text: #dfe0e2;
  --text-2: #b5bac1;
  --text-3: #9b9ca2;
  --text-4: #72767d;

  --accent: #00c956;
  --accent-2: #2dff8a;
  --accent-ink: #06210f;
  --accent-soft: rgba(0, 201, 86, .14);
  --danger: #ed4245;
  --danger-soft: rgba(237, 66, 69, .14);
  --warn: #f0b232;
  --star: #f0b232;
  --focus: #4da3ff;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-2: 0 8px 24px rgba(0, 0, 0, .38);
  --shadow-3: 0 18px 48px rgba(0, 0, 0, .5);

  --r-sm: 6px;
  --r: 10px;
  --r-lg: 14px;
  --r-pill: 999px;

  --rail-w: 244px;
  --topbar-h: 56px;
  --row-h: 40px;

  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;

  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

:root[data-theme='light'] {
  color-scheme: light;

  --bg: #e3dbc7;
  --rail: #e3dbc7;
  --pane: #ebe4d3;
  --surface: #f5efe1;
  --card: #fdfaf1;
  --card-2: #fffdf7;
  --hover: #ded5bf;
  --line: #d6cdb5;
  --line-soft: rgba(32, 48, 31, .09);

  --text: #20301f;
  --text-2: #3d5140;
  --text-3: #5d7060;
  --text-4: #7d8c7e;

  --accent: #33754d;
  --accent-2: #1f5c39;
  --accent-ink: #ffffff;
  --accent-soft: rgba(51, 117, 77, .13);
  --danger: #b3282b;
  --danger-soft: rgba(179, 40, 43, .12);
  --warn: #9a6b12;
  --star: #c08a1b;
  --focus: #1b6fb8;

  --shadow-1: 0 1px 2px rgba(32, 48, 31, .12);
  --shadow-2: 0 8px 24px rgba(32, 48, 31, .16);
  --shadow-3: 0 18px 48px rgba(32, 48, 31, .22);
}

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

html, body {
  margin: 0; padding: 0; height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
ul, ol { margin: 0; padding: 0; list-style: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
img, svg { display: block; max-width: 100%; }
svg { flex: none; }
/* Icons have no intrinsic size, so they get one here and only here. */
.ico { width: 18px; height: 18px; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}
.no-focus-ring :focus { outline: none; }

* { scrollbar-width: thin; scrollbar-color: var(--hover) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--hover); border-radius: 4px; border: 2px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--text-4); background-clip: padding-box; }

.skip-link {
  position: fixed; top: -100px; left: 12px; z-index: 200;
  background: var(--accent); color: var(--accent-ink);
  padding: 10px 16px; border-radius: var(--r); font-weight: 600;
}
.skip-link:focus { top: calc(12px + var(--safe-t)); }

[hidden] { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- boot ---------- */

#root.booting { display: grid; place-items: center; height: 100%; }
.boot { display: grid; justify-items: center; gap: 20px; opacity: .9; }
.boot img { width: 48px; height: 48px; animation: floaty 3s ease-in-out infinite; }
.boot-bar { width: 160px; height: 3px; border-radius: 2px; background: var(--line); overflow: hidden; }
.boot-bar i { display: block; width: 40%; height: 100%; background: var(--accent); border-radius: 2px; animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(350%); } }
@keyframes floaty { 50% { transform: translateY(-5px); } }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 16px; border-radius: var(--r);
  font-weight: 600; font-size: 14px; white-space: nowrap;
  background: var(--card); color: var(--text);
  border: 1px solid var(--line);
  transition: background .12s ease, border-color .12s ease, transform .06s ease;
}
.btn:hover { background: var(--hover); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-primary:hover { background: var(--accent-2); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--hover); color: var(--text); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { height: 30px; padding: 0 12px; font-size: 13px; }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: var(--r-sm);
  color: var(--text-3); transition: background .12s ease, color .12s ease;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.is-on { color: var(--accent); }
.icon-btn.is-star-on { color: var(--star); }
.icon-btn[disabled] { opacity: .4; pointer-events: none; }
.icon-btn svg { width: 18px; height: 18px; }

/* ---------- inputs ---------- */

.input, .textarea, .select {
  width: 100%; min-height: 38px; padding: 8px 12px;
  background: var(--card); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r);
  transition: border-color .12s ease, background .12s ease;
}
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--accent); }
.input::placeholder, .textarea::placeholder { color: var(--text-4); }
.input.is-error { border-color: var(--danger); }
.textarea { min-height: 90px; resize: vertical; }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12px; font-weight: 600; color: var(--text-3); letter-spacing: .02em; }
.field .hint { font-size: 12px; color: var(--text-4); }
.field .err { font-size: 12px; color: var(--danger); }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch i {
  width: 38px; height: 22px; border-radius: var(--r-pill);
  background: var(--hover); position: relative; transition: background .15s ease; flex: none;
}
.switch i::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px;
  border-radius: 50%; background: var(--text-2); transition: transform .15s ease, background .15s ease;
}
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(16px); background: #fff; }
.switch input:focus-visible + i { outline: 2px solid var(--focus); outline-offset: 2px; }

input[type='range'] { width: 100%; accent-color: var(--accent); }

.check {
  appearance: none; -webkit-appearance: none;
  width: 16px; height: 16px; border-radius: 4px; flex: none;
  border: 1.6px solid var(--text-4); background: transparent; cursor: pointer;
  transition: border-color .12s ease, background .12s ease;
}
.check:hover { border-color: var(--text-2); }
.check:checked {
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23fff' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3.5 8.5l3 3 6-7'/%3E%3C/svg%3E") center/13px no-repeat;
  border-color: var(--accent);
}
.check:indeterminate {
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Crect x='3.5' y='7' width='9' height='2' rx='1' fill='%23fff'/%3E%3C/svg%3E") center/13px no-repeat;
  border-color: var(--accent);
}

/* ---------- avatar ---------- */

.avatar {
  width: 36px; height: 36px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 600; color: #fff;
  letter-spacing: .01em; user-select: none;
}
.avatar-sm { width: 26px; height: 26px; font-size: 11px; }
.avatar-lg { width: 44px; height: 44px; font-size: 15px; }

/* ---------- chips ---------- */

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 22px; padding: 0 8px; border-radius: var(--r-sm);
  font-size: 11px; font-weight: 600; letter-spacing: .01em;
  background: var(--hover); color: var(--text-2); white-space: nowrap;
}
.chip i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.chip button { display: grid; place-items: center; color: inherit; opacity: .7; }
.chip button:hover { opacity: 1; }

/* ---------- menus and popovers ---------- */

.menu {
  position: fixed; z-index: 90; min-width: 200px; max-height: 70vh; overflow: auto;
  padding: 6px; border-radius: var(--r);
  background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow-3);
  animation: pop .12s ease;
}
@keyframes pop { from { opacity: 0; transform: translateY(-4px); } }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 10px; border-radius: var(--r-sm); text-align: left;
  color: var(--text-2); font-size: 13px;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--hover); color: var(--text); }
.menu-item svg { width: 16px; height: 16px; }
.menu-item.is-danger { color: var(--danger); }
.menu-item .kbd { margin-left: auto; }
.menu-sep { height: 1px; margin: 5px 6px; background: var(--line); }
.menu-head { padding: 8px 10px 4px; font-size: 11px; font-weight: 700; color: var(--text-4); text-transform: uppercase; letter-spacing: .06em; }

.kbd {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: 5px; background: var(--bg); border: 1px solid var(--line);
  font-family: var(--mono); font-size: 11px; color: var(--text-3);
}

/* ---------- dialog ---------- */

.scrim {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0, 0, 0, .55); backdrop-filter: blur(2px);
  display: grid; place-items: center; padding: 20px;
  animation: fade .14s ease;
}
@keyframes fade { from { opacity: 0; } }
.dialog {
  width: min(520px, 100%); max-height: 86vh; overflow: auto;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--shadow-3);
  padding: 22px;
  animation: rise .16s ease;
}
@keyframes rise { from { opacity: 0; transform: translateY(10px) scale(.98); } }
.dialog h2 { font-size: 17px; margin-bottom: 6px; }
.dialog .dialog-sub { color: var(--text-3); font-size: 13px; margin: 0 0 16px; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

/* ---------- toasts ---------- */

.toasts {
  position: fixed; left: 16px; bottom: calc(16px + var(--safe-b)); z-index: 120;
  display: grid; gap: 8px; max-width: min(420px, calc(100vw - 32px));
}
.toast {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; border-radius: var(--r);
  background: var(--card); border: 1px solid var(--line);
  box-shadow: var(--shadow-2); color: var(--text);
  animation: toast-in .16s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
.toast.is-out { opacity: 0; transform: translateY(8px); transition: .18s ease; }
.toast-msg { flex: 1; font-size: 13px; }
.toast button.toast-action { color: var(--accent); font-weight: 600; font-size: 13px; }
.toast button.toast-action:hover { text-decoration: underline; }
.toast.is-error { border-color: var(--danger); }
.toast.is-error .toast-dot { background: var(--danger); }
.toast-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }

.offline {
  position: fixed; top: 0; left: 0; right: 0; z-index: 130;
  padding: calc(7px + var(--safe-t)) 12px 7px; text-align: center;
  font-size: 12px; font-weight: 600;
  background: var(--warn); color: #1a1206;
}

/* ---------- empty states + spinner ---------- */

.empty {
  display: grid; justify-items: center; align-content: center; gap: 10px;
  padding: 48px 24px; text-align: center; color: var(--text-3); height: 100%;
}
.empty svg { width: 44px; height: 44px; opacity: .5; }
.empty h3 { font-size: 15px; color: var(--text-2); }
.empty p { margin: 0; font-size: 13px; max-width: 34ch; }

.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  background: linear-gradient(90deg, var(--line-soft) 25%, var(--hover) 37%, var(--line-soft) 63%);
  background-size: 400% 100%; border-radius: 6px;
  animation: shimmer 1.3s ease infinite;
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
