/* Clean and minimal, on purpose: one accent, one rule weight, no pills, no
   card borders around every row. The only things allowed to draw the eye are
   a value, a heading, and the warning colour on an uncited fact. */

:root {
  --bg: #fbfaf7;
  --fg: #1c1a17;
  --muted: #6b6560;
  --line: #e6e1d9;
  --card: #fff;
  --accent: #6a5b3e;
  --hi: #f3efe6;
  --warn: #a2522a;
  --danger: #a22a2a;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171614;
    --fg: #ece8e1;
    --muted: #9a938b;
    --line: #2c2a26;
    --card: #1d1c19;
    --accent: #cbb47e;
    --hi: #23211d;
    --warn: #d68a5c;
    --danger: #d97070;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.6 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* --- frame --------------------------------------------------------------- */

#topbar {
  display: flex;
  gap: 20px;
  align-items: center;
  flex-wrap: wrap;
  padding: 14px 20px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}
#topbar .brand { font-weight: 600; text-decoration: none; color: var(--fg); letter-spacing: -0.01em; }
#topbar nav { display: flex; gap: 16px; margin-right: auto; }
#topbar nav a { color: var(--muted); text-decoration: none; }
#topbar nav a:hover { color: var(--fg); }
#who { color: var(--muted); font-size: 0.86rem; }
#signout { border: none; background: none; color: var(--muted); padding: 0; }
#signout:hover { color: var(--fg); }

main { max-width: 860px; margin: 0 auto; padding: 8px 20px 96px; }

#gate { max-width: 380px; margin: 18vh auto; padding: 0 20px; text-align: center; }

h1 { font-size: 1.35rem; font-weight: 600; margin: 8px 0 2px; letter-spacing: -0.01em; }
h2 { font-size: 0.95rem; font-weight: 600; margin: 26px 0 8px; }
h2 a { text-decoration: none; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.error { color: var(--danger); }
.warn { color: var(--warn); }
/* Secondary facts about a thing: its domain, its kind, its tags. Small, grey,
   and never a pill, because a border around two words is decoration rather
   than information. */
.meta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 0.8rem;
  color: var(--muted);
}

/* --- controls ------------------------------------------------------------ */

input, select, textarea, button {
  font: inherit;
  color: inherit;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 10px;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
textarea { width: 100%; min-height: 60px; resize: vertical; }
button { cursor: pointer; }
button.link { background: none; border: none; color: var(--muted); padding: 0; }
button.link:hover { color: var(--fg); }
button.danger { color: var(--danger); }

/* An icon control is a tap target first: 16px of glyph inside a box big enough
   to hit on a phone, with the label carried by aria-label/title rather than by
   text. Only universal actions are drawn this way -- see web/src/icons.ts. */
.icon { display: block; flex: none; }
button.iconbtn, a.iconlink {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  min-height: 28px;
  padding: 0;
  border: none;
  background: none;
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
}
button.iconbtn:hover, a.iconlink:hover { color: var(--fg); }
button.danger.iconbtn:hover { color: var(--danger); }
#signout { min-width: 28px; min-height: 28px; display: inline-flex; align-items: center; }

form { display: flex; flex-direction: column; gap: 8px; }
form .row { display: flex; gap: 8px; flex-wrap: wrap; }
form .row > * { flex: 1 1 140px; }

ul { list-style: none; margin: 0; padding: 0; }

/* --- retrieval: the search box ------------------------------------------- */
/* The box is the first thing on the page, because this surface is for finding
   one fact rather than for reading every fact in order. */

.retrieval { padding: 6px 0 10px; margin-bottom: 8px; }
#gq, #cq {
  width: 100%;
  font-size: 1.05rem;
  padding: 11px 14px;
  border-radius: 8px;
}

/* No filter chrome: a search box, then results. An active filter arriving from
   a link or from a tag in an expanded detail is named on the result line
   instead, so nothing is ever filtered silently. */
.clear { margin-left: 2px; vertical-align: -8px; }

.resultcount { margin: 0 0 6px; font-size: 0.86rem; font-variant-numeric: tabular-nums; }

/* --- lists and cards ----------------------------------------------------- */

.cards li {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.cards li a { text-decoration: none; color: inherit; display: flex; flex-direction: column; gap: 3px; }
.cards li a strong { color: var(--accent); }

.collection { margin-bottom: 8px; }
.group { margin-bottom: 22px; }
.group h2 {
  margin: 18px 0 6px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  font-weight: 600;
}
.group h2 .muted { letter-spacing: 0; }

.facts li.fact {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}
.facts li.superseded { opacity: 0.5; }
.facts li.disputed .kv .v { color: var(--warn); }
.statement { margin: 2px 0 6px; }
.kv { display: flex; gap: 10px; align-items: baseline; }
.kv .k { color: var(--muted); font-size: 0.85rem; }
.kv .v { font-weight: 600; }

/* --- typed tables -------------------------------------------------------- */
/* Facts that share a value type share a shape, so they line up in columns.
   Right-aligned tabular figures are the point: magnitudes compare down the
   column, which is what a list of sentences cannot do. Rules only between
   rows; a box around the table adds nothing the alignment has not already. */

.facts-table { width: 100%; border-collapse: collapse; }
.facts-table th, .facts-table td {
  text-align: left;
  padding: 8px 10px 8px 0;
  border-bottom: 1px solid var(--line);
  vertical-align: baseline;
  font-weight: 400;
}
.facts-table thead th {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  padding-bottom: 5px;
}
.facts-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; }
.facts-table thead .num { font-weight: 400; }
.facts-table .unit { color: var(--muted); white-space: nowrap; width: 1%; }
.facts-table .when { white-space: nowrap; font-variant-numeric: tabular-nums; }
.facts-table .rel { white-space: nowrap; font-size: 0.85rem; }
.facts-table tfoot th, .facts-table tfoot td { font-weight: 600; color: var(--muted); }
.facts-table tfoot .num { color: var(--fg); }
.facts-table tr.superseded { opacity: 0.5; }
.facts-table tr.disputed td, .facts-table tr.disputed th { color: var(--warn); }
.facts-table tr.open > * { background: var(--hi); }
.facts-table .fdetail td { padding-top: 0; background: var(--hi); }

