/* Shared design tokens and base controls for every surface: the extension's
 * popup and the full web app in apps/app.
 *
 * Visual language follows docs/../requirements 10-nonfunctional: Satoshi for
 * display numbers, Inter for UI, a neutral grey scale, four status colours, and
 * three radii (6px buttons, 8px inputs, 12px cards).
 *
 * Colour is rationed. Cold mail is most of what the product shows, so its
 * verdict, its signals and its buttons are drawn in the grey scale (--cold-*)
 * and only the exceptions — a message worth keeping, one we are unsure about,
 * an error, a destructive button — spend a hue.
 *
 * Fonts are vendored (assets/fonts, copied next to this file by each app's
 * build) rather than linked from a CDN: the popup must paint from cache in
 * well under 100ms, and a Chrome Web Store review treats a remote font as a
 * remote resource.
 *   Inter    - SIL Open Font License 1.1
 *   Satoshi  - Indian Type Foundry Free Font License
 */
@font-face {
  font-family: 'Inter';
  src: url('assets/fonts/inter.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Satoshi';
  src: url('assets/fonts/satoshi-500.woff2') format('woff2');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Satoshi';
  src: url('assets/fonts/satoshi-700.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Satoshi', 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Neutrals */
  --fg: #171717;
  --fg-2: #404040;
  --fg-3: #737373;
  --fg-4: #a3a3a3;
  --bg: #ffffff;
  --bg-sunken: #f5f5f5;
  --bg-subtle: #fafafa;
  --bg-hover: #f5f5f5;
  --border: #e5e5e5;
  --border-strong: #d4d4d4;
  --border-faint: #f5f5f5;
  --overlay: rgba(23, 23, 23, .45);

  /* Status */
  --green: #16a34a;
  --green-fg: #15803d;
  --green-bg: #dcfce7;
  --green-soft: #f0fdf4;
  --green-border: #bbf7d0;
  --green-dot: #22c55e;
  --orange: #ea580c;
  --orange-fg: #c2410c;
  --orange-bg: #ffedd5;
  --orange-soft: #fff7ed;
  --orange-border: #fed7aa;
  --orange-dot: #fb923c;
  /* "Cold" is a verdict, not a fault: filing cold mail away is the product
     doing its job, so it reads as a strong neutral. Red below is reserved for
     the two things that really are red — an error, and a destructive action. */
  --cold: #525252;
  --cold-fg: #404040;
  --cold-bg: #ebebeb;
  --cold-soft: #f7f7f7;
  --cold-border: #d4d4d4;
  --cold-dot: #737373;
  --red: #dc2626;
  --red-fg: #b91c1c;
  --red-bg: #fee2e2;
  --red-soft: #fef2f2;
  --red-border: #fecaca;
  --blue: #2563eb;
  --blue-fg: #1d4ed8;
  --blue-bg: #dbeafe;
  --blue-soft: #eff6ff;
  --blue-border: #bfdbfe;
  --yellow: #ca8a04;
  --yellow-fg: #a16207;
  --yellow-bg: #fef9c3;

  /* Inverted (primary buttons, logo tile) */
  --solid: #171717;
  --solid-hover: #404040;
  --solid-fg: #ffffff;

  --r-btn: 6px;
  --r-input: 8px;
  --r-card: 12px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .05);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, .08);
  --shadow-lg: 0 12px 34px rgba(0, 0, 0, .14);
  --ring: 0 0 0 3px rgba(23, 23, 23, .12);
}

