/* Takapandian home search — design system
   Hand-written CSS. No build step, no CDN compile, no flash of unstyled content.
   Warm paper-and-ink palette; one accent hue carries the whole page. */

@layer reset, tokens, base, components, utilities;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  /* Class selectors that set `display` outrank the UA [hidden] rule, so
     toggling .hidden on a flex container silently does nothing. */
  [hidden] { display: none !important; }
  body, h1, h2, h3, h4, p, figure, blockquote, dl, dd { margin: 0; }
  ul[class], ol[class] { list-style: none; margin: 0; padding: 0; }
  img, picture, svg { max-width: 100%; display: block; }
  input, button, textarea, select { font: inherit; color: inherit; }
  button { background: none; border: none; cursor: pointer; }
}

@layer tokens {
  :root {
    color-scheme: light dark;

    --accent-h: 24;
    --accent:        oklch(0.56 0.15 var(--accent-h));
    --accent-soft:   oklch(0.56 0.15 var(--accent-h) / 0.10);
    --accent-border: oklch(0.56 0.15 var(--accent-h) / 0.28);
    --accent-ink:    oklch(0.44 0.14 var(--accent-h));

    --ok:     oklch(0.55 0.12 155);
    --ok-bg:  oklch(0.55 0.12 155 / 0.12);
    --warn:   oklch(0.62 0.13 75);
    --warn-bg:oklch(0.62 0.13 75 / 0.14);
    --bad:    oklch(0.56 0.17 22);
    --bad-bg: oklch(0.56 0.17 22 / 0.12);
    --info:   oklch(0.55 0.10 250);
    --info-bg:oklch(0.55 0.10 250 / 0.12);

    --bg:        oklch(0.985 0.005 85);
    --surface:   oklch(1 0 0);
    --surface-2: oklch(0.965 0.006 85);
    --line:      oklch(0.90 0.008 85);
    --line-soft: oklch(0.94 0.006 85);
    --ink:       oklch(0.24 0.012 60);
    --ink-2:     oklch(0.46 0.010 60);
    --ink-3:     oklch(0.62 0.008 60);

    --shadow-sm: 0 1px 2px oklch(0.3 0.02 60 / 0.06), 0 1px 1px oklch(0.3 0.02 60 / 0.04);
    --shadow-md: 0 4px 16px oklch(0.3 0.02 60 / 0.08), 0 1px 3px oklch(0.3 0.02 60 / 0.05);
    --shadow-lg: 0 16px 48px oklch(0.3 0.02 60 / 0.14);

    --r-sm: 8px;  --r-md: 12px;  --r-lg: 18px;  --r-xl: 26px;
    --sp: 4px;
    --maxw: 1420px;

    --font: ui-sans-serif, -apple-system, "SF Pro Text", "Inter", system-ui, sans-serif;
    --font-display: ui-serif, "New York", Georgia, "Iowan Old Style", serif;
    --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
  }

  @media (prefers-color-scheme: dark) {
    :root {
      --bg:        oklch(0.175 0.008 70);
      --surface:   oklch(0.215 0.009 70);
      --surface-2: oklch(0.255 0.010 70);
      --line:      oklch(0.32 0.010 70);
      --line-soft: oklch(0.28 0.009 70);
      --ink:       oklch(0.94 0.006 80);
      --ink-2:     oklch(0.74 0.008 80);
      --ink-3:     oklch(0.58 0.008 80);
      --accent:      oklch(0.70 0.14 var(--accent-h));
      --accent-ink:  oklch(0.78 0.13 var(--accent-h));
      --shadow-sm: 0 1px 2px oklch(0 0 0 / 0.3);
      --shadow-md: 0 4px 16px oklch(0 0 0 / 0.36);
      --shadow-lg: 0 18px 50px oklch(0 0 0 / 0.5);
    }
  }

  /* The theme toggle stamps data-theme on <html>; it must win both ways. */
  :root[data-theme="light"] {
    --bg: oklch(0.985 0.005 85); --surface: oklch(1 0 0); --surface-2: oklch(0.965 0.006 85);
    --line: oklch(0.90 0.008 85); --line-soft: oklch(0.94 0.006 85);
    --ink: oklch(0.24 0.012 60); --ink-2: oklch(0.46 0.010 60); --ink-3: oklch(0.62 0.008 60);
    --accent: oklch(0.56 0.15 var(--accent-h)); --accent-ink: oklch(0.44 0.14 var(--accent-h));
  }
  :root[data-theme="dark"] {
    --bg: oklch(0.175 0.008 70); --surface: oklch(0.215 0.009 70); --surface-2: oklch(0.255 0.010 70);
    --line: oklch(0.32 0.010 70); --line-soft: oklch(0.28 0.009 70);
    --ink: oklch(0.94 0.006 80); --ink-2: oklch(0.74 0.008 80); --ink-3: oklch(0.58 0.008 80);
    --accent: oklch(0.70 0.14 var(--accent-h)); --accent-ink: oklch(0.78 0.13 var(--accent-h));
    --shadow-lg: 0 18px 50px oklch(0 0 0 / 0.5);
  }
}

