/* mailmill web client. Tokens: flour ground, ink text, mill-race accent, grain-gold unread. */
:root {
  --ground: #EDF0F3;
  --surface: #FFFFFF;
  --sunken: #E3E7EC;
  --ink: #1B2430;
  --muted: #5D6876;
  --line: #D5DBE2;
  --accent: #0B6E69;
  --accent-ink: #FFFFFF;
  --accent-soft: #DCEFED;
  --grain: #C8961A;
  --danger: #B42318;
  --radius-s: 6px;
  --radius-m: 10px;
  --radius-l: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-title: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, sans-serif;
  --rail: 68px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ground: #11151B; --surface: #192029; --sunken: #0D1116; --ink: #E3E7ED; --muted: #94A0AE;
    --line: #29323D; --accent: #3DB5AB; --accent-ink: #062523; --accent-soft: #163632; --grain: #E2B341; --danger: #F97066;
  }
}

* { box-sizing: border-box; }
html, body, #app { height: 100%; margin: 0; }
body {
  background: var(--ground); color: var(--ink); font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; overscroll-behavior: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.grow { flex: 1; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- buttons and fields ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: var(--radius-s); background: var(--surface); cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.icon { padding: 0; width: 36px; }
.btn svg, .rail svg, .tabbar svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.field > span { font-size: 13px; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=date], input[type=time], input[type=tel], input[type=url], select, textarea {
  width: 100%; min-height: 38px; padding: 7px 10px; border: 1px solid var(--line); border-radius: var(--radius-s);
  background: var(--surface); font-size: 16px; /* 16px stops iOS zoom-on-focus */
}
textarea { resize: vertical; min-height: 120px; line-height: 1.5; }
.row { display: flex; gap: 10px; align-items: center; }
.row > .field { flex: 1; }
.check { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; }

/* ---- login ---- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login form { width: min(360px, 100%); }
.login .mark { width: 56px; height: 56px; border-radius: 14px; margin-bottom: 18px; }
.login h1 { font: 700 30px/1.1 var(--font-title); margin: 0 0 6px; letter-spacing: -0.01em; }
.login p { margin: 0 0 24px; color: var(--muted); }
.login .btn { width: 100%; min-height: 44px; }
.error { color: var(--danger); min-height: 1.4em; margin: 0 0 10px; }

/* ---- shell ---- */
.shell { display: grid; grid-template-columns: var(--rail) 1fr; height: 100%; }
.rail {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 0;
  border-right: 1px solid var(--line); background: var(--surface);
}
.rail a, .tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px; text-decoration: none; color: var(--muted);
  font-size: 11px; border-radius: var(--radius-m);
}
.rail a { width: 52px; padding: 8px 0; }
.rail a[aria-current=page], .tabbar a[aria-current=page] { color: var(--accent); }
.rail a[aria-current=page] { background: var(--accent-soft); }
.rail .spacer { flex: 1; }
.rail .mark { width: 34px; height: 34px; border-radius: 9px; margin-bottom: 10px; }
.main { min-width: 0; height: 100%; overflow: hidden; }
.tabbar { display: none; }

/* ---- panes ---- */
.panes { display: grid; height: 100%; }
.panes.mail { grid-template-columns: 220px minmax(300px, 380px) 1fr; }
.panes.two { grid-template-columns: minmax(280px, 360px) 1fr; }
.pane { min-width: 0; height: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch; border-right: 1px solid var(--line); }
.pane:last-child { border-right: 0; }
.pane.side { background: var(--ground); padding: 10px 8px; }
.pane.list { background: var(--surface); display: flex; flex-direction: column; }
.pane.detail { background: var(--surface); display: flex; flex-direction: column; }
.pane-head {
  position: sticky; top: 0; z-index: 2; background: inherit; padding: calc(12px + var(--safe-t)) 16px 10px;
  display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--line);
}
.pane-head h2 { font: 700 22px/1.2 var(--font-title); margin: 0; flex: 1; min-width: 0; letter-spacing: -0.01em; }
.pane-head .back { display: none; }
.search { padding: 10px 16px; border-bottom: 1px solid var(--line); }
.empty { padding: 48px 24px; text-align: center; color: var(--muted); }

/* mailbox list */
.folders a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-s);
  text-decoration: none; color: var(--ink);
}
.folders a[aria-current=true] { background: var(--sunken); font-weight: 600; }
.folders .count { margin-left: auto; font-size: 13px; color: var(--muted); }
.folders .count.unread { color: var(--ink); font-weight: 600; }
.folders .compose { width: 100%; margin-bottom: 12px; min-height: 40px; }
.folders .sub { padding-left: 26px; }