@media (prefers-color-scheme: dark) {
  :root {
    --fg: #fafafa;
    --fg-2: #d4d4d4;
    --fg-3: #a3a3a3;
    --fg-4: #737373;
    --bg: #1c1c1c;
    --bg-sunken: #131313;
    --bg-subtle: #232323;
    --bg-hover: #262626;
    --border: #333333;
    --border-strong: #454545;
    --border-faint: #262626;
    --overlay: rgba(0, 0, 0, .6);

    --green: #22c55e;
    --green-fg: #4ade80;
    --green-bg: #0f2c1b;
    --green-soft: #12281c;
    --green-border: #1c4d31;
    --green-dot: #22c55e;
    --orange: #f97316;
    --orange-fg: #fb923c;
    --orange-bg: #3a1f0c;
    --orange-soft: #2c1a0c;
    --orange-border: #5c3312;
    --orange-dot: #fb923c;
    --cold: #d4d4d4;
    --cold-fg: #e5e5e5;
    --cold-bg: #303030;
    --cold-soft: #262626;
    --cold-border: #4a4a4a;
    --cold-dot: #8a8a8a;
    --red: #ef4444;
    --red-fg: #f87171;
    --red-bg: #3a1414;
    --red-soft: #2b1212;
    --red-border: #5f1f1f;
    --blue: #3b82f6;
    --blue-fg: #60a5fa;
    --blue-bg: #14243f;
    --blue-soft: #131d2e;
    --blue-border: #1e3a6b;
    --yellow: #eab308;
    --yellow-fg: #facc15;
    --yellow-bg: #332a08;

    --solid: #fafafa;
    --solid-hover: #e5e5e5;
    --solid-fg: #171717;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, .5);
    --shadow-lg: 0 12px 34px rgba(0, 0, 0, .6);
    --ring: 0 0 0 3px rgba(250, 250, 250, .16);
  }
  select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23a3a3a3' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); }
}

* { box-sizing: border-box; }

/* An author `display` rule (.row, .banner, …) outranks the UA sheet's
   [hidden] { display: none }, so el.hidden alone would set the attribute and
   keep painting. Declared once, here, for every surface. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: 'cv11' 1;
}

h1, h2, h3 { margin: 0; font-weight: 600; }

a { color: inherit; }

.num { font-family: var(--font-display); font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.muted { color: var(--fg-3); }
.faint { color: var(--fg-4); }
.truncate { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-input);
  background: var(--bg);
  color: var(--fg-2);
  font: 500 13px var(--font);
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s ease, border-color .12s ease, opacity .12s ease;
}
.btn:hover:not(:disabled) { background: var(--bg-subtle); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { border-color: transparent; background: var(--solid); color: var(--solid-fg); padding: 0 14px; }
.btn.primary:hover:not(:disabled) { background: var(--solid-hover); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 12px; border-radius: var(--r-btn); }
.btn.xs { height: 26px; padding: 0 10px; font-size: 11.5px; border-radius: var(--r-btn); }
.btn.lg { height: 44px; padding: 0 20px; font-size: 14px; }
.btn.block { width: 100%; }
.btn.keep { border-color: var(--green-border); background: var(--green-soft); color: var(--green-fg); }
.btn.keep:hover:not(:disabled) { background: var(--green-bg); }
.btn.cold { border-color: var(--cold-border); background: var(--cold-soft); color: var(--cold-fg); }
.btn.cold:hover:not(:disabled) { background: var(--cold-bg); }
.btn.danger { border-color: var(--red-border); background: var(--bg); color: var(--red); }
.btn.danger:hover:not(:disabled) { background: var(--red-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover:not(:disabled) { background: var(--bg-hover); }
.btn.icon { width: 36px; padding: 0; }
.btn.sm.icon { width: 30px; }
/* Official Google sign-in button: white, full-contrast label, subtle lift. */
.btn.google { color: var(--fg); background: var(--bg); box-shadow: var(--shadow-sm); }

/* ---------- Inline notes ---------- */
/* Used by the popup and the dashboard for paused / test-mode / last-error. */
.note {
  padding: 8px 10px;
  border: 1px solid var(--blue-border);
  border-radius: var(--r-input);
  background: var(--blue-soft);
  color: var(--blue-fg);
  font-size: 11.5px;
  line-height: 1.45;
}
.note.bad { border-color: var(--red-border); background: var(--red-soft); color: var(--red); word-break: break-word; }

