/* =============================================================================
   tinycpms · mail — theme
   "Linear x a terminal." Premium dark, accent #00ff94 on near-black.
   preview.js scopes under .tcp-msg and composer.js under .tcp-composer — we
   stay out of those namespaces and only style our shell here.
   ========================================================================== */

:root {
  --bg:        #0a0e14;   /* page background, deepest */
  --bg-1:      #0d1117;   /* panel background */
  --bg-2:      #11161f;   /* raised / hover */
  --bg-3:      #161c27;   /* selected / active */
  --border:    #1b2230;   /* hairline borders */
  --border-2:  #232c3b;   /* stronger borders */
  --text:      #e6edf3;   /* primary text */
  --text-2:    #9aa7b8;   /* secondary text */
  --text-3:    #5f6b7c;   /* tertiary / muted */
  --accent:    #00ff94;   /* signature green */
  --accent-dim:#00b86b;
  --accent-glow: rgba(0, 255, 148, 0.14);
  --danger:    #ff5d6c;

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

  --radius:   10px;
  --radius-sm: 7px;
  --topbar-h: 52px;
  --sidebar-w: 360px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Faint terminal grid + accent glow in the corner — tasteful, GPU-cheap. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(720px 380px at 88% -8%, var(--accent-glow), transparent 60%),
    linear-gradient(transparent 95%, rgba(255,255,255,0.012) 0) 0 0 / 100% 26px,
    linear-gradient(90deg, transparent 95%, rgba(255,255,255,0.012) 0) 0 0 / 26px 100%;
}

#app { position: relative; z-index: 1; height: 100%; }

::selection { background: var(--accent-glow); }

/* Scrollbars — slim, dark, unobtrusive. */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #1d2533; border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: #2a3548; background-clip: padding-box; }

/* =============================================================================
   Buttons
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  padding: 8px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-2);
  background: var(--bg-2);
  color: var(--text);
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, transform .06s ease, color .12s ease;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-3); border-color: #2d3850; }
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--accent);
  color: #05130c;
  border-color: transparent;
  font-weight: 600;
  box-shadow: 0 0 0 1px rgba(0,255,148,0.18), 0 6px 18px rgba(0,255,148,0.12);
}
.btn-primary:hover { background: #25ffa6; }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-2);
}
.btn-ghost:hover { background: var(--bg-2); color: var(--text); }

.icon { display: block; flex: none; }

/* =============================================================================
   Lock screen
   ========================================================================== */
.lock-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
}
.lock-card {
  width: 340px;
  max-width: 100%;
  background: linear-gradient(180deg, var(--bg-1), #0b0f16);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 30px 26px 26px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow);
  text-align: center;
}
.lock-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 4px;
}
.lock-title {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--text-3);
}
.lock-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
  padding: 12px 14px;
  outline: none;
  transition: border-color .12s ease, box-shadow .12s ease;
  text-align: center;
  letter-spacing: .12em;
}
.lock-input:focus {
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.lock-btn { justify-content: center; width: 100%; padding: 11px; }
.lock-error {
  min-height: 16px;
  color: var(--danger);
  font-family: var(--mono);
  font-size: 12px;
}

/* Error shake */
.shake { animation: shake .4s cubic-bezier(.36,.07,.19,.97); }
@keyframes shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-4px); }
  40%, 60% { transform: translateX(4px); }
}

/* =============================================================================
   Brand mark (used in topbar + lock)
   ========================================================================== */
.brand { display: flex; align-items: baseline; gap: 7px; }
.brand-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent), 0 0 0 1px rgba(0,255,148,.25);
  align-self: center;
}
.brand-name { font-weight: 650; letter-spacing: -.01em; font-size: 15px; }
.brand-sub {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-3);
  letter-spacing: .1em;
  text-transform: uppercase;
}

