/* The suite's shared sheet.
 *
 * A tool that is read far more than it is admired, so this optimises for
 * scanning: a tight vertical rhythm, one accent colour used sparingly, and
 * weight rather than colour to signal state. Light and dark both derive from
 * the same tokens, so neither is an afterthought.
 *
 * The type scale (wave-4 polish — every app rides these five steps):
 *   18px/600  page titles          (.reader-head h1, .gridtitle, .docs-h, …)
 *   14px      body                 (base font-size)
 *   13px      list rows, controls
 *   12px      secondary / meta     (colour: --ink-soft)
 *   11px      micro (pills, timestamps in dense lists)
 */

:root {
  color-scheme: light dark;

  --bg: #fbfbfa;
  --panel: #ffffff;
  --rail: #f4f4f2;
  --line: #e5e4e0;
  --ink: #1c1b19;
  --ink-soft: #6b6a66;
  --accent: #3b5bdb;
  --accent-ink: #ffffff; /* text ON the accent — flips dark in dark mode */
  --accent-soft: #edf0fd;
  --danger: #b3261e;
  --star: #b58900;
  --heart: #d64550;
  --warn-bg: #fdf2e9;
  --warn-line: #e0a878;
  --radius: 7px;
  --rail-w: 210px;
  --list-w: 370px;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17171a;
    --panel: #1d1d21;
    --rail: #131316;
    --line: #2c2c31;
    --ink: #e9e8e6;
    --ink-soft: #96948f;
    --accent: #8aa2ff;
    --accent-ink: #14162e; /* dark ink on the lightened accent */
    --accent-soft: #23263a;
    --danger: #ef8a80;
    --star: #e2c04c;
    --heart: #ff8a93;
    --warn-bg: #2c2318;
    --warn-line: #6b4f2c;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
.muted { color: var(--ink-soft); }

/* One visible keyboard-focus treatment for every interactive element (a11y).
 * Inputs keep their own focus ring (defined below); everything else gets
 * this. :focus-visible only — mouse clicks stay quiet. */
a:focus-visible,
button:focus-visible,
summary:focus-visible,
label.upload-btn:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-radius: 4px;
}

/* --- sign in ----------------------------------------------------------- */

.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.card {
  width: 100%;
  max-width: 340px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.wordmark {
  font-size: 20px;
  font-weight: 620;
  letter-spacing: -0.02em;
  margin: 0;
}
.wordmark.small { font-size: 14px; }
.wm-mark { color: var(--accent); }

/* The sign-in card is the product's front door — give the wordmark real
 * presence there (rails keep the small version). */
.auth .wordmark:not(.small) { font-size: 26px; letter-spacing: -0.03em; margin: 2px 0 0; }
.auth .tagline { font-size: 13px; line-height: 1.55; }

.card p.muted { margin: 0 0 14px; }

label {
  font-size: 12px;
  font-weight: 550;
  color: var(--ink-soft);
  margin-top: 10px;
}

input {
  font: inherit;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--ink);
}
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}

/* Buttons: the bare element is the PRIMARY action (accent). Secondary and
 * destructive actions ride the .btn system below (.btn.quiet, .danger).
 * Margin is the layout's job, not the element's — auth cards add their own. */
button {
  font: inherit;
  font-weight: 560;
  margin: 0;
  padding: 9px 14px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
}
button:hover { filter: brightness(1.07); }
button:active { filter: brightness(0.96); }
button:disabled { opacity: 0.5; cursor: default; filter: none; }

.auth .card button[type="submit"]:not(.linky) { margin-top: 18px; }

.error {
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
  border-radius: 6px;
  padding: 8px 10px;
  margin: 6px 0 0;
  font-size: 13px;
}

/* --- shell ------------------------------------------------------------- */

.shell {
  display: grid;
  grid-template-columns: var(--rail-w) var(--list-w) 1fr;
  height: 100vh;
}

.rail {
  background: var(--rail);
  border-right: 1px solid var(--line);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}