.spin { animation: cef-spin .8s linear infinite; }
@keyframes cef-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation-duration: 2.4s; } }

/* ---------- Form controls ---------- */
input[type=text], input[type=number], input[type=password], input[type=search], select, textarea {
  font: 400 13px var(--font);
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-input);
  background: var(--bg);
  color: var(--fg);
}
textarea { height: auto; padding: 8px 10px; font-family: var(--font-mono); font-size: 12px; line-height: 1.5; resize: vertical; }
/* Native select chrome does not match anything else on the page, so draw our
   own chevron and keep the control identical to a secondary button. */
select {
  appearance: none;
  padding: 0 30px 0 10px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23737373' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
select:hover { background-color: var(--bg-subtle); }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; border-color: var(--fg-3); box-shadow: var(--ring); }
input::placeholder, textarea::placeholder { color: var(--fg-4); }

/* Switch: a 34x20 pill, black when on (design 2e). */
.switch { position: relative; width: 34px; height: 20px; flex: none; border: 0; padding: 0; border-radius: 999px; background: var(--border-strong); cursor: pointer; transition: background .15s ease; }
.switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform .15s ease; }
.switch[aria-checked=true] { background: var(--solid); }
.switch[aria-checked=true]::after { transform: translateX(14px); background: var(--solid-fg); }
.switch:focus-visible { outline: none; box-shadow: var(--ring); }

/* Checkbox drawn as a 16px square so it matches the design in both themes. */
.check { position: relative; width: 16px; height: 16px; flex: none; border: 1.5px solid var(--border-strong); border-radius: 4px; background: var(--bg); padding: 0; cursor: pointer; }
.check[aria-checked=true] { border-color: var(--solid); background: var(--solid); }
.check[aria-checked=true]::after {
  content: '';
  position: absolute;
  left: 4px;
  top: 1px;
  width: 4px;
  height: 8px;
  border: solid var(--solid-fg);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.check:focus-visible { outline: none; box-shadow: var(--ring); }

/* ---------- Pills and badges ---------- */
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: var(--r-btn); font-size: 10.5px; font-weight: 600; }
.pill.green { background: var(--green-bg); color: var(--green-fg); }
.pill.orange { background: var(--orange-bg); color: var(--orange); }
.pill.cold { background: var(--cold-bg); color: var(--cold-fg); }
.pill.blue { background: var(--blue-bg); color: var(--blue-fg); }
.pill.grey { background: var(--bg-sunken); color: var(--fg-3); }

.dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.dot.green { background: var(--green-dot); }
.dot.orange { background: var(--orange-dot); }
.dot.cold { background: var(--cold-dot); }
.dot.grey { background: var(--fg-4); }

/* Brand mark: a solid rounded tile with the mail glyph and a red dot.
   Sizes come from the caller (logoMark in ui.js, or the surface's own CSS). */
.logo { position: relative; display: flex; align-items: center; justify-content: center; flex: none; background: var(--solid); color: var(--solid-fg); }
.logo-dot { position: absolute; right: -3px; bottom: -3px; border-radius: 50%; background: var(--red); border: 2px solid var(--bg); }

/* Sender initials. */
.avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  border-radius: 50%;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  color: var(--fg-3);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.avatar.hot { background: var(--cold-bg); border-color: var(--cold-border); color: var(--cold-fg); }

/* ---------- Toast ---------- */
.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 60; pointer-events: none; }
.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px 10px 14px;
  border-radius: 10px;
  background: var(--solid);
  color: var(--solid-fg);
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: cef-rise .18s ease-out;
}
.toast.bad { background: var(--red); color: #fff; }
.toast button { border: 0; background: transparent; color: inherit; font: 600 13px var(--font); cursor: pointer; padding: 2px 4px; opacity: .85; }
.toast button:hover { opacity: 1; }
@keyframes cef-rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Scrollbars ---------- */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border: 3px solid transparent; background-clip: content-box; border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--fg-4); background-clip: content-box; }
