/* Shared across every page — Phase 6 (visual system, docs/phase6-design.md).
   This is a screening instrument, not a listing site: quiet chrome, mono
   numerals, colour only where it carries meaning. Page-specific rules stay
   in viewer/pages/<page>.css — this file only holds what every page shares:
   fonts, tokens, topbar/nav/breadcrumb, and the generic atoms (.hint, .btn,
   .badge, .panel, .flag, motion/focus/print). */

@font-face {
  font-family: Plex;
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
  src: url(fonts/IBMPlexSans-Variable.woff2) format('woff2');
}
@font-face {
  font-family: PlexM;
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  src: url(fonts/IBMPlexMono-Regular.woff2) format('woff2');
}
@font-face {
  font-family: PlexM;
  font-weight: 500;
  font-style: normal;
  font-display: swap;
  src: url(fonts/IBMPlexMono-Medium.woff2) format('woff2');
}
@font-face {
  font-family: PlexM;
  font-weight: 600;
  font-style: normal;
  font-display: swap;
  src: url(fonts/IBMPlexMono-SemiBold.woff2) format('woff2');
}

:root {
  /* chrome — quiet, cool, never warm */
  --paper: #F5F7F8;      /* page background            */
  --surface: #FFFFFF;    /* panels, table              */
  --line: #D7DDE3;       /* borders, dividers          */
  --line-soft: #E7ECF0;  /* row separators             */
  --ink: #14202B;        /* text, topbar, primary btn  */
  --ink-2: #3D4C5A;       /* secondary text             */
  --ink-3: #6B7885;       /* labels, hints              */

  /* signals — these carry data. Never use them decoratively. */
  --good: #1B6E52;    --good-bg: #E4F0EA;   /* below median, positive margin   */
  --bad: #9E2F27;     --bad-bg: #F7E5E3;    /* above median, dealbreaker       */
  --watch: #8C6210;   --watch-bg: #FAF0DC;  /* costly flags, caution           */
  --ai: #4A5A8A;      --ai-bg: #EBEEF6;     /* anything read from listing text */
  --neg: #5A7391;     --neg-bg: #EAEFF4;    /* negotiable-tier risk (calm)     */

  --r: 4px;  /* one radius on panels/buttons/inputs. 2px on chips/flags. */

  /* Topbar only — a deliberately distinct dark blue (2026-09-06, Rickard's
     request), not the same value as --ink. Kept as its own token rather
     than reused elsewhere, so it stays a one-off accent for the topbar,
     not something that quietly starts meaning "primary" everywhere else. */
  --topbar-bg: #1B3A6B;

  /* legacy aliases — kept only so page CSS not yet swept still resolves to
     a real, correctly-meaning colour rather than breaking outright. New
     rules should reach for the tokens above directly, never these. */
  --border: var(--line);
  --bg: var(--surface);
  --bg-alt: var(--paper);
  --text: var(--ink);
  --text-muted: var(--ink-3);
  --accent: var(--ink);
  --header-bg: var(--line-soft);
  --warn: var(--watch);
}

* { box-sizing: border-box; }

html { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }

