/* Werkstatt 76 Mail. Tokens follow DESIGN.md (software surfaces are dark). One typeface:
   Space Grotesk, self-hosted. No external requests: the CSP only admits 'self'. */

@font-face {
  font-family: "Space Grotesk";
  src: url("/static/fonts/SpaceGrotesk-var.woff2") format("woff2");
  font-weight: 300 700;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
    U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
    U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Space Grotesk";
  src: url("/static/fonts/SpaceGrotesk-ext-var.woff2") format("woff2");
  font-weight: 300 700;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304,
    U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0,
    U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  color-scheme: dark;
  --bg: #17140f;
  --panel: #0f0d0a;
  --surface: #211e19;
  --raised: #2a261f;
  --line: #332f28;
  --line-strong: #4a443a;
  --fg: #f3ede1;
  --fg-soft: #cfc6b6;
  --muted: #8f8574;
  --accent: #c46a44;
  --accent-hover: #d27a53;
  --accent-soft: rgba(196, 106, 68, 0.16);
  --on-accent: #17140f;
  --danger: #e0806a;
  --focus: #e9a27f;

  --font: "Space Grotesk", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --step--1: 0.8125rem;
  --step-0: 0.9375rem;
  --step-1: 1.125rem;
  --step-2: 1.5rem;
  --step-3: 2rem;

  --rail: 232px;
  --list: 384px;
  --radius: 6px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 400 var(--step-0)/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
.grow { flex: 1; }
.icon { display: inline-flex; width: 1.15em; height: 1.15em; flex: none; }
.icon svg { width: 100%; height: 100%; }
#app, .app { height: 100%; }

/* ---- splash (static, in index.html, before Python is up) ---------------------------- */
.splash {
  height: 100%; display: grid; place-content: center; justify-items: center; gap: 22px;
}
.splash-dots { display: flex; gap: 6px; }
.splash-dots span {
  width: 6px; height: 6px; background: var(--muted);
  animation: pulse 1.2s var(--ease) infinite;
}
.splash-dots span:nth-child(2) { animation-delay: 0.15s; }
.splash-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes pulse { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }

/* ---- brand -------------------------------------------------------------------------- */
.lockup { display: inline-flex; align-items: center; gap: calc(var(--plate) * 0.32); }
.plate {
  width: var(--plate); height: var(--plate); flex: none;
  background: var(--accent); color: var(--on-accent);
  display: grid; place-items: center;
  clip-path: polygon(0 0, calc(100% - var(--chamfer)) 0, 100% var(--chamfer), 100% 100%, 0 100%);
}
.plate span {
  font-weight: 700; font-size: calc(var(--plate) * 0.54); letter-spacing: -0.03em; line-height: 1;
}
.lockup-word {
  font-weight: 700; font-size: calc(var(--plate) * 0.7); letter-spacing: -0.04em;
  line-height: 0.9; white-space: nowrap;
}

/* ---- buttons ------------------------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 38px; padding: 0 14px; border: 1px solid var(--line-strong);
  border-radius: var(--radius); background: transparent; font-weight: 500;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease);
}
.btn:hover { background: var(--raised); }
.btn:disabled { opacity: 0.55; cursor: progress; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { border-color: transparent; color: var(--fg-soft); }
.btn-ghost:hover { color: var(--fg); }
.btn-wide { width: 100%; }
.btn-small { min-height: 30px; padding: 0 10px; font-size: var(--step--1); }
.btn-icon {
  display: inline-grid; place-items: center; width: 38px; height: 38px; flex: none;
  border: 0; border-radius: var(--radius); background: transparent; color: var(--fg-soft);
  font-size: 1.15rem;
}
.btn-icon:hover { background: var(--raised); color: var(--fg); }
.btn-icon.is-on { color: var(--accent); }
.btn-icon.btn-small { width: 28px; height: 28px; font-size: 0.95rem; }
.only-narrow { display: none; }

/* ---- sign in ------------------------------------------------------------------------ */
.login {
  min-height: 100%; display: grid; place-content: center; gap: 18px; padding: 24px 16px;
  overflow-y: auto; height: 100%;
}
.login-card {
  width: min(400px, calc(100vw - 32px));
  padding: 32px 28px 28px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius);
}
.login-title {
  margin: 28px 0 4px; font-size: var(--step-3); font-weight: 700; letter-spacing: -0.035em;
  line-height: 1.05;
}
.login-lede { margin: 0 0 24px; color: var(--fg-soft); }
.login-form { display: grid; gap: 6px; }
.field-label {
  margin-top: 10px; font-size: var(--step--1); font-weight: 500; color: var(--fg-soft);
}
.field-input, .search-input, .compose-input {
  width: 100%; min-height: 42px; padding: 0 12px; border: 1px solid var(--line-strong);
  border-radius: var(--radius); background: var(--bg);
}
.field-input:focus, .compose-input:focus, .search-input:focus, .compose-body:focus {
  outline: 2px solid var(--focus); outline-offset: -1px; border-color: transparent;
}
.login-form .btn-wide { margin-top: 18px; min-height: 44px; }
.login-error { margin: 8px 0 0; color: var(--danger); font-size: var(--step--1); }
.login-foot {
  margin: 0; text-align: center; color: var(--muted); font-size: var(--step--1);
  letter-spacing: 0.08em; text-transform: uppercase;
}

