/* CardMail - design tokens and components.
   Dark mode is a selected set of values, not an inverted one. Status colours are
   fixed and always ship with an icon and a word, never colour on its own. */

:root {
  color-scheme: light;

  --plane:        #f6f6f4;
  --surface:      #fcfcfb;
  --surface-2:    #f1f1ee;
  --surface-sunk: #ebebe7;

  --ink:          #0b0b0b;
  --ink-2:        #52514e;
  --ink-muted:    #77756f;

  --line:         #e1e0d9;
  --line-strong:  #c9c8c0;
  --ring:         rgba(11, 11, 11, .10);

  --brand:        #4338ca;
  --brand-ink:    #ffffff;
  --brand-hover:  #3a30b0;
  --brand-wash:   #eeecfb;
  --brand-line:   #cfcaf4;

  --good:         #0ca30c;
  --warning:      #fab219;
  --critical:     #d03b3b;
  --good-wash:    #e7f6e7;
  --warning-wash: #fdf3dc;
  --critical-wash:#fbe9e9;

  --shadow-sm: 0 1px 2px rgba(11, 11, 11, .06), 0 1px 1px rgba(11, 11, 11, .04);
  --shadow-md: 0 4px 12px rgba(11, 11, 11, .07), 0 1px 3px rgba(11, 11, 11, .05);
  --shadow-lg: 0 18px 48px rgba(11, 11, 11, .16), 0 2px 8px rgba(11, 11, 11, .08);

  --r-sm: 8px;
  --r:    12px;
  --r-lg: 18px;
  --r-pill: 999px;

  --sidebar: 244px;
  --font: system-ui, -apple-system, "Segoe UI Variable Text", "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --plane:        #0d0d0d;
    --surface:      #1a1a19;
    --surface-2:    #232322;
    --surface-sunk: #121211;
    --ink:          #ffffff;
    --ink-2:        #c3c2b7;
    --ink-muted:    #939189;
    --line:         #2c2c2a;
    --line-strong:  #3d3d3a;
    --ring:         rgba(255, 255, 255, .10);
    --brand:        #9085e9;
    --brand-ink:    #14121f;
    --brand-hover:  #a29aee;
    --brand-wash:   #221f38;
    --brand-line:   #3b3564;
    --good-wash:    #102a10;
    --warning-wash: #2e2510;
    --critical-wash:#2f1414;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .5);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, .55);
    --shadow-lg: 0 20px 56px rgba(0, 0, 0, .7);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --plane:        #0d0d0d;
  --surface:      #1a1a19;
  --surface-2:    #232322;
  --surface-sunk: #121211;
  --ink:          #ffffff;
  --ink-2:        #c3c2b7;
  --ink-muted:    #939189;
  --line:         #2c2c2a;
  --line-strong:  #3d3d3a;
  --ring:         rgba(255, 255, 255, .10);
  --brand:        #9085e9;
  --brand-ink:    #14121f;
  --brand-hover:  #a29aee;
  --brand-wash:   #221f38;
  --brand-line:   #3b3564;
  --good-wash:    #102a10;
  --warning-wash: #2e2510;
  --critical-wash:#2f1414;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .5);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, .55);
  --shadow-lg: 0 20px 56px rgba(0, 0, 0, .7);
}

/* ------------------------------------------------------------ base */

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--plane);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 640; letter-spacing: -.011em; }
h1 { font-size: 1.3rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: .94rem; }
p  { margin: 0; }

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 4px;
}

::selection { background: var(--brand-wash); }

.muted { color: var(--ink-2); }
.dim   { color: var(--ink-muted); }
.small { font-size: .82rem; }
.tiny  { font-size: .75rem; }
.grow  { flex: 1; min-width: 0; }
.spacer { flex: 1; }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mt { margin-top: 20px; }
.tabular { font-variant-numeric: tabular-nums; }

.row  { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.col  { display: flex; flex-direction: column; gap: 10px; }

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

#shell { display: flex; min-height: 100%; }

#sidebar {
  width: var(--sidebar);
  flex: 0 0 var(--sidebar);
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 18px 12px 12px;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 1.12rem;
  font-weight: 700;
  letter-spacing: -.02em;
  padding: 0 10px 16px;
  color: var(--ink);
}
.brand-mark {
  width: 28px; height: 28px;
  flex: 0 0 28px;
  border-radius: 9px;
  background: var(--brand);
  color: var(--brand-ink);
  display: grid; place-items: center;
  font-size: .9rem; font-weight: 700;
  box-shadow: var(--shadow-sm);
}
/* The name is one flex item, so the gap does not split "Card" from "Mail". */
.brand-name { white-space: nowrap; }
.brand-name .accent { color: var(--brand); }