/* =============================================================================
   Top bar
   ========================================================================== */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(13, 17, 23, 0.72);
  backdrop-filter: blur(10px);
  position: relative;
  z-index: 5;
}
.topbar-spacer { flex: 1; }

.live {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-1);
}
.live-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }
.live-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--text-2);
}

/* Mail | Leads segmented toggle */
.nav-toggle {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.nav-tab {
  font-family: var(--sans);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: .01em;
  color: var(--text-3);
  background: transparent;
  border: none;
  border-radius: 999px;
  padding: 5px 15px;
  cursor: pointer;
  transition: color .12s ease, background .12s ease;
}
.nav-tab:hover { color: var(--text); }
.nav-tab.active {
  color: #05130c;
  background: var(--accent);
  box-shadow: 0 0 0 1px rgba(0,255,148,.2), 0 4px 12px rgba(0,255,148,.14);
}

/* =============================================================================
   Body layout: sidebar + reading
   ========================================================================== */
.body {
  height: calc(100% - var(--topbar-h));
  min-height: 0;
}
/* Mail's two-pane grid lives inside #body so the whole pane can be swapped out
   for the Leads workspace without disturbing the topbar. */
.mail-grid {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100%;
  min-height: 0;
}
#leads-root { height: 100%; min-height: 0; overflow-y: auto; }

/* ----- Sidebar / thread list -------------------------------------------- */
.sidebar {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-1);
}
.sidebar-head {
  padding: 12px 12px 10px;
  border-bottom: 1px solid var(--border);
}
.search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  padding: 0 10px;
  color: var(--text-3);
  transition: border-color .12s ease, box-shadow .12s ease;
}
.search-wrap:focus-within {
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 3px var(--accent-glow);
  color: var(--accent);
}
.search-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  padding: 9px 0;
}
.search-input::placeholder { color: var(--text-3); }

.thread-list { flex: 1; overflow-y: auto; padding: 6px; min-height: 0; }

.thread {
  display: grid;
  grid-template-columns: 14px 1fr;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 10px;
  cursor: pointer;
  color: var(--text);
  font: inherit;
  transition: background .1s ease, border-color .1s ease;
}
.thread:hover { background: var(--bg-2); }
.thread.selected {
  background: var(--bg-3);
  border-color: var(--border-2);
  box-shadow: inset 2px 0 0 var(--accent);
}
.thread-dot-col { display: flex; justify-content: center; padding-top: 5px; }
.unseen-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}
.thread-main { min-width: 0; }