/* ---- shell -------------------------------------------------------------------------- */
.shell {
  height: 100%; display: grid; grid-template-columns: var(--rail) var(--list) minmax(0, 1fr);
  position: relative;
}
.scrim { display: none; }

/* rail */
.rail {
  display: flex; flex-direction: column; gap: 2px; padding: 20px 12px 12px;
  background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto;
}
.rail-brand { display: flex; align-items: baseline; justify-content: space-between; padding: 0 8px 22px; }
.rail-brand .lockup { align-self: center; }
.rail-product {
  font-size: var(--step--1); color: var(--muted); letter-spacing: 0.12em; text-transform: uppercase;
}
.rail-write { margin-bottom: 14px; min-height: 42px; }
.folder {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 38px; padding: 0 10px;
  border: 0; border-radius: var(--radius); background: transparent; color: var(--fg-soft);
  text-align: left;
}
.folder:hover { background: var(--surface); color: var(--fg); }
.folder.is-current { background: var(--surface); color: var(--fg); box-shadow: inset 2px 0 0 var(--accent); }
.folder-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-count {
  font-size: var(--step--1); font-weight: 600; color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.rail-foot {
  margin-top: auto; display: flex; align-items: center; gap: 4px; padding: 14px 4px 0 10px;
  border-top: 1px solid var(--line);
}
.rail-address {
  flex: 1; margin: 0; font-size: var(--step--1); color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* list */
.list {
  display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line);
  background: var(--bg);
}
.list-head { display: flex; align-items: center; gap: 8px; padding: 16px 12px 10px 20px; }
.list-title { margin: 0; font-size: var(--step-2); font-weight: 700; letter-spacing: -0.03em; }
.list-total {
  flex: 1; color: var(--muted); font-size: var(--step--1); font-variant-numeric: tabular-nums;
  padding-top: 6px;
}
.search {
  display: flex; align-items: center; gap: 8px; margin: 0 16px; padding-left: 12px;
  border: 1px solid var(--line-strong); border-radius: var(--radius); color: var(--muted);
  background: var(--bg);
}
.search:focus-within { outline: 2px solid var(--focus); outline-offset: -1px; border-color: transparent; }
.search-input { border: 0; padding-left: 0; min-height: 38px; background: transparent; }
.search-input:focus { outline: none; }
.chips { display: flex; gap: 6px; padding: 10px 16px 12px; border-bottom: 1px solid var(--line); }
.chip {
  min-height: 28px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 999px;
  background: transparent; color: var(--fg-soft); font-size: var(--step--1);
}
.chip.is-on { background: var(--fg); border-color: var(--fg); color: var(--bg); font-weight: 600; }
.list-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.row {
  display: grid; gap: 2px; width: 100%; padding: 12px 18px 13px 20px; border: 0;
  border-bottom: 1px solid var(--line); background: transparent; text-align: left;
  position: relative;
}
.row:hover { background: var(--surface); }
.row.is-open { background: var(--raised); }
.row.is-unread::before {
  content: ""; position: absolute; left: 8px; top: 19px; width: 6px; height: 6px;
  background: var(--accent);
}
.row-top { display: flex; align-items: center; gap: 8px; min-width: 0; }
.row-sender {
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--fg-soft);
}
.row.is-unread .row-sender, .row.is-unread .row-subject { color: var(--fg); font-weight: 600; }
.row-count {
  font-size: 0.75rem; color: var(--muted); border: 1px solid var(--line-strong);
  padding: 0 5px; border-radius: 3px; font-variant-numeric: tabular-nums;
}
.row-clip { color: var(--muted); }
.row-flag { color: var(--accent); }
.row-date {
  flex: none; font-size: var(--step--1); color: var(--muted); font-variant-numeric: tabular-nums;
}
.row-subject, .row-preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-subject { color: var(--fg-soft); }
.row-preview { color: var(--muted); font-size: var(--step--1); }
.list-more { width: calc(100% - 32px); margin: 14px 16px 24px; }
.list-empty, .reader-empty {
  height: 100%; display: grid; place-content: center; justify-items: center; gap: 6px;
  color: var(--muted); padding: 40px 24px; text-align: center;
}
.empty-icon { width: 34px; height: 34px; color: var(--line-strong); }
.row-skeleton { height: 74px; border-bottom: 1px solid var(--line); background:
  linear-gradient(90deg, transparent, var(--surface), transparent) 0 0 / 200% 100%;
  animation: sheen 1.4s linear infinite; }
@keyframes sheen { to { background-position: -200% 0; } }