.nav { display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex;
  align-items: center;
  justify-content: flex-start;   /* the base button rule centres; nav items do not */
  gap: 11px;
  width: 100%;
  padding: 9px 11px;
  border: 0;
  border-radius: var(--r-sm);
  background: none;
  font: inherit;
  font-size: .9rem;
  font-weight: 500;
  color: var(--ink-2);
  cursor: pointer;
  text-align: left;
}
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.active { background: var(--brand-wash); color: var(--brand); font-weight: 600; }
/* Fixed box with min-width:0 - otherwise a wide glyph's intrinsic size opens the
   flex item up and the labels stop lining up with each other. */
.nav-item .ico {
  font-size: 1rem;
  flex: 0 0 20px;
  width: 20px;
  min-width: 0;
  text-align: center;
  overflow: hidden;
}
.nav-item .pill {
  margin-left: auto;
  font-size: .72rem;
  font-weight: 650;
  padding: 1px 7px;
  border-radius: var(--r-pill);
  background: var(--surface-sunk);
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}
.nav-item.active .pill { background: var(--brand); color: var(--brand-ink); }

.side-foot { margin-top: auto; border-top: 1px solid var(--line); padding-top: 10px; }

.who {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 8px; border-radius: var(--r-sm);
}
.who:hover { background: var(--surface-2); }
.who .name { font-weight: 600; font-size: .86rem; }

.avatar {
  width: 30px; height: 30px; flex: 0 0 30px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--brand-wash);
  color: var(--brand);
  font-weight: 680;
  font-size: .76rem;
  border: 1px solid var(--brand-line);
}
.avatar.lg { width: 42px; height: 42px; flex-basis: 42px; font-size: .95rem; }

#main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

#topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 14px 24px;
  background: color-mix(in srgb, var(--plane) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
#topbar .sub { font-size: .8rem; color: var(--ink-2); }

#views { padding: 22px 24px 96px; max-width: 1240px; width: 100%; }

.view { display: flex; flex-direction: column; gap: 18px; }

/* ------------------------------------------------------------ panels */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}
.panel > header {
  display: flex; align-items: baseline; gap: 10px;
  margin-bottom: 4px;
}
.panel > header .spacer { flex: 1; }
.panel-note { margin: 2px 0 14px; font-size: .84rem; color: var(--ink-2); }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.grid-inbox { display: grid; grid-template-columns: minmax(0, 1fr) 290px; gap: 18px; align-items: start; }

/* ------------------------------------------------------------ buttons */

button, .button {
  font: inherit;
  font-size: .875rem;
  font-weight: 550;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 14px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: background .12s, border-color .12s, transform .06s;
}
button:hover, .button:hover { background: var(--surface-2); text-decoration: none; }
button:active, .button:active { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: not-allowed; transform: none; }

button.primary, .button.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-ink);
  font-weight: 600;
}
button.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }

button.danger {
  color: var(--critical);
  border-color: color-mix(in srgb, var(--critical) 40%, var(--line-strong));
}
button.danger:hover { background: var(--critical-wash); }

button.link, .button.link {
  border: 0; background: none; padding: 4px 6px;
  color: var(--brand); font-weight: 550;
}
button.link:hover { background: var(--brand-wash); }

button.ghost { border-color: transparent; background: var(--surface-2); }
button.icon { padding: 7px 9px; }
button.block { width: 100%; }
button.lg { padding: 11px 18px; font-size: .94rem; }

/* ------------------------------------------------------------ forms */

label.field {
  display: flex; flex-direction: column; gap: 5px;
  font-size: .82rem; font-weight: 600; color: var(--ink-2);
  margin-bottom: 12px;
}
label.field > small { font-weight: 450; color: var(--ink-muted); }

/* Matches inputs with no type attribute too - `input[type="text"]` would not,
   and the contact form builds its fields as a bare <input name="…">. */