body {
  margin: 0;
  min-height: 100vh;
  font: 14px/1.5 Plex, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

/* Every numeral, ID and cadastral reference — comparing a column of
   figures only works when the digits line up. Functional, not stylistic. */
.num, td.n, th.n, .count, .score,
.mono {
  font-family: PlexM, ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}
td.n, th.n { text-align: right; white-space: nowrap; }

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

/* ---- Topbar — a dark, distinct blue (2026-09-06, Rickard's request),
   back to a dark bar after briefly matching the panels' white — see
   --topbar-bg's own comment for why it's a separate token from --ink. ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  height: 52px;
  padding: 0 16px;
  background: var(--topbar-bg);
  color: #fff;
}
.topbar .brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  text-decoration: none;
}
.topbar .brand-mark {
  width: 16px;
  height: 16px;
  border: 1.5px solid #fff;
  border-radius: 3px;
}
.mainnav { display: flex; gap: 2px; }
.navlink {
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  text-decoration: none;
  padding: 6px 12px;
  border-radius: var(--r);
}
.navlink:hover { background: rgba(255, 255, 255, 0.12); }
.navlink.is-current { background: rgba(255, 255, 255, 0.18); font-weight: 600; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 14px; font-size: 12.5px; color: rgba(255, 255, 255, 0.75); }

.crumbs {
  padding: 8px 16px;
  font-size: 12px;
  color: var(--ink-3);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.crumbs a { color: var(--ink-2); text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }
.crumb-sep { margin: 0 6px; color: var(--line); }
.crumb-current { color: var(--ink); font-weight: 500; }

/* ---- Small legacy topbar bits still referenced by page-specific markup. ---- */
.nav-link { font-size: 12px; color: var(--ink-2); text-decoration: none; margin-right: 14px; }
.nav-link:hover { text-decoration: underline; }
/* .nav-link's own dark --ink-2 is unreadable against the dark-blue topbar
   background when used inside .topbar-actions (e.g. property.php's "Report"
   link) — same class of bug this project has hit before whenever the
   topbar's own colour changed but a sibling rule's text colour didn't move
   with it. Scoped override, doesn't touch .nav-link's other real usage
   (properties.php's filter-rail "Manage / delete searches" link, on a
   light background, which was never broken). */
.topbar-actions .nav-link { color: rgba(255, 255, 255, 0.85); font-size: 14px; font-weight: 500; }
.topbar-actions .nav-link:hover { color: #fff; }
.export-link { color: var(--good); font-weight: 600; }

.hint { font-size: 12px; color: var(--ink-3); margin: 4px 0 0; }
.hint.error { color: var(--bad); }

/* ---- Panels — the one shared surface every page's content sits on. ---- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
}
.panel-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 13px;
  font-weight: 600;
}
.panel-header .note { font-size: 12px; font-weight: 400; color: var(--ink-3); }

/* ---- Generic action button. One filled style (ink), one outline, one
   danger — a page should have at most one filled/primary button visible
   at a time. ---- */
.btn {
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  padding: 7px 16px;
  border: none;
  border-radius: var(--r);
  background: var(--ink);
  color: #fff;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.15); }
.btn:disabled { opacity: 0.5; cursor: default; filter: none; }
.btn-danger { background: #fff; color: var(--bad); border: 1px solid var(--bad); }
.btn-danger:hover { background: var(--bad-bg); filter: none; }
.btn-outline { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn-outline:hover { background: var(--paper); filter: none; }
.btn-ai { background: var(--ai); color: #fff; }
.btn-ai:hover { filter: brightness(1.1); }

/* ---- Generic status pill. ---- */
.badge, .chip {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 8px;
  background: var(--line-soft);
  color: var(--ink-3);
}

/* ---- Risk / capability flags — square, a 2px left rule carries the
   tier colour, radius on the right corners only. An annotation on data,
   not a tag on a blog post. ---- */
.flag {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  padding: 1px 6px 1px 5px;
  margin: 1px 4px 1px 0;
  border-left: 2px solid;
  border-radius: 0 2px 2px 0;
  white-space: nowrap;
}
.flag.f-deal { border-color: var(--bad); background: var(--bad-bg); color: var(--bad); }
.flag.f-cost { border-color: var(--watch); background: var(--watch-bg); color: var(--watch); }
.flag.f-neg { border-color: var(--neg); background: var(--neg-bg); color: var(--neg); }

/* ---- AI-derived value marker — a small superscript, not a badge (a
   badge on every AI-sourced cell in a dense table would drown it). Portal
   data carries no marker at all: it's the default, it doesn't need
   defending. ---- */
.ai-mark {
  font-size: 9px;
  font-weight: 700;
  color: var(--ai);
  vertical-align: super;
  margin-left: 2px;
  cursor: help;
}

.form-status { font-size: 12px; color: var(--ink-3); }
.form-status.error { color: var(--bad); }
.form-status.success { color: var(--good); }

/* ---- Shared toast (app.js's PS.toast) ---- */
.ps-toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  max-width: 320px;
  padding: 10px 14px;
  border-radius: var(--r);
  font-size: 12px;
  font-weight: 600;
  background: var(--ink);
  color: #fff;
  box-shadow: 0 4px 16px rgba(20, 32, 43, 0.22);
  opacity: 0;
  transform: translateY(6px);
  pointer-events: none;
  transition: opacity 0.15s, transform 0.15s;
  z-index: 100;
}
.ps-toast-visible { opacity: 1; transform: translateY(0); }
.ps-toast-success { background: var(--good); }
.ps-toast-error { background: var(--bad); }

/* ---- Motion and a quality floor ---- */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
:focus-visible { outline: 2px solid var(--ai); outline-offset: 1px; }

@media print {
  .topbar, .crumbs, .filter-rail, .results-toolbar { display: none !important; }
}

/* ---- Mobile, 2026-09-14 (Rickard's request) — shared rules every page
   benefits from; page-specific layout changes (results table → cards,
   filter rail → drawer, search form spacing) live in each page's own CSS.
   Detection is via @media breakpoints, not JS user-agent sniffing — a
   breakpoint reacts correctly to any phone/browser and to resizing or
   rotation, where UA strings are fragile and explicitly discouraged. ---- */
@media (max-width: 640px) {
  .topbar {
    flex-wrap: wrap;
    height: auto;
    min-height: 52px;
    padding: 8px 12px;
    row-gap: 8px;
  }
  .mainnav { order: 3; width: 100%; justify-content: space-between; gap: 0; }
  .navlink { padding: 6px 8px; font-size: 12.5px; }
  .topbar-actions { order: 2; margin-left: auto; font-size: 12px; }

  /* Prevents iOS Safari's automatic zoom-on-focus for any text input under
     16px — a real, well-known mobile papercut, not a style preference. */
  input, select, textarea { font-size: 16px; }
}

/* Progressive enhancement only (feature-queried, harmless where
   unsupported): 100vh on mobile Safari can be taller than what's actually
   visible once the address bar is showing, clipping content under
   .page's own overflow:hidden. 100dvh tracks the real visible viewport. */
@supports (height: 100dvh) {
  @media (max-width: 640px) {
    body { height: 100dvh; }
  }
}
