/* ==========================================================================
   TOWN OF LISBON, MAINE — WEB DESIGN SYSTEM
   v1.0

   Shared tokens, chrome and components for town web applications.
   Import this FIRST, then a page-specific stylesheet for anything unique.

     <link rel="stylesheet" href="lisbon-design.css">
     <link rel="stylesheet" href="my-page.css">

   Rules that keep pages consistent:
     1. Never hardcode a colour, radius or shadow — use a token.
     2. Single light theme. Do not add prefers-color-scheme blocks.
     3. Scope responsive queries to `screen` so printing is unaffected.
     4. Uppercase labels use .eyebrow, never a bare <h2> with custom styles.
   ========================================================================== */

/* ---------------------------------------------------------------- fonts --- */
/* Outfit, self-hosted — no third-party request from a resident's browser. */
@font-face { font-family: "Outfit"; font-style: normal; font-weight: 400; font-display: swap; src: url("fonts/outfit-400.woff2") format("woff2"); }
@font-face { font-family: "Outfit"; font-style: normal; font-weight: 500; font-display: swap; src: url("fonts/outfit-500.woff2") format("woff2"); }
@font-face { font-family: "Outfit"; font-style: normal; font-weight: 600; font-display: swap; src: url("fonts/outfit-600.woff2") format("woff2"); }
@font-face { font-family: "Outfit"; font-style: normal; font-weight: 700; font-display: swap; src: url("fonts/outfit-700.woff2") format("woff2"); }