/* reader */
.reader { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--bg); }
.reader-body { flex: 1; min-height: 0; overflow-y: auto; }
.reader-inner { max-width: 860px; padding: 0 32px 64px; }
.reader-tools {
  position: sticky; top: 0; z-index: 2; display: flex; gap: 2px; padding: 12px 0 10px;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.reader-subject {
  margin: 28px 0 18px; font-size: var(--step-3); font-weight: 700; letter-spacing: -0.035em;
  line-height: 1.12; text-wrap: balance; overflow-wrap: anywhere;
}
.images-bar {
  display: flex; align-items: center; gap: 10px; margin: 0 0 18px; padding: 8px 8px 8px 14px;
  border: 1px solid var(--line); border-radius: var(--radius); color: var(--fg-soft);
  font-size: var(--step--1);
}
.images-bar span:not(.icon) { flex: 1; }
.msg { padding: 18px 0 22px; border-top: 1px solid var(--line); }
.msg-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 16px; margin-bottom: 14px; }
.msg-who { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; min-width: 0; }
.msg-from { font-weight: 600; }
.msg-address { color: var(--muted); font-size: var(--step--1); overflow-wrap: anywhere; }
.msg-date { color: var(--muted); font-size: var(--step--1); font-variant-numeric: tabular-nums; }
.msg-to { grid-column: 1 / -1; margin: 0; color: var(--muted); font-size: var(--step--1); }
.mail-sheet { border-radius: var(--radius); overflow: hidden; background: #fbf8f2; }
.mail-frame { display: block; width: 100%; height: 120px; border: 0; background: #fbf8f2; }
.mail-text {
  white-space: pre-wrap; overflow-wrap: anywhere; color: var(--fg); max-width: 72ch;
  line-height: 1.6;
}
.mail-text a { color: var(--accent-hover); }
.atts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.att {
  display: inline-flex; align-items: center; gap: 8px; max-width: 100%; min-height: 36px;
  padding: 0 12px; border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--surface); font-size: var(--step--1);
}
button.att:hover { border-color: var(--accent); }
.att.is-static { padding-right: 4px; }
.att-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.att-size { color: var(--muted); font-variant-numeric: tabular-nums; }
.msg-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 18px; }
.msg-actions .btn-ghost { border-color: var(--line-strong); }
.msg-skeleton { height: 260px; margin-top: 28px; background: var(--surface); border-radius: var(--radius); }

/* composer */
.composer-slot { display: contents; }
.composer {
  position: fixed; right: 24px; bottom: 0; z-index: 20; width: min(620px, calc(100vw - 48px));
  height: min(640px, calc(100vh - 48px)); display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line-strong); border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0; box-shadow: 0 -12px 48px rgba(0, 0, 0, 0.45);
  animation: rise 0.22s var(--ease);
}
@keyframes rise { from { transform: translateY(16px); opacity: 0; } }
.compose-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 8px 8px 18px; border-bottom: 1px solid var(--line);
}
.compose-title { margin: 0; font-size: var(--step-0); font-weight: 600; }
.compose-row {
  display: flex; align-items: center; gap: 8px; padding: 2px 10px 2px 18px;
  border-bottom: 1px solid var(--line);
}
.compose-label { width: 58px; flex: none; color: var(--muted); font-size: var(--step--1); }
.compose-input { border: 0; background: transparent; padding: 0; min-height: 40px; }
.compose-body {
  flex: 1; min-height: 140px; width: 100%; padding: 14px 18px; border: 0; resize: none;
  background: transparent; line-height: 1.6;
}
.compose-atts > div { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 18px 4px; }
.compose-error { margin: 0; padding: 8px 18px 0; color: var(--danger); font-size: var(--step--1); }
.compose-foot { display: flex; align-items: center; gap: 6px; padding: 12px 14px 14px 18px; }

/* notice */
.notice {
  position: fixed; left: 50%; bottom: 20px; z-index: 30; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; max-width: calc(100vw - 32px);
  padding: 8px 8px 8px 16px; background: var(--fg); color: var(--bg); border-radius: var(--radius);
  font-size: var(--step--1); font-weight: 500; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}
.notice .btn-icon { color: var(--bg); }
.notice .btn-icon:hover { background: rgba(0, 0, 0, 0.08); color: var(--bg); }

/* ---- narrow ------------------------------------------------------------------------- */
@media (max-width: 1180px) {
  :root { --list: 340px; --rail: 212px; }
  .reader-inner { padding: 0 24px 56px; }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .only-narrow { display: inline-grid; }
  .rail {
    position: fixed; inset: 0 auto 0 0; z-index: 25; width: min(300px, 84vw);
    transform: translateX(-102%); transition: transform 0.24s var(--ease);
  }
  .rail.is-open { transform: none; }
  .scrim { display: block; position: fixed; inset: 0; z-index: 24; background: rgba(0, 0, 0, 0.5); }
  .list { border-right: 0; }
  .list-head { padding: 12px 8px 8px 8px; }
  .reader { display: none; }
  .shell.show-reader .list { display: none; }
  .shell.show-reader .reader { display: flex; }
  .reader-inner { padding: 0 16px 48px; }
  .reader-subject { font-size: var(--step-2); margin-top: 20px; }
  .composer {
    inset: 0; width: auto; height: auto; border: 0; border-radius: 0; animation: none;
  }
  .msg-head { grid-template-columns: minmax(0, 1fr); }
}

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