/*
 * Copyright © 2026 Krzysztof Kasprowicz
 * Licensed under the GNU Affero General Public License, Version 3. See LICENSE in the project root for license information.
 * Project repository: https://github.com/fathomise/MailFathom
 */

/* What every artboard shares: the palette, the typeface, how a control answers a press, a keyboard focus, and a
   request for less motion, and how a surface arrives and leaves. Each colour token states its light and its dark value together, and `color-scheme` picks between
   them, so a page that follows the browser and an artboard that sets `data-theme` read the same declarations. */
:root { color-scheme: light dark; }
[data-theme="light"] { color-scheme: light; }
[data-theme="dark"] { color-scheme: dark; }

:root {
  /* Surfaces and lines: one neutral hue, 262, in both themes. */
  --bg: light-dark(oklch(0.982 0.003 262), oklch(0.183 0.016 262));
  --panel: light-dark(oklch(0.996 0.002 262), oklch(0.246 0.016 262));
  --rail: light-dark(oklch(0.958 0.006 262), oklch(0.212 0.017 262));
  --sub: light-dark(oklch(0.970 0.005 262), oklch(0.277 0.016 262));
  --hover: light-dark(oklch(0.925 0.010 262), oklch(0.325 0.021 262));
  --line: light-dark(oklch(0.912 0.008 262), oklch(0.336 0.018 262));
  --line2: light-dark(oklch(0.950 0.005 262), oklch(0.283 0.015 262));
  --border2: light-dark(oklch(0.862 0.012 262), oklch(0.416 0.022 262));

  /* Text. `faint` is the lightest value that still reads at 4.5:1 on every surface above, `hover` included, so no
     step of the ramp is decoration only. */
  --text: light-dark(oklch(0.240 0.014 262), oklch(0.945 0.007 262));
  --text2: light-dark(oklch(0.400 0.014 262), oklch(0.845 0.011 262));
  --muted: light-dark(oklch(0.465 0.014 262), oklch(0.765 0.013 262));
  --faint: light-dark(oklch(0.515 0.014 262), oklch(0.700 0.014 262));

  /* The one accent. */
  --accent: light-dark(oklch(0.480 0.185 262), oklch(0.615 0.175 262));
  --accent-2: light-dark(oklch(0.410 0.170 262), oklch(0.735 0.150 262));
  --accent-d: light-dark(oklch(0.385 0.150 262), oklch(0.865 0.085 262));
  --accent-soft: light-dark(oklch(0.945 0.038 258), oklch(0.320 0.070 262));
  --accent-line: light-dark(oklch(0.870 0.062 258), oklch(0.430 0.095 262));
  --onaccent: #ffffff;

  /* States: each a fill, a tint to sit behind it, and a text value that reads on that tint. */
  --ok: light-dark(oklch(0.56 0.14 155), oklch(0.72 0.14 155));
  --ok-soft: light-dark(oklch(0.945 0.038 155), oklch(0.30 0.045 155));
  --ok-text: light-dark(oklch(0.44 0.11 155), oklch(0.82 0.12 155));
  --warn: light-dark(oklch(0.62 0.155 62), oklch(0.74 0.13 55));
  --warn-soft: light-dark(oklch(0.955 0.045 75), oklch(0.315 0.05 50));
  --warn-text: light-dark(oklch(0.46 0.135 55), oklch(0.87 0.10 62));
  --err: light-dark(oklch(0.545 0.195 25), oklch(0.660 0.190 25));
  --err-soft: light-dark(oklch(0.958 0.028 25), oklch(0.325 0.078 22));
  --err-text: light-dark(oklch(0.470 0.180 25), oklch(0.845 0.105 25));
  --hl: light-dark(oklch(0.945 0.070 88), oklch(0.345 0.055 85));
  --hl-line: light-dark(oklch(0.775 0.145 85), oklch(0.72 0.13 85));

  /* Depth: shadows carry the neutral hue rather than black. */
  --inset: light-dark(rgba(255, 255, 255, 0.65), rgba(255, 255, 255, 0.045));
  --sh-1: light-dark(oklch(0.30 0.02 262 / 0.07), oklch(0.10 0.03 262 / 0.38));
  --sh-2: light-dark(oklch(0.30 0.025 262 / 0.14), oklch(0.10 0.03 262 / 0.50));
  --sh-3: light-dark(oklch(0.28 0.03 262 / 0.28), oklch(0.09 0.035 262 / 0.64));
  --scrim: light-dark(oklch(0.26 0.03 262 / 0.36), oklch(0.12 0.045 262 / 0.66));
}