/* --------------------------------------------------------------- tokens --- */
:root {
  color-scheme: light;

  /* @group Brand blues */
  --navy:       #043454;   /* masthead, footer, primary button, headings   */
  --navy-2:     #0A4368;   /* primary button hover                          */
  --navy-3:     #12587F;   /* links, hover accents                          */
  --blue:       #1D5B82;   /* title band, chart series                      */
  --blue-light: #B0D3EB;   /* on-navy secondary text, chart accents         */
  --blue-pale:  #E6F1F8;   /* row hover, selected pill, quiet tint          */

  /* @group Neutrals */
  /* Warmed slightly so they sit on the cream ground. */
  --ink:      #10222E;     /* body text                                     */
  --ink-2:    #2C3E49;     /* secondary text                                */
  --slate:    #566671;     /* labels, captions                              */
  --slate-2:  #61707A;     /* placeholders, chevrons, muted values          */
  --line:     #DED7C9;     /* strong rule                                   */
  --line-2:   #EDE7DB;     /* hairline rule                                 */

  /* @group Forest green */
  /* From the pine trees in the town logo. --green is a GRAPHIC colour only
     (3.5:1 on cream); use --green-deep for anything that has to be read. */
  --green:       #528F53;   /* rules, marks, chart series                    */
  --green-deep:  #3E7340;   /* green text and icons, passes AA               */
  --green-pale:  #EAF3EA;   /* green tint fill                               */

  /* @group Grounds */
  --cream:     #F8F1E6;    /* page background                               */
  --cream-2:   #FCF8F1;    /* inset fields                                  */
  --surface:   #FFFFFF;    /* cards, panels                                 */
  --surface-2: #FAFCFD;    /* subtle alternate surface                      */

  /* @group Semantic */
  /* Deliberately NOT the brand blues, so "up/down" never reads as "selected".
     Amber for increases, green for decreases. */
  --rise:    #96570F;
  --rise-bg: #FAEFDD;
  --fall:    #346335;
  --fall-bg: #EAF3EA;

  /* @group Focus */
  --focus: #12587F;   /* focus ring on every interactive element */

  /* @group Text roles */
  /* These must not follow the brand navy blindly. */
  --heading:  #043454;     /* headings on a light surface                   */
  --on-tint:  #043454;     /* text sitting on a --blue-pale fill            */
  --dot-last: #043454;     /* emphasised chart endpoint                     */

  /* @group Radii */
  /* Pills for controls, soft rectangles for surfaces. */
  --r-sm: 6px;
  --r:    10px;
  --r-lg: 14px;
  --pill: 999px;

  /* @group Elevation */
  --shadow-1: 0 1px 2px rgba(4, 52, 84, .07), 0 2px 6px rgba(4, 52, 84, .06);
  --shadow-2: 0 4px 14px rgba(4, 52, 84, .11), 0 2px 5px rgba(4, 52, 84, .06);
  --shadow-3: 0 22px 60px rgba(4, 52, 84, .30);

  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  /* Brand lockup sizing — the title band's top padding depends on the spill. */
  --brand-size:   132px;  /* logo height in the masthead            */
  --brand-spill:  46px;   /* how far the plate hangs below the masthead */
  --masthead-pad: .8rem;  /* masthead vertical padding — the spill maths uses it */

  --sans: "Outfit", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* ------------------------------------------------------------ base/reset --- */
* { box-sizing: border-box; }

/* An author `display` rule outranks the UA's [hidden] rule, so elements
   toggled with .hidden = true would otherwise stay visible. */
[hidden] { display: none !important; }

html { height: 100%; }

body {
  margin: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  font-weight: 400;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; text-wrap: balance; }
a { color: var(--navy-3); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

/* Page gutter. Every full-width band puts its content in one of these. */
.wrap { width: min(1180px, 100% - 2.5rem); margin-inline: auto; }

/* Uppercase section label. The one way to title a block of content. */
.eyebrow {
  font-size: .68rem; font-weight: 700; letter-spacing: .13em;
  text-transform: uppercase; color: var(--slate);
}

/* ------------------------------------------------------------ app shell --- */
/* Opt in with <body class="app-shell">: masthead pinned to the top of the
   window, footer to the bottom, everything between scrolling in .appscroll.
   Flex column rather than position:fixed — fixed bands overlap the scrolling
   content and need compensating padding that drifts out of sync. */
body.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;        /* keeps the footer put when mobile chrome slides */
  overflow: hidden;
}
body.app-shell .masthead,
body.app-shell footer { flex: 0 0 auto; }
body.app-shell .appscroll {
  flex: 1 1 auto;
  min-height: 0;         /* without this a flex child will not shrink and scroll */
  overflow-y: auto;
  overscroll-behavior: contain;
}
.appscroll > main { padding-bottom: 2.2rem; }

/* ------------------------------------------------------------- masthead --- */
.masthead { background: var(--navy); color: #fff; position: relative; z-index: 3;
            border-bottom: 3px solid var(--green); }
.masthead a { color: #fff; }
.masthead-top { display: flex; align-items: center; gap: 1.15rem; padding: var(--masthead-pad) 0; flex-wrap: wrap; }

/* Brand lockup. The logo sits on a cream plate that deliberately hangs below
   the masthead into the band beneath it, so the identity breaks the banding
   instead of sitting inside it. --brand-spill is how far it hangs; the title
   band's top padding is set to clear it. */
.brandplate {
  display: block; flex: none;
  background: var(--cream);
  border-radius: var(--r-lg);
  padding: .6rem .8rem;
  box-shadow: var(--shadow-2);
  /* Anchored to the top of the row and pulled up by its own overhang plus the
     masthead padding, so --brand-spill is exactly the visible overhang. */
  align-self: flex-start;
  margin-bottom: calc((var(--brand-spill) + var(--masthead-pad)) * -1);
  position: relative; z-index: 4;
}
.brandmark { display: block; height: var(--brand-size); width: auto; }



.wordmark { display: flex; flex-direction: column; line-height: 1.2; }
.wordmark b { font-size: 1.2rem; font-weight: 600; letter-spacing: .015em; }
.wordmark span {
  font-size: .66rem; font-weight: 500; letter-spacing: .17em;
  text-transform: uppercase; color: var(--blue-light);
}

.masthead-links {
  margin-left: auto; display: flex; gap: 1.5rem; flex-wrap: wrap;
  justify-content: flex-end; align-items: baseline;
  font-size: .8rem; font-weight: 500; letter-spacing: .07em; text-transform: uppercase;
}
/* Always underlined; the underline changes colour on hover rather than
   appearing on hover, so the links never shift and the target is obvious. */
.masthead-links a {
  color: #fff;
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 6px;
  text-decoration-color: rgba(255, 255, 255, .38);
  transition: text-decoration-color .14s ease, color .14s ease;
}
.masthead-links a:hover,
.masthead-links a:focus-visible { text-decoration-color: var(--green); }
@media (prefers-reduced-motion: reduce) { .masthead-links a { transition: none; } }

/* Title band — the mid-blue stripe that names the page. */
.titlebar { background: var(--blue); }
.titlebar .wrap { padding: calc(var(--brand-spill) + 1.1rem) 0 2.5rem; }
.titlebar h1 {
  color: #fff; font-weight: 700; letter-spacing: .015em; text-transform: uppercase;
  font-size: clamp(1.5rem, 3.6vw, 2.15rem); line-height: 1.12;
}
.titlebar p { color: #CFE4F2; margin: .45rem 0 0; max-width: 60ch; font-size: .97rem; }

/* --------------------------------------------------------------- footer --- */
footer { background: var(--navy); color: #BFD2DF; padding: 1.35rem 0 1.45rem; font-size: .84rem; box-shadow: 0 -6px 18px rgba(4,52,84,.18); }
footer .wrap { display: flex; gap: 2.5rem; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; }
footer b {
  color: #fff; font-size: .7rem; font-weight: 700; letter-spacing: .13em;
  text-transform: uppercase; display: block; margin-bottom: .35rem;
}
footer a { color: #fff; }
footer .disclaimer { max-width: 52ch; line-height: 1.5; }

/* ------------------------------------------------------------- surfaces --- */
/* .panel — an elevated white block with its own padding. Use for a control
   bar or a self-contained block of content. Add .panel--overlap to lift it
   into the title band above it. */
.panel {
  background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-2);
  padding: 1.4rem 1.6rem 1.45rem;
}
.panel--overlap { margin-top: -1.4rem; position: relative; z-index: 2; }

/* .card — an elevated white block with NO padding, for tables and lists that
   should meet its edges. */
.card {
  background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow-1);
  overflow: hidden; position: relative;
}

/* Horizontal scroll container. Add .scroll-l / .scroll-r to the parent .card
   to fade whichever edge still has content beyond it. */
.scrollx { overflow-x: auto; }
.card::before, .card::after {
  content: ""; position: absolute; top: 0; bottom: 0; width: 26px;
  pointer-events: none; opacity: 0; transition: opacity .15s ease; z-index: 3;
}
.card::before { left: 0;  background: linear-gradient(to right, rgba(4,52,84,.13), rgba(4,52,84,0)); }
.card::after  { right: 0; background: linear-gradient(to left,  rgba(4,52,84,.13), rgba(4,52,84,0)); }
.card.scroll-l::before, .card.scroll-r::after { opacity: 1; }

/* Quiet aside inside a panel or sheet. */
.note {
  font-size: .83rem; color: var(--slate); background: var(--blue-pale);
  border-left: 3px solid var(--blue-light); padding: .7rem .95rem;
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
}

/* Empty / zero-result state. */
.empty {
  background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow-1);
  padding: 3.2rem 1.5rem; text-align: center; color: var(--slate);
}
.empty strong { display: block; font-size: 1.18rem; font-weight: 600; color: var(--heading); margin-bottom: .4rem; }

/* ------------------------------------------------------------- controls --- */
.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border-radius: var(--pill); border: 1.5px solid transparent;
  padding: .6rem 1.15rem; display: inline-flex; align-items: center; gap: .5rem;
  white-space: nowrap; transition: background-color .13s ease, border-color .13s ease;
}
.btn-primary { background: var(--navy); color: #fff; padding-inline: 1.7rem; }
.btn-primary:hover { background: var(--navy-2); }
.btn-ghost { background: var(--surface); color: var(--ink-2); border-color: var(--line); font-weight: 500; font-size: .88rem; }
.btn-ghost:hover { border-color: var(--blue); color: var(--navy-3); }

/* Pill text input. */
.field {
  width: 100%; font: inherit; font-size: 1.05rem; color: var(--ink);
  padding: .8rem 1.25rem .8rem 1.35rem;
  border: 1.5px solid var(--line); border-radius: var(--pill);
  background: var(--cream-2);
}
.field::placeholder { color: var(--slate-2); }
.field:focus { border-color: var(--blue); background: var(--surface); outline: none; box-shadow: 0 0 0 3px var(--blue-pale); }

/* Segmented control — pick one. Radio inputs + labels inside .chips. */
.chips { display: flex; flex-wrap: wrap; gap: .25rem; background: var(--cream); padding: .25rem; border-radius: var(--pill); }
.chips input { position: absolute; opacity: 0; width: 0; height: 0; }
.chips label {
  font-size: .84rem; font-weight: 500; padding: .34rem .85rem; border-radius: var(--pill);
  cursor: pointer; color: var(--slate); white-space: nowrap;
}
.chips input:checked + label { background: var(--navy); color: #fff; font-weight: 600; }
.chips input:focus-visible + label { outline: 3px solid var(--focus); outline-offset: 2px; }

/* Toggle pills — pick any number. Checkbox inputs + labels inside .toggles. */
.toggles { display: flex; gap: .4rem; flex-wrap: wrap; }
.toggles input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggles label {
  font-size: .84rem; font-weight: 500; font-variant-numeric: tabular-nums;
  padding: .34rem .8rem; border: 1.5px solid var(--line); border-radius: var(--pill);
  cursor: pointer; color: var(--slate); background: var(--surface);
}
.toggles label:hover { border-color: var(--blue); color: var(--navy-3); }
.toggles input:checked + label { background: var(--blue-pale); border-color: var(--navy-3); color: var(--on-tint); font-weight: 600; }
.toggles input:focus-visible + label { outline: 3px solid var(--focus); outline-offset: 2px; }

/* Change badge. Amber = went up, green = went down. */
.delta { font-size: .73rem; font-weight: 600; padding: .1rem .38rem; border-radius: var(--pill); }
.delta.up { color: var(--rise); background: var(--rise-bg); }
.delta.down { color: var(--fall); background: var(--fall-bg); }

@media (prefers-reduced-motion: reduce) {
  .btn, .card::before, .card::after { transition: none; }
}

/* ---------------------------------------------------------------- data ---- */
/* table.data — the house table. Put it inside a .card > .scrollx. */
table.data {
  border-collapse: separate; border-spacing: 0; width: 100%;
  font-variant-numeric: tabular-nums; font-size: .92rem;
  /* Fixed layout so columns stay put between renders instead of resizing to
     whatever the current result set happens to contain. Pair with a <colgroup>. */
  table-layout: fixed;
}
table.data thead th {
  background: var(--cream); color: var(--slate);
  font-size: .66rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  text-align: left; white-space: nowrap; padding: .6rem .9rem;
  border-bottom: 1px solid var(--line);
}
table.data th.num, table.data td.num { text-align: right; }
table.data td { padding: .55rem .9rem; white-space: nowrap; vertical-align: top; }

table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { color: var(--navy-3); }
table.data th .arrow { opacity: 0; margin-left: .3rem; font-size: .8em; }
table.data th[aria-sort] .arrow { opacity: 1; }
table.data th[aria-sort] { color: var(--navy); }

/* Definition grid — label above value, in responsive columns. */
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(155px, 1fr)); gap: .1rem 1.6rem; }
.fact { padding: .55rem 0; border-top: 1px solid var(--line-2); }
.fact dt { font-size: .77rem; color: var(--slate); }
.fact dd { margin: .12rem 0 0; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- chart --- */
.chartbox { border-radius: var(--r-sm); background: var(--surface); box-shadow: inset 0 0 0 1px var(--line-2); padding: .95rem .6rem .35rem; }
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis-text { fill: var(--slate); font-size: 11px; font-family: var(--sans); font-variant-numeric: tabular-nums; }
.chart .series-area { fill: var(--blue); opacity: .15; }
/* .chart.alt switches the series to forest green — used when a second metric
   is being shown, so the two readings never look like the same number. */
.chart.alt .series-area { fill: var(--green); opacity: .18; }
.chart.alt .series-line { stroke: var(--green-deep); }
.chart.alt .dot { stroke: var(--green-deep); }
.chart.alt .dot-last { fill: var(--green-deep); }
.chart .series-line { fill: none; stroke: var(--blue); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--surface); stroke: var(--blue); stroke-width: 2.5; }
.chart .dot-last { fill: var(--dot-last); stroke: var(--surface); stroke-width: 2.5; }
.chart .val-text { fill: var(--ink-2); font-size: 11px; font-weight: 700; font-family: var(--sans); font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------- overlay sheet --- */
.scrim {
  position: fixed; inset: 0; background: rgba(4, 24, 38, .58);
  display: none; z-index: 50; padding: 2.5rem 1.25rem; overflow-y: auto;
}
.scrim.open { display: block; }
.sheet {
  background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-3);
  width: min(880px, 100%); margin-inline: auto; overflow: hidden;
}
.sheet-head {
  background: var(--navy); color: #fff; padding: 1.25rem 1.6rem;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem;
}
.sheet-head h2 { font-size: 1.35rem; font-weight: 600; color: #fff; }
.sheet-head .sub { color: var(--blue-light); font-size: .87rem; margin-top: .22rem; }
.sheet-body { padding: 1.5rem 1.6rem 1.7rem; display: flex; flex-direction: column; gap: 1.7rem; }
.x {
  background: rgba(255,255,255,.15); border: 0; color: #fff; cursor: pointer;
  width: 34px; height: 34px; border-radius: 50%; font-size: 1.15rem; line-height: 1; flex: none;
}
.x:hover { background: rgba(255,255,255,.3); }

/* ---------------------------------------------------------------- toast --- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--footer-h, 5rem) + 1rem); transform: translateX(-50%);
  background: var(--navy); color: #fff; padding: .75rem 1.2rem; border-radius: var(--pill);
  border: 1px solid var(--blue-light);
  box-shadow: var(--shadow-3); font-size: .88rem; z-index: 100; max-width: min(32rem, calc(100% - 2rem));
}

/* ----------------------------------------------------------- responsive --- */
/* Scoped to `screen`: a bare max-width query also matches the PAPER width when
   printing, which silently reflows a printout to the phone layout. */

/* The town navigation tightens rather than disappearing — these are the only
   links back to the rest of the town site. */
@media screen and (max-width: 1040px) {
  .masthead-links { gap: 1.1rem; font-size: .74rem; letter-spacing: .05em; }
}
@media screen and (max-width: 780px) {
  /* Stay on the logo's row and let the links wrap within the nav. Wrapping the
     whole nav to a second flex line would put it underneath the plate's
     overhang, which hides the first link. */
  /* nowrap on the row forces the nav to shrink beside the plate; without it the
     nav wraps to a second flex line and slides under the plate's overhang. */
  .masthead-top { flex-wrap: nowrap; }
  .masthead-links { gap: .45rem .9rem; font-size: .72rem; flex: 1 1 auto; min-width: 0; }
}

@media screen and (max-width: 620px) {
  :root { --brand-size: 88px; --brand-spill: 26px; --masthead-pad: .65rem; }
  .wrap { width: calc(100% - 1.75rem); }
  .panel { padding: 1.15rem; }

  .chips { width: 100%; }
  .chips label { flex: 1; text-align: center; }
  .scrim { padding: 0; }
  .sheet { border-radius: 0; min-height: 100vh; }
}

/* On a phone a permanently pinned footer costs too much of the screen, so the
   shell relaxes back into a normally scrolling page. */
@media screen and (max-width: 760px) {
  body.app-shell { height: auto; min-height: 100dvh; overflow: visible; display: block; }
  body.app-shell .appscroll { overflow: visible; }
  .appscroll > main { padding-bottom: 1rem; }
  footer { margin-top: 2rem; box-shadow: none; }
  .toast { bottom: 1.5rem; }
}

/* ---------------------------------------------------------------- print --- */
/* Print-only page header. Populate it from script before window.print(). */
.printhead { display: none; }

@media print {
  @page { margin: 0.5in; }

  /* The shell clips to the viewport on screen; on paper it has to flow. */
  html, body, body.app-shell { height: auto; overflow: visible; display: block; }
  body.app-shell .appscroll { overflow: visible; min-height: 0; }
  .appscroll > main { padding-bottom: 0; }

  body { background: #fff; color: #000; font-size: 9.5pt; }
  .wrap { width: 100%; }

  .masthead, .titlebar, .panel, .x, .toast, footer { display: none !important; }
  .brandplate { display: none !important; }

  .printhead {
    display: block !important;
    border-bottom: 2.5px solid var(--navy);
    padding-bottom: .35rem; margin-bottom: 1rem;
  }
  .printhead .ph-town { font-size: 14pt; font-weight: 700; letter-spacing: .01em; color: var(--navy); }
  .printhead .ph-sub  { font-size: 9pt; color: #444; margin-top: .12rem; }

  .card { box-shadow: none; border-radius: 0; }
  .scrollx { overflow: visible; }
  table.data { width: 100%; font-size: 8.5pt; }
  table.data thead { display: table-header-group; }
  table.data thead th { background: none; border-bottom: 1.2px solid #000; color: #333; padding: .28rem .4rem; }
  table.data td { padding: .26rem .45rem; }
  .delta { background: none !important; padding: 0; }
  .chartbox { box-shadow: inset 0 0 0 1px #CFCFCF; background: none; break-inside: avoid; }
  .note { background: none; border-left: 2px solid #9A9A9A; font-size: 8.5pt; }
  section { break-inside: avoid; }
}
