/* Material 3 inspired tokens (blue baseline), light and dark. */
:root {
  --primary: #3a5ba9; --on-primary: #fff;
  --primary-container: #dae2ff; --on-primary-container: #001946;
  --secondary-container: #dce2f9; --on-secondary-container: #141b2c;
  --surface: #f9f9ff; --surface-dim: #d9d9e0;
  --surface-1: #f3f3fa; --surface-2: #ededf4; --surface-3: #e7e8ee;
  --on-surface: #191c20; --on-surface-variant: #44474f;
  --outline: #757780; --outline-variant: #c5c6d0;
  --error: #ba1a1a;
  --radius: 16px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --primary: #b1c5ff; --on-primary: #002c70;
    --primary-container: #1f4290; --on-primary-container: #dae2ff;
    --secondary-container: #3f4759; --on-secondary-container: #dce2f9;
    --surface: #111318; --surface-dim: #111318;
    --surface-1: #191b20; --surface-2: #1d2024; --surface-3: #282a2f;
    --on-surface: #e2e2e9; --on-surface-variant: #c5c6d0;
    --outline: #8f9099; --outline-variant: #44474f;
    --error: #ffb4ab;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
/* No double-tap zoom on iOS (pinch zoom still works). */
html, button, a, input, label, .item { touch-action: manipulation; }
body {
  margin: 0; background: var(--surface); color: var(--on-surface);
  font: 400 15px/1.5 "Roboto Flex", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
}
[hidden] { display: none !important; }
.material-symbols-rounded { font-size: 22px; line-height: 1; font-variation-settings: "FILL" 0, "wght" 400; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
input { font: inherit; color: inherit; }
.muted { color: var(--on-surface-variant); }
.small { font-size: 13px; }
.strong { font-weight: 600; }
.error { color: var(--error); min-height: 1.2em; margin: 0; }

/* buttons */
.filled, .tonal, .text {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 22px; border-radius: 999px; font-weight: 500;
}
.filled { background: var(--primary); color: var(--on-primary); }
.tonal { background: var(--secondary-container); color: var(--on-secondary-container); }
.text { color: var(--primary); height: 40px; padding: 0 12px; }
.filled:disabled { opacity: .5; }
.icon-btn { width: 44px; height: 44px; border-radius: 999px; display: grid; place-items: center; color: var(--on-surface-variant); }
.icon-btn:hover, .text:hover { background: color-mix(in srgb, var(--on-surface) 8%, transparent); }

/* sign-in screens */
.screen.center { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.card { background: var(--surface-1); border-radius: 28px; padding: 32px; }
.hero { width: min(420px, 100%); display: flex; flex-direction: column; gap: 14px; text-align: center; }
.hero h1 { margin: 4px 0 0; font-size: 26px; font-weight: 500; }
.hero p { margin: 0; }
.logo { width: 64px; height: 64px; margin: 0 auto; border-radius: 20px; display: grid; place-items: center; background: var(--primary-container); color: var(--on-primary-container); }
.logo .material-symbols-rounded { font-size: 34px; }
.field { display: flex; flex-direction: column; text-align: left; gap: 4px; font-size: 13px; color: var(--on-surface-variant); }
.field input { height: 52px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--outline); background: transparent; font-size: 16px; }
.field input:focus { outline: 2px solid var(--primary); border-color: transparent; }

.check { display: flex; gap: 12px; align-items: flex-start; text-align: left; font-size: 14px; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--primary); flex: none; }
#librus-remembered { display: flex; align-items: center; gap: 6px; margin: 0; }
#librus-remembered .material-symbols-rounded { font-size: 16px; }

/* app layout */
.app { height: 100%; display: grid; grid-template-columns: 256px 1fr; grid-template-rows: 64px 1fr; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; padding: 0 12px 0 16px; }
.brand { display: flex; align-items: center; gap: 10px; width: 232px; font-size: 20px; font-weight: 500; }
.brand .material-symbols-rounded { color: var(--primary); font-size: 28px; font-variation-settings: "FILL" 1; }
.search { flex: 1; min-width: 0; max-width: 720px; height: 48px; display: flex; align-items: center; gap: 10px; padding: 0 16px; border-radius: 999px; background: var(--surface-3); color: var(--on-surface-variant); }
.search input { flex: 1; min-width: 0; width: 100%; border: 0; background: transparent; outline: 0; font-size: 16px; color: var(--on-surface); }
.topbar > button { flex: none; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--primary); color: var(--on-primary); font-weight: 600; font-size: 14px; flex: none; }
.avatar.big { width: 42px; height: 42px; font-size: 17px; }

