/* ============================================================
   Arcly Mail — mail.arcly.com
   Design language inherited from arcly.com landing page:
   bg #eef1f6 radial field, ink #241d1a, arcly red #b11116,
   Montserrat 600/700 for brand, system stack for UI.
   ============================================================ */

@font-face {
  font-family: "Montserrat";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("./fonts/montserrat-600-latin.woff2") format("woff2");
}
@font-face {
  font-family: "Montserrat";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("./fonts/montserrat-700-latin.woff2") format("woff2");
}

:root {
  --bg: #eef1f6;
  --bg-hi: #fbfcfe;
  --bg-lo: #e0e5ef;
  --ink: #241d1a;
  --ink-soft: #4a423e;
  --muted: #8a8580;
  --accent: #b11116;
  --accent-dark: #7d0b0f;
  --accent-soft: #b111160f;
  --accent-wash: #b1111608;
  --pane: #ffffff;
  --pane-alt: #f6f8fb;
  --line: #dde2ec;
  --line-soft: #e8ecf3;
  --unread-dot: #b11116;
  --ok: #0a7d4a;
  --shadow-lg: 0 24px 60px -24px rgba(36, 29, 26, 0.25);
  --shadow-sm: 0 1px 2px rgba(36, 29, 26, 0.06), 0 8px 24px -16px rgba(36, 29, 26, 0.18);
  --radius: 12px;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-brand: "Montserrat", var(--font-ui);
  --font-mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(1100px 700px at 50% 28%, var(--bg-hi) 0%, var(--bg) 60%, var(--bg-lo) 100%) fixed;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button { font: inherit; color: inherit; }
input, select { font: inherit; }
a { color: var(--accent); }

/* ---------- brand lockup ---------- */
.brandmark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  user-select: none;
  white-space: nowrap;
}
.brandmark img { width: 28px; height: 28px; display: block; }
.brandmark .word {
  font-family: var(--font-brand);
  font-weight: 700;
  font-size: 19px;
  letter-spacing: 0.005em;
  line-height: 1;
}
.brandmark .word .tld { font-weight: 600; color: var(--accent); }

/* ============================================================
   Auth screens (setup / login / demo)
   ============================================================ */
.auth-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(24px, 4vmin);
}
.auth-card {
  width: min(400px, 92vw);
  background: var(--pane);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  padding: 36px 36px 30px;
  text-align: center;
  animation: rise 700ms cubic-bezier(.22,.61,.36,1) both;
}
.auth-card .logo { width: 76px; height: 76px; margin: 0 auto 14px; display: block; user-select: none; -webkit-user-drag: none; }
.auth-card h1 {
  margin: 0 0 4px;
  font-family: var(--font-brand);
  font-weight: 700;
  font-size: 30px;
  letter-spacing: 0.005em;
  line-height: 1.1;
}
.auth-card h1 .tld { font-weight: 600; color: var(--accent); }
.auth-card .sub { margin: 0 0 24px; color: var(--muted); font-size: 13px; }
.auth-card form { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.auth-card label { font-size: 12px; font-weight: 600; color: var(--ink-soft); }
.auth-card input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--pane-alt);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.auth-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: #fff; }
.auth-err {
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 8px;
  font-size: 12.5px;
  padding: 8px 10px;
  display: none;
}
.auth-err.show { display: block; }
.auth-card .foot { margin-top: 18px; font-size: 12px; color: var(--muted); }
.auth-card .foot a, .linklike { color: var(--accent); text-decoration: none; background: none; border: 0; padding: 0; cursor: pointer; font-size: inherit; }
.auth-card .foot a:hover, .linklike:hover { text-decoration: underline; }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--pane);
  border-radius: 9px;
  padding: 9px 16px;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--pane-alt); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn.slim { padding: 5px 11px; font-size: 12.5px; border-radius: 7px; }
.btn[disabled] { opacity: .55; cursor: default; }

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .auth-card, .app { animation: none !important; }
}

/* ============================================================
   App shell — topbar + three panes
   ============================================================ */
.app {
  display: none;
  height: 100dvh;
  flex-direction: column;
  animation: rise 500ms cubic-bezier(.22,.61,.36,1) both;
}
.app.on { display: flex; }

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 18px;
  background: rgba(255,255,255,0.72);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar .searchbox {
  flex: 1;
  max-width: 560px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--pane-alt);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 14px;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.topbar .searchbox:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: #fff; }
