:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f0f3f7;
  --ink: #16202c;
  --ink-soft: #5b6875;
  --line: #dce3ec;
  --green: #1f8a4c;
  --green-bg: #e5f4ea;
  --green-ink: #12602f;
  --red: #c02a37;
  --red-bg: #fbe7e8;
  --red-ink: #8f1a26;
  --brand: #0b4f6c;
  --focus: #2f6fed;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 32, 44, .06), 0 6px 18px rgba(16, 32, 44, .06);
  --tap: 44px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e141b; --surface: #161f28; --surface-2: #1d2833; --ink: #eaf0f6; --ink-soft: #9db0c2;
    --line: #2a3742; --green: #35b96a; --green-bg: #123324; --green-ink: #74e39e; --red: #f0616f;
    --red-bg: #3a1a1f; --red-ink: #ffb2b9; --brand: #7fc6e6; --focus: #7ea6ff;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 22px rgba(0,0,0,.35);
  }
}
:root[data-theme="dark"] {
  --bg: #0e141b; --surface: #161f28; --surface-2: #1d2833; --ink: #eaf0f6; --ink-soft: #9db0c2;
  --line: #2a3742; --green: #35b96a; --green-bg: #123324; --green-ink: #74e39e; --red: #f0616f;
  --red-bg: #3a1a1f; --red-ink: #ffb2b9; --brand: #7fc6e6; --focus: #7ea6ff;
}
:root[data-theme="light"] {
  --bg: #f4f6f9; --surface: #ffffff; --surface-2: #f0f3f7; --ink: #16202c; --ink-soft: #5b6875;
  --line: #dce3ec; --green: #1f8a4c; --green-bg: #e5f4ea; --green-ink: #12602f; --red: #c02a37;
  --red-bg: #fbe7e8; --red-ink: #8f1a26; --brand: #0b4f6c; --focus: #2f6fed;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--ink);
  -webkit-text-size-adjust: 100%; line-height: 1.4;
  overflow-x: hidden;
}

/* Header */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.2) blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar__row { display: flex; align-items: center; gap: 10px; padding: 10px 14px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; margin-right: auto; }
.brand img { width: 34px; height: 34px; border-radius: 8px; }
.brand__eyebrow { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); }
.brand__title { font-size: 15px; font-weight: 700; }
.brand__col { display: flex; flex-direction: column; line-height: 1.15; }
.linkbtn { min-height: var(--tap); display: inline-flex; align-items: center; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-weight: 600; text-decoration: none; font: inherit; cursor: pointer; }

/* Controls */
.controls { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px 14px 12px; align-items: center; }
.control { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--ink-soft); }
.control select {
  min-height: var(--tap); border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); padding: 0 10px; font: inherit; font-weight: 600;
}
.control--check { flex-direction: row; align-items: center; gap: 8px; min-height: var(--tap); font-size: 14px; color: var(--ink); font-weight: 600; }
.control--check input { width: 22px; height: 22px; }
.statusline { margin-left: auto; font-size: 12px; color: var(--ink-soft); align-self: center; }

/* Layout */
.shell { max-width: 900px; margin: 0 auto; padding: 12px 14px 40px; display: grid; gap: 12px; }

/* Property card */
.pcard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; }
.pcard__head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.pcard__id { display: flex; align-items: baseline; gap: 8px; margin-right: auto; }
.pcard__name { font-size: 20px; font-weight: 800; }
.pcard__market { font-size: 12px; color: var(--ink-soft); font-weight: 600; }
.pcard__badge { font-size: 12px; font-weight: 700; padding: 5px 10px; border-radius: 999px; }
.pcard__badge--attention { background: var(--red-bg); color: var(--red-ink); }
.pcard__badge--clear { background: var(--green-bg); color: var(--green-ink); }
.pcard__flag { font-size: 11px; font-weight: 700; padding: 4px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-soft); border: 1px dashed var(--line); }

/* Lights grid — wraps, never scrolls horizontally */
.lights { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.chip {
  min-height: var(--tap); display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  border-radius: 12px; border: 1.5px solid transparent; font: inherit; font-weight: 700; cursor: pointer;
  text-align: left; width: 100%;
}
.chip--green { background: var(--green-bg); color: var(--green-ink); border-color: color-mix(in srgb, var(--green) 35%, transparent); }
.chip--red { background: var(--red-bg); color: var(--red-ink); border-color: color-mix(in srgb, var(--red) 40%, transparent); }
.chip__icon { flex: none; width: 24px; height: 24px; border-radius: 999px; display: grid; place-items: center; font-size: 15px; font-weight: 900; color: #fff; }
.chip--green .chip__icon { background: var(--green); }
.chip--red .chip__icon { background: var(--red); }
.chip__label { flex: 1 1 auto; font-size: 14px; }
.chip__hold { flex: none; font-size: 10px; letter-spacing: .05em; text-transform: uppercase; background: rgba(0,0,0,.12); padding: 2px 6px; border-radius: 6px; }
.chip--held { outline: 2px dashed currentColor; outline-offset: -4px; }

.empty { text-align: center; color: var(--ink-soft); padding: 40px 16px; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }

/* Detail sheet */
.sheet { position: fixed; inset: 0; z-index: 50; background: rgba(9, 16, 24, .5); display: flex; align-items: flex-end; justify-content: center; }
.sheet__panel {
  background: var(--surface); width: 100%; max-width: 560px; border-radius: 18px 18px 0 0; padding: 16px 16px 24px;
  box-shadow: 0 -8px 30px rgba(0,0,0,.3); animation: rise .18s ease-out; max-height: 88vh; overflow-y: auto;
}
@keyframes rise { from { transform: translateY(14px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet__head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 10px; }
.sheet__kicker { margin: 0; font-size: 12px; color: var(--ink-soft); font-weight: 700; }
.sheet__title { margin: 2px 0 0; font-size: 22px; }
.sheet__close { margin-left: auto; min-width: var(--tap); min-height: var(--tap); border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); font-size: 16px; cursor: pointer; }
.drow { display: grid; grid-template-columns: 130px 1fr; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); font-size: 14px; }
.drow__k { color: var(--ink-soft); font-weight: 600; }
.drow__v { font-weight: 600; }
.sheet__actions { margin-top: 14px; }
.sheet__actions-label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); margin: 0 0 8px; font-weight: 700; }
.sheet__reason { width: 100%; min-height: var(--tap); border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); padding: 0 12px; font: inherit; margin-bottom: 8px; }
.sheet__buttons { display: flex; gap: 8px; }
.btn { flex: 1; min-height: var(--tap); border-radius: 10px; border: 1px solid var(--line); font: inherit; font-weight: 700; cursor: pointer; background: var(--surface-2); color: var(--ink); }
.btn--green { background: var(--green); color: #fff; border-color: var(--green); }
.btn--red { background: var(--red); color: #fff; border-color: var(--red); }
.btn--ghost { width: 100%; margin-top: 8px; background: var(--surface); }

/* Login */
.login { max-width: 380px; margin: 40px auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.login h1 { font-size: 20px; margin: 6px 0 14px; }
.login label { display: block; font-size: 13px; color: var(--ink-soft); font-weight: 600; margin-bottom: 6px; }
.login input { width: 100%; min-height: var(--tap); border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); padding: 0 12px; font: inherit; margin-bottom: 12px; }
.login .btn--green { width: 100%; }
.formmsg { color: var(--red-ink); font-size: 13px; min-height: 18px; margin-top: 8px; }

/* Focus visibility */
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 8px; }

@media (prefers-reduced-motion: reduce) {
  .sheet__panel { animation: none; }
  * { scroll-behavior: auto; }
}

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