/* Wohnungsscanner Dinslaken — one stylesheet, no build step.
 *
 * Two genuinely different interfaces over one set of DOM:
 *
 *   desktop  a table. You are comparing 156 rows, and that is what tables do.
 *   phone    a feed of price-first cards. You are triaging on a bus with
 *            twenty seconds, and a fifteen-column table reflowed into
 *            fifteen label/value lines is 449px and 86 screens of scrolling.
 *
 * The type choice that matters here is numeric: every figure is tabular so
 * that rents line up down the column and can be compared without reading.
 * No webfont — this is opened on cellular, and a triage tool that waits on a
 * font download has already failed at its one job.
 */

:root {
  --ground:   #f2f4f1;
  --surface:  #ffffff;
  --sunk:     #ecefea;
  --ink:      #161a17;
  --ink-2:    #4d544c;
  --muted:    #838a81;
  --line:     #e0e4dd;
  --line-2:   #cbd1c6;

  --accent:   #2f6b4f;      /* actions, links, "this is yours to do" */
  --accent-w: #e6f0ea;
  --hot:      #a8501b;      /* the one warm signal: found within the hour */
  --hot-w:    #fbeee2;
  --bad:      #9b2c22;

  --num: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
  --r: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ground:  #12140f;
    --surface: #1b1e19;
    --sunk:    #23261f;
    --ink:     #e7eae2;
    --ink-2:   #b4bbaf;
    --muted:   #868d81;
    --line:    #2b2f27;
    --line-2:  #3b4136;
    --accent:  #7cc39c;
    --accent-w:#1a2a21;
    --hot:     #e0a06a;
    --hot-w:   #2b2016;
    --bad:     #e88b80;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
main { padding: 14px clamp(12px, 3vw, 28px) 72px; }

.n { font-variant-numeric: tabular-nums; }
.vh {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

/* ------------------------------------------------------------- chrome -- */

.topbar {
  display: flex; gap: 8px 14px; align-items: center; justify-content: space-between;
  padding: 9px clamp(12px, 3vw, 28px);
  background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand {
  font-weight: 650; letter-spacing: -0.01em; color: var(--ink);
  text-decoration: none; white-space: nowrap;
}
.topbar nav { display: flex; gap: 13px; align-items: center; flex: 0 1 auto; min-width: 0; }
.topbar nav a, .topbar .linkish { white-space: nowrap; }
.badge { white-space: nowrap; }

@media (max-width: 560px) {
  /* "Wohnungen Dinslaken" plus four controls does not fit 390px. The place
     name is the redundant half — you know which town you are searching. */
  .brand { font-size: 15px; }
  .brand .ortname { display: none; }
  .topbar { gap: 6px 10px; flex-wrap: wrap; }
  .topbar nav { gap: 11px; flex-wrap: wrap; }
  .topbar nav a, .topbar .linkish { font-size: 13px; }
}

@media (max-width: 400px) {
  /* At 320px even the wrapped bar overflows. The unread badge is the item to
     drop: the line directly beneath it already says "N noch nicht angesehen". */
  .topbar .badge { display: none; }
  .topbar { padding-left: 10px; padding-right: 10px; }
}
.topbar nav a { color: var(--ink-2); text-decoration: none; font-size: 14px; }
.topbar nav a.on { color: var(--accent); font-weight: 600; }

.badge {
  background: var(--accent-w); color: var(--accent);
  border-radius: 99px; padding: 2px 9px; font-size: 12px; font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.inline { display: inline; max-width: 100%; }
.linkish, button.linkish {
  background: none; border: 0; padding: 0; color: var(--muted);
  font: inherit; font-size: 13px; font-weight: 400; cursor: pointer;
  text-decoration: underline; border-radius: 0;
}
.linkish:hover, button.linkish:hover { color: var(--ink); }

/* -------------------------------------------------------------- login -- */

.login {
  max-width: 21rem; margin: 12vh auto; padding: 26px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
}
.login h1 { margin: 0 0 4px; font-size: 1.25rem; letter-spacing: -0.015em; }
.login form { display: flex; flex-direction: column; gap: 8px; margin-top: 18px; }
.login input { padding: 10px 11px; font-size: 16px; border: 1px solid var(--line-2);
               border-radius: 7px; background: var(--surface); color: var(--ink); }

/* ------------------------------------------------------------- filter -- */

.filterbox {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); margin-bottom: 10px;
}
.filterbox > summary {
  display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap;
  padding: 11px 14px; cursor: pointer; list-style: none;
}
.filterbox > summary::-webkit-details-marker { display: none; }
.filterbox > summary::after {
  content: "▾"; margin-left: auto; color: var(--muted); transition: transform .15s;
}
.filterbox[open] > summary::after { transform: rotate(180deg); }
.fsum-label { font-weight: 600; }
.fsum-active { color: var(--accent); font-weight: 500; }
.fsum-none { color: var(--muted); }

.filterbox form {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px 14px; padding: 4px 14px 14px; border-top: 1px solid var(--line);
  padding-top: 14px;
}
.filterbox label { display: flex; flex-direction: column; gap: 4px;
                   font-size: 12px; color: var(--muted); }
.checks { display: flex; gap: 16px; align-items: center; }
.filterbox label.check { flex-direction: row; align-items: center; gap: 7px;
                         font-size: 14px; color: var(--ink-2); }
.factions { display: flex; gap: 14px; align-items: center; }

select, input[type="number"], input[type="password"] {
  font: inherit; font-size: 16px;           /* 16px stops iOS zooming on focus */
  padding: 8px 9px; background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-2); border-radius: 7px; width: 100%;
}
button[type="submit"] {
  font: inherit; font-weight: 600; padding: 9px 17px; background: var(--accent);
  color: #fff; border: 0; border-radius: 7px; cursor: pointer;
}
button[type="submit"]:hover { filter: brightness(1.08); }
button[type="submit"].linkish {
  background: none; color: var(--muted); font-weight: 400;
  padding: 0; text-decoration: underline;
}
button[type="submit"].linkish:hover { color: var(--ink); filter: none; }

.sortbar { display: none; }
.count {
  display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: baseline;
  color: var(--ink-2); margin: 0 0 10px; font-size: 14px;
}
.count p { margin: 0; }
.count strong { font-variant-numeric: tabular-nums; color: var(--ink); }
.leer, .muted { color: var(--muted); }
.klein { font-size: 12.5px; }
.fehler { color: var(--bad); }
.warnbox { background: var(--hot-w); color: var(--hot); border-left: 3px solid currentColor;
           padding: 10px 14px; border-radius: 0 7px 7px 0; }

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

.chip {
  display: inline-block; font-size: 11.5px; line-height: 1.5; padding: 1px 7px;
  border-radius: 99px; background: var(--sunk); color: var(--ink-2); white-space: nowrap;
}
.chip.wbs-ja   { background: var(--accent-w); color: var(--accent); font-weight: 600; }
.chip.wbs-ok   { background: var(--sunk); color: var(--ink-2); }
.chip.wbs-nein { background: transparent; color: var(--muted); }
.chip.privat   { background: var(--accent-w); color: var(--accent); }
.chip.weg      { background: var(--sunk); color: var(--muted); }

.dot {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent); margin-right: 6px; vertical-align: 0.12em;
}
.unit { color: var(--muted); font-size: .82em; font-weight: 400; }
.teil { color: var(--muted); }
.src { color: var(--accent); text-decoration: none; font-size: 13px; white-space: nowrap; }
.src + .src { margin-left: 10px; }
.src:hover { text-decoration: underline; }

/* -------------------------------------------------- desktop: a table --- */

.tablewrap { overflow-x: auto; background: var(--surface);
             border: 1px solid var(--line); border-radius: var(--r); }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line);
         vertical-align: middle; }