input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="submit"]),
select, textarea {
  font: inherit;
  font-size: .9rem;
  font-weight: 450;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  padding: 9px 11px;
  width: 100%;
  min-width: 0;
}
textarea { resize: vertical; line-height: 1.45; }
input::placeholder, textarea::placeholder { color: var(--ink-muted); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-wash);
}
input[type="search"] { background: var(--surface-2); }

.check {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: .85rem; color: var(--ink-2); cursor: pointer;
  white-space: nowrap;
}
.check input { width: auto; accent-color: var(--brand); margin: 0; }

.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.inline-form input, .inline-form select { width: auto; flex: 1 1 150px; }

/* ------------------------------------------------------------ stat tiles */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}
.tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 14px 15px;
  display: flex; flex-direction: column; gap: 3px;
  text-align: left;
}
.tile .label {
  font-size: .76rem; font-weight: 600;
  color: var(--ink-2);
  text-transform: uppercase; letter-spacing: .05em;
  display: flex; align-items: center; gap: 6px;
}
.tile .value { font-size: 1.85rem; font-weight: 680; letter-spacing: -.025em; line-height: 1.1; }
.tile .foot { font-size: .78rem; color: var(--ink-muted); }
button.tile { cursor: pointer; }
button.tile:hover { border-color: var(--brand-line); background: var(--surface); }

/* A small square of status colour, never the only signal - a word sits beside it. */
.dot {
  width: 9px; height: 9px; flex: 0 0 9px;
  border-radius: 3px;
  background: var(--ink-muted);
}
.dot.good     { background: var(--good); }
.dot.warning  { background: var(--warning); }
.dot.critical { background: var(--critical); }

/* ------------------------------------------------------------ status rows */

.checks { display: flex; flex-direction: column; gap: 9px; }

.checkrow {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface-2);
}
.checkrow .state {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: .74rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em;
  padding: 3px 9px 3px 7px;
  border-radius: var(--r-pill);
  flex: 0 0 auto;
  border: 1px solid transparent;
}
.checkrow .state .glyph { font-size: .85rem; line-height: 1; }
.state.good     { background: var(--good-wash);     color: var(--ink); border-color: color-mix(in srgb, var(--good) 35%, transparent); }
.state.warning  { background: var(--warning-wash);  color: var(--ink); border-color: color-mix(in srgb, var(--warning) 45%, transparent); }
.state.critical { background: var(--critical-wash); color: var(--ink); border-color: color-mix(in srgb, var(--critical) 40%, transparent); }
.state.pending  { background: var(--surface-sunk);  color: var(--ink-2); border-color: var(--line); }

.checkrow .body { flex: 1; min-width: 0; }
.checkrow .title { font-weight: 620; font-size: .9rem; }
.checkrow .detail { font-size: .83rem; color: var(--ink-2); margin-top: 2px; word-break: break-word; }

/* ------------------------------------------------------------ banner */

.banner {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px 16px;
  border-radius: var(--r);
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.banner.warn { background: var(--warning-wash); border-color: color-mix(in srgb, var(--warning) 45%, transparent); }
.banner.bad  { background: var(--critical-wash); border-color: color-mix(in srgb, var(--critical) 40%, transparent); }
.banner .glyph { font-size: 1.1rem; line-height: 1.3; }
.banner b { display: block; margin-bottom: 2px; }

/* ------------------------------------------------------------ scan */

.drops { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 6px 0 16px; }

.drop {
  position: relative;
  display: grid; place-items: center;
  aspect-ratio: 16 / 10;
  border: 2px dashed var(--line-strong);
  border-radius: var(--r);
  background: var(--surface-2);
  cursor: pointer;
  overflow: hidden;
  text-align: center;
  padding: 12px;
  transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--brand); background: var(--brand-wash); }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.drop .hint { pointer-events: none; }
.drop .hint .big { font-size: 1.6rem; display: block; line-height: 1.2; }
.drop .hint .cap { font-size: .86rem; font-weight: 600; }
.drop .hint .sub { font-size: .76rem; color: var(--ink-muted); }
.drop img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  display: none;
}
.drop.filled img { display: block; }
.drop.filled .hint { display: none; }
.drop .clear {
  position: absolute; top: 7px; right: 7px;
  display: none; z-index: 2;
  padding: 3px 8px; font-size: .75rem;
  background: var(--surface); border-radius: var(--r-pill);
  box-shadow: var(--shadow-md);
}
.drop.filled .clear { display: inline-flex; }

