/* Tender Radar — application stylesheet (green re-skin).
   Server-rendered Jinja + htmx, no build step. Styles semantic HTML + a small
   set of component classes so the thin templates look polished with minimal
   markup. Served from /static (CSP 'self').

   Inter is SELF-HOSTED from /static/fonts/ — same-origin, so the strict CSP
   (default-src 'self', which font-src falls back to) allows it with no CSP edit.
   Never use Google Fonts (that would breach the CSP). */

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/static/fonts/Inter-Regular.woff2") format("woff2");
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/static/fonts/Inter-Medium.woff2") format("woff2");
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/static/fonts/Inter-SemiBold.woff2") format("woff2");
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/static/fonts/Inter-Bold.woff2") format("woff2");
}

:root {
  /* Tender Radar green brand */
  --accent: #15924f;
  --accent-hover: #0f7a40;          /* AA-safe for small green text/links */
  --accent-bg: rgba(21, 146, 79, .09);
  --accent-line: rgba(21, 146, 79, .22);

  /* Back-compat brand aliases (kept so older selectors + tests resolve). */
  --brand: #15924f;
  --brand-dark: #0f7a40;
  --brand-tint: var(--accent-bg);

  /* surfaces (warm neutral, faint green tint) */
  --bg-0: #F6F8F6;
  --bg-1: #FFFFFF;
  --bg-2: #EEF1EE;
  --bg-elevated: #FFFFFF;

  --fg: #0E1A13;
  --fg-2: rgba(14, 26, 19, .66);
  --fg-3: rgba(14, 26, 19, .42);
  --fg-4: rgba(14, 26, 19, .16);

  --line: #E2E7E2;
  --line-subtle: #EDF0ED;
  --input-border: #D2D8D2;

  /* status */
  --success: #15924f;
  --warning: #C77700;
  --warn-bg: rgba(199, 119, 0, .08);
  --warn-line: rgba(199, 119, 0, .25);
  --error: #D14343;
  --err-bg: rgba(209, 67, 67, .07);
  --err-line: rgba(209, 67, 67, .25);

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 22px;
  --r-full: 9999px;

  --shadow-xs: 0 1px 2px rgba(16, 40, 25, .04);
  --shadow-sm: 0 1px 3px rgba(16, 40, 25, .05), 0 4px 10px rgba(16, 40, 25, .04);
  --shadow-md: 0 8px 24px rgba(16, 40, 25, .08);
  --shadow-lg: 0 20px 48px rgba(16, 40, 25, .12);

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; -webkit-font-smoothing: antialiased; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--fg);
  background: var(--bg-0);
  line-height: 1.6;
  font-size: 15px;
  letter-spacing: -0.2px;
}

img { display: block; max-width: 100%; }

/* ---- Header / nav ---- */
header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255, 255, 255, .9);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
header .nav-in {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 62px;
}
header a { text-decoration: none; color: inherit; }
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: -0.5px;
  font-size: 16px;
  color: var(--fg);
}
.brand .radar { width: 30px; height: 30px; flex: 0 0 auto; }
.brand-logo { height: 30px; width: auto; display: block; border-radius: 6px; }

/* centred tab links */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-2);
  padding: 4px;
  border-radius: var(--r-full);
}
.tab {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--fg-2);
  padding: 7px 16px;
  border-radius: var(--r-full);
  white-space: nowrap;
}
.tab:hover { color: var(--fg); }
.tab.active {
  background: var(--bg-1);
  color: var(--accent);
  box-shadow: var(--shadow-xs);
  font-weight: 600;
}

/* CSS-only user menu (native <details>) */
.usermenu { position: relative; }
.usermenu > summary { list-style: none; cursor: pointer; }
.usermenu > summary::-webkit-details-marker { display: none; }
.userbtn {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  background: var(--bg-1);
  padding: 5px 12px 5px 5px;
  border-radius: var(--r-full);
}
.userbtn:hover { border-color: var(--accent-line); box-shadow: var(--shadow-xs); }
.avatar {
  width: 30px;
  height: 30px;
  border-radius: var(--r-full);
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  flex: 0 0 auto;
}
.userbtn .email {
  font-size: 13.5px;
  font-weight: 500;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 248px;
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 60;
}
.dropdown__head {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-subtle);
  margin-bottom: 6px;
}
.dropdown__head .nm { font-weight: 600; font-size: 13.5px; }
.dropdown__head .em { font-size: 12px; color: var(--fg-3); word-break: break-all; }
.ditem {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--r-sm);
  font-size: 13.5px;
  color: var(--fg);
  width: 100%;
  text-align: left;
}
.ditem:hover { background: var(--accent-bg); color: var(--accent); text-decoration: none; }
.dmenu form { margin: 0; }
.dmenu form button.ditem {
  margin: 0;
  background: none;
  border: none;
  font: inherit;
  font-size: 13.5px;
  cursor: pointer;
  color: var(--error);
}
.dmenu form button.ditem:hover { background: rgba(209, 67, 67, .08); color: var(--error); }
.dsep { height: 1px; background: var(--line-subtle); margin: 6px 4px; }