th {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); font-weight: 600; white-space: nowrap;
  background: var(--ground); position: sticky; top: 49px; z-index: 5;
}
th a { color: inherit; text-decoration: none; }
th a.on { color: var(--accent); }
tbody tr:last-child td { border-bottom: 0; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }

.c-kalt { font-family: var(--num); font-size: 15px; font-weight: 600; white-space: nowrap; }
.c-zi, .c-qm, .c-ppm, .c-warm, .c-km { font-family: var(--num); color: var(--ink-2); white-space: nowrap; }
.c-seen { white-space: nowrap; color: var(--ink-2); font-size: 13px; }
.c-seen.frisch { color: var(--hot); font-weight: 600; }
.c-open { width: 34px; padding-right: 0; }

tr.istneu td { background: color-mix(in srgb, var(--accent-w) 55%, transparent); }
tr.inaktiv .c-kalt, tr.inaktiv .c-ort { text-decoration: line-through; }
tr.inaktiv td { color: var(--muted); }

td select, td textarea {
  font: inherit; font-size: 13px; width: 100%; min-width: 5.5rem;
  background: var(--ground); color: var(--ink);
  border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px;
}

/* The table was 1627px wide in a 1382px frame, which pushed Status and
   Notizen — the only two columns you actually WRITE to — off the right edge
   on a 1440px screen. Everything a person reads is now inside the fold; the
   long strings truncate instead. */