.qr-row { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.qr-box {
  flex: 0 0 auto;
  width: 168px; height: 168px;
  display: grid; place-items: center;
  background: #fff;               /* QR codes need a plain light quiet-zone to scan reliably */
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 10px;
  overflow: hidden;
}
.qr-box img { width: 100%; height: 100%; image-rendering: pixelated; }
.qr-info { flex: 1 1 240px; min-width: 220px; display: flex; flex-direction: column; gap: 10px; }
.qr-url {
  flex: 1 1 auto; min-width: 0;
  font-size: .8rem;
  padding: 7px 10px;
  border-radius: var(--r-sm);
  background: var(--surface-sunk);
  color: var(--ink-2);
  overflow-x: auto;
  white-space: nowrap;
}

/* A phone scanning a QR code shown on its own screen makes no sense, and the
   cards a phone sends over are for the laptop to deal with, not the phone. */
@media (max-width: 720px) {
  .qr-panel, .desk-only { display: none; }
}

/* Cards waiting on the laptop, sent from someone's phone. */
.handoffs { display: flex; flex-direction: column; gap: 10px; }
.handoff {
  display: flex; gap: 12px; align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface-sunk);
}
.handoff img {
  width: 64px; height: 42px; flex: 0 0 64px;
  object-fit: cover;
  border-radius: var(--r-sm);
  background: var(--surface);
}
.handoff .who { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.handoff .who b { font-size: .92rem; }
.handoff .who span { font-size: .8rem; color: var(--ink-2); }
.handoff.is-new { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-wash); }
#handoff-count {
  padding: 2px 9px;
  border-radius: var(--r-pill);
  background: var(--brand-wash); color: var(--brand);
  font-size: .76rem; font-weight: 700;
}

/* Phone side: what this phone has already pushed across to the laptop. */
.sent { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.sent .line {
  display: flex; gap: 10px; align-items: center;
  padding: 9px 11px;
  border-radius: var(--r-sm);
  background: var(--surface-sunk);
  font-size: .85rem;
}
.sent .line .tick { color: var(--good); font-weight: 700; }
.sent .line.bad .tick { color: var(--critical); }
.sent .line .grow { flex: 1 1 auto; min-width: 0; }

.steps { display: flex; flex-direction: column; gap: 10px; }
.step { display: flex; gap: 12px; align-items: flex-start; }
.step .n {
  width: 24px; height: 24px; flex: 0 0 24px;
  border-radius: 50%;
  background: var(--brand-wash); color: var(--brand);
  display: grid; place-items: center;
  font-size: .78rem; font-weight: 700;
}
.step .t { font-size: .87rem; color: var(--ink-2); padding-top: 2px; }
.step .t b { color: var(--ink); font-weight: 600; }

/* ------------------------------------------------------------ contacts */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 12px;
}
.contact {
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
  padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
  text-align: left;
  cursor: pointer;
}
.contact:hover { border-color: var(--brand-line); box-shadow: var(--shadow-md); }
.contact .top { display: flex; gap: 11px; align-items: flex-start; }
/* Each sits on its own line - as inline spans they would run together. */
.contact .nm { display: block; font-weight: 640; font-size: .95rem; }
.contact .dz { display: block; font-size: .8rem; color: var(--ink-2); }
.contact .co { display: block; font-size: .84rem; color: var(--ink); font-weight: 550; }
.contact .meta { font-size: .76rem; color: var(--ink-muted); display: flex; gap: 8px; flex-wrap: wrap; }
.contact .acts { display: flex; gap: 6px; margin-top: auto; }
.contact .acts a {
  flex: 1;
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  font-size: .78rem; font-weight: 600;
  padding: 6px 8px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--ink-2);
  border: 1px solid var(--line);
}
.contact .acts a:hover { background: var(--brand-wash); color: var(--brand); border-color: var(--brand-line); text-decoration: none; }

/* ------------------------------------------------------------ inbox */

.segments {
  display: inline-flex;
  padding: 3px;
  gap: 3px;
  background: var(--surface-sunk);
  border: 1px solid var(--line);
  border-radius: var(--r);
  width: 100%;
}
.segment {
  flex: 1;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; background: none;
  padding: 9px 12px;
  border-radius: var(--r-sm);
  font-size: .87rem; font-weight: 600;
  color: var(--ink-2);
}
.segment:hover { background: var(--surface-2); }
.segment.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.segment .n {
  font-size: .76rem; font-weight: 700;
  padding: 1px 7px; border-radius: var(--r-pill);
  background: var(--surface-sunk); color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}