/* message list */
.msgs { list-style: none; margin: 0; padding: 0; }
.msgs li { border-bottom: 1px solid var(--line); }
.msgs a { display: grid; grid-template-columns: 14px 1fr auto; gap: 2px 8px; padding: 11px 16px 11px 8px; text-decoration: none; color: inherit; }
.msgs a[aria-current=true] { background: var(--accent-soft); }
.msgs .dot { grid-row: 1; align-self: center; width: 8px; height: 8px; border-radius: 50%; }
.msgs .unread .dot { background: var(--grain); }
.msgs .from { font-weight: 500; }
.msgs .unread .from, .msgs .unread .subj { font-weight: 650; }
.msgs .date { font-size: 13px; color: var(--muted); }
.msgs .subj, .msgs .prev { grid-column: 2 / 4; }
.msgs .prev { color: var(--muted); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.msgs .flag { color: var(--grain); }
.more { margin: 14px auto; display: flex; }

/* reader */
.reader-head { padding: 18px 20px 12px; border-bottom: 1px solid var(--line); }
.reader-head h1 { font: 700 21px/1.25 var(--font-title); margin: 0 0 12px; overflow-wrap: anywhere; }
.reader-meta { display: flex; gap: 12px; align-items: flex-start; }
.avatar {
  flex: none; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 700;
}
.reader-meta .who { font-weight: 600; }
.reader-meta .to { font-size: 13px; color: var(--muted); }
.toolbar { display: flex; gap: 4px; flex-wrap: wrap; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 20px; border-bottom: 1px solid var(--line); }
.attachments a { padding: 6px 10px; border: 1px solid var(--line); border-radius: var(--radius-s); text-decoration: none; font-size: 14px; }
.notice { padding: 8px 20px; font-size: 14px; background: var(--sunken); display: flex; gap: 10px; align-items: center; }
.mailframe { flex: 1; width: 100%; min-height: 300px; border: 0; background: #fff; }

/* ---- sheets (modals) ---- */
.sheet-backdrop { position: fixed; inset: 0; background: rgb(10 14 20 / 45%); z-index: 50; display: grid; place-items: center; padding: 16px; }
.sheet {
  width: min(640px, 100%); max-height: calc(100% - 32px); overflow: auto; background: var(--surface);
  border-radius: var(--radius-l); box-shadow: 0 24px 60px rgb(0 0 0 / 25%);
}
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: inherit; z-index: 1; }
.sheet-head h2 { font: 700 18px/1.2 var(--font-title); margin: 0; flex: 1; }
.sheet-body { padding: 16px; }
.compose .addr { display: grid; grid-template-columns: 56px 1fr; align-items: center; border-bottom: 1px solid var(--line); }
.compose .addr label { color: var(--muted); font-size: 14px; padding-left: 16px; }
.compose .addr input { border: 0; border-radius: 0; background: transparent; }
.compose textarea { border: 0; border-radius: 0; min-height: 260px; padding: 14px 16px; }
.compose .files { padding: 8px 16px; display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; gap: 6px; align-items: center; padding: 4px 10px; border-radius: 999px; background: var(--sunken); font-size: 13px; }
.chip button { border: 0; background: none; cursor: pointer; padding: 0; color: var(--muted); }

/* ---- calendar ---- */
.cal { display: flex; flex-direction: column; height: 100%; background: var(--surface); }
.cal-grid { flex: 1; display: grid; grid-template-columns: repeat(7, 1fr); grid-auto-rows: 1fr; min-height: 0; }
.cal-dow { display: grid; grid-template-columns: repeat(7, 1fr); border-bottom: 1px solid var(--line); }
.cal-dow div { padding: 6px 8px; font-size: 12px; color: var(--muted); }
.day { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 4px; min-height: 0; overflow: hidden; cursor: pointer; display: flex; flex-direction: column; gap: 2px; }
.day:nth-child(7n) { border-right: 0; }
.day .n { font-size: 13px; width: 26px; height: 26px; display: grid; place-items: center; border-radius: 50%; }
.day.other .n { color: var(--muted); opacity: .6; }
.day.today .n { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.day.selected { background: var(--accent-soft); }
.ev { font-size: 12px; padding: 1px 6px; border-radius: 4px; background: var(--accent-soft); color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-left: 3px solid var(--accent); }
.ev.allday { background: var(--accent); color: var(--accent-ink); border-left: 0; }
.agenda { list-style: none; margin: 0; padding: 0; }
.agenda li { display: grid; grid-template-columns: 74px 1fr; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); cursor: pointer; }
.agenda .when { font-size: 13px; color: var(--muted); }
.agenda .t { font-weight: 600; }
.agenda-title { font: 650 14px/1.2 var(--font-title); margin: 0; padding: 14px 16px 6px; color: var(--muted); }

/* ---- contacts and notes ---- */
.people { list-style: none; margin: 0; padding: 0; }
.people a { display: flex; gap: 12px; align-items: center; padding: 10px 16px; text-decoration: none; color: inherit; border-bottom: 1px solid var(--line); }
.people a[aria-current=true] { background: var(--accent-soft); }
.people .letter { padding: 6px 16px; font-size: 13px; font-weight: 700; color: var(--muted); background: var(--ground); }
.card-view { padding: 24px 20px; max-width: 640px; }
.card-view h1 { font: 700 26px/1.2 var(--font-title); margin: 12px 0 2px; }
.card-view dl { display: grid; grid-template-columns: 110px 1fr; gap: 10px 14px; margin: 22px 0; }
.card-view dt { color: var(--muted); font-size: 14px; }
.card-view dd { margin: 0; overflow-wrap: anywhere; }
.big-avatar { width: 72px; height: 72px; font-size: 26px; }
.multi .row { margin-bottom: 8px; }
.multi .row select { width: 110px; flex: none; }

.notes-list .note-item { display: block; padding: 12px 16px; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; }
.notes-list .note-item[aria-current=true] { background: var(--accent-soft); }
.notes-list .note-item strong { display: block; }
.notes-list .pin { color: var(--grain); margin-right: 4px; }
.note-edit { display: flex; flex-direction: column; flex: 1; }
.note-edit input { border: 0; font: 700 24px/1.2 var(--font-title); padding: 18px 20px 6px; background: transparent; }
.note-edit textarea { flex: 1; border: 0; padding: 8px 20px 20px; font-size: 16px; background: transparent; resize: none; }
.saved { font-size: 13px; color: var(--muted); }

/* settings */
.settings { padding: 8px 20px 40px; max-width: 720px; }
.settings section { margin: 22px 0; padding-bottom: 22px; border-bottom: 1px solid var(--line); }
.settings h3 { font: 700 17px/1.2 var(--font-title); margin: 0 0 6px; }
.settings p { margin: 0 0 12px; color: var(--muted); }
.tokens { list-style: none; padding: 0; margin: 0 0 12px; }
.tokens li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.secret { font-family: ui-monospace, Menlo, monospace; background: var(--sunken); padding: 10px 12px; border-radius: var(--radius-s); user-select: all; overflow-wrap: anywhere; }

#toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--ink); color: var(--ground); padding: 10px 16px; border-radius: var(--radius-m); z-index: 100;
  transition: opacity .18s, transform .18s; pointer-events: none; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- phone layout: stack navigation + bottom tab bar ---- */
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .rail { display: none; }
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr); background: var(--surface); border-top: 1px solid var(--line);
    padding: 6px 0 calc(6px + var(--safe-b));
  }
  .tabbar a { padding: 4px 0; }
  .panes.mail, .panes.two { grid-template-columns: 1fr; }
  .pane { border-right: 0; }
  .panes > .pane { display: none; }
  .panes[data-level="0"] > .pane:nth-child(1),
  .panes[data-level="1"] > .pane:nth-child(2),
  .panes[data-level="2"] > .pane:nth-child(3) { display: flex; flex-direction: column; }
  .panes.two[data-level="1"] > .pane:nth-child(2) { display: flex; }
  .pane.side { padding-top: calc(10px + var(--safe-t)); }
  .pane-head .back { display: inline-flex; }
  .sheet-backdrop { padding: 0; place-items: end stretch; }
  .sheet { width: 100%; max-height: calc(100% - var(--safe-t) - 12px); border-radius: var(--radius-l) var(--radius-l) 0 0; padding-bottom: var(--safe-b); }
  .cal-grid .ev { display: none; }
  .day { align-items: center; }
  .cal .pane-head h2 { font-size: 19px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .cal .pane-head .label { display: none; }
  .cal .pane-head .btn.primary { width: 36px; padding: 0; }
  .day.has-ev::after { content: ""; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
  .card-view dl { grid-template-columns: 1fr; gap: 2px; }
  .card-view dd { margin-bottom: 10px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