.rail-head { display: flex; flex-direction: column; gap: 2px; padding: 0 6px; }
.address {
  font-size: 12px;
  color: var(--ink-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.labels { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; }
.labels a {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 13px;
}
.labels a:hover { background: color-mix(in srgb, var(--ink) 6%, transparent); }
.labels a.on { background: var(--accent-soft); color: var(--accent); font-weight: 570; }

.pill {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
}
.labels a.on .pill { color: inherit; }

.logout { margin-top: auto; }

/* The shared rail foot (_rail_foot.html): cross-app links + sign-out. */
.rail-foot { margin-top: auto; display: grid; gap: 6px; padding: 0 6px; }
.rail-foot > a { font-size: 12px; color: var(--ink-soft); }
.rail-foot > a:hover { color: var(--ink); }
.rail-foot .logout { margin-top: 4px; }
.linky {
  margin: 0;
  padding: 0;
  background: none;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 450;
}
.linky:hover { color: var(--ink); filter: none; }

/* --- thread list ------------------------------------------------------- */

.list {
  border-right: 1px solid var(--line);
  overflow-y: auto;
  background: var(--panel);
  min-width: 0;
}

.search { padding: 12px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 1; }
.search input { width: 100%; }
.searched { padding: 8px 14px 0; margin: 0; font-size: 12px; }

.list ul { list-style: none; margin: 0; padding: 0; }

.row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1px 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.row:hover { background: color-mix(in srgb, var(--ink) 3%, transparent); }
.row.on { background: var(--accent-soft); box-shadow: inset 2px 0 0 var(--accent); }

.who {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.when {
  font-size: 11px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.subject, .snippet {
  grid-column: 1 / -1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.subject { font-size: 13px; }
.snippet { font-size: 12px; color: var(--ink-soft); }

/* Weight, not colour — unread has to survive a colourblind reader and a bad screen. */
.row.unread .who,
.row.unread .subject { font-weight: 650; }

.count {
  font-size: 11px;
  color: var(--ink-soft);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 0 5px;
  margin-left: 4px;
}

/* --- reader ------------------------------------------------------------ */

.reader { overflow-y: auto; padding: 0 0 48px; min-width: 0; }

.reader-head {
  padding: 22px 28px 14px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--bg);
}
.reader-head h1 { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; margin: 0 0 2px; }
.reader-head p { margin: 0; font-size: 12px; }

.message { padding: 20px 28px; border-bottom: 1px solid var(--line); }
.message > header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  margin-bottom: 12px;
}
.from { font-weight: 570; }
.to { font-size: 12px; margin-left: 6px; }
.message time { font-size: 12px; color: var(--ink-soft); white-space: nowrap; }

.warn {
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
  border-radius: 6px;
  padding: 9px 11px;
  font-size: 13px;
  margin: 0 0 14px;
}

.body { font-size: 14px; overflow-wrap: anywhere; }
.body pre {
  font-family: var(--font);
  font-size: 14px;
  white-space: pre-wrap;
  margin: 0;
}
.body img { max-width: 100%; height: auto; }
.body table { max-width: 100%; border-collapse: collapse; }
.body a { color: var(--accent); text-decoration: underline; }
.body blockquote {
  margin: 12px 0;
  padding-left: 12px;
  border-left: 2px solid var(--line);
  color: var(--ink-soft);
}

.attachments { list-style: none; margin: 16px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.attachments li {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
}
.attachments a { color: var(--accent); }

/* Empty states: one warm, typography-led shape for every list surface.
 * Templates may add a leading <p class="empty-title"> above the hint line. */
.empty {
  display: grid;
  place-items: center;
  align-content: center;
  min-height: 46vh;
  gap: 4px;
  padding: 24px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 13px;
}
.empty p { margin: 0; max-width: 360px; line-height: 1.6; }
.empty .empty-title { color: var(--ink); font-size: 15px; font-weight: 600; }
.empty-note { margin-top: 30px; text-align: center; }

/* --- narrow ------------------------------------------------------------ */

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; height: auto; }
  .rail { flex-direction: row; align-items: center; overflow-x: auto; }
  .rail-head { flex-direction: row; align-items: baseline; gap: 8px; }
  .labels { grid-auto-flow: column; }
  .logout { margin: 0 0 0 auto; }
  .rail-foot { margin: 0 0 0 auto; display: flex; align-items: center; gap: 12px; }
  .rail-foot .logout { margin: 0; }
  .list { border-right: 0; }
}

/* --- composer ----------------------------------------------------------- */

.composer { padding: 20px 28px 32px; display: flex; flex-direction: column; gap: 10px; }
.composer textarea {
  font: inherit;
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  resize: vertical;
  min-height: 92px;
}
.composer textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}
.composer button { margin: 0; align-self: flex-start; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.note {
  font-size: 12px;
  color: var(--ink-soft);
  border-left: 2px solid var(--line);
  padding-left: 10px;
  margin: 0 0 12px;
}

/* --- drive ------------------------------------------------------------- */

.shell.drive { grid-template-columns: var(--rail-w) 1fr 380px; }

/* Rail + one content column: compose, drafts, contacts, the doc editor. */
.shell.page { grid-template-columns: var(--rail-w) 1fr; }
.pagecol { overflow-y: auto; min-width: 0; }

/* The app switcher (_apps.html) — five entries must hold at every rail width.
 * A one-row flex clipped at --rail-w 210px ("Mail Drive Photos Doc…", found
 * live), so the rail uses a two-column grid: 3 tidy rows, aligned edges, and
 * each cell ellipsizes instead of clipping the row. The narrow (<=900px)
 * layout flips the rail horizontal and restores the inline pill row there —
 * the rail scrolls sideways, so one row is safe again. Widest label at
 * 12px/570 ("Photos") ≈ 56px incl. padding; a 210px rail gives each of the
 * two columns ≈ 91px — comfortable, with ellipsis as the backstop. */
.apps {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2px;
  margin: 10px 0 14px;
  padding: 0 2px;
}
.apps a {
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 570;
  color: var(--ink-soft);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.apps a.on { background: var(--accent-soft); color: var(--accent); }
.apps a:hover { color: var(--ink); background: color-mix(in srgb, var(--ink) 6%, transparent); }
.apps a.on:hover { background: var(--accent-soft); color: var(--accent); }

@media (max-width: 900px) {
  .apps { display: flex; margin: 0; flex: none; }
  .apps a { border-radius: 999px; flex: none; }
}

.storage { font-size: 12px; padding: 0 6px; }

.dlist.dropping, .gridwrap.dropping { outline: 2px dashed var(--accent); outline-offset: -6px; }

.crumbs { padding: 10px 14px 0; margin: 0; font-size: 13px; }
.crumbs a:hover { color: var(--accent); }

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  min-height: 53px; /* one toolbar height across drive/photos/mail-search */
  border-bottom: 1px solid var(--line);
}
.toolbar form { display: flex; gap: 6px; }
.toolbar input[type="text"] { padding: 6px 9px; font-size: 13px; }
.toolbar button, .upload-btn {
  margin: 0;
  padding: 7px 12px;
  font-size: 13px;
  border-radius: 6px;
}
.upload-btn {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 560;
  cursor: pointer;
}
.upload-btn:hover { filter: brightness(1.07); }

.uploads { list-style: none; margin: 0; padding: 6px 14px; display: grid; gap: 4px; }
.uploads li { display: flex; align-items: center; gap: 10px; font-size: 12px; }
.uploads progress { flex: 1; height: 6px; }

.entries { list-style: none; margin: 0; padding: 0; }
.entry {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
}
.entry:hover { background: color-mix(in srgb, var(--ink) 3%, transparent); }
.entry .name-link { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.entry .icon { flex: 0 0 auto; }
.entry .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry .meta { font-size: 12px; }
.entry .when { font-size: 12px; color: var(--ink-soft); white-space: nowrap; }
.entry form { margin: 0; }
.entry button { margin: 0; }

.rowmenu { position: relative; }
.rowmenu summary {
  list-style: none;
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 6px;
  color: var(--ink-soft);
}
.rowmenu summary::-webkit-details-marker { display: none; }
.rowmenu[open] summary { background: var(--accent-soft); color: var(--accent); }
.rowmenu .menu {
  position: absolute;
  right: 0;
  z-index: 5;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  display: grid;
  gap: 8px;
  min-width: 240px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}
.rowmenu .menu form { display: flex; gap: 6px; }
.rowmenu .menu input, .rowmenu .menu select { flex: 1; padding: 6px 8px; font-size: 13px; }
.rowmenu .menu button { margin: 0; padding: 6px 10px; font-size: 13px; }

.detail-body { padding: 0 0 48px; }
.detail-body .error { margin: 12px 20px 0; }
.preview { padding: 16px 20px 0; }
.preview img { max-width: 100%; border-radius: var(--radius); border: 1px solid var(--line); }

.actions { display: flex; gap: 8px; align-items: center; padding: 16px 20px 0; }
.actions form { margin: 0; }
.actions button { margin: 0; }
/* The .btn system — the ONE button hierarchy, for <a> and <button> alike:
 *   .btn          primary   (accent fill)
 *   .btn.quiet    secondary (soft accent fill)
 *   .danger       destructive (outline that turns --danger on hover)   */
.btn {
  display: inline-block;
  padding: 8px 14px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 560;
  font-size: 13px;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.07); }
.btn:active { filter: brightness(0.96); }
.btn.quiet { background: var(--accent-soft); color: var(--accent); }
.btn.quiet:hover { filter: none; background: color-mix(in srgb, var(--accent) 18%, var(--panel)); }
button.danger, .btn.danger {
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid var(--line);
}
button.danger:hover, .btn.danger:hover { color: var(--danger); border-color: var(--danger); filter: none; }

.panel { margin: 14px 20px 0; border: 1px solid var(--line); border-radius: var(--radius); }
.panel summary {
  cursor: pointer;
  padding: 10px 12px;
  font-weight: 570;
  font-size: 13px;
}
.panel > *:not(summary) { margin: 0 12px 12px; }
.panel form { display: flex; gap: 6px; margin-top: 8px; }
.panel form input, .panel form select { flex: 1; padding: 6px 9px; font-size: 13px; }
.panel form button { margin: 0; padding: 6px 12px; font-size: 13px; }
.panel .note { margin-top: 10px; }

.sharemint {
  margin: 12px 20px 0;
  padding: 10px 12px;
  background: var(--accent-soft);
  border-radius: var(--radius);
  font-size: 13px;
}
.sharemint p { margin: 0 0 6px; }
.sharemint input { width: 100%; font-family: var(--mono); font-size: 12px; }

.sharelist, .versions { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; font-size: 13px; }
.sharelist li, .versions li { display: flex; align-items: center; gap: 10px; }
.sharelist li span, .versions li span { flex: 1; }
.versions a { color: var(--accent); font-size: 12px; }
.sharelist form, .versions form { margin: 0; }

.share-card { max-width: 460px; }
.share-card h1 { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; margin: 10px 0 2px; }
.sharefiles { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 8px; font-size: 13px; }
.sharefiles li { display: flex; align-items: center; gap: 10px; }
.sharefiles li > span { flex: 1; }
.sharefiles a { color: var(--accent); }

@media (max-width: 900px) {
  .shell.drive { grid-template-columns: 1fr; }
  .shell.page { grid-template-columns: 1fr; }
}

.aux { margin: 10px 0 0; font-size: 12px; text-align: center; }

.upload-error { color: var(--danger); }
.meta.failed { color: var(--danger); font-size: 12px; }

/* --- photos ------------------------------------------------------------ */

.shell.photos { grid-template-columns: var(--rail-w) 1fr; }

.gridwrap { overflow-y: auto; padding: 0 20px 48px; min-width: 0; background: var(--panel); }
.gridwrap .toolbar { border-bottom: 0; padding: 16px 0 4px; }
.gridtitle { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; margin: 0; flex: 1; }

.newcollection { display: flex; gap: 6px; margin-top: 14px; padding: 0 2px; }
.newcollection input { flex: 1; padding: 6px 8px; font-size: 12px; }
.newcollection button { margin: 0; }

.photogrid {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px;
}
.photogrid li { aspect-ratio: 1; }
.photogrid a { display: block; height: 100%; }
.photogrid img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  display: block;
}
.tile-fallback {
  display: grid;
  place-items: center;
  height: 100%;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--ink-soft);
  padding: 8px;
  overflow: hidden;
  text-align: center;
  overflow-wrap: anywhere;
}
.panel.sharing { margin: 10px 0 0; }

.photopage { min-height: 100vh; display: flex; flex-direction: column; background: var(--bg); }
.photobar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.photobar .name { font-weight: 600; }
.photobar .muted { font-size: 12px; flex: 1; }
.photobar .inline-form { margin: 0; }
.photobar button { margin: 0; }
.photoview { flex: 1; display: grid; place-items: center; padding: 20px; }
.photoview img { max-width: 100%; max-height: calc(100vh - 120px); border-radius: var(--radius); }

.pshare { min-height: 100vh; background: var(--bg); }
.pshare .photogrid { padding: 16px 20px 48px; margin: 0; }
.photogrid.share li { aspect-ratio: auto; }
.photogrid.share img { height: auto; object-fit: contain; }