th, td { padding: 8px 8px; }
.c-ort  { max-width: 12rem; }
.c-src  { max-width: 15rem; }
.c-wbs  { max-width: 9rem; }
.c-src, .c-wbs { overflow: hidden; text-overflow: ellipsis; }
.c-warm, .c-km { width: 1%; }
.c-status { width: 9rem; }
.c-notes  { width: 12rem; }
td textarea { resize: vertical; min-height: 2em; }
td select.ok, td textarea.ok { border-color: var(--accent); }
td select.fehler, td textarea.fehler { border-color: var(--bad); }

.disclose {
  display: none;                      /* desktop shows every column already */
  background: none; border: 0; padding: 6px; cursor: pointer; color: var(--muted);
}
.chev {
  display: block; width: 8px; height: 8px; border-right: 1.8px solid currentColor;
  border-bottom: 1.8px solid currentColor; transform: rotate(45deg);
  transition: transform .15s ease;
}
[aria-expanded="true"] .chev { transform: rotate(225deg); }

.todo { color: var(--ink-2); max-width: 62ch; }
.todo li { margin-bottom: 9px; }
h1 { font-size: 1.35rem; letter-spacing: -0.02em; margin: 0 0 12px; }
h2 { font-size: 1.05rem; letter-spacing: -0.01em; margin: 26px 0 8px; }

/* Between a phone and a wide desktop the table still does not fit. Warmmiete
   and Entfernung are the two least-consulted columns — both are one tap away
   in the card view, and neither decides whether you call about a flat. */
@media (min-width: 861px) and (max-width: 1400px) {
  .c-warm, .c-km { display: none; }
}

/* ---------------------------------------------- phone: a card feed ----- */