/* ---- Layout ---- */
main {
  max-width: 1120px;
  margin: 2.5rem auto;
  padding: 0 1.5rem;
}
.pagehead { margin-bottom: 1.5rem; }
.eyebrow {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--accent);
  margin-bottom: 6px;
}

/* grids */
.grid { display: grid; gap: 1.5rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

/* page wrapper — a plain centring container directly on --bg-0 (NO card
   chrome), so real .card elements float on the background instead of sitting
   inside a second bordered box (the old double-border look). */
main > section {
  margin-bottom: 1.5rem;
}

/* cards float on the page background with a 1px border + soft resting shadow. */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 1.75rem;
  box-shadow: var(--shadow-sm);
}
.card--accent { border-color: var(--accent-line); }
.card--pad { padding: 2.25rem; }

/* KPI tiles read as interactive at-a-glance cards: a subtle hover lift. */
.kpi { padding: 1.5rem; transition: box-shadow .15s ease, transform .15s ease; }
.kpi:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.kpi .label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--fg-3);
  font-weight: 600;
}
.kpi .val { font-size: 28px; font-weight: 600; letter-spacing: -1px; margin-top: 8px; }
.kpi .val small { font-size: 15px; color: var(--fg-3); font-weight: 500; letter-spacing: 0; }
.kpi .sub { font-size: 12px; color: var(--fg-2); margin-top: 4px; }

/* ---- Typography ---- */
h1, h2, h3, h4 { font-weight: 600; letter-spacing: -0.5px; line-height: 1.15; color: var(--fg); }
h1 { font-size: 1.9rem; margin: 0 0 0.5rem; }
h2 { font-size: 1.25rem; margin: 1.5rem 0 0.6rem; }
h2:first-of-type { margin-top: 0.25rem; }
h3 { font-size: 1.1rem; letter-spacing: -0.3px; margin: 0 0 0.5rem; }
p { margin: 0.5rem 0; }
a { color: var(--accent-hover); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--fg-2); }
.small { font-size: 13.5px; }
.xs { font-size: 12px; }
.note { font-size: 12px; color: var(--fg-3); margin-top: 10px; }
.divline { height: 1px; background: var(--line-subtle); margin: 1.5rem 0; }

/* small flex helpers */
.row { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 0.6rem; }

/* ---- Forms ---- */
form { margin: 1rem 0 0; }
label {
  display: block;
  font-weight: 600;
  color: var(--fg);
  margin: 1rem 0 0.45rem;
  font-size: 13.5px;
}
.label { display: block; font-size: 13.5px; font-weight: 600; margin-bottom: 7px; }
input[type="email"],
input[type="password"],
input[type="text"],
select {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--input-border);
  border-radius: var(--r-md);
  font: inherit;
  font-size: 15px;
  color: var(--fg);
  background: var(--bg-1);
  outline: none;
}
input:focus-visible,
select:focus-visible,
button:focus-visible,
summary:focus-visible,
a:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
  outline: none;
}
fieldset {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  margin: 1.25rem 0 0;
  padding: 1rem 1.25rem;
}
legend { font-weight: 600; color: var(--fg); padding: 0 0.4rem; }
fieldset label,
label:has(input[type="checkbox"]),
label:has(input[type="radio"]) {
  font-weight: 400;
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  margin: 0.5rem 0;
}
input[type="checkbox"],
input[type="radio"] { width: auto; margin-top: 0.3rem; accent-color: var(--accent); }

/* ---- Buttons ---- */
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 1.25rem;
  padding: 11px 22px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--r-full);
  font: inherit;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover { background: var(--accent-hover); box-shadow: var(--shadow-md); }

