/* ---- Tokens ------------------------------------------------------------ */

:root {
  --bg: #fbfaf8;
  --surface: #ffffff;
  --sunken: #f3f1ed;
  --line: #e7e3dc;
  --text: #1c1b19;
  --muted: #6f6a62;
  --faint: #a29c92;
  --accent: #2f5bea;
  --accent-soft: color-mix(in oklab, var(--accent) 10%, transparent);
  --select: #e9eefc;
  --clash: #c2410c;
  --ok: #15803d;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 8px 32px rgb(0 0 0 / 0.08);
  --avatar-l: 0.9;
  --avatar-c: 0.06;
  --avatar-text: 0.38;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141413;
    --surface: #1b1b19;
    --sunken: #222220;
    --line: #2e2d2a;
    --text: #ecebe8;
    --muted: #a19d95;
    --faint: #6d6a64;
    --accent: #7b9cff;
    --select: #23293a;
    --clash: #fb923c;
    --ok: #4ade80;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 12px 40px rgb(0 0 0 / 0.5);
    --avatar-l: 0.32;
    --avatar-c: 0.06;
    --avatar-text: 0.88;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #141413;
  --surface: #1b1b19;
  --sunken: #222220;
  --line: #2e2d2a;
  --text: #ecebe8;
  --muted: #a19d95;
  --faint: #6d6a64;
  --accent: #7b9cff;
  --select: #23293a;
  --clash: #fb923c;
  --ok: #4ade80;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 12px 40px rgb(0 0 0 / 0.5);
  --avatar-l: 0.32;
  --avatar-c: 0.06;
  --avatar-text: 0.88;
  color-scheme: dark;
}

/* ---- Base -------------------------------------------------------------- */

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
kbd {
  font: 500 11px/1 var(--mono);
  color: var(--muted);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 2px 5px;
  background: var(--surface);
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- Layout ------------------------------------------------------------ */

#root { height: 100%; }
.app {
  display: grid;
  grid-template-columns: 232px minmax(340px, 420px) 1fr;
  grid-template-rows: minmax(0, 1fr) 28px;
  height: 100%;
}
.app > * { min-height: 0; }
.status { grid-column: 1 / -1; }

/* ---- Sidebar ----------------------------------------------------------- */

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 16px 12px;
  border-right: 1px solid var(--line);
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; padding: 4px 8px; letter-spacing: -0.01em; }
.brand-mark {
  width: 18px; height: 18px; border-radius: 6px;
  background: linear-gradient(135deg, var(--accent), color-mix(in oklab, var(--accent) 40%, #20c997));
}
.compose {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 12px; border-radius: 10px;
  background: var(--text); color: var(--bg); font-weight: 600;
  transition: transform 120ms var(--ease);
}
.compose:active { transform: scale(0.98); }
.compose kbd { background: transparent; color: inherit; border-color: color-mix(in oklab, var(--bg) 35%, transparent); }
.side-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--faint); margin: 0 8px 6px; }
.nav { display: flex; flex-direction: column; gap: 1px; }
.nav-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 8px; border-radius: 7px; color: var(--muted); text-align: left;
}
.nav-item:hover { background: var(--sunken); color: var(--text); }
.nav-item.active { background: var(--sunken); color: var(--text); font-weight: 600; }
.nav-count { font-size: 12px; font-variant-numeric: tabular-nums; color: var(--faint); }
.nav-item.active .nav-count { color: var(--accent); }

.agenda { margin-top: auto; }
.agenda-list { list-style: none; margin: 0; padding: 0 8px; display: flex; flex-direction: column; gap: 6px; }
.agenda-item { display: grid; grid-template-columns: 44px 1fr; gap: 6px; font-size: 13px; padding-left: 8px; border-left: 2px solid var(--line); }
.agenda-time { color: var(--muted); font-variant-numeric: tabular-nums; }
.agenda-item.past { opacity: 0.45; }
.agenda-item.now { border-left-color: var(--accent); }
.agenda-item.now .agenda-title { font-weight: 600; }
.agenda-item.tentative .agenda-title { font-style: italic; }
.agenda-empty { margin: 0 8px; color: var(--muted); font-size: 13px; }