.segment.active .n { background: var(--brand); color: var(--brand-ink); }

.emails { display: flex; flex-direction: column; }

.mailrow {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px 6px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.mailrow:hover { background: var(--surface-2); }
.mailrow.sel { background: var(--brand-wash); }
.mailrow:last-child { border-bottom: 0; }
.mailrow input[type="checkbox"] { margin-top: 4px; accent-color: var(--brand); width: auto; flex: 0 0 auto; }
.mailrow .who-line { display: flex; align-items: baseline; gap: 8px; }
.mailrow .from { font-weight: 620; font-size: .89rem; }
.mailrow .when { font-size: .75rem; color: var(--ink-muted); margin-left: auto; flex: 0 0 auto; }
.mailrow .subj { font-size: .88rem; margin-top: 1px; }
.mailrow.unread .subj, .mailrow.unread .from { font-weight: 700; }
.mailrow .prev { font-size: .8rem; color: var(--ink-muted); margin-top: 2px; }
.mailrow .tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: .72rem; font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--r-pill);
  background: var(--surface-sunk);
  color: var(--ink-2);
  border: 1px solid var(--line);
}
.chip.why { background: var(--brand-wash); color: var(--brand); border-color: var(--brand-line); }

.bulkbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 12px;
  margin-bottom: 8px;
  border-radius: var(--r);
  background: var(--brand-wash);
  border: 1px solid var(--brand-line);
  font-size: .85rem;
}
.bulkbar b { color: var(--brand); }

.pager { display: flex; align-items: center; justify-content: center; gap: 10px; padding-top: 14px; }

