/* ============================================================
   wiretaplitigation.com — chat surface
   civic-watchdog direction: bold type, high contrast, mobile-first
   ============================================================ */

:root {
  --bg:           #fafaf7;       /* warm off-white */
  --surface:      #ffffff;
  --surface-alt:  #f3f1ea;       /* card / striped row */
  --ink:          #0e1116;       /* near-black */
  --ink-soft:     #2a2e34;
  --muted:        #5b6470;
  --rule:         #e6e3d8;       /* warm hairline */
  --rule-soft:    #efece4;
  --accent:       #b3261e;       /* brick red for CTAs / section marks */
  --accent-hot:   #8c1d17;       /* hover */
  --accent-tint:  #fde9e8;
  --link:         #1f4dbf;
  --ok:           #1a7f37;
  --warn:         #8a1f1f;
  --shadow-sm:    0 1px 2px rgba(14, 17, 22, 0.05);
  --shadow-md:    0 2px 8px rgba(14, 17, 22, 0.06);
  --radius-sm:    6px;
  --radius:       8px;
  --radius-lg:    12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

@media (min-width: 720px) {
  html, body { font-size: 17px; }
}

.container {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 1.1rem;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  font-family: inherit;
  font-size: inherit;
}

/* ------------------------------------------------------------
   Site head
   ------------------------------------------------------------ */

.site-head {
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
  padding: 1.6rem 0 1.4rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.brand-mark {
  display: inline-block;
  width: 0.85rem;
  height: 0.85rem;
  background: var(--accent);
  border-radius: 2px;
}

.brand-name {
  font-weight: 800;
  letter-spacing: -0.01em;
  font-size: 1.45rem;
  color: var(--ink);
  text-transform: none;
}

@media (min-width: 720px) {
  .brand-name { font-size: 1.7rem; }
}

.tagline {
  margin: 0.7rem 0 0;
  color: var(--ink-soft);
  font-size: 1rem;
  max-width: 60ch;
}

@media (min-width: 720px) {
  .tagline { font-size: 1.05rem; }
}

/* ------------------------------------------------------------
   Stats strip
   ------------------------------------------------------------ */

.stats {
  background: var(--bg);
  border-bottom: 1px solid var(--rule);
  padding: 1.1rem 0;
}

.stats-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.6rem;
}

@media (min-width: 560px) {
  .stats-row { grid-template-columns: repeat(3, 1fr); gap: 1rem; }
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0.4rem 0;
}

.stat-num {
  font-family: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  font-weight: 600;
  font-size: 1.55rem;
  color: var(--ink);
  line-height: 1.1;
}

@media (min-width: 720px) {
  .stat-num { font-size: 1.8rem; }
}

.stat-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 500;
}

/* ------------------------------------------------------------
   Main / chat surface
   ------------------------------------------------------------ */

main#app {
  padding-top: 1.4rem;
  padding-bottom: 1.4rem;
}

#messages {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin-bottom: 1rem;
  min-height: 12vh;
}

#messages:empty { min-height: 0; }

/* Empty state — sample queries above the input */
.empty-state {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  padding: 1.1rem 1.1rem 1rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
}

.empty-state.is-hidden { display: none; }

.empty-lead {
  margin: 0 0 0.7rem;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--ink);
}

.empty-lead::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  background: var(--accent);
  margin-right: 0.5rem;
  vertical-align: middle;
  border-radius: 1px;
}