.thread-line1 {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
}
.thread-party {
  font-weight: 600;
  font-size: 13.5px;
  color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.thread.unseen .thread-party { color: #fff; }
.thread-time {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-3);
  flex: none;
}
.thread.unseen .thread-time { color: var(--accent); }

.thread-line2 {
  display: flex; align-items: center; gap: 6px;
  margin-top: 2px;
}
.thread-subject {
  font-size: 12.5px;
  color: var(--text-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.thread.unseen .thread-subject { color: var(--text); font-weight: 500; }
.count-chip {
  flex: none;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-2);
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  border-radius: 999px;
  padding: 1px 6px;
  line-height: 1.5;
}
.thread-snippet {
  margin-top: 3px;
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Empty states (sidebar) */
.list-empty {
  padding: 40px 22px;
  text-align: center;
  color: var(--text-3);
}
.list-empty-title { font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.list-empty-sub { font-size: 12.5px; line-height: 1.5; }

/* ----- Reading pane ------------------------------------------------------ */
.reading {
  overflow-y: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.reading-empty {
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: var(--text-3);
  padding: 40px;
}
.reading-empty .icon { color: var(--border-2); }
.reading-empty-title { font-size: 16px; font-weight: 600; color: var(--text-2); }
.reading-empty-sub { font-size: 13px; }
.reading-loading {
  margin: auto;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-3);
  letter-spacing: .1em;
}

.thread-head {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 18px 28px 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(13,17,23,0.82);
  backdrop-filter: blur(10px);
}
.thread-head-subject {
  margin: 0;
  font-size: 18px;
  font-weight: 650;
  letter-spacing: -.01em;
  line-height: 1.3;
}
.thread-head-meta {
  margin-top: 5px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-3);
  letter-spacing: .06em;
}

.conversation {
  padding: 18px 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.msg-slot { /* preview.js renders .tcp-msg inside here */ }
.msg-fallback {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  color: var(--text-2);
  font-size: 13px;
  background: var(--bg-1);
  white-space: pre-wrap;
}

/* ----- Reply bar + composer host ---------------------------------------- */
.reply-bar {
  padding: 4px 28px 8px;
}
.composer-host {
  padding: 0 28px 32px;
}
.composer-host:empty { padding: 0; }

/* =============================================================================
   Compose overlay (new message)
   ========================================================================== */
.compose-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(5, 8, 12, 0.62);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: start center;
  padding: 6vh 20px 20px;
  overflow-y: auto;
}
.compose-overlay-inner {
  width: 760px;
  max-width: 100%;
  background: var(--bg-1);
  border: 1px solid var(--border-2);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.compose-overlay-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
}
.compose-overlay-title { font-weight: 600; }
.compose-overlay-head .btn-ghost { font-size: 20px; line-height: 1; padding: 4px 10px; }
.compose-mount { padding: 4px; /* composer.js scopes under .tcp-composer */ }

/* =============================================================================
   Help overlay
   ========================================================================== */
.help-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(5, 8, 12, 0.62);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  padding: 20px;
}
.help-card {
  width: 420px;
  max-width: 100%;
  background: var(--bg-1);
  border: 1px solid var(--border-2);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.help-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.help-title { font-weight: 650; letter-spacing: -.01em; }
.help-head .btn-ghost { font-size: 20px; line-height: 1; padding: 2px 10px; }
.help-list { padding: 10px 18px 18px; }
.help-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 7px 0;
}
.kbd {
  flex: none;
  min-width: 64px;
  text-align: center;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text);
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 4px 8px;
}
.help-desc { font-size: 13px; color: var(--text-2); }

/* ----- Topbar actions + mobile overflow menu ---------------------------- */
.topbar-actions { display: inline-flex; align-items: center; gap: 14px; }
.topbar-menu-btn { display: none; font-size: 20px; line-height: 1; padding: 4px 12px; }

/* The mobile action sheet: a bottom sheet of big, tappable rows. */
.action-menu {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(5, 8, 12, 0.62);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
}
.menu-card {
  width: 100%;
  background: var(--bg-1);
  border-top: 1px solid var(--border-2);
  border-radius: 16px 16px 0 0;
  box-shadow: var(--shadow);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.menu-item {
  appearance: none;
  background: transparent;
  border: none;
  color: var(--text);
  font: inherit;
  font-size: 16px;
  font-weight: 550;
  text-align: left;
  padding: 16px 18px;
  border-radius: 10px;
  cursor: pointer;
}
.menu-item:active { background: var(--bg-3); }

/* =============================================================================
   Responsive degradation (laptop-first; collapses gracefully narrower)
   ========================================================================== */
@media (max-width: 1100px) {
  :root { --sidebar-w: 300px; }
  .conversation, .thread-head, .reply-bar, .composer-host { padding-left: 18px; padding-right: 18px; }
}
@media (max-width: 760px) {
  .mail-grid { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); max-height: 42vh; }
  .live, .live-label, .brand-sub { display: none; }
  /* Collapse the inline actions into the ⋯ menu so nothing clips off-screen. */
  .topbar-actions { display: none; }
  .topbar-menu-btn { display: inline-flex; }
  .topbar { gap: 10px; padding: 0 12px; }
  .conversation, .thread-head, .reply-bar, .composer-host { padding-left: 14px; padding-right: 14px; }
}