@layer base {
  html { -webkit-text-size-adjust: 100%; }
  body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--ink);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    min-height: 100dvh;
  }
  a { color: var(--accent-ink); text-decoration-color: var(--accent-border); text-underline-offset: 2px; }
  :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
  ::selection { background: var(--accent-soft); }
}

@layer components {

  /* ---------- shell ---------- */
  .wrap { max-width: var(--maxw); margin-inline: auto; padding-inline: clamp(16px, 3vw, 32px); }

  .topbar {
    position: sticky; top: 0; z-index: 40;
    background: color-mix(in oklab, var(--bg) 82%, transparent);
    backdrop-filter: saturate(180%) blur(14px);
    border-bottom: 1px solid var(--line-soft);
  }
  .topbar__in { display: flex; align-items: center; gap: 16px; height: 62px; }
  .brand { display: flex; align-items: baseline; gap: 10px; margin-right: auto; min-width: 0; }
  .brand__mark {
    font-family: var(--font-display); font-size: 20px; font-weight: 600;
    letter-spacing: -0.02em; white-space: nowrap;
  }
  .brand__sub { color: var(--ink-3); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  .iconbtn {
    display: grid; place-items: center; width: 34px; height: 34px;
    border-radius: 10px; color: var(--ink-2); transition: background .15s, color .15s;
  }
  .iconbtn:hover { background: var(--surface-2); color: var(--ink); }

  .whoami {
    font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
    color: var(--accent-ink); background: var(--accent-soft);
    border: 1px solid var(--accent-border); padding: 5px 10px; border-radius: 999px;
  }

  /* ---------- run banner ---------- */
  .runbar {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    font-size: 13px; padding: 10px 14px; border-radius: var(--r-md);
    border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
    margin-block: 18px 22px;
  }
  .runbar[data-tone="stale"] { border-color: var(--warn); background: var(--warn-bg); color: var(--ink); }
  .runbar[data-tone="dead"]  { border-color: var(--bad);  background: var(--bad-bg);  color: var(--ink); font-weight: 500; }
  .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
  .runbar[data-tone="stale"] .dot { background: var(--warn); }
  .runbar[data-tone="dead"]  .dot { background: var(--bad); }

  /* ---------- toolbar / filters ---------- */
  .toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 20px; }
  .chip {
    font-size: 13px; padding: 7px 13px; border-radius: 999px;
    border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
    transition: all .15s; white-space: nowrap;
  }
  .chip:hover { border-color: var(--ink-3); color: var(--ink); }
  .chip[aria-pressed="true"] {
    background: var(--accent); border-color: var(--accent); color: white; font-weight: 500;
  }
  .chip__n { opacity: .65; margin-left: 5px; font-variant-numeric: tabular-nums; }
  .spacer { flex: 1 1 auto; }

  select.control, input.control {
    font-size: 13px; padding: 7px 11px; border-radius: 9px;
    border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  }

  /* ---------- grid ---------- */
  .grid {
    display: grid; gap: 20px;
    grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
    align-items: start;
  }

  .card {
    position: relative; display: flex; flex-direction: column;
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--r-lg); overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: box-shadow .18s, transform .18s, border-color .18s;
  }
  .card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); border-color: var(--ink-3); }
  .card[data-gone="true"] { opacity: .5; }
  .card[data-selected="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft), var(--shadow-md); }

  .card__media { position: relative; aspect-ratio: 16 / 10; background: var(--surface-2); }
  .card__media img { width: 100%; height: 100%; object-fit: cover; }
  /* No photo yet — collapse to a slim strip rather than a large grey void. */
  .card__media--empty { aspect-ratio: 16 / 3.4; display: grid; place-items: center; color: var(--ink-3); font-size: 11.5px; }

  .tier {
    position: absolute; top: 10px; left: 10px; z-index: 2;
    font-size: 10.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
    padding: 5px 9px; border-radius: 7px; color: white;
    background: oklch(0.35 0.02 60 / 0.82); backdrop-filter: blur(8px);
  }
  .tier[data-t="top_fit"]      { background: oklch(0.50 0.14 155 / 0.92); }
  .tier[data-t="strong_match"] { background: oklch(0.50 0.11 200 / 0.92); }
  .tier[data-t="borderline"]   { background: oklch(0.55 0.13 75 / 0.94); }
  .tier[data-t="verify"]       { background: oklch(0.52 0.15 30 / 0.92); }

  .pricedrop {
    position: absolute; top: 10px; right: 10px; z-index: 2;
    font-size: 11px; font-weight: 700; padding: 5px 9px; border-radius: 7px;
    background: oklch(0.50 0.14 155 / 0.94); color: white; backdrop-filter: blur(8px);
  }

  .card__body { padding: 15px 16px 16px; display: flex; flex-direction: column; gap: 11px; flex: 1; }

  .price { font-size: 21px; font-weight: 650; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
  .addr { font-size: 13.5px; color: var(--ink-2); line-height: 1.35; }
  .addr b { color: var(--ink); font-weight: 550; }

  .specs {
    display: flex; flex-wrap: wrap; gap: 4px 12px;
    font-size: 12.5px; color: var(--ink-2); font-variant-numeric: tabular-nums;
  }
  .specs span { white-space: nowrap; }

  .commutes { display: flex; gap: 8px; }
  .commute {
    flex: 1; display: flex; flex-direction: column; gap: 1px;
    padding: 8px 10px; border-radius: var(--r-sm);
    background: var(--surface-2); border: 1px solid var(--line-soft);
  }
  .commute[data-good="true"] { background: var(--ok-bg); border-color: transparent; }
  .commute[data-good="over"] { background: var(--bad-bg); border-color: transparent; }
  .commute__k { font-size: 10px; letter-spacing: .07em; text-transform: uppercase; color: var(--ink-3); }
  .commute__v { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
  .commute__v small { font-weight: 400; font-size: 11px; color: var(--ink-3); }

  .badges { display: flex; flex-wrap: wrap; gap: 5px; }
  .badge {
    font-size: 11px; padding: 3px 8px; border-radius: 6px; font-weight: 500;
    background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line-soft);
  }
  .badge[data-tone="ok"]   { background: var(--ok-bg);   color: var(--ok);   border-color: transparent; }
  .badge[data-tone="warn"] { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
  .badge[data-tone="bad"]  { background: var(--bad-bg);  color: var(--bad);  border-color: transparent; }
  .badge[data-tone="info"] { background: var(--info-bg); color: var(--info); border-color: transparent; }

  .headline { font-size: 12.5px; color: var(--ink-2); font-style: italic; }

  /* ---------- ratings ---------- */
  .ratings {
    display: flex; align-items: center; gap: 10px; margin-top: auto;
    padding-top: 12px; border-top: 1px solid var(--line-soft);
  }
  .rate { display: flex; align-items: center; gap: 6px; }
  .rate__who { font-size: 10px; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); width: 26px; }
  .rate__val {
    min-width: 30px; text-align: center; font-size: 13px; font-weight: 650;
    font-variant-numeric: tabular-nums; padding: 3px 6px; border-radius: 6px;
    background: var(--surface-2); border: 1px solid var(--line);
  }
  .rate__val[data-set="true"] { background: var(--accent-soft); border-color: var(--accent-border); color: var(--accent-ink); }
  .rate__val[data-mine="true"] { cursor: pointer; }
  .rate__val[data-mine="true"]:hover { border-color: var(--accent); }

  .disagree {
    margin-left: auto; font-size: 10.5px; font-weight: 700; letter-spacing: .05em;
    text-transform: uppercase; color: var(--warn); background: var(--warn-bg);
    padding: 4px 8px; border-radius: 6px;
  }

  /* ---------- drawer ---------- */
  dialog.drawer {
    border: none; padding: 0; background: transparent; max-width: none; max-height: none;
    width: 100%; height: 100%; margin: 0;
    /* The UA stylesheet sets `color: CanvasText` on <dialog>, which beats
       inheritance from <body>. Under `color-scheme: light dark`, a viewer whose
       OS is dark but who has chosen the light theme gets CanvasText = white,
       i.e. white text on a white panel. Pin it to our own token. */
    color: var(--ink);
  }
  dialog.drawer::backdrop { background: oklch(0.15 0.01 60 / 0.5); backdrop-filter: blur(3px); }
  .drawer__panel {
    position: fixed; inset-block: 0; right: 0; width: min(680px, 100%);
    background: var(--bg); color: var(--ink); border-left: 1px solid var(--line);
    box-shadow: var(--shadow-lg); overflow-y: auto;
    animation: slidein .22s cubic-bezier(.2,.7,.3,1);
  }
  @keyframes slidein { from { transform: translateX(24px); opacity: 0; } }
  @media (prefers-reduced-motion: reduce) { .drawer__panel { animation: none; } .card:hover { transform: none; } }

  .drawer__head {
    position: sticky; top: 0; z-index: 3; display: flex; align-items: flex-start; gap: 12px;
    padding: 18px 22px; border-bottom: 1px solid var(--line);
    background: color-mix(in oklab, var(--bg) 88%, transparent); backdrop-filter: blur(12px);
  }
  .drawer__body { padding: 22px; display: flex; flex-direction: column; gap: 26px; }

  .section__h {
    font-size: 11px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
    color: var(--ink-3); margin-bottom: 10px;
  }

  .kv { display: grid; grid-template-columns: minmax(120px, auto) 1fr; gap: 7px 16px; font-size: 13.5px; }
  .kv dt { color: var(--ink-3); }
  .kv dd { margin: 0; font-variant-numeric: tabular-nums; }

  .reqrow {
    display: flex; align-items: flex-start; gap: 10px; padding: 9px 0;
    border-bottom: 1px solid var(--line-soft); font-size: 13.5px;
  }
  .reqrow:last-child { border-bottom: none; }
  .reqmark { flex: none; width: 18px; height: 18px; border-radius: 5px; display: grid; place-items: center;
             font-size: 11px; font-weight: 800; margin-top: 1px; }
  .reqmark[data-r="pass"]    { background: var(--ok-bg);   color: var(--ok); }
  .reqmark[data-r="fail"]    { background: var(--bad-bg);  color: var(--bad); }
  .reqmark[data-r="partial"] { background: var(--warn-bg); color: var(--warn); }
  .reqmark[data-r="unknown"] { background: var(--surface-2); color: var(--ink-3); }
  .reqrow__k { font-weight: 500; }
  .reqrow__d { color: var(--ink-3); font-size: 12.5px; }

  textarea.notes {
    width: 100%; min-height: 96px; resize: vertical; padding: 11px 13px;
    border-radius: var(--r-md); border: 1px solid var(--line);
    background: var(--surface); font-size: 13.5px; line-height: 1.55;
  }
  textarea.notes:disabled { background: var(--surface-2); color: var(--ink-2); }

  .btn {
    font-size: 13px; font-weight: 550; padding: 8px 15px; border-radius: 9px;
    border: 1px solid var(--line); background: var(--surface); color: var(--ink);
    transition: all .15s;
  }
  .btn:hover { border-color: var(--ink-3); }
  .btn--primary { background: var(--accent); border-color: var(--accent); color: white; }
  .btn--primary:hover { filter: brightness(1.06); }
  .btn--ghost { border-color: transparent; color: var(--ink-2); }
  .btn--ghost:hover { background: var(--surface-2); color: var(--ink); }
  .btn:disabled { opacity: .5; cursor: not-allowed; }

  .stars { display: flex; gap: 3px; }
  .star {
    width: 26px; height: 30px; border-radius: 6px; font-size: 12px; font-weight: 650;
    color: var(--ink-3); background: var(--surface-2); border: 1px solid var(--line-soft);
    font-variant-numeric: tabular-nums; transition: all .12s;
  }
  .star:hover { border-color: var(--accent); color: var(--accent-ink); }
  .star[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: white; }

  /* ---------- compare ---------- */
  .comparebar {
    position: fixed; bottom: 18px; left: 50%; translate: -50% 0; z-index: 50;
    display: flex; align-items: center; gap: 12px;
    padding: 11px 14px 11px 18px; border-radius: 999px;
    background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-lg);
    font-size: 13px;
  }
  .cmp-wrap { overflow-x: auto; }
  table.cmp { border-collapse: collapse; width: 100%; font-size: 13px; min-width: 520px; }
  table.cmp th, table.cmp td {
    padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line-soft);
    vertical-align: top;
  }
  table.cmp thead th { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); }
  table.cmp tbody th {
    font-weight: 500; color: var(--ink-3); position: sticky; left: 0;
    background: var(--bg); font-size: 12.5px; white-space: nowrap;
  }
  table.cmp td { font-variant-numeric: tabular-nums; }
  table.cmp td[data-best="true"] { color: var(--ok); font-weight: 650; }

  .spark { display: block; overflow: visible; }

  .empty {
    text-align: center; padding: 72px 20px; color: var(--ink-3);
    border: 1px dashed var(--line); border-radius: var(--r-lg);
  }
  .empty h3 { font-family: var(--font-display); font-size: 19px; color: var(--ink-2); margin-bottom: 6px; }

  /* ---------- login ---------- */
  .login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
  .login__card {
    width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--r-xl); padding: 38px 34px; box-shadow: var(--shadow-md);
  }
  .login__card h1 { font-family: var(--font-display); font-size: 25px; letter-spacing: -0.02em; margin-bottom: 6px; }
  .login__card p { color: var(--ink-3); font-size: 13.5px; margin-bottom: 24px; }
  .login__card input {
    width: 100%; padding: 12px 14px; border-radius: var(--r-md);
    border: 1px solid var(--line); background: var(--bg); font-size: 15px; margin-bottom: 12px;
  }
  .login__card button { width: 100%; padding: 12px; font-size: 14.5px; }
  .login__err { color: var(--bad); font-size: 13px; margin-top: 12px; min-height: 18px; }

  .toast {
    position: fixed; bottom: 18px; left: 18px; z-index: 60;
    padding: 10px 16px; border-radius: 10px; font-size: 13px;
    background: var(--ink); color: var(--bg); box-shadow: var(--shadow-lg);
    animation: pop .18s ease-out;
  }
  @keyframes pop { from { opacity: 0; translate: 0 6px; } }
}

@layer utilities {
  .sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
        clip-path: inset(50%); white-space: nowrap; }
  .muted { color: var(--ink-3); }
  .mono { font-family: var(--mono); font-size: .92em; }
  .row { display: flex; align-items: center; gap: 10px; }
  .col { display: flex; flex-direction: column; gap: 10px; }
}