.topbar .searchbox svg { flex: none; opacity: .45; }
.topbar .searchbox input { flex: 1; border: 0; background: none; outline: none; font-size: 13.5px; }
.topbar .spacer { flex: 1; }
.topbar .who { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--muted); }
.badge-demo {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid #b1111633;
  padding: 2px 9px;
  border-radius: 999px;
  text-transform: uppercase;
}

.cols {
  flex: 1;
  display: grid;
  grid-template-columns: 232px minmax(300px, 390px) 1fr;
  min-height: 0;
}

/* ---------- sidebar ---------- */
.side {
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 14px 10px 20px;
  background: transparent;
}
.side h3 {
  margin: 18px 8px 6px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
}
.side h3:first-child { margin-top: 2px; }
.mbx {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  border: 0;
  background: none;
  text-align: left;
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--ink-soft);
  font-size: 13.5px;
}
.mbx:hover { background: #ffffffb0; }
.mbx.on { background: #fff; color: var(--ink); font-weight: 600; box-shadow: var(--shadow-sm); }
.mbx.on svg { color: var(--accent); }
.mbx svg { flex: none; opacity: .8; }
.mbx .n { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mbx .c { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.mbx.on .c { color: var(--accent); font-weight: 700; }
.mbx.child { padding-left: 28px; font-size: 13px; }
.side .acct {
  margin: 2px 8px 6px;
  font-size: 12px;
  color: var(--ink-soft);
  font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.addr-chip {
  display: flex; align-items: center; gap: 8px;
  width: 100%; border: 0; background: none; text-align: left;
  padding: 5px 10px; border-radius: 8px; cursor: pointer;
  font-size: 12.5px; color: var(--ink-soft);
  overflow: hidden;
}
.addr-chip:hover { background: #ffffffb0; }
.addr-chip.on { background: #fff; font-weight: 600; box-shadow: var(--shadow-sm); }
.addr-chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: none; opacity: .8; }
.addr-chip span.a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side .settings-link { margin-top: 22px; }

/* ---------- message list ---------- */
.list {
  border-right: 1px solid var(--line);
  overflow-y: auto;
  background: rgba(255,255,255,0.55);
  min-height: 0;
}
.list-head {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  font-weight: 700; font-size: 13px;
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line-soft);
}
.list-head .cnt { color: var(--muted); font-weight: 500; font-size: 12px; }
.list-head .grow { flex: 1; }
.rows { list-style: none; margin: 0; padding: 6px; display: flex; flex-direction: column; gap: 2px; }
.row {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  grid-template-rows: auto auto auto;
  column-gap: 8px;
  padding: 9px 10px 9px 6px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid transparent;
}
.row:hover { background: #fff; border-color: var(--line-soft); }
.row.on { background: #fff; border-color: var(--line); box-shadow: var(--shadow-sm); }
.row .dot { grid-row: 1; align-self: center; justify-self: center; width: 8px; height: 8px; border-radius: 50%; }
.row.unread .dot { background: var(--unread-dot); }
.row .from { grid-column: 2; font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.unread .from { color: var(--ink); }
.row .when { grid-column: 3; grid-row: 1; font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.row .subj { grid-column: 2 / 4; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-soft); }
.row.unread .subj { font-weight: 600; color: var(--ink); }
.row .prev { grid-column: 2 / 4; font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .clip { display: inline-block; vertical-align: -2px; margin-left: 6px; opacity: .5; }
.list .more { display: block; margin: 8px auto 14px; }
.list .empty, .read .empty {
  padding: 60px 24px; text-align: center; color: var(--muted); font-size: 13px;
}
.list .empty .logo-ghost, .read .empty .logo-ghost {
  width: 54px; height: 54px; margin: 0 auto 12px; opacity: .16; display: block;
  filter: grayscale(1);
}

/* ---------- reading pane ---------- */
.read { overflow-y: auto; min-height: 0; background: transparent; }
.read-inner { max-width: 860px; margin: 0 auto; padding: 22px 26px 60px; }
.read h2.subject {
  margin: 4px 0 14px;
  font-size: 19px;
  font-weight: 700;
  line-height: 1.3;
}
.msg {
  background: var(--pane);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 14px;
  overflow: hidden;
}
.msg-head {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
}
.msg-head .avatar {
  flex: none;
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
  color: #fff; font-weight: 700; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}
.msg-head .who { flex: 1; min-width: 0; }
.msg-head .who .f { font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-head .who .t { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-head .when { font-size: 12px; color: var(--muted); flex: none; }
.msg-body { border-top: 1px solid var(--line-soft); }
.msg-body iframe {
  display: block; width: 100%; border: 0; background: #fff;
}
.msg-body .plain {
  padding: 16px 18px;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 13.5px;
}
.msg.folded .msg-body { display: none; }
.imgbar {
  display: flex; align-items: center; gap: 10px;
  font-size: 12.5px; color: var(--ink-soft);
  background: var(--pane-alt);
  border-bottom: 1px solid var(--line-soft);
  padding: 7px 16px;
}
.attachbar {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 10px 16px 14px;
  border-top: 1px solid var(--line-soft);
}
.attach {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12.5px;
  border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 10px;
  color: var(--ink-soft); text-decoration: none;
  background: var(--pane-alt);
}
.attach:hover { border-color: var(--accent); color: var(--accent); }
.read-tools { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }

/* ---------- AI panel ---------- */
.ai-card {
  border: 1px solid #b1111626;
  background: linear-gradient(180deg, #fff 0%, #fdf6f6 100%);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 14px 16px;
  margin-bottom: 14px;
  font-size: 13.5px;
}
.ai-card h4 {
  margin: 0 0 6px;
  font-size: 11px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
  color: var(--accent);
  display: flex; align-items: center; gap: 6px;
}
.ai-card .body { white-space: pre-wrap; }
.ai-card.thinking .body { color: var(--muted); }

/* ---------- settings overlay ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(36,29,26,0.35);
  backdrop-filter: blur(3px);
  display: none; align-items: flex-start; justify-content: center;
  padding: 7vh 20px 20px;
}
.overlay.on { display: flex; }
.sheet {
  width: min(560px, 94vw);
  max-height: 84dvh;
  overflow-y: auto;
  background: var(--pane);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 26px 28px;
  animation: rise 350ms cubic-bezier(.22,.61,.36,1) both;
}
.sheet h2 { margin: 0 0 4px; font-family: var(--font-brand); font-weight: 700; font-size: 20px; }
.sheet .sub { color: var(--muted); font-size: 12.5px; margin: 0 0 18px; }
.sheet h3 { font-size: 13px; margin: 22px 0 8px; }
.sheet .tokrow {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; margin-bottom: 8px;
  font-size: 13px;
}
.sheet .tokrow .email { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.sheet .tokrow .meta { color: var(--muted); font-size: 11.5px; }
.sheet .addrow { display: flex; gap: 8px; margin-top: 6px; }
.sheet .addrow input { flex: 1; padding: 9px 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--pane-alt); outline: none; }
.sheet .addrow input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: #fff; }
.sheet .hint { font-size: 12px; color: var(--muted); margin-top: 6px; }
.sheet .hint code { font-family: var(--font-mono); font-size: 11px; background: var(--pane-alt); padding: 1px 5px; border-radius: 4px; }
.sheet .closebar { display: flex; justify-content: flex-end; margin-top: 22px; }
.sheet .err { color: var(--accent); font-size: 12.5px; margin-top: 6px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff;
  font-size: 13px; padding: 10px 18px; border-radius: 999px;
  box-shadow: var(--shadow-lg);
  opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s;
  z-index: 99;
}
.toast.on { opacity: 1; transform: translateX(-50%) translateY(-4px); }

/* ---------- narrow screens ---------- */
@media (max-width: 900px) {
  .cols { grid-template-columns: 200px 1fr; }
  .read { display: none; position: fixed; inset: 0; top: 53px; z-index: 20; background: var(--bg); }
  .read.open { display: block; }
  .read .backbar { display: flex; }
}
.read .backbar { display: none; padding: 10px 14px 0; }
@media (max-width: 640px) {
  .cols { grid-template-columns: 1fr; }
  .side { display: none; }
}
