/* Housing First field desk — multi-theme, rights-based, hardened stance */

/*
  All themes define the complete variable set on html[data-theme="..."].
  :root is the fallback only (console). Switching sets data-theme on <html>.
*/

:root {
  --bg: #0b1220;
  --bg-2: #111b2e;
  --card: #16233a;
  --ink: #e8eef8;
  --muted: #9aabc4;
  --line: #2a3c5a;
  --accent: #3d8bfd;
  --accent-ink: #061018;
  --good: #3dd68c;
  --warn: #f5c542;
  --bad: #ff6b7a;
  --radius: 14px;
  --header-bg: rgba(11, 18, 32, 0.92);
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

html[data-theme="console"] {
  --bg: #0b1220;
  --bg-2: #111b2e;
  --card: #16233a;
  --ink: #e8eef8;
  --muted: #9aabc4;
  --line: #2a3c5a;
  --accent: #3d8bfd;
  --accent-ink: #061018;
  --good: #3dd68c;
  --warn: #f5c542;
  --bad: #ff6b7a;
  --radius: 14px;
  --header-bg: rgba(11, 18, 32, 0.92);
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

html[data-theme="calm"] {
  --bg: #f1f5f9;
  --bg-2: #ffffff;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --good: #059669;
  --warn: #d97706;
  --bad: #dc2626;
  --radius: 14px;
  --header-bg: rgba(241, 245, 249, 0.96);
  --shadow: 0 4px 16px rgba(15, 23, 42, 0.08);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

html[data-theme="midnight"] {
  --bg: #020617;
  --bg-2: #0a0f1a;
  --card: #0f172a;
  --ink: #f1f5f9;
  --muted: #94a3b8;
  --line: #1e293b;
  --accent: #818cf8;
  --accent-ink: #020617;
  --good: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 14px;
  --header-bg: rgba(2, 6, 23, 0.96);
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

html[data-theme="forest"] {
  --bg: #0c1912;
  --bg-2: #0a1510;
  --card: #14261c;
  --ink: #ecfdf5;
  --muted: #a7f3d0;
  --line: #1a3326;
  --accent: #34d399;
  --accent-ink: #042f1a;
  --good: #6ee7b7;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 14px;
  --header-bg: rgba(12, 25, 18, 0.96);
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

html[data-theme="contrast"] {
  --bg: #000000;
  --bg-2: #111111;
  --card: #111111;
  --ink: #ffffff;
  --muted: #cccccc;
  --line: #ffffff;
  --accent: #ffff00;
  --accent-ink: #000000;
  --good: #00ff00;
  --warn: #ffaa00;
  --bad: #ff3333;
  --radius: 4px;
  --header-bg: rgba(0, 0, 0, 0.98);
  --shadow: none;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

html[data-theme="matrix"] {
  --bg: #000000;
  --bg-2: #001100;
  --card: rgba(0, 24, 0, 0.88);
  --ink: #00ff41;
  --muted: #00cc33;
  --line: #003300;
  --accent: #00ff41;
  --accent-ink: #000000;
  --good: #00ff41;
  --warn: #ffff00;
  --bad: #ff0040;
  --radius: 8px;
  --header-bg: rgba(0, 0, 0, 0.92);
  --shadow: 0 0 12px rgba(0, 255, 65, 0.25);
  --font: "Courier New", Courier, monospace;
}

html[data-theme="cyberpunk"] {
  --bg: #0d0221;
  --bg-2: #15052e;
  --card: #1a0a3e;
  --ink: #f0e6ff;
  --muted: #b794f6;
  --line: #4c1d95;
  --accent: #ff00aa;
  --accent-ink: #0d0221;
  --good: #00ffcc;
  --warn: #ffcc00;
  --bad: #ff3366;
  --radius: 12px;
  --header-bg: rgba(13, 2, 33, 0.96);
  --shadow: 0 0 20px rgba(255, 0, 170, 0.2);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

html[data-theme="terminal"] {
  --bg: #0c0c0c;
  --bg-2: #111111;
  --card: #161616;
  --ink: #33ff33;
  --muted: #22aa22;
  --line: #1a3a1a;
  --accent: #33ff33;
  --accent-ink: #0c0c0c;
  --good: #33ff33;
  --warn: #cccc00;
  --bad: #ff3333;
  --radius: 2px;
  --header-bg: rgba(12, 12, 12, 0.96);
  --shadow: none;
  --font: "Courier New", Courier, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); min-height: 100%; font-family: var(--font); }
a { color: var(--accent); }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 20px; }

header.app {
  position: sticky; top: 0; z-index: 20;
  background: var(--header-bg); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
header.app .bar {
  display: flex; align-items: center; gap: 10px 14px; min-height: 60px; flex-wrap: wrap;
  padding-top: 8px; padding-bottom: 8px;
}
.brand {
  font-weight: 800; letter-spacing: .02em; color: var(--ink); text-decoration: none;
  white-space: nowrap; font-size: 15px;
}
nav.primary { display: flex; gap: 2px; flex-wrap: wrap; flex: 1; min-width: 0; }
nav.primary a {
  color: var(--muted); text-decoration: none; padding: 7px 9px; border-radius: 8px; font-size: 13px;
  white-space: nowrap;
}
nav.primary a:hover, nav.primary a.on { background: var(--card); color: var(--ink); }

.header-tools {
  display: flex; align-items: center; gap: 8px; margin-left: auto; flex-wrap: wrap;
}
.theme-switcher {
  display: flex; align-items: center; gap: 6px;
}
.theme-switcher .theme-label { font-size: 12px; color: var(--muted); margin: 0; white-space: nowrap; }
.theme-switcher select {
  width: auto; min-width: 110px; padding: 7px 10px; font-size: 13px;
  background: var(--bg-2); color: var(--ink); border: 1px solid var(--line); border-radius: 8px;
}
.mobile-nav {
  display: none; width: auto; min-width: 120px; max-width: 180px;
  padding: 7px 10px; font-size: 13px;
  background: var(--bg-2); color: var(--ink); border: 1px solid var(--line); border-radius: 8px;
}
.print-btn {
  padding: 7px 12px !important; font-size: 13px !important;
  background: transparent !important; color: var(--ink) !important;
  border: 1px solid var(--line) !important;
}
.print-btn:hover { background: var(--card) !important; }

.hero { padding: 36px 0 20px; }
.hero h1 { font-size: clamp(26px, 4.2vw, 42px); margin: 0 0 12px; line-height: 1.18; letter-spacing: -0.02em; }
.lede { color: var(--muted); max-width: 68ch; line-height: 1.6; font-size: 1.02rem; }
.badge {
  display: inline-block; font-size: 12px; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; color: var(--accent); border: 1px solid var(--line);
  padding: 4px 10px; border-radius: 999px; margin-bottom: 12px;
}

.grid { display: grid; gap: 14px; }
.stats { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.cols { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 8px; font-size: 15px; color: var(--muted); font-weight: 600; }
.big { font-size: 32px; font-weight: 800; letter-spacing: -0.02em; }
.delta.up { color: var(--bad); }
.delta.down { color: var(--good); }

.section { padding: 28px 0; }
.section h2 { margin: 0 0 12px; font-size: 22px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; }
.neg { color: var(--good); }
.pos { color: var(--bad); }

.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent); color: var(--accent-ink); font-weight: 700;
  border: 0; border-radius: 10px; padding: 10px 14px; text-decoration: none; cursor: pointer;
  font-size: 14px;
}
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }

label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
input, select, textarea {
  width: 100%; background: var(--bg-2); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font: inherit;
}
textarea { min-height: 220px; resize: vertical; font-family: inherit; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

.callout {
  background: var(--card); border-left: 4px solid var(--accent);
  padding: 14px 18px; margin: 16px 0; border-radius: 0 var(--radius) var(--radius) 0;
  line-height: 1.5;
}
.note { font-size: 13px; color: var(--muted); margin-top: 10px; }
.chart { display: flex; align-items: flex-end; gap: 8px; min-height: 180px; padding: 8px 0; overflow-x: auto; }
.barcol { display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 52px; }
.barcol .b { width: 28px; background: var(--accent); border-radius: 6px 6px 0 0; }
.barcol span { font-size: 11px; color: var(--muted); text-align: center; line-height: 1.2; }

.tool-result {
  margin-top: 12px; padding: 12px; background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 8px; line-height: 1.5;
}
.tool-result strong { color: var(--accent); }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.tab {
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: transparent; color: var(--muted); cursor: pointer; font-size: 14px; font-weight: 600;
}
.tab.on, .tab:hover { background: var(--card); color: var(--ink); border-color: var(--accent); }
.panel { display: none; }
.panel.on { display: block; }

footer {
  margin-top: 48px; padding: 28px 0 40px; border-top: 1px solid var(--line);
  color: var(--muted); font-size: 14px; line-height: 1.55;
}
footer a { color: var(--accent); }

/* Matrix rain canvas */
#matrix-rain {
  position: fixed; inset: 0; z-index: -1; pointer-events: none; opacity: 0.35;
  display: none;
}
html[data-theme="matrix"] #matrix-rain { display: block; }

/* ===== Letter form enhancements ===== */
.input-row {
  display: flex; gap: 8px; align-items: stretch; flex-wrap: wrap;
}
.input-row input { flex: 1; min-width: 140px; }
.input-row .btn { flex-shrink: 0; white-space: nowrap; }

.form-sep {
  border: 0; border-top: 1px solid var(--line); margin: 20px 0 16px;
}
.form-subhead {
  margin: 0 0 6px; font-size: 15px; color: var(--ink);
}
#shareUrl {
  font-family: ui-monospace, "Cascadia Code", "Segoe UI Mono", monospace;
  font-size: 12px;
}
.qr-wrap {
  margin-top: 12px; text-align: center;
}
.qr-wrap canvas {
  display: inline-block; border: 1px solid var(--line); border-radius: 8px;
  background: #fff;
}
.copied {
  font-size: 13px; color: var(--good); font-weight: 600;
}
.note.error { color: var(--bad); }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

.letter-meta { font-size: 13px; color: var(--muted); margin: 0 0 8px; }

/* Focus visible for keyboard users */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button:focus:not(:focus-visible),
a:focus:not(:focus-visible) {
  outline: none;
}

@media print {
  .no-print, header.app, footer, #matrix-rain, .theme-switcher { display: none !important; }
  body { background: #fff; color: #000; }
  .card { border: none; box-shadow: none; background: transparent; }
  textarea#draft {
    border: none; width: 100%; min-height: 80vh;
    font-size: 12pt; line-height: 1.45; color: #000;
  }
}

.workflow {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
  margin: 28px 0;
}
.workflow .card a { font-weight: 700; }

/* ===== Responsive: tablet ===== */
@media (max-width: 960px) {
  nav.primary { display: none; }
  .mobile-nav { display: block; }
  .theme-label { display: none; }
  header.app .bar { gap: 8px; }
  .wrap { padding: 0 16px; }
}

/* ===== Responsive: phone ===== */
@media (max-width: 560px) {
  header.app .bar {
    min-height: 52px;
    gap: 8px;
  }
  .brand { font-size: 14px; }
  .header-tools { width: 100%; margin-left: 0; gap: 8px; }
  .mobile-nav { flex: 1 1 auto; max-width: none; min-width: 0; }
  .theme-switcher { flex: 0 0 auto; }
  .theme-switcher select { min-width: 96px; }
  .print-btn {
    padding: 7px 12px !important;
    width: auto !important;
    flex: 0 0 auto;
  }

  .hero { padding: 24px 0 16px; }
  .hero h1 { font-size: clamp(22px, 7vw, 30px); }
  .lede { font-size: 0.98rem; }
  .big { font-size: 26px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .card { padding: 14px; }
  .section { padding: 20px 0; }
  .section h2 { font-size: 18px; }
  .actions { gap: 8px; }
  .btn { padding: 10px 12px; font-size: 13px; justify-content: center; }
  main .btn { width: 100%; }
  main .actions .btn { width: auto; flex: 1 1 auto; min-width: calc(50% - 4px); }
  .print-btn { width: auto !important; }
  .input-row { flex-direction: column; }
  .input-row .btn { width: 100%; }
  table { font-size: 13px; }
  th, td { padding: 6px 4px; }
  .chart { gap: 4px; }
  .barcol { min-width: 40px; }
  .barcol .b { width: 22px; }
  footer { margin-top: 32px; padding: 20px 0 28px; font-size: 13px; }
}

/* ===== Desktop comfort ===== */
@media (min-width: 1100px) {
  .wrap { max-width: 1120px; }
  .hero { padding: 48px 0 28px; }
  nav.primary a { padding: 8px 11px; font-size: 14px; }
}

@media print {
  .no-print, header.app, footer, #matrix-rain, .theme-switcher, .print-btn, .header-tools { display: none !important; }
  body { background: #fff !important; color: #000 !important; }
  .card { border: 1px solid #ccc; box-shadow: none; background: #fff; }
  a { color: #000; }
}


/* Letter draft toolbar */
.letter-toolbar {
  display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between;
  gap: 10px; margin-bottom: 10px;
}
.letter-toolbar .letter-meta { margin: 0; flex: 1; min-width: 180px; }
.letter-toolbar-actions { margin: 0; }
.letter-toolbar-actions .btn { width: auto; }
.letter-print-view { display: none; }
#copyStatusDraft {
  color: var(--good); font-weight: 600; font-size: 13px;
}