.drawer { padding: 8px 12px; display: flex; flex-direction: column; gap: 2px; }
.nav-item { height: 48px; display: flex; align-items: center; gap: 14px; padding: 0 16px; border-radius: 999px; font-weight: 500; color: var(--on-surface-variant); text-align: left; }
.nav-item:hover { background: color-mix(in srgb, var(--on-surface) 8%, transparent); }
.nav-item.active { background: var(--secondary-container); color: var(--on-secondary-container); }
.nav-item.active .material-symbols-rounded { font-variation-settings: "FILL" 1; }
.badge { margin-left: auto; font-size: 13px; font-weight: 600; }
.drawer-foot { margin-top: auto; padding: 16px 8px; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }

.panes { display: grid; grid-template-columns: minmax(320px, 440px) minmax(0, 1fr); gap: 12px; padding: 0 16px 16px 0; min-height: 0; }
.list-pane, .read-pane { background: var(--surface-1); border-radius: var(--radius); overflow: auto; min-height: 0; }
.list-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: baseline; justify-content: space-between; padding: 16px 20px 8px; background: var(--surface-1); }
.list-head h2 { margin: 0; font-size: 18px; font-weight: 500; }
.list { list-style: none; margin: 0; padding: 0 8px 8px; }
.item { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 4px 14px; align-items: center; padding: 12px; border-radius: 14px; cursor: pointer; }
.item:hover { background: color-mix(in srgb, var(--on-surface) 6%, transparent); }
.item.selected { background: var(--primary-container); color: var(--on-primary-container); }
.item .avatar { grid-row: span 2; width: 40px; height: 40px; color: #fff; }
.avatar.big { color: #fff; }
.item .who { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .when { font-size: 12px; color: var(--on-surface-variant); white-space: nowrap; }
.item .subject { grid-column: 2 / -1; min-width: 0; color: var(--on-surface-variant); display: flex; gap: 6px; align-items: center; }
.item .subject .title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .subject .material-symbols-rounded { font-size: 16px; flex: none; }
.item .role { font-weight: 400; color: var(--on-surface-variant); font-size: 13px; }
.item.unread .who, .item.unread .subject { font-weight: 700; color: var(--on-surface); }
.item.unread .when { color: var(--primary); font-weight: 600; }
.item.selected .subject, .item.selected .when { color: inherit; }
.more { margin: 8px auto 20px; display: flex; }

.empty { height: 100%; display: grid; place-content: center; justify-items: center; gap: 8px; color: var(--on-surface-variant); }
.empty .material-symbols-rounded { font-size: 56px; opacity: .5; }
#reader { padding: 8px 32px 40px; max-width: 860px; }
.reader-bar { min-height: 8px; }
#r-title { font-size: 24px; font-weight: 400; margin: 12px 0 20px; line-height: 1.3; }
.r-meta { display: flex; gap: 14px; align-items: center; margin-bottom: 20px; }
.r-body { white-space: pre-wrap; font-size: 16px; line-height: 1.6; overflow-wrap: anywhere; }
.attachments { list-style: none; padding: 0; margin: 0 0 20px; display: flex; flex-wrap: wrap; gap: 8px; }
.attachments li { display: flex; align-items: center; gap: 6px; padding: 6px 12px; border: 1px solid var(--outline-variant); border-radius: 10px; font-size: 14px; }

.skeleton { height: 64px; margin: 6px 12px; border-radius: 14px; background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

.snackbar { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--on-surface); color: var(--surface); padding: 12px 20px; border-radius: 8px; max-width: calc(100% - 32px); z-index: 20; }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.32); z-index: 9; }
.only-mobile { display: none; }

/* compose */
.fab { display: inline-flex; align-items: center; gap: 12px; height: 56px; padding: 0 20px 0 16px; border-radius: 16px; background: var(--primary-container); color: var(--on-primary-container); font-weight: 500; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.fab:hover { box-shadow: 0 3px 8px rgba(0,0,0,.25); }
.drawer-fab { align-self: flex-start; margin: 4px 0 14px; }
.mobile-fab { display: none; }
.reader-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 52px; padding-top: 8px; }
#reply-btn { margin-left: auto; height: 40px; padding: 0 18px 0 14px; }

.composer { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 24px; background: rgba(0,0,0,.4); }
.composer-card { width: min(680px, 100%); height: min(640px, 100%); display: flex; flex-direction: column; background: var(--surface-1); border-radius: 28px; overflow: hidden; box-shadow: 0 8px 32px rgba(0,0,0,.35); }
.composer-bar { display: flex; align-items: center; gap: 8px; padding: 10px 14px 10px 8px; }
.composer-bar h2 { flex: 1; margin: 0; font-size: 18px; font-weight: 500; }
.c-row { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 8px; min-height: 52px; padding: 6px 20px; border-bottom: 1px solid var(--outline-variant); }
.c-row input { flex: 1; min-width: 120px; height: 40px; border: 0; outline: 0; background: transparent; font-size: 16px; }
.chips { display: contents; }
.chip { display: inline-flex; align-items: center; gap: 4px; height: 32px; padding: 0 4px 0 12px; border-radius: 8px; background: var(--secondary-container); color: var(--on-secondary-container); font-size: 14px; max-width: 100%; }
.chip span.name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button { width: 24px; height: 24px; border-radius: 999px; display: grid; place-items: center; }
.chip button .material-symbols-rounded { font-size: 18px; }
.chip.fixed { padding-right: 12px; }
.suggestions { list-style: none; margin: 0; padding: 4px 8px; max-height: 280px; overflow: auto; border-bottom: 1px solid var(--outline-variant); background: var(--surface-2); }
.suggestions li { padding: 10px 12px; border-radius: 10px; cursor: pointer; display: flex; justify-content: space-between; gap: 12px; }
.suggestions li .group { color: var(--on-surface-variant); font-size: 13px; white-space: nowrap; }
.suggestions li.active, .suggestions li:hover { background: color-mix(in srgb, var(--on-surface) 8%, transparent); }
.suggestions li.note { cursor: default; color: var(--on-surface-variant); }
.composer-card textarea { flex: 1; min-height: 120px; resize: none; border: 0; outline: 0; padding: 16px 20px; background: transparent; color: inherit; font: inherit; font-size: 16px; line-height: 1.55; }
.c-error { padding: 0 20px 12px; }

/* phones: list first, message full-screen, drawer as a modal sheet */
@media (max-width: 800px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .only-mobile { display: grid; }
  .brand { display: none; }
  .topbar { padding: 0 8px; padding-top: env(safe-area-inset-top); height: calc(64px + env(safe-area-inset-top)); }
  .drawer { position: fixed; inset: 0 auto 0 0; width: 300px; background: var(--surface-1); z-index: 10; transform: translateX(-105%); transition: transform .25s ease; padding-top: calc(16px + env(safe-area-inset-top)); border-radius: 0 20px 20px 0; }
  .drawer.open { transform: none; }
  .panes { grid-template-columns: minmax(0, 1fr); padding: 0; }
  .list { padding: 0 4px 8px; }
  .item { padding: 12px 10px; gap: 2px 12px; }
  #r-title { font-size: 21px; }
  .list-pane, .read-pane { border-radius: 0; background: var(--surface); }
  .list-head { background: var(--surface); }
  .read-pane { display: none; }
  .app.reading .list-pane { display: none; }
  .app.reading .read-pane { display: block; }
  #reader { padding: 0 20px calc(40px + env(safe-area-inset-bottom)); }
  .drawer-fab { display: none; }
  .mobile-fab { display: inline-flex; position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 5; }
  body.reading-mode .mobile-fab, #app[hidden] ~ .mobile-fab { display: none; }
  .composer { padding: 0; background: var(--surface); }
  .composer-card { width: 100%; height: 100%; border-radius: 0; box-shadow: none; background: var(--surface); padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
  .c-row { padding: 6px 16px; }
  .composer-card textarea { padding: 14px 16px; }
  .reader-bar { padding-top: 4px; }
}
