/* ==========================================================================
   FirstLook design tokens + base components
   Derived from the FirstMate / FirstMeasure portal (index.php, platform-ui.js,
   brand-kit.css). Shared by the web app (server/public/css/firstlook.css) and
   the Chrome extension (extension/ui/firstlook.css). Keep both copies in sync:
   `node scripts/sync-brand.mjs` copies this file + fonts into both places.
   ========================================================================== */

@font-face { font-family: 'Montserrat'; font-weight: 400; font-style: normal; font-display: swap; src: url('../fonts/montserrat-regular.woff2') format('woff2'); }
@font-face { font-family: 'Montserrat'; font-weight: 500; font-style: normal; font-display: swap; src: url('../fonts/montserrat-medium.woff2') format('woff2'); }
@font-face { font-family: 'Montserrat'; font-weight: 600; font-style: normal; font-display: swap; src: url('../fonts/montserrat-semibold.woff2') format('woff2'); }
@font-face { font-family: 'Montserrat'; font-weight: 700; font-style: normal; font-display: swap; src: url('../fonts/montserrat-bold.woff2') format('woff2'); }
@font-face { font-family: 'Montserrat'; font-weight: 800 1000; font-style: normal; font-display: swap; src: url('../fonts/montserrat-extrabold.woff2') format('woff2'); }