.sample-queries {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.sample {
  text-align: left;
  background: var(--surface-alt);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 0.6rem 0.85rem;
  cursor: pointer;
  font-size: 0.95rem;
  color: var(--ink-soft);
  width: 100%;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.sample:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ------------------------------------------------------------
   Messages
   ------------------------------------------------------------ */

.msg {
  padding: 0.85rem 1rem;
  border-radius: var(--radius);
  max-width: 92%;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.msg.user {
  align-self: flex-end;
  background: var(--ink);
  color: #fff;
  font-weight: 500;
  white-space: pre-wrap;
}

.msg.assistant {
  align-self: stretch;
  background: var(--surface);
  border: 1px solid var(--rule);
  max-width: 100%;
  box-shadow: var(--shadow-sm);
}

.msg.assistant > *:first-child { margin-top: 0; }
.msg.assistant > *:last-child  { margin-bottom: 0; }
.msg.assistant p              { margin: 0.55rem 0; }
.msg.assistant ul,
.msg.assistant ol             { margin: 0.4rem 0 0.4rem 1.4rem; padding: 0; }
.msg.assistant li             { margin: 0.2rem 0; }
.msg.assistant h1,
.msg.assistant h2,
.msg.assistant h3             { margin: 1rem 0 0.5rem; line-height: 1.25; font-weight: 700; }
.msg.assistant h2             { font-size: 1.15rem; }
.msg.assistant h3             { font-size: 1.0rem; }

.msg.assistant code {
  background: var(--surface-alt);
  padding: 0.1rem 0.32rem;
  border-radius: 4px;
  font-size: 0.88em;
  font-family: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
}
.msg.assistant pre {
  background: var(--surface-alt);
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 0.5rem 0;
  -webkit-overflow-scrolling: touch;
}
.msg.assistant pre code { background: transparent; padding: 0; }
.msg.assistant blockquote {
  border-left: 3px solid var(--rule);
  padding-left: 0.9rem;
  color: var(--muted);
  margin: 0.5rem 0;
}

/* Tables — horizontal scroll on narrow screens */
.msg.assistant table {
  display: block;
  overflow-x: auto;
  white-space: nowrap;
  border-collapse: collapse;
  margin: 0.7rem 0;
  font-size: 0.92rem;
  width: 100%;
  -webkit-overflow-scrolling: touch;
}
.msg.assistant table tbody { white-space: normal; }
.msg.assistant th,
.msg.assistant td {
  border: 1px solid var(--rule);
  padding: 0.45rem 0.65rem;
  text-align: left;
  vertical-align: top;
}
.msg.assistant th {
  background: var(--surface-alt);
  font-weight: 600;
  font-size: 0.84rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
}
.msg.assistant tr:nth-child(even) td { background: var(--surface-alt); }
.msg.assistant a { color: var(--link); }

.msg.error {
  align-self: stretch;
  background: #fff5f5;
  border: 1px solid #f4b4b4;
  color: var(--warn);
}

/* Tool-call ribbon during streaming */
.tools-block {
  align-self: stretch;
  background: var(--surface-alt);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.75rem;
  font-size: 0.82rem;
  font-family: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  max-width: 100%;
}
.tools-block:empty { display: none; }
.tool-line { display: flex; align-items: center; gap: 0.4rem; }
.tool-line-running { color: var(--accent); }
.tool-line-running::before { content: "▸ "; color: var(--accent); }
.tool-line-running::after  { content: " · running…"; color: var(--accent); }
.tool-line-done { color: var(--ok); }
.tool-line-done::before { content: "✓ "; color: var(--ok); }

/* Streaming cursor */
.msg.assistant.streaming::after {
  content: "▌";
  display: inline-block;
  margin-left: 2px;
  animation: blink 1s step-end infinite;
  color: var(--accent);
}
@keyframes blink { 50% { opacity: 0; } }

/* ------------------------------------------------------------
   Entity chips
   ------------------------------------------------------------ */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.05rem 0.55rem;
  margin: 0 0.1rem;
  font-family: inherit;
  font-size: 0.92em;
  font-weight: 500;
  background: var(--surface-alt);
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s, color 0.1s;
  vertical-align: baseline;
  line-height: 1.4;
}
.chip:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip-case        { background: #ecf0fb; color: #1f4dbf; border-color: #cfdcff; }
.chip-defendant   { background: #f1ecff; color: #5b3bbf; border-color: #d8c8ff; }
.chip-legislator  { background: #ecfbf3; color: #1a7f37; border-color: #b6efce; }
.chip-case:hover       { background: #1f4dbf; border-color: #1f4dbf; color: #fff; }
.chip-defendant:hover  { background: #5b3bbf; border-color: #5b3bbf; color: #fff; }
.chip-legislator:hover { background: #1a7f37; border-color: #1a7f37; color: #fff; }
.chip-case.chip-open       { background: #1f4dbf; color: #fff; border-color: #1f4dbf; }
.chip-defendant.chip-open  { background: #5b3bbf; color: #fff; border-color: #5b3bbf; }
.chip-legislator.chip-open { background: #1a7f37; color: #fff; border-color: #1a7f37; }
.chip-loading::after {
  content: " ⟳";
  animation: spin 0.9s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Expandable entity card */
.entity-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1.05rem;
  margin: 0.6rem 0;
  font-size: 0.93rem;
  box-shadow: var(--shadow-sm);
}
.entity-card.entity-card-error {
  border-left-color: var(--warn);
  color: var(--warn);
}
.entity-card .card-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
  flex-wrap: wrap;
}
.entity-card h3 {
  margin: 0;
  font-size: 1.0rem;
  font-weight: 700;
}
.entity-card h4 {
  margin: 0.7rem 0 0.3rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.entity-card .card-type {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  background: var(--surface-alt);
  padding: 0.12rem 0.55rem;
  border-radius: 999px;
}
.entity-card .card-grid {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.18rem 0.7rem;
  margin: 0;
  font-size: 0.9rem;
}
.entity-card dt { color: var(--muted); }
.entity-card dd { margin: 0; }
.entity-card .card-table {
  display: block;
  overflow-x: auto;
  white-space: nowrap;
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
  margin: 0.25rem 0 0.45rem;
  -webkit-overflow-scrolling: touch;
}
.entity-card .card-table th,
.entity-card .card-table td {
  border-bottom: 1px solid var(--rule-soft);
  padding: 0.32rem 0.5rem;
  text-align: left;
  vertical-align: top;
}
.entity-card .card-table th {
  background: var(--surface-alt);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 600;
}
.entity-card .card-summary {
  margin: 0.35rem 0 0;
  color: var(--ink);
  white-space: pre-wrap;
}
.entity-card .chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin: 0.35rem 0;
}

/* ------------------------------------------------------------
   Inline charts and maps
   ------------------------------------------------------------ */

.chart-block,
.map-block {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 0.85rem 1rem 1rem;
  margin: 0.7rem 0;
  box-shadow: var(--shadow-sm);
}
.chart-title,
.map-title {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: var(--ink);
}
.chart-canvas-wrap {
  position: relative;
  width: 100%;
  height: 320px;
}
@media (max-width: 560px) {
  .chart-canvas-wrap { height: 240px; }
}
.map-canvas {
  width: 100%;
  height: 360px;
  border-radius: var(--radius-sm);
  overflow: hidden;
}
@media (max-width: 560px) {
  .map-canvas { height: 280px; }
}
.chart-error {
  color: var(--warn);
  font-family: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.85rem;
}
.leaflet-popup-content button.chip { margin-top: 0.3rem; }

/* ------------------------------------------------------------
   Follow-ups
   ------------------------------------------------------------ */

.followups {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.85rem 0 0.2rem;
  align-items: center;
}
.followups-label {
  font-size: 0.74rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-right: 0.2rem;
  font-weight: 500;
}
.followup {
  border: 1px solid var(--rule);
  background: var(--surface);
  color: var(--ink-soft);
  padding: 0.35rem 0.75rem;
  font-size: 0.88rem;
  border-radius: 999px;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.followup:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ------------------------------------------------------------
   Cache tag, status
   ------------------------------------------------------------ */

.cache-tag {
  display: inline-block;
  margin-top: 0.6rem;
  font-size: 0.72rem;
  color: var(--ok);
  background: #e9f7ee;
  border: 1px solid #b6efce;
  padding: 0.12rem 0.55rem;
  border-radius: 999px;
}

#status {
  margin-top: 0.6rem;
  font-size: 0.85rem;
  color: var(--muted);
  min-height: 1.2em;
}

/* ------------------------------------------------------------
   Chat input form
   ------------------------------------------------------------ */

#chatform {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}

#chatform input {
  flex: 1;
  min-width: 0;
  padding: 0.85rem 1rem;
  font-size: 1rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  -webkit-appearance: none;
  appearance: none;
}

#chatform input:focus {
  outline: 2px solid var(--accent-tint);
  border-color: var(--accent);
}

#chatform button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-width: 56px;
  min-height: 44px;
  padding: 0 1.2rem;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: background 0.12s;
}

#chatform button:hover:not(:disabled) { background: var(--accent-hot); }
#chatform button:disabled { opacity: 0.5; cursor: not-allowed; }

.send-arrow { display: none; }

@media (max-width: 480px) {
  .send-label { display: none; }
  .send-arrow { display: inline-block; }
  #chatform button { padding: 0; min-width: 50px; }
}

/* ------------------------------------------------------------
   Footer
   ------------------------------------------------------------ */

.site-foot {
  border-top: 1px solid var(--rule);
  background: var(--bg);
  padding: 1.3rem 0 1.6rem;
  margin-top: 1.5rem;
  font-size: 0.82rem;
  color: var(--muted);
}
.site-foot p { margin: 0; max-width: 60ch; }
.site-foot strong { color: var(--ink); font-weight: 600; }
