:root {
  --bg: #f6f6f4;
  --panel: #ffffff;
  --text: #1d1d1b;
  --muted: #6b6b66;
  --line: #e2e2dd;
  --accent: #2f5d8a;
  --accent-text: #ffffff;
  --warn: #a15c00;
  --error: #b3261e;
  --ok: #2e7d32;
  --select: #e8eff7;
  --radius: 8px;
  --top: 52px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615;
    --panel: #1f1f1d;
    --text: #ececea;
    --muted: #9a9a93;
    --line: #33332f;
    --accent: #7fb0e0;
    --accent-text: #0e1a26;
    --warn: #e0a050;
    --error: #f2857d;
    --ok: #7fcf86;
    --select: #24303c;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 8px; }
h2 { font-size: 16px; margin: 0; }
h3 { font-size: 14px; margin: 16px 0 6px; color: var(--muted); }
pre { white-space: pre-wrap; word-wrap: break-word; font: inherit; margin: 0; }
[hidden] { display: none !important; }

button, .button, input, textarea, select {
  font: inherit; color: inherit; background: var(--panel);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px;
}
button, .button { cursor: pointer; display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.button:hover { text-decoration: none; }
button:disabled { opacity: .5; cursor: default; }
button.primary, .button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.ghost { background: transparent; }
button.small, .small { font-size: 12px; padding: 3px 8px; }
button.link { background: none; border: none; color: var(--accent); padding: 0 4px; }
.button.on { border-color: var(--accent); color: var(--accent); }
input, textarea, select { width: 100%; }
textarea { resize: vertical; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.muted { color: var(--muted); }
.error { color: var(--error); }
.ok { color: var(--ok); }
.pad { padding: 12px; }
.empty { color: var(--muted); padding: 24px 12px; text-align: center; }
.untrusted { color: var(--warn); font-size: 12px; }
.plain { list-style: none; margin: 0; padding: 0; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.row > .field { flex: 1; min-width: 120px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 12px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 6px; }
.check input { width: auto; }
.toolbar { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.toolbar select { width: auto; }
.count { background: var(--accent); color: var(--accent-text); border-radius: 9px; padding: 0 6px; font-size: 11px; margin-left: auto; }
.tag { font-size: 11px; border: 1px solid var(--line); border-radius: 9px; padding: 0 6px; color: var(--muted); margin-right: 6px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin: 12px 0; }
.card h3 { margin-top: 0; }
.notice { border-left: 3px solid var(--warn); padding-left: 10px; margin-top: 10px; }
.secret { display: flex; gap: 8px; align-items: center; background: var(--bg); border-radius: 6px; padding: 6px 8px; margin: 6px 0; }
.secret code { flex: 1; overflow-wrap: anywhere; font-size: 12px; }
.narrow { max-width: 760px; margin: 0 auto; padding: 16px; }

.badge-demo { background: var(--warn); color: #fff; border-radius: 10px; padding: 1px 8px; font-size: 12px; font-weight: 600; display: inline-block; }

.gate { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.gate-card { width: 100%; max-width: 380px; }
.gate-card .badge-demo { margin: 0 0 12px; }

.shell {
  display: grid; height: 100%;
  grid-template-columns: 180px 1fr;
  grid-template-rows: var(--top) 1fr;
  grid-template-areas: "top top" "side view";
}
.shell.with-assistant { grid-template-columns: 180px 1fr 380px; grid-template-areas: "top top top" "side view assistant"; }
.top { grid-area: top; display: flex; align-items: center; gap: 10px; padding: 0 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; color: var(--text); }
.search { flex: 1; max-width: 560px; margin-left: 12px; }
.side { grid-area: side; display: flex; flex-direction: column; padding: 8px; gap: 2px; border-right: 1px solid var(--line); overflow: auto; }
.side a { display: flex; align-items: center; padding: 7px 10px; border-radius: 6px; color: var(--text); }
.side a.on { background: var(--select); color: var(--accent); font-weight: 600; }
.side a:hover { text-decoration: none; background: var(--select); }
.view { grid-area: view; overflow: auto; min-width: 0; }
.route { display: flow-root; height: 100%; min-height: 0; }
.assistant { grid-area: assistant; display: flex; flex-direction: column; border-left: 1px solid var(--line); background: var(--panel); min-height: 0; }

.pane-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.back { display: none; }

.mail-layout, .contacts-layout, .files-layout { display: grid; height: 100%; min-height: 0; }
.mail-layout { grid-template-columns: 170px minmax(260px, 360px) 1fr; }
.contacts-layout, .files-layout { grid-template-columns: minmax(260px, 380px) 1fr; }
.box-pane { border-right: 1px solid var(--line); overflow: auto; padding: 8px; }
.boxes { list-style: none; margin: 0; padding: 0; }
.boxes a { display: flex; padding: 6px 8px; border-radius: 6px; color: var(--text); }
.boxes a.on { background: var(--select); font-weight: 600; }
.list-pane { border-right: 1px solid var(--line); overflow: auto; min-height: 0; }
.list-pane.over { outline: 2px dashed var(--accent); outline-offset: -6px; }
.reader-pane { overflow: auto; min-width: 0; padding-bottom: 24px; }
.reader-pane > * { margin-left: 12px; margin-right: 12px; }
.reader-pane > .pane-head { margin: 0; }
.messages { list-style: none; margin: 0; padding: 0; }
.row { content-visibility: auto; contain-intrinsic-size: auto 64px; }
.messages .row { display: block; border-bottom: 1px solid var(--line); }
.messages .row a { display: block; padding: 8px 12px; color: var(--text); }
.messages .row a:hover { text-decoration: none; background: var(--select); }
.messages .row.on a { background: var(--select); }
.row-top { display: flex; justify-content: space-between; gap: 8px; }
.from { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.date { color: var(--muted); font-size: 12px; white-space: nowrap; }
.subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unseen .from, .unseen .subject { font-weight: 650; }
.flag { color: var(--warn); }
.sentinel { height: 1px; }
.subject-line { flex: 1; }
.mail { border-bottom: 1px solid var(--line); padding: 10px 0; }
.mail summary { cursor: pointer; }
.meta { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 8px 0; font-size: 13px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; overflow-wrap: anywhere; }
.mail-frame { width: 100%; height: 60vh; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.mail-text { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 10px; max-height: 60vh; overflow: auto; }
.attachments { padding-left: 0; list-style: none; }
.reader-pane .toolbar { padding: 8px 0; }

.calendar { display: flex; flex-direction: column; height: 100%; }
.week { display: flex; flex-direction: column; flex: 1; min-height: 520px; padding: 0 8px 8px; }
.week-head, .week-allday, .week-body { display: grid; grid-template-columns: 44px repeat(7, 1fr); }
.week-head span { text-align: center; padding: 6px 0; font-size: 12px; color: var(--muted); }
.week-head .today { color: var(--accent); font-weight: 700; }
.week-allday > div { border-left: 1px solid var(--line); min-height: 26px; padding: 2px; }
.week-body { flex: 1; border-top: 1px solid var(--line); }
.hours { display: flex; flex-direction: column; }
.hours span { flex: 1; font-size: 11px; color: var(--muted); border-top: 1px solid transparent; }
.day-col { position: relative; border-left: 1px solid var(--line); background: repeating-linear-gradient(to bottom, transparent 0, transparent calc(100% / 14 - 1px), var(--line) calc(100% / 14 - 1px), var(--line) calc(100% / 14)); }
.event { display: block; width: 100%; text-align: left; font-size: 12px; padding: 2px 4px; border-radius: 4px; background: var(--select); border: 1px solid var(--accent); color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.day-col .event { position: absolute; left: 2px; right: 2px; width: auto; white-space: normal; }
.event.invitation { border-style: dashed; }
.event.cancelled { text-decoration: line-through; opacity: .6; }
.agenda { padding: 0 16px 16px; }
.agenda h3 { text-transform: capitalize; }
.agenda-item { width: 100%; justify-content: flex-start; gap: 12px; margin: 2px 0; }
.agenda-item .time { color: var(--muted); min-width: 110px; }

.contact-card > * { margin-left: 0; }
.file-preview .preview-image { max-width: 100%; max-height: 60vh; border-radius: 6px; border: 1px solid var(--line); }
.file-preview .preview-pdf { width: 100%; height: 70vh; border: 1px solid var(--line); border-radius: 6px; }
.crumbs { font-weight: 600; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }
.chip { border: 1px solid var(--line); border-radius: 14px; padding: 3px 10px; color: var(--text); }
.chip.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.results { list-style: none; padding: 0; margin: 0; }
.results li a { display: block; padding: 10px 4px; border-bottom: 1px solid var(--line); color: var(--text); }
.results li a:hover { background: var(--select); text-decoration: none; }
.results .title { font-weight: 600; }
.results .date { float: right; }

.settings { border-collapse: collapse; width: 100%; }
.settings th { text-align: left; font-weight: 500; color: var(--muted); padding: 4px 12px 4px 0; vertical-align: top; width: 38%; }
.settings td { padding: 4px 0; overflow-wrap: anywhere; }
.device { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.approval header { margin-bottom: 8px; }
.approval .decision { margin-top: 8px; }

.chat { flex: 1; overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.bubble { white-space: pre-wrap; padding: 8px 10px; border-radius: 10px; max-width: 92%; }
.bubble.user { align-self: flex-end; background: var(--select); }
.bubble.assistant { align-self: flex-start; background: var(--bg); }
.bubble.error { color: var(--error); }
.steps { list-style: none; margin: 0; padding: 0; font-size: 12px; }
.ask { display: flex; gap: 6px; padding: 10px; border-top: 1px solid var(--line); }
.ask textarea { flex: 1; min-height: 44px; }

.modal { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--text); padding: 16px; width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 32px); }
.modal::backdrop { background: rgb(0 0 0 / .35); }
.modal h2 { margin-bottom: 12px; }
.modal footer { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }

.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 50; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: var(--text); color: var(--bg); padding: 8px 12px; border-radius: 8px; display: flex; gap: 8px; align-items: center; box-shadow: 0 2px 10px rgb(0 0 0 / .2); }
.toast .link { color: var(--bg); text-decoration: underline; font-weight: 600; }
.toast.error { background: var(--error); color: #fff; }

@media (max-width: 1100px) {
  .shell.with-assistant { grid-template-columns: 180px 1fr; grid-template-areas: "top top" "side view"; }
  .shell.with-assistant .assistant { position: fixed; inset: var(--top) 0 0 auto; width: min(420px, 100vw); z-index: 20; box-shadow: -4px 0 16px rgb(0 0 0 / .15); }
  .mail-layout { grid-template-columns: minmax(260px, 360px) 1fr; }
  .box-pane { display: none; }
}

@media (max-width: 760px) {
  :root { --top: 96px; }
  .shell, .shell.with-assistant { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; grid-template-areas: "top" "view" "side"; }
  .top { flex-wrap: wrap; padding: 8px 12px; gap: 8px; }
  .search { order: 5; flex-basis: 100%; margin: 0; max-width: none; }
  .side { flex-direction: row; border-right: none; border-top: 1px solid var(--line); overflow-x: auto; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); background: var(--panel); }
  .side a { flex: none; font-size: 13px; }
  .mail-layout, .contacts-layout, .files-layout { grid-template-columns: 1fr; }
  .mail-layout .box-pane { display: block; border-right: none; border-bottom: 1px solid var(--line); max-height: 30vh; }
  .reading .box-pane, .reading .list-pane { display: none; }
  .mail-layout:not(.reading) .reader-pane, .contacts-layout:not(.reading) .reader-pane, .files-layout:not(.reading) .reader-pane { display: none; }
  .back { display: inline; }
  .list-pane { border-right: none; }
  .week-head, .week-allday, .week-body { grid-template-columns: 30px repeat(7, minmax(44px, 1fr)); }
  .week { overflow-x: auto; }
  .shell.with-assistant .assistant { inset: 0; width: 100vw; }
}