/* button variants (opt-in classes) */
.btn { /* alias so .btn markup reads like the mockup */ }
.btn--outline,
button.btn--outline {
  background: transparent;
  color: var(--fg);
  border: 1.5px solid var(--line);
}
.btn--outline:hover,
button.btn--outline:hover { background: var(--bg-1); border-color: var(--accent-line); box-shadow: none; }
.btn--danger,
button.btn--danger {
  background: transparent;
  color: var(--error);
  border: 1.5px solid var(--err-line);
}
.btn--danger:hover,
button.btn--danger:hover { background: var(--err-bg); box-shadow: none; }
.btn--block { width: 100%; }
/* Explicit accent button (some markup opts in by class rather than the base tag). */
.btn--accent,
button.btn--accent,
a.btn--accent { background: var(--accent); color: #fff; border: none; }
.btn--accent:hover,
button.btn--accent:hover,
a.btn--accent:hover { background: var(--accent-hover); box-shadow: var(--shadow-md); text-decoration: none; }
/* Small + large size variants. */
.btn--sm,
a.btn--sm,
button.btn--sm { padding: 7px 14px; font-size: 12px; margin-top: 0; }
.btn--lg,
a.btn--lg,
button.btn--lg { padding: 14px 28px; font-size: 15px; }
/* Anchors styled as buttons keep button geometry. */
a.btn--outline,
a.btn--danger,
a.btn--accent {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 11px 22px;
  border-radius: var(--r-full);
  font-weight: 600;
  font-size: 13.5px;
  white-space: nowrap;
}
a.btn--outline:hover { text-decoration: none; }

/* ---- Chips (keywords / provinces) ---- */
.counter {
  display: inline-block;
  background: var(--accent-bg);
  color: var(--accent-hover);
  font-weight: 600;
  font-size: 13px;
  padding: 0.3rem 0.8rem;
  border-radius: var(--r-full);
}
ul.chips {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
ul.chips li { display: inline-flex; }
ul.chips form { margin: 0; }
ul.chips button {
  margin: 0;
  background: var(--accent-bg);
  color: var(--accent-hover);
  border: 1px solid var(--accent-line);
  border-radius: var(--r-full);
  padding: 0.4rem 0.85rem;
  font-weight: 500;
  font-size: 13.5px;
}
ul.chips button:hover {
  background: var(--err-bg);
  color: var(--error);
  border-color: var(--err-line);
  box-shadow: none;
}
/* the inline add form: input + button on one row */
#keyword-manager > form:last-of-type { display: flex; gap: 0.5rem; align-items: flex-end; flex-wrap: wrap; }
#keyword-manager > form:last-of-type label { width: 100%; margin-bottom: 0; }
#keyword-manager > form:last-of-type input { flex: 1 1 12rem; }
#keyword-manager > form:last-of-type button { margin-top: 0; }

/* ---- Province chips (htmx toggle, persists immediately — no Save button) ---- */
.chips-row { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.chips-row form { margin: 0; display: inline-flex; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 6px 7px 14px;
  border-radius: var(--r-full);
  background: var(--bg-2);
  color: var(--fg);
  font-size: 13.5px;
  font-weight: 500;
  border: 1px solid var(--line);
}
.chip button {
  margin: 0;
  border: none;
  background: var(--fg-4);
  color: var(--fg);
  width: 18px;
  height: 18px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: none;
}
.chip button:hover { background: var(--err-bg); color: var(--error); box-shadow: none; }
/* add-chips ARE the submit button (one click adds the province) */
button.chip--add {
  margin: 0;
  background: transparent;
  border: 1px dashed var(--line);
  color: var(--fg-3);
  border-radius: var(--r-full);
  padding: 7px 14px;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: none;
}
button.chip--add:hover {
  background: var(--accent-bg);
  border-color: var(--accent-line);
  color: var(--accent-hover);
  box-shadow: none;
}

/* ---- Badges ---- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 11px;
  border-radius: var(--r-full);
  background: var(--bg-2);
  color: var(--fg-2);
}
.badge--paid { background: var(--accent-bg); color: var(--accent-hover); }
.badge--free { background: var(--bg-2); color: var(--fg-2); }
.badge--ok { background: var(--accent-bg); color: var(--accent-hover); }
.badge--warn { background: var(--warn-bg); color: var(--warning); }
/* a quiet neutral tag (procurement type) and a muted "Cancelled" marker (B3) */
.badge--soft { background: var(--bg-2); color: var(--fg-3); font-weight: 500; }
.badge--cancelled {
  background: var(--bg-2);
  color: var(--fg-3);
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; display: inline-block; }

/* matches table: procurement/cancelled tag row + the Documents disclosure */
.t-tags { display: inline-flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
details.docs > summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-hover);
  white-space: nowrap;
}
details.docs[open] > summary { margin-bottom: 6px; }
.docs-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.docs-list a { font-size: 13px; }

/* ---- Segmented control ---- */
.seg { display: inline-flex; background: var(--bg-2); border-radius: var(--r-full); padding: 4px; }
.seg .opt { font-size: 13.5px; font-weight: 500; color: var(--fg-2); padding: 8px 18px; border-radius: var(--r-full); }
.seg .opt.on { background: var(--bg-1); color: var(--accent); font-weight: 600; box-shadow: var(--shadow-xs); }

/* ---- Callouts / alerts ---- */
.ok,
[role="status"].ok {
  background: var(--accent-bg);
  border: 1px solid var(--accent-line);
  color: var(--accent-hover);
  padding: 0.75rem 1rem;
  border-radius: var(--r-md);
  margin: 1rem 0;
  font-size: 13.5px;
}
.error,
[role="alert"].error {
  background: var(--err-bg);
  border: 1px solid var(--err-line);
  color: var(--error);
  padding: 0.75rem 1rem;
  border-radius: var(--r-md);
  margin: 1rem 0;
}
.alert--info {
  background: var(--accent-bg);
  border: 1px solid var(--accent-line);
  color: var(--accent-hover);
  padding: 0.85rem 1rem;
  border-radius: var(--r-md);
  margin: 1rem 0;
  font-size: 13.5px;
}
.upgrade-prompt {
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
  color: var(--warning);
  padding: 1rem 1.25rem;
  border-radius: var(--r-md);
  margin: 1rem 0;
}
.upgrade-prompt a { margin-right: 1rem; font-weight: 600; color: var(--warning); }

/* ---- Danger zone ---- */
.danger {
  border: 1px solid var(--err-line);
  border-radius: var(--r-lg);
  padding: 1.5rem;
  background: rgba(209, 67, 67, .025);
}
.danger h3 { color: var(--error); }

/* ---- Tables ---- */
.tablewrap { border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; }
table { width: 100%; border-collapse: collapse; margin: 1rem 0; font-size: 13.5px; }
.tablewrap table { margin: 0; }
th {
  text-align: left;
  padding: 12px 16px;
  background: var(--bg-0);
  border-bottom: 1px solid var(--line);
  color: var(--fg-2);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
}
td { padding: 14px 16px; border-bottom: 1px solid var(--line-subtle); vertical-align: top; }
tr:last-child td { border-bottom: none; }
.t-title { font-weight: 600; color: var(--fg); }
.t-link { color: var(--accent-hover); font-weight: 600; white-space: nowrap; }
td .badge { margin: 0 4px 4px 0; }

/* matches pagination (§C): compact page-size select + count/pager row */
select.pagesize { width: auto; padding: 6px 10px; font-size: 13px; margin: 0; }
.matches-pager { margin-top: 1rem; }
.matches-pager .btn--sm { margin-top: 0; }

/* follow a tender (§E): the star toggle on match rows + Followed page */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.follow-cell form { margin: 0; display: inline; }
.follow-btn {
  margin: 0;
  padding: 2px 4px;
  background: transparent;
  border: none;
  box-shadow: none;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  color: var(--fg-4);
}
.follow-btn:hover { background: transparent; box-shadow: none; color: var(--warning); }
.follow-btn.is-following { color: var(--warning); }
.changelog { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.changelog li { font-size: 13.5px; line-height: 1.5; }

/* matches export (§D): a small "Export ▾" disclosure menu (xlsx / CSV) */
.export-menu { position: relative; display: inline-block; }
.export-menu > summary { list-style: none; cursor: pointer; }
.export-menu > summary::-webkit-details-marker { display: none; }
.export-menu__items {
  position: absolute;
  right: 0;
  margin-top: 4px;
  min-width: 150px;
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  z-index: 20;
}
.export-menu__items a { padding: 9px 14px; font-size: 13px; color: var(--fg); }
.export-menu__items a:hover { background: var(--bg-1); text-decoration: none; }

/* ---- Plan feature lists ---- */
main ul:not(.chips) { padding-left: 1.25rem; }
main ul:not(.chips) li { margin: 0.35rem 0; }
ul.ticks { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 0.6rem; }
ul.ticks li { margin: 0; padding-left: 1.5rem; position: relative; font-size: 13.5px; }
ul.ticks li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.45em;
  width: 8px;
  height: 5px;
  border-left: 2px solid var(--accent);
  border-bottom: 2px solid var(--accent);
  transform: rotate(-45deg);
}

.price { font-size: 2.1rem; font-weight: 600; letter-spacing: -1.2px; margin: 0.5rem 0 0; }
.price small { font-size: 15px; color: var(--fg-3); font-weight: 500; letter-spacing: 0; }

@media (max-width: 780px) {
  .tabs { display: none; }
  .userbtn .email { display: none; }
}
@media (max-width: 480px) {
  main { margin: 1.25rem auto; }
  .card { padding: 1.25rem; }
}