:root {
  /* Brand */
  --fl-red: #d93025;
  --fl-red-rgb: 217, 48, 37;
  --fl-red-dark: #b0261e;
  --fl-red-deep: #8f1d18;
  --fl-red-soft: rgba(217, 48, 37, .08);
  --fl-red-tint: rgba(217, 48, 37, .12);
  --fl-on-red: #ffffff;
  --fl-gradient: linear-gradient(155deg, #8f1d18 0%, #c52a21 42%, #e45147 100%);
  --fl-gradient-bar: linear-gradient(90deg, #b1241c 0%, #d93025 38%, #ef5a4f 100%);

  /* Neutrals (Untitled-UI greys used across the portal) */
  --fl-ink: #101828;
  --fl-ink-2: #202124;
  --fl-text: #344054;
  --fl-text-2: #475467;
  --fl-muted: #667085;
  --fl-muted-2: #98a2b3;
  --fl-line: #d0d5dd;
  --fl-line-2: #e4e7ec;
  --fl-line-3: #eaecf0;
  --fl-line-soft: #edf0f4;
  --fl-bg: #f0f2f5;
  --fl-bg-2: #f7f8fa;
  --fl-surface: #ffffff;
  --fl-surface-2: #f8fafc;
  --fl-surface-3: #f2f4f7;

  /* Dark chrome (recorder controls, player) — from FirstMate call window theme */
  --fl-night: #0b1018;
  --fl-night-2: #111827;
  --fl-night-3: #1d2939;
  --fl-night-line: #344054;
  --fl-glass-dark: rgba(15, 23, 42, .86);

  /* Status */
  --fl-success: #067647;  --fl-success-bg: #e6f4ea; --fl-success-line: #b7e1c1; --fl-success-text: #137333;
  --fl-warning: #b54708;  --fl-warning-bg: #fffaeb; --fl-warning-line: #fedf89;
  --fl-danger: #b42318;   --fl-danger-bg: #fce8e6;  --fl-danger-line: #f4b4ae;  --fl-danger-text: #c5221f;
  --fl-info: #175cd3;     --fl-info-bg: #eef2f6;    --fl-info-line: #d0d5dd;

  /* Radii */
  --fl-r-xs: 6px;
  --fl-r-sm: 8px;
  --fl-r-md: 10px;
  --fl-r-lg: 12px;
  --fl-r-xl: 16px;
  --fl-r-2xl: 18px;
  --fl-r-pill: 999px;

  /* Shadows (slate-tinted) */
  --fl-shadow-xs: 0 1px 2px rgba(16, 24, 40, .04);
  --fl-shadow-sm: 0 4px 12px rgba(15, 23, 42, .06);
  --fl-shadow: 0 10px 30px rgba(0, 0, 0, .08);
  --fl-shadow-lift: 0 20px 44px rgba(0, 0, 0, .12);
  --fl-shadow-pop: 0 18px 42px rgba(15, 23, 42, .18);
  --fl-shadow-dialog: 0 24px 70px rgba(15, 23, 42, .28);
  --fl-shadow-red: 0 10px 22px rgba(var(--fl-red-rgb), .25);

  /* Motion */
  --fl-ease: cubic-bezier(.22, 1, .36, 1);
  --fl-ease-std: cubic-bezier(.2, .8, .2, 1);
  --fl-fast: .14s;
  --fl-med: .18s;
  --fl-slow: .32s;

  /* Focus */
  --fl-focus: 0 0 0 3px rgba(var(--fl-red-rgb), .14);
  --fl-focus-border: rgba(var(--fl-red-rgb), .45);

  --fl-font: 'Montserrat', Inter, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  --fl-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--fl-font);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.45;
  color: var(--fl-ink);
  background: var(--fl-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
h1, h2, h3, h4 { margin: 0; font-weight: 800; color: var(--fl-ink); letter-spacing: -.3px; }
h1 { font-size: 26px; line-height: 1.3; }
h2 { font-size: 20px; line-height: 1.3; }
h3 { font-size: 16px; line-height: 1.35; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img, svg, video { display: block; max-width: 100%; }
::selection { background: rgba(var(--fl-red-rgb), .18); }

/* Scrollbars (portal style) */
* { scrollbar-width: thin; scrollbar-color: rgba(71, 84, 103, .52) transparent; }
*::-webkit-scrollbar { width: 12px; height: 12px; }
*::-webkit-scrollbar-thumb { background: rgba(71, 84, 103, .52); border: 3px solid transparent; border-radius: 999px; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background-color: rgba(52, 64, 84, .78); }
*::-webkit-scrollbar-track { background: transparent; }

/* ---------- Type helpers ---------- */
.fl-eyebrow { font-size: 11px; font-weight: 800; color: var(--fl-muted); letter-spacing: .5px; text-transform: uppercase; }
.fl-label { display: block; font-size: 10px; font-weight: 800; color: var(--fl-muted); letter-spacing: .04em; text-transform: uppercase; margin-bottom: 6px; }
.fl-muted { color: var(--fl-muted); font-weight: 600; }
.fl-small { font-size: 12px; }
.fl-tiny { font-size: 11px; }

/* ---------- Buttons ---------- */
.fl-btn {
  --h: 38px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: var(--h); padding: 0 16px;
  border: 1px solid transparent; border-radius: var(--fl-r-pill);
  font-size: 13px; font-weight: 800; white-space: nowrap; line-height: 1;
  background: var(--fl-surface); color: var(--fl-text);
  transition: background var(--fl-med) ease, border-color var(--fl-med) ease, color var(--fl-med) ease, box-shadow var(--fl-med) ease, transform var(--fl-med) ease;
  user-select: none;
}
.fl-btn:focus-visible { outline: 2px solid var(--fl-red); outline-offset: 2px; }
.fl-btn:disabled, .fl-btn[aria-disabled="true"] { opacity: .55; pointer-events: none; }
.fl-btn svg { width: 16px; height: 16px; flex: none; }
.fl-btn--primary { background: var(--fl-red); color: var(--fl-on-red); box-shadow: var(--fl-shadow-red); }
.fl-btn--primary:hover { background: var(--fl-red-dark); transform: translateY(-1px); }
.fl-btn--primary:active { transform: translateY(0); }
.fl-btn--secondary { border-color: var(--fl-line); background: var(--fl-surface); color: var(--fl-text); }
.fl-btn--secondary:hover { border-color: rgba(var(--fl-red-rgb), .35); color: var(--fl-red); }
.fl-btn--ghost { background: transparent; color: var(--fl-text); }
.fl-btn--ghost:hover { background: var(--fl-surface-3); }
.fl-btn--danger { background: var(--fl-danger); color: #fff; }
.fl-btn--danger:hover { background: #912018; }
.fl-btn--dark { background: var(--fl-night-2); color: #fff; }
.fl-btn--dark:hover { background: var(--fl-night-3); }
.fl-btn--sm { --h: 32px; padding: 0 12px; font-size: 12px; }
.fl-btn--lg { --h: 46px; padding: 0 22px; font-size: 14px; }
.fl-btn--block { width: 100%; }
.fl-btn--square { padding: 0; width: var(--h); border-radius: var(--fl-r-md); }
.fl-btn--round { padding: 0; width: var(--h); border-radius: 50%; }

/* Icon button (34px round, portal top bar style) */
.fl-icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px; padding: 0;
  border-radius: var(--fl-r-pill); border: 1px solid rgba(0, 0, 0, .10);
  background: var(--fl-surface); color: var(--fl-text-2);
  transition: color var(--fl-fast) ease, border-color var(--fl-fast) ease, background var(--fl-fast) ease;
}
.fl-icon-btn:hover { color: var(--fl-red); border-color: rgba(var(--fl-red-rgb), .30); }
.fl-icon-btn svg { width: 16px; height: 16px; }

/* ---------- Inputs ---------- */
.fl-input, .fl-select, .fl-textarea {
  width: 100%; height: 40px; padding: 0 12px;
  border: 1px solid var(--fl-line); border-radius: var(--fl-r-md);
  background: var(--fl-surface); color: var(--fl-ink);
  font-size: 13px; font-weight: 600;
  transition: border-color var(--fl-fast) ease, box-shadow var(--fl-fast) ease, background var(--fl-fast) ease;
}
.fl-textarea { height: auto; min-height: 84px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.fl-select { appearance: none; padding-right: 34px; 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='%23667085' stroke-width='2.5' 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 12px center; }
.fl-input::placeholder, .fl-textarea::placeholder { color: var(--fl-muted-2); font-weight: 600; }
.fl-input:focus, .fl-select:focus, .fl-textarea:focus { outline: none; border-color: var(--fl-focus-border); box-shadow: var(--fl-focus); }
.fl-search { position: relative; }
.fl-search .fl-input { height: 36px; border-radius: var(--fl-r-pill); background: var(--fl-surface-2); padding-left: 36px; }
.fl-search .fl-input:focus { background: #fff; }
.fl-search > svg { position: absolute; left: 12px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%); color: var(--fl-muted); pointer-events: none; }

/* Toggle switch (portal 34x20) */
.fl-switch { position: relative; display: inline-block; width: 34px; height: 20px; flex: none; }
.fl-switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; z-index: 1; }
.fl-switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--fl-line); transition: background var(--fl-med) ease; }
.fl-switch span::after { content: ''; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(15, 23, 42, .18); transition: transform var(--fl-med) var(--fl-ease); }
.fl-switch input:checked + span { background: var(--fl-red); }
.fl-switch input:checked + span::after { transform: translateX(14px); }
.fl-switch input:focus-visible + span { box-shadow: var(--fl-focus); }

/* Segmented control */
.fl-seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: var(--fl-r-pill); background: var(--fl-surface-3); border: 1px solid var(--fl-line-3); }
.fl-seg button { border: 0; background: transparent; height: 30px; padding: 0 14px; border-radius: var(--fl-r-pill); font-size: 12px; font-weight: 800; color: var(--fl-muted); transition: background var(--fl-med) ease, color var(--fl-med) ease, box-shadow var(--fl-med) ease; display: inline-flex; align-items: center; gap: 6px; }
.fl-seg button[aria-pressed="true"], .fl-seg button.is-active { background: #fff; color: var(--fl-ink); box-shadow: 0 1px 3px rgba(16, 24, 40, .12); }

/* ---------- Surfaces ---------- */
.fl-card { background: var(--fl-surface); border: 1px solid var(--fl-line-3); border-radius: var(--fl-r-xl); box-shadow: var(--fl-shadow-xs); }
.fl-card__head { padding: 12px 16px; border-bottom: 1px solid var(--fl-line-soft); background: #fbfcfe; border-radius: var(--fl-r-xl) var(--fl-r-xl) 0 0; font-weight: 800; }
.fl-panel { background: var(--fl-surface); border: 1px solid var(--fl-line-2); border-radius: var(--fl-r-xl); }
.fl-divider { height: 1px; background: var(--fl-line-soft); border: 0; margin: 12px 0; }

/* Badge / chip */
.fl-badge { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 9px; border-radius: var(--fl-r-pill); font-size: 10.5px; font-weight: 800; letter-spacing: .3px; text-transform: uppercase; background: var(--fl-surface-3); color: var(--fl-text-2); }
.fl-badge--red { background: var(--fl-red-soft); color: var(--fl-red); }
.fl-badge--green { background: var(--fl-success-bg); color: var(--fl-success-text); }
.fl-badge--amber { background: var(--fl-warning-bg); color: var(--fl-warning); }
.fl-badge--dark { background: rgba(15, 23, 42, .78); color: #fff; backdrop-filter: blur(6px); }
.fl-chip { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 11px; border-radius: var(--fl-r-pill); border: 1px solid var(--fl-line-3); background: #fff; font-size: 12px; font-weight: 700; color: var(--fl-text); transition: border-color var(--fl-fast) ease, color var(--fl-fast) ease, background var(--fl-fast) ease; }
.fl-chip:hover { border-color: rgba(var(--fl-red-rgb), .3); }
.fl-chip.is-active { border-color: rgba(var(--fl-red-rgb), .28); background: var(--fl-red-soft); color: var(--fl-red); }

/* Avatar */
.fl-avatar { display: inline-grid; place-items: center; flex: none; width: 32px; height: 32px; border-radius: 50%; background: #e8f0fe; color: #185abc; font-size: 12px; font-weight: 800; text-transform: uppercase; overflow: hidden; }
.fl-avatar--sm { width: 24px; height: 24px; font-size: 10px; }
.fl-avatar--lg { width: 40px; height: 40px; font-size: 14px; }

/* ---------- Dialog ---------- */
.fl-backdrop { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 18px; background: rgba(15, 23, 42, .42); backdrop-filter: blur(3px); animation: fl-fade var(--fl-med) ease; }
.fl-dialog { width: min(460px, calc(100vw - 36px)); max-height: calc(100vh - 36px); overflow: auto; background: #fff; border: 1px solid rgba(15, 23, 42, .10); border-radius: var(--fl-r-2xl); box-shadow: var(--fl-shadow-dialog); animation: fl-pop var(--fl-slow) var(--fl-ease); }
.fl-dialog__head { padding: 18px 20px 4px; }
.fl-dialog__title { font-size: 16px; font-weight: 800; color: var(--fl-ink); }
.fl-dialog__body { padding: 10px 20px 8px; display: grid; gap: 12px; color: var(--fl-text-2); }
.fl-dialog__actions { padding: 14px 20px 20px; display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- Menu / popover ---------- */
.fl-menu { min-width: 200px; padding: 6px; background: rgba(255, 255, 255, .98); border: 1px solid rgba(15, 23, 42, .10); border-radius: 14px; box-shadow: var(--fl-shadow-pop); backdrop-filter: blur(14px); animation: fl-drop var(--fl-med) var(--fl-ease); }
.fl-menu__item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; background: none; border-radius: var(--fl-r-md); font-size: 13px; font-weight: 700; color: var(--fl-text); text-align: left; }
.fl-menu__item:hover, .fl-menu__item:focus-visible { background: var(--fl-surface-3); outline: none; color: var(--fl-ink); }
.fl-menu__item svg { width: 16px; height: 16px; color: var(--fl-muted); }
.fl-menu__item--danger { color: var(--fl-danger); }
.fl-menu__item--danger svg { color: var(--fl-danger); }
.fl-menu__sep { height: 1px; margin: 5px 4px; background: var(--fl-line-soft); }

/* ---------- Toast ---------- */
.fl-toasts { position: fixed; right: 18px; bottom: 18px; z-index: 2000; display: grid; gap: 10px; pointer-events: none; }
.fl-toast { pointer-events: auto; display: flex; align-items: center; gap: 12px; min-width: 280px; max-width: 380px; padding: 12px 14px 12px 12px; background: rgba(255, 255, 255, .96); border: 1px solid rgba(0, 0, 0, .08); border-radius: var(--fl-r-xl); box-shadow: 0 18px 50px rgba(0, 0, 0, .16); backdrop-filter: blur(10px); animation: fl-toast-in var(--fl-slow) var(--fl-ease); }
.fl-toast__ic { display: grid; place-items: center; flex: none; width: 36px; height: 36px; border-radius: 12px; background: var(--fl-success-bg); color: var(--fl-success-text); }
.fl-toast--error .fl-toast__ic { background: var(--fl-danger-bg); color: var(--fl-danger-text); }
.fl-toast--info .fl-toast__ic { background: var(--fl-info-bg); color: var(--fl-text-2); }
.fl-toast__t1 { font-size: 13px; font-weight: 800; color: #111; }
.fl-toast__t2 { font-size: 12px; font-weight: 600; color: #666; }

/* ---------- Tooltip ---------- */
[data-tip] { position: relative; }
[data-tip]:hover::after, [data-tip]:focus-visible::after {
  content: attr(data-tip); position: absolute; left: 50%; bottom: calc(100% + 8px); transform: translateX(-50%);
  padding: 7px 10px; border-radius: 9px; background: rgba(15, 23, 42, .96); color: #fff;
  font-size: 11px; font-weight: 700; line-height: 1.3; white-space: nowrap; pointer-events: none; z-index: 50;
  box-shadow: 0 10px 24px rgba(15, 23, 42, .22); animation: fl-fade .12s ease;
}

/* ---------- Skeleton / empty ---------- */
.fl-skel { background: linear-gradient(90deg, #eef0f3 0%, #f6f7f9 40%, #eef0f3 80%); background-size: 200% 100%; animation: fl-shimmer 1.3s linear infinite; border-radius: var(--fl-r-md); }
.fl-empty { display: grid; place-items: center; gap: 10px; padding: 56px 24px; text-align: center; color: var(--fl-muted); }

/* ---------- Spinner ---------- */
.fl-spinner { width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid rgba(var(--fl-red-rgb), .18); border-top-color: var(--fl-red); animation: fl-spin .8s linear infinite; }

/* ---------- Recording dot ---------- */
.fl-rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--fl-red); box-shadow: 0 0 0 0 rgba(var(--fl-red-rgb), .6); animation: fl-pulse 1.6s ease-out infinite; }

/* ---------- Keyframes ---------- */
@keyframes fl-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes fl-pop { from { opacity: 0; transform: translateY(8px) scale(.985); } to { opacity: 1; transform: none; } }
@keyframes fl-drop { from { opacity: 0; transform: translateY(-8px) scale(.985); } to { opacity: 1; transform: none; } }
@keyframes fl-toast-in { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes fl-spin { to { transform: rotate(360deg); } }
@keyframes fl-shimmer { to { background-position: -200% 0; } }
@keyframes fl-pulse { 0% { box-shadow: 0 0 0 0 rgba(var(--fl-red-rgb), .55); } 70% { box-shadow: 0 0 0 9px rgba(var(--fl-red-rgb), 0); } 100% { box-shadow: 0 0 0 0 rgba(var(--fl-red-rgb), 0); } }

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