@media (max-width: 860px) {
  main { padding: 12px 12px 72px; }

  .sortbar {
    display: flex; gap: 8px; align-items: flex-end; margin-bottom: 10px;
  }
  .sortbar label { display: flex; flex-direction: column; gap: 4px;
                   font-size: 12px; color: var(--muted); flex: 1 1 auto; }
  .sortbar select { font-size: 15px; padding: 7px 8px; }
  .sortbar select[name="dir"] { flex: 0 0 auto; width: auto; }

  .tablewrap { border: 0; background: none; overflow: visible; border-radius: 0; }
  table, tbody { display: block; width: 100%; }
  thead { display: none; }

  /* One flat = one card. Three lines, price first.
     ┌───────────────────────────────────────┐
     │ ● 689 €     3 Zi · 80,6 m² · 8,5 €/m² │
     │   Duisburg · Walsum       vor 12 Min. │
     │   WBS-kompatibel   leg ↗           ›  │
     └───────────────────────────────────────┘ */
  tr.flat {
    display: grid;
    grid-template-columns: 1fr auto 34px;
    grid-template-areas:
      "kalt  facts facts"
      "ort   seen  seen"
      "wbs   src   open";
    column-gap: 8px; row-gap: 3px;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: 11px 12px 10px;
    margin-bottom: 8px;
  }
  tr.flat > td { display: block; border: 0; padding: 0; text-align: left;
                 min-width: 0; }   /* grid items default to min-width:auto and
                                      refuse to shrink below their content */

  .c-kalt { grid-area: kalt; font-size: 22px; letter-spacing: -0.02em; line-height: 1.15; }
  .c-ort  { grid-area: ort; font-size: 14px; }
  .c-wbs  { grid-area: wbs; }
  .c-src  { grid-area: src; text-align: right; }
  .c-seen { grid-area: seen; text-align: right; font-size: 12.5px; }
  .c-open { grid-area: open; width: auto; text-align: right; }

  /* rooms / m² / €/m² share one line, right-aligned against the price */
  .c-zi, .c-qm, .c-ppm {
    grid-area: facts; text-align: right; font-size: 13.5px; color: var(--ink-2);
    align-self: center;
  }
  .c-zi  { padding-right: 0; }
  /* Must out-specify `tr.flat > td { display: block }` above, or these render
     stacked on top of .c-zi in the same grid area. */
  tr.flat > td.c-qm,
  tr.flat > td.c-ppm { display: none; }   /* folded into .c-zi::after below */

  /* Compose "3 Zi · 80,6 m² · 8,5" without three separate grid cells. */
  tr.flat { position: relative; }
  .c-zi::after {
    content: " · " attr(data-qm) " · " attr(data-ppm);
    color: var(--muted); font-weight: 400;
  }
  .c-zi:not([data-qm])::after { content: ""; }

  .disclose { display: block; margin-left: auto; }

  /* Secondary detail, hidden until the card is opened. Visible without JS.
     Every selector here carries `tr.flat > td` because the base rule above is
     (0,1,2) and a bare `.c-warm` is (0,1,0) — it would lose, silently, and the
     row would render as a run-together block instead of a label/value pair. */
  tr.flat > td.c-warm,
  tr.flat > td.c-km,
  tr.flat > td.c-status,
  tr.flat > td.c-notes {
    grid-column: 1 / -1;
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    padding: 6px 0 0; font-size: 13px; color: var(--ink-2);
    border-top: 1px solid var(--line); margin-top: 4px;
  }
  tr.flat > td.c-warm::before,
  tr.flat > td.c-km::before,
  tr.flat > td.c-status::before,
  tr.flat > td.c-notes::before {
    content: attr(data-label); color: var(--muted); font-size: 12px;
    flex: 0 0 5.5rem;
  }
  tr.flat > td.c-status { align-items: center; }
  tr.flat > td.c-notes  { align-items: center; }
  .c-status select, .c-notes textarea { flex: 1 1 auto; max-width: none; font-size: 15px; }

  /* A detail row with nothing in it is noise — "Entfernung — km" tells you
     less than the absence of the line would. */
  tr.flat > td.leer { display: none; }

  tr.flat.zu > td.c-warm, tr.flat.zu > td.c-km,
  tr.flat.zu > td.c-status, tr.flat.zu > td.c-notes { display: none; }
  tr.flat.zu { row-gap: 2px; }

  /* State, restated for a card rather than a row. */
  tr.istneu { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
  tr.istneu td { background: none; }
  tr.flat.istneu { box-shadow: inset 3px 0 0 var(--accent); }
  tr.inaktiv { opacity: .62; }

  .c-src .src + .src { margin-left: 0; display: block; }
  .count { font-size: 13.5px; }
}

@media (max-width: 380px) {
  .c-kalt { font-size: 20px; }
  .c-zi, .c-qm, .c-ppm { font-size: 12.5px; }

  /* Keep the three-line card; buy the room from the chevron and the padding
     rather than by giving the disclosure a row of its own. */
  tr.flat { grid-template-columns: 1fr auto 24px; padding: 10px 10px 9px; column-gap: 6px; }
  .disclose { padding: 4px 0; }
  .c-zi, .c-qm, .c-ppm { white-space: normal; }

}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