/* ---- List pane --------------------------------------------------------- */

.list-pane { display: flex; flex-direction: column; min-width: 0; border-right: 1px solid var(--line); background: var(--surface); }
.list-head { padding: 14px 16px 10px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.search {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border-radius: 9px; background: var(--sunken); color: var(--muted);
}
.search:focus-within { box-shadow: 0 0 0 2px var(--accent-soft); color: var(--text); }
.search input { flex: 1; border: 0; background: none; outline: none; min-width: 0; }
.search input::-webkit-search-cancel-button { display: none; }
.search-icon { font-size: 16px; line-height: 1; }
.list-title { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.list-title h1 { font-size: 20px; margin: 0; letter-spacing: -0.02em; }
.list-count { font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; }
.brief { margin: 0; font-size: 13px; color: var(--muted); }
.brief strong { color: var(--text); font-weight: 600; }
.brief .clash { color: var(--clash); }

.list-viewport { position: relative; flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.list-spacer { position: relative; }
.list-empty { position: absolute; inset: 40px 16px auto; text-align: center; color: var(--muted); }

.row {
  position: absolute; left: 0; right: 0; top: 0; height: 78px;
  display: flex; gap: 12px; padding: 10px 16px; line-height: 1.35;
  border-bottom: 1px solid color-mix(in oklab, var(--line) 60%, transparent);
  cursor: default; contain: strict;
}
.row:hover { background: color-mix(in oklab, var(--sunken) 60%, transparent); }
.row.selected { background: var(--select); }
.row.selected::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); }
.avatar {
  flex: none; width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center; font-size: 12px; font-weight: 600;
  background: oklch(var(--avatar-l) var(--avatar-c) var(--hue));
  color: oklch(var(--avatar-text) 0.08 var(--hue));
}
.avatar.large { width: 40px; height: 40px; font-size: 14px; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.row-top { display: flex; justify-content: space-between; gap: 8px; }
.row-name, .row-subject, .row-snippet { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-name { color: var(--muted); }
.row-date { flex: none; font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; }
.row-subject { color: var(--muted); }
.row-snippet { font-size: 13px; color: var(--faint); }
.row.unread .row-name, .row.unread .row-subject { color: var(--text); font-weight: 600; }
.row.unread .row-date { color: var(--accent); font-weight: 600; }
.row.starred .row-date::before { content: "★ "; color: #e3a008; }
.row.invite .row-subject::before { content: "◷ "; color: var(--accent); }

/* ---- Reader ------------------------------------------------------------ */

.reader { overflow-y: auto; min-width: 0; }
.reader-empty { height: 100%; display: grid; place-content: center; text-align: center; color: var(--muted); gap: 4px; }
.reader-empty p { margin: 0; }
.reader-empty-title { font-size: 16px; color: var(--text); font-weight: 600; }

.message { max-width: 760px; margin: 0 auto; padding: 16px 40px 64px; animation: enter 160ms var(--ease); }
@keyframes enter { from { opacity: 0; transform: translateY(4px); } }
.toolbar { position: sticky; top: 0; display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 0 12px; background: var(--bg); z-index: 1; }
.action {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 5px 9px; border-radius: 8px; border: 1px solid var(--line); color: var(--muted); font-size: 13px;
}
.action:hover { color: var(--text); background: var(--sunken); }
.action.on { color: var(--accent); border-color: color-mix(in oklab, var(--accent) 40%, var(--line)); }
.action kbd { padding: 1px 4px; font-size: 10px; }
.back { display: none; font-size: 18px; padding: 2px 8px; }
.subject { font-size: 24px; line-height: 1.25; letter-spacing: -0.02em; margin: 12px 0 16px; }
.sender { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.sender-name { font-weight: 600; }
.sender-email { font-size: 13px; color: var(--muted); }
.sender-date { margin-left: auto; font-size: 13px; color: var(--muted); text-align: right; }
.body { font-size: 15px; line-height: 1.65; max-width: 64ch; }
.body p { margin: 0 0 1em; white-space: pre-wrap; }

.invite-card {
  border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 28px;
  background: var(--surface); box-shadow: var(--shadow);
}
.invite-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.invite-title { font-weight: 650; font-size: 16px; }
.invite-when { color: var(--text); }
.invite-where { color: var(--muted); font-size: 13px; }
.choices { display: flex; gap: 0; align-self: flex-start; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.choice { padding: 6px 12px; color: var(--muted); }
.choice + .choice { border-left: 1px solid var(--line); }
.choice:hover { background: var(--sunken); color: var(--text); }
.choice.on { background: var(--accent); color: #fff; }
.strip { margin: 18px 0 8px; }
.strip-track { position: relative; height: 34px; border-radius: 8px; background: var(--sunken); }
.strip-hour { position: absolute; top: -16px; font-size: 10px; color: var(--faint); transform: translateX(-50%); }
.strip-hour:first-child { transform: none; }
.strip-block { position: absolute; top: 7px; height: 20px; border-radius: 5px; background: color-mix(in oklab, var(--muted) 35%, transparent); }
.strip-block.clash { background: color-mix(in oklab, var(--clash) 45%, transparent); }
.strip-block.invite { background: var(--accent); box-shadow: 0 0 0 2px var(--surface); }
.invite-note { margin: 10px 0 0; font-size: 13px; }
.invite-note.ok { color: var(--ok); }
.invite-note.clash { color: var(--clash); }
.invite-meta { margin: 6px 0 0; font-size: 13px; color: var(--muted); }
.invite-people { margin: 12px 0 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 6px; font-size: 12px; }
.invite-people li { padding: 2px 8px; border-radius: 99px; background: var(--sunken); color: var(--muted); }
.invite-people li.accepted { color: var(--ok); }
.invite-people li.declined { text-decoration: line-through; }
.invite-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.invite-actions select { font: inherit; padding: 5px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--text); }
.invite-card.cancelled .invite-title { text-decoration: line-through; }

/* ---- Status bar -------------------------------------------------------- */

.status {
  display: flex; align-items: center; gap: 10px; padding: 0 14px;
  border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums;
  white-space: nowrap; overflow: hidden;
}
.status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.status .dot.off { background: var(--clash); }
.status .sep { width: 1px; height: 12px; background: var(--line); }
.status .grow { flex: 1; }
.link { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); }
.link:hover { color: var(--text); }
.smtp-form { border-top: 1px solid var(--line); margin-top: 16px; padding-top: 16px; }
.smtp-form h3 { font-size: 14px; margin: 0 0 12px; }

/* ---- Overlays ---------------------------------------------------------- */

.overlay {
  position: fixed; inset: 0; z-index: 20; display: grid; justify-items: center; align-items: start;
  padding-top: 14vh; background: color-mix(in oklab, var(--bg) 55%, transparent); backdrop-filter: blur(3px);
  animation: fade 120ms var(--ease);
}
@keyframes fade { from { opacity: 0; } }
.palette, .help {
  width: min(600px, calc(100vw - 32px)); background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--shadow); overflow: hidden;
}
.palette-input { width: 100%; padding: 16px 18px; border: 0; border-bottom: 1px solid var(--line); background: none; font-size: 16px; outline: none; }
.palette-list { list-style: none; margin: 0; padding: 6px; max-height: 50vh; overflow-y: auto; }
.palette-item { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 8px; cursor: default; }
.palette-item.active { background: var(--select); }
.palette-section { width: 56px; font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: 0.05em; }
.palette-label { flex: 1; }
.help { padding: 20px 24px; }
.help h2 { margin: 0 0 14px; font-size: 16px; }
.help dl { display: grid; grid-template-columns: max-content 1fr; gap: 9px 18px; margin: 0; align-items: center; }
.help dd { margin: 0; color: var(--muted); }

.toast-host { position: fixed; left: 50%; bottom: 44px; transform: translateX(-50%); z-index: 30; }
.toast {
  display: flex; align-items: center; gap: 14px; padding: 10px 12px 10px 16px; border-radius: 12px;
  background: var(--text); color: var(--bg); box-shadow: var(--shadow); animation: rise 180ms var(--ease);
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.toast-undo { display: inline-flex; gap: 8px; align-items: center; font-weight: 600; color: inherit; }
.toast-undo kbd { background: transparent; color: inherit; border-color: color-mix(in oklab, var(--bg) 35%, transparent); }

.composer-host { position: fixed; right: 24px; bottom: 44px; z-index: 15; }
.composer {
  width: min(520px, calc(100vw - 32px)); display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
  animation: rise 180ms var(--ease);
}
.composer-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; font-weight: 600; border-bottom: 1px solid var(--line); }
.icon { font-size: 18px; color: var(--muted); padding: 0 4px; }
.composer-field { border: 0; border-bottom: 1px solid var(--line); padding: 10px 14px; background: none; outline: none; }
.composer-body { border: 0; padding: 12px 14px; min-height: 220px; resize: vertical; background: none; outline: none; line-height: 1.55; }
.composer-foot { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--line); }
.primary { display: inline-flex; gap: 10px; align-items: center; padding: 7px 14px; border-radius: 9px; background: var(--accent); color: #fff; font-weight: 600; }
.primary kbd { background: transparent; color: inherit; border-color: rgb(255 255 255 / 0.4); }
.hint { font-size: 12px; color: var(--faint); }

/* ---- Small screens ----------------------------------------------------- */

@media (max-width: 1100px) {
  .app { grid-template-columns: 200px minmax(300px, 360px) 1fr; }
  .message { padding: 16px 24px 64px; }
}

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 1fr 28px; }
  .sidebar { display: none; }
  .reader { display: none; }
  .app.reading .list-pane { display: none; }
  .app.reading .reader { display: block; }
  .back { display: inline-block; }
  .message { padding: 8px 16px 48px; }
  .status .sep, .status span:nth-child(n + 5):not(.grow) { display: none; }
  .composer-host { right: 16px; left: 16px; }
}

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

/* ---- Live mail and settings ------------------------------------------- */

.badge {
  font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 1px 7px; margin-left: 2px;
}
.folders .nav-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-footer {
  margin-top: auto; display: flex; align-items: center; gap: 8px;
  padding: 10px 8px 0; border-top: 1px solid var(--line);
}
.account-footer-text { flex: 1; min-width: 0; }
.account-footer-email { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-footer-status { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-footer-status.error, .account-status.error { color: var(--clash); }
.gear { font-size: 16px; }
.status .dot.busy { background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

.body-loading { color: var(--muted); }
.body:has(.mail-frame) { max-width: none; }
.mail-frame { display: block; width: 100%; min-height: 120px; border: 0; border-radius: 10px; background: #fff; color-scheme: light; }
.body-bar { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; font-size: 12px; color: var(--muted); margin: 0 0 12px; }
.body-bar .view-toggle { margin-left: auto; }
.body-bar .link { font-size: 12px; text-decoration: underline; }
.body-error { color: var(--clash); }
.attachments { list-style: none; padding: 0; margin: 0 0 20px; display: flex; flex-wrap: wrap; gap: 8px; }
.attachment {
  display: flex; gap: 8px; align-items: baseline; font-size: 13px;
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; background: var(--surface);
}
.attachment-size { color: var(--faint); font-size: 12px; }
a.attachment-name { color: var(--text); text-decoration: none; }
a.attachment-name:hover { text-decoration: underline; }
.attachment-download { color: var(--muted); text-decoration: none; padding: 0 2px; }
.attachment-download:hover { color: var(--text); }
.composer-files { list-style: none; margin: 0; padding: 8px 14px 0; display: flex; flex-wrap: wrap; gap: 6px; }
.composer-files .attachment { align-items: center; padding: 4px 4px 4px 10px; }
.composer-files .attachment.forwarded { padding: 4px 10px; color: var(--muted); }
.composer-files .attachment.uploading { opacity: 0.6; }
.composer-files .attachment.failed .attachment-size { color: var(--clash); }
.composer.dragging { outline: 2px dashed var(--accent); outline-offset: -6px; }

.settings-overlay { padding-top: 8vh; overflow-y: auto; }
.settings {
  width: min(640px, calc(100vw - 32px)); background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; box-shadow: var(--shadow); padding: 22px 24px 20px; margin-bottom: 8vh;
}
.settings-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.settings-head h2 { margin: 0; font-size: 20px; letter-spacing: -0.01em; }
.settings-intro { margin: 0 0 18px; color: var(--muted); }
.account-list { list-style: none; margin: 10px 0 18px; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.account-row {
  display: flex; gap: 14px; justify-content: space-between; align-items: center;
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
}
.account-main { min-width: 0; flex: 1; }
.account-email { font-weight: 600; }
.account-server { font-size: 12px; color: var(--faint); }
.account-status { font-size: 13px; color: var(--muted); margin-top: 2px; }
.account-status.syncing { color: var(--accent); }
.account-buttons { display: flex; gap: 8px; flex: 0 1 300px; flex-wrap: wrap; justify-content: flex-end; align-content: flex-start; }

.account-form { display: flex; flex-direction: column; gap: 14px; margin-top: 8px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form-row { display: grid; grid-template-columns: 1fr 96px; gap: 14px; grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field-label { font-size: 12px; font-weight: 600; color: var(--muted); }
.field-hint { font-size: 11.5px; color: var(--faint); }
.field input, .field select {
  border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; background: var(--bg); color: var(--text);
  outline: none; min-width: 0;
}
.field input:focus, .field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-result { margin: 0; font-size: 13px; padding: 8px 10px; border-radius: 8px; }
.form-result.ok { color: var(--ok); background: color-mix(in oklab, var(--ok) 10%, transparent); }
.form-result.error { color: var(--clash); background: color-mix(in oklab, var(--clash) 10%, transparent); }
.form-result.busy { color: var(--muted); background: var(--sunken); }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; }
.form-note { margin: 0; font-size: 12px; color: var(--faint); }
.form-grid > .form-note { grid-column: 1 / -1; }
.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.choice {
  display: flex; align-items: center; gap: 7px; padding: 7px 12px; border: 1px solid var(--line); border-radius: 9px;
  font-size: 13px; cursor: pointer;
}
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.secondary {
  padding: 7px 13px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); font-weight: 500;
}
.secondary:hover:not(:disabled) { background: var(--sunken); }
.danger { padding: 7px 13px; border-radius: 9px; color: var(--clash); border: 1px solid transparent; }
.danger:hover, .danger.confirm { border-color: color-mix(in oklab, var(--clash) 40%, transparent); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
.add-account { align-self: flex-start; }
.demo-link { margin-top: 14px; font-size: 13px; text-decoration: underline; text-underline-offset: 3px; }

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .account-row { flex-direction: column; align-items: stretch; }
}
.row.has-attachment .row-subject::after { content: " \1F4CE"; font-size: 11px; filter: grayscale(1); opacity: 0.7; }

/* ---- Calendar ---------------------------------------------------------- */

.app.calendar-mode .calendar { grid-column: 2 / 4; }
.calendar { position: relative; display: grid; grid-template-rows: auto auto minmax(0, 1fr); background: var(--surface); border-left: 1px solid var(--line); min-width: 0; }
.cal-head { display: flex; align-items: center; gap: 16px; padding: 14px 20px 10px; flex-wrap: wrap; }
.cal-head h1 { font-size: 20px; margin: 0; font-weight: 600; min-width: 12ch; }
.cal-nav { display: flex; gap: 6px; }
.cal-nav button { padding: 4px 12px; }
.cal-error { color: var(--clash); font-size: 12px; margin: 0; }
.cal-days, .cal-grid { display: grid; grid-template-columns: 56px repeat(7, minmax(0, 1fr)); }
.cal-days { border-bottom: 1px solid var(--line); padding-right: var(--scrollbar, 0); }
.cal-day-head { padding: 6px 6px 8px; border-left: 1px solid var(--line); min-width: 0; }
.cal-weekday { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.cal-date { display: inline-block; font-size: 20px; font-weight: 500; line-height: 32px; min-width: 32px; text-align: center; border-radius: 16px; margin-left: -4px; }
.cal-day-head.today .cal-date { background: var(--accent); color: #fff; }
.cal-all-day { display: flex; flex-direction: column; gap: 2px; margin-top: 4px; min-height: 22px; cursor: cell; border-radius: 4px; }
.cal-all-day:hover { background: var(--sunken); }
.cal-all-day .cal-chip { cursor: pointer; }
.cal-chip { all: unset; cursor: pointer; font-size: 12px; padding: 1px 6px; border-radius: 4px; background: color-mix(in srgb, var(--event) 22%, transparent); border-left: 3px solid var(--event); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-scroll { overflow-y: auto; min-height: 0; }
.cal-hours { border-right: 1px solid var(--line); }
.cal-hour { font-size: 11px; color: var(--faint); text-align: right; padding-right: 8px; transform: translateY(-7px); box-sizing: border-box; }
.cal-day { position: relative; border-left: 1px solid var(--line); background-image: linear-gradient(var(--line) 1px, transparent 1px); background-size: 100% 48px; min-width: 0; }
.cal-day.today { background-color: color-mix(in srgb, var(--accent) 4%, transparent); }
.cal-now { position: absolute; left: -1px; right: 0; height: 2px; background: var(--clash); z-index: 2; }
.cal-now::before { content: ""; position: absolute; left: -4px; top: -3px; width: 8px; height: 8px; border-radius: 4px; background: var(--clash); }
.cal-event {
  all: unset; position: absolute; box-sizing: border-box; cursor: pointer; overflow: hidden; z-index: 1;
  display: flex; flex-direction: column; padding: 3px 6px; border-radius: 5px; font-size: 12px; line-height: 1.3;
  background: color-mix(in srgb, var(--event) 20%, var(--surface)); border-left: 3px solid var(--event); color: var(--text);
}
.cal-event:hover { background: color-mix(in srgb, var(--event) 30%, var(--surface)); }
.cal-event.movable { touch-action: none; }
.cal-event.dragging { opacity: 0.35; }
.cal-resize { position: absolute; left: 0; right: 0; bottom: 0; height: 6px; cursor: ns-resize; }
.cal-columns { display: contents; }
.cal-grid { position: relative; touch-action: pan-y; }
.cal-day { cursor: cell; }
.cal-ghost {
  position: absolute; z-index: 3; box-sizing: border-box; pointer-events: none; padding: 3px 6px; margin: 0 2px;
  max-width: calc((100% - 56px) / 7 - 4px); border-radius: 5px; font-size: 12px; font-weight: 600;
  background: color-mix(in srgb, var(--event) 35%, var(--surface)); border-left: 3px solid var(--event);
  box-shadow: 0 6px 18px rgb(0 0 0 / 0.18);
}
.cal-event.selected { outline: 2px solid var(--event); outline-offset: 1px; }
.cal-event.free { background: transparent; border-style: dashed; }
/* Meetings not (yet) said yes to: lighter; declined ones step back further. */
.cal-event.unsure { background: repeating-linear-gradient(135deg, color-mix(in srgb, var(--event) 14%, var(--surface)) 0 6px, var(--surface) 6px 12px); }
.cal-event.declined { opacity: 0.5; background: var(--surface); }
.cal-event.declined .cal-event-title { text-decoration: line-through; }
.cal-going { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 12px 0; }
.cal-event.short { flex-direction: row; gap: 6px; padding-top: 1px; }
.cal-event-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-event-time, .cal-event-place { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-details {
  position: absolute; top: 12px; right: 12px; bottom: 12px; width: min(340px, 90%); z-index: 5; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px;
  box-shadow: 0 12px 32px rgb(0 0 0 / 0.14);
}
.cal-details-head { display: flex; align-items: flex-start; gap: 10px; }
.cal-details-head h2 { flex: 1; font-size: 17px; margin: 0; line-height: 1.3; }
.cal-dot { width: 12px; height: 12px; border-radius: 4px; background: var(--event); margin-top: 4px; flex: none; }
.cal-when, .cal-where, .cal-which { margin: 10px 0 0; font-size: 14px; }
.cal-which { color: var(--muted); font-size: 12px; }
.cal-people { list-style: none; padding: 0; margin: 14px 0 0; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.cal-person { display: flex; justify-content: space-between; gap: 8px; }
.cal-status { color: var(--muted); font-size: 12px; }
.cal-person.declined span:first-child { text-decoration: line-through; color: var(--muted); }
.cal-notes { white-space: pre-wrap; font-size: 13px; color: var(--muted); margin: 14px 0 0; }
.cal-actions { margin-top: 18px; justify-content: space-between; }
.cal-choice { margin-top: 16px; padding: 12px; border-radius: 10px; background: var(--sunken); }
.cal-choice p { margin: 0 0 10px; font-size: 13px; }
.cal-editor { display: flex; flex-direction: column; gap: 12px; }
.cal-editor .cal-dot { margin-top: 11px; }
.cal-title-input {
  flex: 1; min-width: 0; font-size: 17px; font-weight: 600; border: none; border-bottom: 2px solid var(--line);
  background: transparent; padding: 4px 0; outline: none;
}
.cal-title-input:focus { border-bottom-color: var(--accent); }
.cal-check { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.cal-times { display: grid; grid-template-columns: auto 1fr auto; gap: 6px 8px; align-items: center; }
.cal-times input, .cal-editor textarea, .cal-editor select {
  border: 1px solid var(--line); border-radius: 9px; padding: 7px 9px; background: var(--bg); color: var(--text);
  outline: none; min-width: 0; font: inherit; font-size: 13px;
}
.cal-times input[hidden] { display: none; }
.cal-times input:focus, .cal-editor textarea:focus, .cal-editor select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.cal-editor textarea { resize: vertical; }
.cal-editor .form-actions { margin-top: 4px; }
.cal-setup { grid-row: 1 / -1; align-self: center; justify-self: center; max-width: 380px; text-align: center; padding: 24px; }
.cal-setup p { color: var(--muted); }
.live-agenda { margin: 4px 0 0; padding: 0 10px; }
.danger-link { color: var(--clash); margin-right: auto; }
@media (max-width: 900px) {
  .app.calendar-mode .calendar { grid-column: 1 / -1; grid-row: 1; }
}

/* Calendar server: devices and their app passwords */
.cal-setup-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.dav-intro p, .dav-connect p { margin: 0 0 10px; font-size: 13px; color: var(--muted); }
.dav-connect { display: flex; flex-direction: column; gap: 6px; }
.dav-row { display: grid; grid-template-columns: 90px 1fr; align-items: baseline; gap: 8px; }
.dav-value { font-size: 12.5px; user-select: all; overflow-wrap: anywhere; }
.dav-password { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.dav-secret { font-size: 15px; letter-spacing: 0.04em; user-select: all; }
.device-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.device { display: flex; align-items: baseline; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.device-name { font-weight: 500; }
.device .field-hint { flex: 1; }
.device-add { display: flex; gap: 8px; margin-top: 10px; }
.device-add input { flex: 1; }
.dav-import { display: flex; flex-direction: column; gap: 6px; }

/* ---- Contacts ---------------------------------------------------------- */

.app.calendar-mode .contacts { grid-column: 2 / 4; }
.contacts { display: grid; grid-template-columns: minmax(260px, 340px) minmax(0, 1fr); min-width: 0; min-height: 0; background: var(--surface); border-left: 1px solid var(--line); }
.contact-list-pane { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); }
.contact-tools { display: flex; gap: 8px; margin-top: 8px; }
.contact-tools button { padding: 5px 12px; }
.contact-list { list-style: none; margin: 0; padding: 4px 8px 16px; overflow-y: auto; flex: 1; }
.contact-row { all: unset; box-sizing: border-box; width: 100%; display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px; cursor: pointer; }
.contact-row:hover { background: var(--sunken); }
.contact-row.selected { background: var(--accent-soft); }
.contact-row:focus-visible { outline: 2px solid var(--accent); }
.contact-row-text { display: flex; flex-direction: column; min-width: 0; }
.contact-row-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-row-sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-empty { padding: 24px 10px; color: var(--muted); text-align: center; }
.contact-detail { overflow-y: auto; min-width: 0; padding: 24px clamp(16px, 4vw, 48px); }
.contact-card, .contact-editor { max-width: 560px; display: flex; flex-direction: column; gap: 12px; }
.contact-head { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; }
.contact-head h2 { margin: 0; font-size: 20px; }
.contact-head .icon { margin-left: auto; }
.contact-head .avatar.large { width: 56px; height: 56px; font-size: 19px; }
.contact-org { margin: 2px 0 0; color: var(--muted); }
.contact-field { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 12px; align-items: baseline; padding: 6px 0; border-bottom: 1px solid var(--line); }
.contact-field a, .contact-field .link { color: var(--accent); overflow-wrap: anywhere; text-align: left; }
.contact-address, .contact-note { white-space: pre-wrap; }
.contact-rows { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.contact-rows legend { margin-bottom: 6px; }
.contact-address-edit { display: flex; flex-direction: column; gap: 6px; width: 100%; }
.contact-row-edit { display: grid; grid-template-columns: 110px minmax(0, 1fr) auto; gap: 8px; width: 100%; align-items: center; }
.contact-row-edit.two { grid-template-columns: 1fr 1fr; }
.contact-row-edit.three { grid-template-columns: 110px 1fr 1fr; padding-right: 32px; }
.contact-editor input, .contact-editor select, .contact-editor textarea {
  border: 1px solid var(--line); border-radius: 9px; padding: 7px 9px; background: var(--bg); color: var(--text);
  outline: none; min-width: 0; font: inherit; font-size: 13px;
}
.contact-editor input:focus, .contact-editor select:focus, .contact-editor textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
@media (max-width: 900px) {
  .app.calendar-mode .contacts { grid-column: 1 / -1; grid-row: 1; }
  .contacts { grid-template-columns: 1fr; }
  .contacts:has(.contact-card, .contact-editor) .contact-list-pane { display: none; }
}

/* Address suggestions under To, Cc and Guests */
.addr { position: relative; display: block; }
.addr > input { width: 100%; box-sizing: border-box; }
.addr-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 2px); z-index: 20; list-style: none; margin: 0; padding: 4px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
}
.addr-item { display: flex; gap: 8px; align-items: baseline; padding: 6px 8px; border-radius: 7px; cursor: pointer; font-size: 13px; }
.addr-item.on, .addr-item:hover { background: var(--accent-soft); }
.addr-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.addr-email { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.addr-known { margin-left: auto; color: var(--accent); font-size: 8px; }

/* ---- Signing in -------------------------------------------------------- */

.signin { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--bg); box-sizing: border-box; }
.signin-card { width: min(360px, 100%); display: flex; flex-direction: column; gap: 12px; padding: 28px; border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); border: 1px solid var(--line); }
.signin-card .brand { font-size: 18px; margin-bottom: 4px; }
.signin-note { margin: 0; color: var(--muted); font-size: 14px; }
.signin-card input { border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; background: var(--bg); color: var(--text); font: inherit; outline: none; }
.signin-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.signin-error { margin: 0; color: var(--clash); font-size: 13px; }
.signin-card button { padding: 10px; }

.settings-backup { margin: 14px 0 0; font-size: 12.5px; color: var(--muted); }
.settings-backup:empty { display: none; }
.settings-backup-error { color: var(--clash); }