body {
  font-family: 'Geist', system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
p, li, h1, h2, h3, h4 { text-wrap: pretty; }
::selection { background: var(--accent-soft); color: var(--text); }

/* An artboard's control is usually a `div` whose `style-hover` the runtime turns into a generated `scp…` class, and
   that class is the only mark it carries. It takes the colour transition; the press below stays with what declares
   itself a button, because a list row shrinking under a finger that is about to swipe it reads as a fault.
   Matched by the runtime's class prefix, so a regenerated runtime that names it differently loses the
   transition on those controls and nothing else. Give them a role when that happens. */
:where(button, [role="button"], [role="tab"], [role="menuitem"], [class^="scp"], [class*=" scp"]) {
  transition: scale 140ms cubic-bezier(0.16, 1, 0.3, 1), background-color 160ms ease, color 160ms ease;
}
:where(button, [role="button"], [role="tab"], [role="menuitem"]):active:not(:disabled) { scale: 0.98; }

:where(button, a, input, select, textarea, [tabindex], [role="button"]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Motion. One vocabulary for every surface that arrives or leaves: an element names its kind in `data-motion` and,
   where it can also leave, its phase in `data-phase` (`in` or `out`). The prototype keeps a closing surface mounted
   for as long as its kind takes to arrive and turns its phase to `out`, so a close animates as well as an open (`motionHold` in its
   component). Every kind moves on `translate`, `scale` and `opacity` — the individual properties — so it composes
   with whatever `transform` an element already positions itself with. An arrival fills backwards only, so once it
   ends nothing of it stays on the element — no stacking context, no containing block for a fixed child. */
:root {
  --motion-fast: 120ms;
  --motion-base: 180ms;
  --motion-slow: 240ms;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in: cubic-bezier(0.4, 0, 1, 1);
  --ease-sheet: cubic-bezier(0.32, 0.72, 0, 1);
}

@keyframes mfpulse { 0%,100% { opacity: 0.35 } 50% { opacity: 1 } }
@keyframes mfspin { to { transform: rotate(360deg) } }
@keyframes mfshim { from { background-position: 130% 0 } to { background-position: -130% 0 } }
@keyframes mftin { from { opacity: 0; transform: translateX(22px) scale(0.97) } }
@keyframes mftout { to { opacity: 0; transform: translateX(22px) scale(0.97) } }
@keyframes mftbar { from { transform: scaleX(1) } to { transform: scaleX(0) } }

@keyframes mf-scrim-in { from { background-color: transparent } }
@keyframes mf-scrim-out { to { background-color: transparent } }
@keyframes mf-fade-in { from { opacity: 0 } }
@keyframes mf-fade-out { to { opacity: 0 } }
@keyframes mf-pop-in { from { opacity: 0; scale: 0.96 } }
@keyframes mf-pop-out { to { opacity: 0; scale: 0.96 } }
@keyframes mf-rise-in { from { opacity: 0; translate: 0 18px } }
@keyframes mf-rise-out { to { opacity: 0; translate: 0 18px } }
@keyframes mf-sheet-in { from { translate: 0 100% } }
@keyframes mf-sheet-out { to { translate: 0 100% } }
@keyframes mf-drawer-in { from { translate: -100% 0 } }
@keyframes mf-drawer-out { to { translate: -100% 0 } }
@keyframes mf-push-in { from { opacity: 0; translate: 48px 0 } }
@keyframes mf-back-in { from { opacity: 0; translate: -48px 0 } }
@keyframes mf-screen-in { from { opacity: 0; translate: 0 6px } }
@keyframes mf-disclose-in { from { height: 0; padding-block: 0; opacity: 0 } }
@keyframes mf-disclose-out { to { height: 0; padding-block: 0; opacity: 0 } }
@keyframes mf-unfold-in { from { opacity: 0; translate: 0 -10px } }
@keyframes mf-unfold-out { to { opacity: 0; translate: 0 -10px } }

/* scrim — the dimmed backdrop behind a sheet, a drawer, a dialog or a menu: only its colour fades, so what it holds
   moves on its own. */
[data-motion="scrim"] { animation: mf-scrim-in var(--motion-base) var(--ease-out) backwards; }
[data-motion="scrim"][data-phase="out"] { animation: mf-scrim-out var(--motion-base) var(--ease-in) both; }
/* fade — content replacing its skeleton, a section revealed in place; out is the skeleton giving way. */
[data-motion="fade"] { animation: mf-fade-in var(--motion-base) var(--ease-out) backwards; }
[data-motion="fade"][data-phase="out"] { animation: mf-fade-out var(--motion-base) var(--ease-in) both; }
/* veil — a skeleton laid over content that is already there: arrives at once, fades away when the content is ready. */
[data-motion="veil"][data-phase="out"] { animation: mf-fade-out var(--motion-base) var(--ease-out) both; }
/* pop — a menu, a popover, a centred dialog, a floating pill: grows out of 96 %. */
[data-motion="pop"] { animation: mf-pop-in var(--motion-fast) var(--ease-out) backwards; }
[data-motion="pop"][data-phase="out"] { animation: mf-pop-out var(--motion-fast) var(--ease-in) both; }
/* rise — the docked composer on wider compositions: comes up 18 px from where it docks. */
[data-motion="rise"] { animation: mf-rise-in var(--motion-base) var(--ease-out) backwards; }
[data-motion="rise"][data-phase="out"] { animation: mf-rise-out var(--motion-base) var(--ease-in) both; }
/* sheet — a bottom sheet, and on the phone every full-screen surface (compose, a form dialog, Settings): enters from
   the bottom edge on the sheet curve the notification gesture springs on, leaves the same way. */
[data-motion="sheet"] { animation: mf-sheet-in var(--motion-slow) var(--ease-sheet) backwards; }
[data-motion="sheet"][data-phase="out"] { animation: mf-sheet-out var(--motion-slow) var(--ease-in) both; }
/* drawer — the folder list on the tablet and the phone, from the left edge. */
[data-motion="drawer"] { animation: mf-drawer-in var(--motion-slow) var(--ease-sheet) backwards; }
[data-motion="drawer"][data-phase="out"] { animation: mf-drawer-out var(--motion-slow) var(--ease-in) both; }
/* push / back — one pane at a time, as a shared horizontal axis: the detail arrives from 48 px to the right and Back
   brings the list from 48 px to the left, both fading through, so going deeper and coming back read as opposite
   directions. The pane being left is already gone, so nothing slides over an empty frame. */
[data-motion="push"] { animation: mf-push-in var(--motion-slow) var(--ease-sheet) backwards; }
[data-motion="back"] { animation: mf-back-in var(--motion-slow) var(--ease-sheet) backwards; }
/* screen — switching space from the rail or the bottom navigation: the spaces are peers, so they cross-fade with a
   6 px settle rather than slide. */
[data-motion="screen"] { animation: mf-screen-in var(--motion-base) var(--ease-out) backwards; }
/* disclose — a band opened in the flow of a column, the list's filters: unfolds from no height and folds back to none,
   so the list under it moves with it rather than jumping. */
[data-motion="disclose"] { min-height: 0; overflow: clip; animation: mf-fade-in var(--motion-base) var(--ease-out) backwards; }
[data-motion="disclose"][data-phase="out"] { animation: mf-fade-out var(--motion-base) var(--ease-in) both; }
/* Only an engine interpolating a height to `auto` travels it; elsewhere the band fades in place rather than sitting
   collapsed for half its arrival and then jumping. */
@supports (interpolate-size: allow-keywords) {
  [data-motion="disclose"] { interpolate-size: allow-keywords; animation-name: mf-disclose-in; }
  [data-motion="disclose"][data-phase="out"] { animation-name: mf-disclose-out; }
}
/* unfold — the earlier messages of a conversation shown around the one being read: each settles 10 px down into
   place, and hiding them folds them back up before they are taken out. The message being read stays still. */
[data-motion="unfold"] { animation: mf-unfold-in var(--motion-base) var(--ease-out) backwards; }
[data-motion="unfold"][data-phase="out"] { animation: mf-unfold-out var(--motion-base) var(--ease-in) both; }
[data-phase="out"] { pointer-events: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* A chip that explains itself — every verdict and confidence chip on an AI block. The chip is focusable and holds its
   sentence in a `role="tooltip"` child. A mouse's hover is the shortcut; keyboard focus and a tap reach the same
   sentence, so nothing exists only under a hover. It goes by itself: when the pointer leaves, when focus moves on, on
   Escape (`data-tip-dismissed`, set in design.js), and 4 s after a tap. Under a finger the chip is drawn at 36 and its
   target reaches 44 past its edge, as every chip in a wrapping group does. The client also pulls the sentence back
   inside the window where it would spill past it. */
[data-tip] { position: relative; cursor: help; }
[data-tip] > [role="tooltip"] {
  position: absolute; inset-inline-start: 0; top: calc(100% + 6px); z-index: 30;
  width: max-content; max-width: min(288px, calc(100vw - 32px)); box-sizing: border-box;
  padding: 7px 10px; border-radius: 8px; background: var(--text); color: var(--panel);
  font-family: 'Geist', system-ui, sans-serif; font-size: 13px; font-weight: 400; line-height: 1.4; text-wrap: pretty;
  box-shadow: 0 6px 18px var(--sh-2); pointer-events: none; visibility: hidden; opacity: 0;
  transition: opacity var(--motion-fast, 120ms) ease;
}
@media (hover: hover) { [data-tip]:hover > [role="tooltip"] { visibility: visible; opacity: 1; transition-delay: 400ms; } }
/* A control's name — its `title` in every artboard — drawn by design.js as the same bubble, one at a time, fixed to the
   window so a scrolling strip or a clipped column never cuts it. */
.mf-name-tip {
  position: fixed; z-index: 1000; pointer-events: none;
  width: max-content; max-width: min(288px, calc(100vw - 32px)); box-sizing: border-box;
  padding: 7px 10px; border-radius: 8px; background: var(--text); color: var(--panel);
  font-family: 'Geist', system-ui, sans-serif; font-size: 13px; font-weight: 400; line-height: 1.4; text-wrap: pretty;
  box-shadow: 0 6px 18px var(--sh-2);
}
[data-tip]:focus-visible:not([data-tip-dismissed]) > [role="tooltip"] { visibility: visible; opacity: 1; }
@media (hover: none) {
  [data-tip]:focus:not([data-tip-dismissed]) > [role="tooltip"] { visibility: visible; opacity: 1; animation: mf-tip-gone 1ms 4s forwards; }
}
@keyframes mf-tip-gone { to { visibility: hidden; opacity: 0; } }
@media (pointer: coarse) {
  [data-tip] { min-height: 36px; box-sizing: border-box; }
  [data-tip]::after { content: ''; position: absolute; inset: -4px 0; }
}