.rowkey {
  background: none;
  border: none;
  padding: 0;
  text-align: left;
  color: var(--fg);
  cursor: pointer;
  font: inherit;
  border-radius: 0;
}
.rowkey:hover { color: var(--accent); }
.kv .k.rowkey { color: var(--muted); font-size: 0.85rem; }
/* An uncited fact is the thing this whole design exists to make visible. */
.dot-warn { color: var(--warn); font-weight: 700; }
.uncited { color: var(--warn); font-size: 0.86rem; margin: 4px 0 0; }

/* --- the expanded detail ------------------------------------------------- */
/* Everything a row does not show: the prose, the tags it was catalogued under,
   its sources, and the edit affordances. */

.detail { padding: 6px 0 10px; max-width: 62ch; }
.detail .statement { margin: 0 0 6px; }
.detail .meta { margin-bottom: 6px; }
button.tag {
  background: none;
  border: none;
  padding: 0;
  border-radius: 0;
  font-size: inherit;
  color: var(--muted);
  text-decoration: underline dotted var(--line);
  text-underline-offset: 3px;
}
button.tag:hover { color: var(--fg); text-decoration-color: var(--accent); }
button.tag::before { content: "#"; opacity: 0.5; }

.cites { margin-top: 8px; font-size: 0.86rem; }
.cites li { padding: 4px 0; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.cites blockquote { flex-basis: 100%; }
.cites .cite { color: var(--muted); }
.cites blockquote {
  margin: 3px 0 0;
  padding-left: 10px;
  border-left: 2px solid var(--line);
  color: var(--muted);
}
.row-actions { display: flex; gap: 14px; align-items: center; margin-top: 8px; }

/* --- forms tucked away --------------------------------------------------- */

.panel { margin-top: 28px; border-top: 1px solid var(--line); padding-top: 12px; }
.panel summary { cursor: pointer; color: var(--muted); }
.panel[open] summary { color: var(--fg); }
.panel form { margin-top: 10px; }
.cite-add summary { font-size: 0.86rem; color: var(--muted); cursor: pointer; }
.cite-add form { width: 240px; margin-top: 6px; }

/* --- duplicates ---------------------------------------------------------- */

.pairs li {
  display: grid;
  grid-template-columns: 48px 1fr 1fr;
  gap: 14px;
  align-items: start;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.score { font-variant-numeric: tabular-nums; color: var(--muted); }

/* --- sources ------------------------------------------------------------- */
/* A drive-letter path opens on one machine and on no phone, which is the exact
   failure this warning exists to make loud rather than discovered later. */
.warnline { margin: 4px 0; font-size: 0.86rem; color: var(--warn); }
.warnline code { word-break: break-all; color: var(--muted); }
.source form { margin-top: 8px; }

@media (max-width: 620px) {
  main { padding: 8px 16px 96px; }
  #topbar { padding: 12px 16px; gap: 12px; }
  .pairs li { grid-template-columns: 1fr; }
  .facts-table .unit, .facts-table thead th:nth-child(3) { display: none; }
  .facts-table .fdetail td { display: table-cell; }
}

/* --- the building section ------------------------------------------------- */
/* The one visual in this app. It is drawn only when every level it needs is in
   the rows on screen (see web/src/stack.ts); otherwise the text below stands
   on its own, which is why nothing here is load-bearing for comprehension. */

.stack { margin: 10px 0 22px; padding: 0; }
.stack svg { display: block; max-width: 100%; height: auto; }
.stack figcaption { color: var(--muted); font-size: 0.8rem; margin-top: 4px; }

/* Grey for the building, one accent for the two things that are ours. A second
   hue would imply a second meaning there is nothing to attach it to. */
.s-podium { fill: var(--hi); stroke: var(--line); }
.s-carpark, .s-facilities, .s-shops, .s-residential { fill: var(--hi); stroke: var(--line); }
.s-carpark { fill: none; }
.s-facilities { fill: var(--line); opacity: 0.55; }
.s-shops { fill: var(--line); opacity: 0.8; }
.s-residential { fill: var(--card); }
.s-roof { fill: none; stroke: var(--line); stroke-dasharray: 3 3; }
.s-mine { fill: var(--accent); stroke: var(--accent); }
.s-leader { stroke: var(--accent); stroke-width: 1; }
.s-mezz { stroke: var(--line); stroke-dasharray: 2 3; }

.stack text { font: 11px/1 ui-sans-serif, system-ui, sans-serif; fill: var(--muted); }
.s-left { text-anchor: end; }
.s-tower { text-anchor: middle; fill: var(--fg); font-weight: 600; }
.s-tick { font-size: 9.5px; }
.s-mine-label { fill: var(--accent); font-weight: 600; }

@media (max-width: 620px) {
  /* Below this width the annotations collide with the drawing rather than
     label it, and an unreadable diagram is worse than none: the rows below
     say the same thing in words. */
  .stack { display: none; }
}
