/* DealSizer. Mobile first: the base rules target a 390px phone, wider layouts come last. */

:root {
  color-scheme: light;
  --ink: #14213d;
  --muted: #5b6677;
  --line: #d9dee6;
  --line-soft: #edf0f4;
  --bg: #f3f5f8;
  --card: #fff;
  --field: #fff;
  --field-line: #c3cad4;
  --bar: #14213d;
  --neutral-soft: #e6eaf1;
  --neutral-ink: #3d4a61;
  --disabled: #eceff3;
  --accent: #0f766e;
  --accent-soft: #e3f4f1;
  --accent-line: #9ad7cf;
  --primary: #0f766e;
  --seg-on: #14213d;
  --seg-on-ink: #fff;
  --green: #15803d;
  --green-soft: #e4f5e9;
  --amber: #b45309;
  --amber-soft: #fdf1dc;
  --amber-line: #f1cf95;
  --red: #b91c1c;
  --red-soft: #fde8e8;
  --radius: 10px;
}

/* Dark theme: follows the system unless the header button set data-theme on <html>. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme=light]) {
    color-scheme: dark;
    --ink: #e7ecf5; --muted: #9aa7bd; --line: #2b3954; --line-soft: #233049;
    --bg: #0d1424; --card: #162036; --field: #0f182b; --field-line: #3b4b6b; --bar: #080d19;
    --neutral-soft: #2a3752; --neutral-ink: #c5cfdf; --disabled: #111a2c;
    --accent: #2dd4bf; --accent-soft: #123c3a; --accent-line: #1d6f68; --primary: #0f8176;
    --seg-on: #e7ecf5; --seg-on-ink: #14213d;
    --green: #4ade80; --green-soft: #12351f;
    --amber: #fbbf24; --amber-soft: #3a2a0c; --amber-line: #7a5a14;
    --red: #f87171; --red-soft: #3d1717;
  }
}
:root[data-theme=dark] {
  color-scheme: dark;
  --ink: #e7ecf5; --muted: #9aa7bd; --line: #2b3954; --line-soft: #233049;
  --bg: #0d1424; --card: #162036; --field: #0f182b; --field-line: #3b4b6b; --bar: #080d19;
  --neutral-soft: #2a3752; --neutral-ink: #c5cfdf; --disabled: #111a2c;
  --accent: #2dd4bf; --accent-soft: #123c3a; --accent-line: #1d6f68; --primary: #0f8176;
  --seg-on: #e7ecf5; --seg-on-ink: #14213d;
  --green: #4ade80; --green-soft: #12351f;
  --amber: #fbbf24; --amber-soft: #3a2a0c; --amber-line: #7a5a14;
  --red: #f87171; --red-soft: #3d1717;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
body.has-mini { padding-bottom: 64px; }
main { padding: 12px; max-width: 1180px; margin: 0 auto; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 10px; display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
h3 { font-size: 13px; margin: 16px 0 8px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
p { margin: 0 0 6px; }
a { color: var(--accent); }
.muted { color: var(--muted); font-weight: 400; }
.small { font-size: 12px; }
.strong { font-weight: 700; }

/* Header */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 12px; background: var(--bar); color: #fff;
}
.brand { color: #fff; font-weight: 800; font-size: 18px; text-decoration: none; letter-spacing: -.01em; }
.brand span { color: #5eead4; }
.top nav { display: flex; align-items: center; gap: 12px; font-size: 14px; white-space: nowrap; }
/* On a phone the logo is the link to the deal list; the text link comes back on wider screens. */
.top nav .nav-deals { display: none; }
.top nav .ico { display: inline-flex; padding: 3px; background: none; border: 0; color: #cfd6e2; cursor: pointer; }
.top nav .ico svg { width: 19px; height: 19px; display: block; }
/* The button shows the theme it switches to: a moon in light mode, a sun in dark mode. */
.top nav .ico .sun, :root[data-theme=dark] .top nav .ico .moon { display: none; }
:root[data-theme=dark] .top nav .ico .sun { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme=light]) .top nav .ico .moon { display: none; }
  :root:not([data-theme=light]) .top nav .ico .sun { display: block; }
}
.top nav a { color: #cfd6e2; text-decoration: none; }
.lang { display: inline-flex; border: 1px solid #44506a; border-radius: 6px; overflow: hidden; }
.lang a { padding: 3px 8px; font-size: 12px; font-weight: 600; }
.top nav .lang a.on { background: #5eead4; color: #14213d; }

/* Shown while the server cannot be reached */
.offline {
  position: fixed; left: 12px; right: 12px; bottom: 12px; z-index: 11; max-width: 560px; margin: 0 auto;
  padding: 8px 12px; border: 1px solid var(--amber-line); border-radius: 8px; box-shadow: 0 2px 10px rgba(0, 0, 0, .18);
  background: var(--amber-soft); color: var(--amber); font-size: 13px; font-weight: 600; text-align: center;
}
.has-mini .offline { bottom: calc(68px + env(safe-area-inset-bottom)); }

/* Cards and form controls */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 10px; }
label small { display: block; font-weight: 400; margin-top: 3px; }
/* 16px keeps iOS Safari from zooming in when a field takes focus. */
input, select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 8px 9px;
  font: inherit; font-size: 16px; font-weight: 400; color: var(--ink);
  background: var(--field); border: 1px solid var(--field-line); border-radius: 7px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
input.num { text-align: right; font-variant-numeric: tabular-nums; }
input[type=checkbox], input[type=radio] { display: inline-block; width: 20px; height: 20px; margin: 0; accent-color: var(--accent); vertical-align: middle; }
textarea { resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.grid4 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.gap-top { margin-top: 14px; }

.btn {
  display: inline-block; padding: 9px 14px; font: inherit; font-size: 14px; font-weight: 600;
  color: var(--ink); background: var(--field); border: 1px solid var(--field-line); border-radius: 7px;
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.link { background: none; border: 0; padding: 0; font: inherit; font-size: 13px; color: var(--red); text-decoration: underline; cursor: pointer; }
.icon { width: 30px; height: 34px; padding: 0; font-size: 20px; line-height: 1; color: var(--muted); background: none; border: 0; cursor: pointer; }
.danger { margin: 18px 2px; }

.chip { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.status-intake { background: var(--neutral-soft); color: var(--neutral-ink); }
.status-docs_pending { background: var(--amber-soft); color: var(--amber); }
.status-ready { background: var(--green-soft); color: var(--green); }
.tag { font-size: 10px; font-weight: 600; padding: 1px 5px; border-radius: 4px; background: var(--accent-soft); color: var(--accent); }

/* Segmented control (opex mode, document status) */
.seg { display: inline-flex; border: 1px solid var(--field-line); border-radius: 7px; overflow: hidden; background: var(--field); }
.seg label { margin: 0; }
.seg label input { position: absolute; opacity: 0; width: 0; height: 0; }
.seg label span, .seg button {
  display: block; padding: 7px 12px; font: inherit; font-size: 13px; font-weight: 600;
  color: var(--muted); background: none; border: 0; cursor: pointer;
}
.seg label input:checked + span { background: var(--seg-on); color: var(--seg-on-ink); }
.seg.small button { padding: 6px 8px; font-size: 12px; }
.seg button + button { border-left: 1px solid var(--field-line); }
.seg button.on.st-missing { background: var(--red-soft); color: var(--red); }
.seg button.on.st-received { background: var(--green-soft); color: var(--green); }
.seg button.on.st-na { background: var(--neutral-soft); color: var(--neutral-ink); }

/* Deal list */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 6px 0 14px; }
.deal-cards { display: grid; gap: 12px; }
.deal-card { display: block; margin: 0; color: inherit; text-decoration: none; }
.deal-card h2 { font-size: 16px; margin: 0; display: block; }
.deal-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.pairs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 10px 0 0; }
.pairs dt { font-size: 11px; color: var(--muted); }
.pairs dd { margin: 0; font-size: 17px; font-variant-numeric: tabular-nums; }

/* Editor: section links */
.sections {
  position: sticky; top: 0; z-index: 5; display: flex; gap: 6px; overflow-x: auto;
  margin: -12px -12px 10px; padding: 8px 12px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.sections a {
  flex: none; padding: 5px 11px; border-radius: 999px; background: var(--card); border: 1px solid var(--line);
  color: var(--ink); font-size: 13px; font-weight: 600; text-decoration: none;
}
#property, #income, #results, #docs, #onepager { scroll-margin-top: 54px; }

/* Rent roll */
.bulk { display: grid; grid-template-columns: 52px auto 1fr 1fr auto; gap: 6px; align-items: center; margin-bottom: 8px; }
.bulk input { margin: 0; padding: 8px 6px; }
.bulk span { color: var(--muted); }
.units { width: 100%; border-collapse: collapse; margin-bottom: 8px; table-layout: fixed; }
.units th { font-size: 11px; font-weight: 600; color: var(--muted); text-align: left; padding: 0 2px 2px; }
.units td { padding: 2px; }
.units input { margin: 0; padding: 7px 6px; }
.units th:nth-child(1) { width: 20%; }
.units th:nth-child(2) { width: 30%; }
.units th:nth-child(4) { width: 34px; }
.units th:nth-child(5) { width: 32px; }
.units .c, .units th.c { text-align: center; }

/* Operating expenses: one total or itemized, switched by the radio buttons */
#income:has(input[name=opex_mode][value=total]:checked) .opex-items,
#income:has(input[name=opex_mode][value=itemized]:checked) .opex-total { display: none; }
.opex-total, .opex-items { margin-top: 10px; }

/* Results */
.rows { margin: 0; }
.rows > div { display: flex; justify-content: space-between; gap: 8px; padding: 5px 0; border-bottom: 1px solid var(--line-soft); }
.rows dt { color: var(--muted); }
.rows dd { margin: 0; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rows .total { border-bottom: 0; border-top: 2px solid var(--ink); margin-top: 2px; padding-top: 8px; font-size: 19px; font-weight: 800; }
.rows .total dt { color: var(--ink); font-size: 15px; align-self: center; }
.rows.compact > div { font-size: 13px; padding: 4px 0; flex-wrap: wrap; }
.vac-warn { margin: 10px 0 0; padding: 7px 9px; border-left: 4px solid var(--amber); border-radius: 7px; background: var(--amber-soft); color: var(--amber); font-size: 12.5px; font-weight: 600; }
.saved { font-size: 11px; font-weight: 600; color: var(--green); opacity: 0; transition: opacity .3s; }
.saved.show { opacity: 1; }

.scenarios { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-items: start; }
.scn { padding: 10px; margin-bottom: 12px; min-width: 0; }
.scn h3 { margin: 0 0 8px; color: var(--ink); font-size: 13px; }
.scn-mli { border-color: var(--accent-line); }
.scn-mli h3 { color: var(--accent); }
.scn-inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 0 6px; }
.scn-inputs label { font-size: 10.5px; margin-bottom: 7px; white-space: nowrap; }
.scn-inputs input { padding: 6px 5px; }
.scn:has(.scn-out[data-eligible="0"]) { background: var(--disabled); border-color: var(--line); }
.scn:has(.scn-out[data-eligible="0"]) h3 { color: var(--muted); }
.scn:has(.scn-out[data-eligible="0"]) .scn-inputs { display: none; }
.scn-out[data-eligible="0"] .when-eligible, .scn-out[data-eligible="1"] .when-ineligible { display: none; }
.not-eligible { font-size: 16px; font-weight: 700; color: var(--muted); margin: 14px 0 6px; }

.constraint { display: flex; flex-direction: column; padding: 5px 7px; margin-top: 5px; border: 1px solid var(--line-soft); border-radius: 7px; }
.constraint span { font-size: 11px; color: var(--muted); }
.constraint b { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.constraint.binds { background: var(--amber-soft); border-color: var(--amber-line); }
.constraint.binds span { color: var(--amber); font-weight: 600; }
.max-loan { margin: 10px 0 6px; }
.max-loan span { display: block; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.max-loan b { display: block; font-size: 21px; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; white-space: nowrap; }
.max-loan em { font-style: normal; font-size: 11px; font-weight: 600; color: var(--amber); }
.fit { margin-top: 8px; padding: 7px 8px; border-radius: 7px; font-size: 12px; border-left: 4px solid; }
.fit b, .fit span { display: block; }
.fit-green { background: var(--green-soft); border-color: var(--green); color: var(--green); }
.fit-amber { background: var(--amber-soft); border-color: var(--amber); color: var(--amber); }
.fit-red { background: var(--red-soft); border-color: var(--red); color: var(--red); }

/* Sticky figures at the bottom of the phone screen */
.mini {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: grid; grid-template-columns: repeat(3, 1fr);
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); background: var(--bar); color: #fff; text-decoration: none;
}
.mini small { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: .04em; color: #9fb0c9; }
.mini b { font-size: 15px; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Documents */
.progress { height: 8px; background: var(--neutral-soft); border-radius: 999px; overflow: hidden; margin-bottom: 8px; }
.progress div { height: 100%; background: var(--green); border-radius: 999px; transition: width .25s; }
.docs { list-style: none; margin: 0; padding: 0; }
.doc { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--line-soft); }
.doc:last-child { border-bottom: 0; }
.doc-name { font-size: 14px; }
.doc-na .doc-name { color: var(--muted); text-decoration: line-through; }
.doc .seg { flex: none; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.checks label { font-size: 14px; color: var(--ink); font-weight: 400; margin: 0; }
.disclaimer { padding: 6px 12px 18px; text-align: center; font-size: 11px; color: var(--muted); }
.narrow { max-width: 640px; }

/* About page */
.about { max-width: 720px; margin: 0 auto; }
.about .lead { font-size: 17px; margin: 8px 0 16px; }
.about p { margin: 0 0 10px; }
.about ul, .about ol { margin: 0 0 6px; padding-left: 20px; }
.about li { margin-bottom: 7px; }
.about table { width: 100%; border-collapse: collapse; margin: 6px 0 10px; font-variant-numeric: tabular-nums; }
.about th, .about td { text-align: right; padding: 6px 4px; border-bottom: 1px solid var(--line-soft); }
.about th:first-child, .about td:first-child { text-align: left; }
.about th { font-size: 12px; color: var(--muted); }
.about .punch { padding: 9px 11px; border-radius: 7px; background: var(--accent-soft); color: var(--accent); font-weight: 700; }

@media (min-width: 640px) {
  .top nav { gap: 14px; }
  .top nav .nav-deals { display: inline; }
  .deal-cards { grid-template-columns: repeat(2, 1fr); }
  .grid4 { grid-template-columns: repeat(4, 1fr); }
  .scn { padding: 14px; }
  .scn-inputs label { font-size: 12px; }
}

@media (min-width: 960px) {
  main { padding: 20px; }
  body.has-mini { padding-bottom: 0; }
  .has-mini .offline { bottom: 12px; }
  .mini, .sections { display: none; }
  .deal-cards { grid-template-columns: repeat(3, 1fr); }
  .editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
  .results { position: sticky; top: 12px; }
  .below { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 16px; align-items: start; }
  .below .danger { grid-column: 1 / -1; }
}