.senders { display: flex; flex-direction: column; gap: 8px; }
.sender {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-2);
}
.sender .n {
  font-size: .72rem; font-weight: 700;
  padding: 1px 7px; border-radius: var(--r-pill);
  background: var(--surface-sunk); color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------ progress */

.job {
  display: flex; align-items: center; gap: 12px;
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: var(--r);
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: .85rem;
}
.bar {
  flex: 1;
  height: 7px;
  border-radius: var(--r-pill);
  background: var(--surface-sunk);
  overflow: hidden;
}
.bar > i {
  display: block; height: 100%;
  width: 0%;
  border-radius: var(--r-pill);
  background: var(--brand);
  transition: width .3s ease;
}
.bar.indeterminate > i { width: 35%; animation: slide 1.2s ease-in-out infinite; }
@keyframes slide {
  0%   { margin-left: -35%; }
  100% { margin-left: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  .bar.indeterminate > i { animation: none; width: 100%; opacity: .4; }
  * { transition: none !important; }
}

.spinner {
  width: 15px; height: 15px; flex: 0 0 15px;
  border: 2px solid var(--brand-line);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------ empty states */

.empty {
  text-align: center;
  padding: 44px 20px;
  color: var(--ink-2);
}
.empty .glyph { font-size: 2.1rem; display: block; margin-bottom: 8px; opacity: .7; }
.empty b { display: block; color: var(--ink); font-size: .96rem; margin-bottom: 4px; }
.empty p { font-size: .86rem; max-width: 34ch; margin: 0 auto; }

/* ------------------------------------------------------------ table */

.tbl { width: 100%; border-collapse: collapse; font-size: .87rem; }
.tbl th {
  text-align: left; font-size: .74rem; font-weight: 650;
  text-transform: uppercase; letter-spacing: .05em;
  color: var(--ink-muted);
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}
.tbl td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }

.list { display: flex; flex-direction: column; gap: 7px; }
.listrow {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  font-size: .86rem;
}

/* ------------------------------------------------------------ dialogs */

dialog {
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  color: var(--ink);
  padding: 0;
  max-width: min(840px, calc(100vw - 32px));
  width: 100%;
  max-height: calc(100vh - 48px);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
dialog.narrow { max-width: min(480px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(11, 11, 11, .45); backdrop-filter: blur(3px); }
dialog > form, dialog > .dlg { display: flex; flex-direction: column; max-height: calc(100vh - 48px); }

.dlg-head {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.dlg-body { padding: 18px; overflow-y: auto; flex: 1 1 auto; }
.dlg-foot {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
  flex: 0 0 auto;
}

.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.fields label.field.wide { grid-column: 1 / -1; }

.dlg-split { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 18px; }
.shots { display: flex; flex-direction: column; gap: 10px; }
.shots img {
  width: 100%; border-radius: var(--r);
  border: 1px solid var(--line);
  background: var(--surface-2);
  cursor: zoom-in;
}

/* email reader */
.m-head { padding: 14px 18px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.m-head .line { font-size: .82rem; color: var(--ink-2); }
.m-body {
  margin: 0; padding: 18px;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font);
  font-size: .89rem;
  line-height: 1.6;
  overflow-y: auto;
  flex: 1 1 auto;
}
.atts { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 18px 12px; }

/* ------------------------------------------------------------ toast */

#toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 140%);
  z-index: 99;
  max-width: min(440px, calc(100vw - 32px));
  padding: 12px 18px;
  border-radius: var(--r);
  background: var(--ink);
  color: var(--plane);
  font-size: .88rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  transition: transform .25s cubic-bezier(.2, .8, .3, 1), opacity .2s;
  display: flex; align-items: center; gap: 9px;
  opacity: 0;
  pointer-events: none;
}
#toast.show { transform: translate(-50%, 0); opacity: 1; }
#toast.bad { background: var(--critical); color: #fff; }

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

.gate {
  min-height: 100vh;
  /* Flex, not grid: a centred grid item is sized to max-content, so max-width
     would win over a narrow phone screen and the card would overflow. */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background:
    radial-gradient(1100px 520px at 50% -10%, var(--brand-wash), transparent 70%),
    var(--plane);
}
.gate-card {
  width: 410px; max-width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 28px;
  box-shadow: var(--shadow-lg);
}
.gate-card .brand { justify-content: center; padding: 0 0 6px; font-size: 1.35rem; }
.gate-card h1 { text-align: center; font-size: 1.1rem; margin-bottom: 4px; }
.gate-card .lede { text-align: center; font-size: .86rem; color: var(--ink-2); margin-bottom: 20px; }
.gate-foot { text-align: center; font-size: .78rem; color: var(--ink-muted); margin-top: 16px; }

/* ------------------------------------------------------------ mobile */

#tabbar { display: none; }

@media (max-width: 900px) {
  .grid-2, .grid-inbox { grid-template-columns: minmax(0, 1fr); }
  .dlg-split { grid-template-columns: minmax(0, 1fr); }
  .shots { flex-direction: row; }
}

@media (max-width: 720px) {
  body { font-size: 16px; }
  #sidebar { display: none; }
  #topbar { padding: 12px 16px; }
  #views { padding: 16px 16px 92px; }

  /* A phone is a camera for CardMail and nothing else, so it gets no nav at
     all - and without the bar there is nothing to keep clear at the bottom. */
  body.capture-only #tabbar { display: none; }
  body.capture-only #views { padding-bottom: 24px; }
  /* Room to hold the phone steady over a card and still see the whole tile. */
  body.capture-only .drop { min-height: 210px; }
  .panel { padding: 15px; border-radius: var(--r); }
  .fields { grid-template-columns: 1fr; }
  .drops { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .segment { flex-direction: column; gap: 3px; font-size: .78rem; padding: 8px 6px; }

  #tabbar {
    display: flex;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  #tabbar .nav-item {
    /* The sidebar's full-width nav items would each take a whole row here and
       stack the bar five deep over the page - across the bar they share it. */
    flex: 1 1 0;
    width: auto;
    min-width: 0;
    flex-direction: column;
    gap: 2px;
    font-size: .68rem;
    padding: 6px 2px;
    border-radius: var(--r-sm);
    justify-content: center;
    text-align: center;
  }
  #tabbar .nav-item .ico { font-size: 1.15rem; }
  #tabbar .nav-item .pill {
    position: absolute;
    transform: translate(14px, -6px);
    font-size: .62rem;
    padding: 0 5px;
  }
  #tabbar .nav-item { position: relative; }
  dialog { max-width: 100vw; max-height: 100vh; height: 100%; border-radius: 0; border: 0; }
  dialog > form, dialog > .dlg { max-height: 100vh; height: 100%; }
}
