:root {
  color-scheme: light dark;
  --bg: var(--tg-theme-bg-color, #f2f1ed);
  --surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #1b1e1c);
  --muted: var(--tg-theme-hint-color, #70746f);
  --accent: var(--tg-theme-button-color, #236b4a);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: color-mix(in srgb, var(--text) 13%, transparent);
  --safe-top: var(--tg-content-safe-area-inset-top, env(safe-area-inset-top));
  --safe-bottom: var(--tg-content-safe-area-inset-bottom, env(safe-area-inset-bottom));
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background:
    radial-gradient(circle at 85% 0%, color-mix(in srgb, var(--accent) 12%, transparent), transparent 34rem),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
}

button, textarea { font: inherit; }

button { -webkit-tap-highlight-color: transparent; }

.shell {
  width: min(100%, 680px);
  min-height: 100vh;
  margin: 0 auto;
  padding: calc(24px + var(--safe-top)) 18px calc(30px + var(--safe-bottom));
}

.hero { padding: 18px 4px 12px; }

.eyebrow {
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 750;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

h1, h2, p { margin: 0; }

h1 {
  margin-top: 7px;
  font-size: clamp(2.25rem, 11vw, 3.8rem);
  line-height: 0.94;
  letter-spacing: -0.055em;
  max-width: 9ch;
}

.subtitle { margin-top: 13px; color: var(--muted); font-size: 0.97rem; }
.home-picker { display: block; margin-top: 13px; }
.home-picker select { width: 100%; max-width: 330px; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: var(--surface); color: var(--text); font: inherit; }

.privacy-note {
  display: flex;
  gap: 11px;
  align-items: flex-start;
  margin: 18px 0;
  padding: 14px 15px;
  background: color-mix(in srgb, var(--accent) 9%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 18%, transparent);
  border-radius: 16px;
  color: color-mix(in srgb, var(--text) 78%, var(--accent));
  font-size: 0.84rem;
  line-height: 1.42;
}

.privacy-icon { color: var(--accent); font-size: 0.65rem; margin-top: 4px; }

.layers {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 1px 10px;
  scrollbar-width: none;
}

.layers::-webkit-scrollbar { display: none; }

.layer {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 14px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 650;
  cursor: pointer;
}

.layer.active { background: var(--text); color: var(--bg); border-color: var(--text); }

.stack-section, .inbox-section {
  margin-top: 14px;
  padding: 18px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: 0 18px 45px color-mix(in srgb, #000 7%, transparent);
}

.inbox-section { margin-top: 22px; }
.incidents { display: grid; gap: 9px; }
.incident-card { padding: 13px 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--bg); }
.incident-topline { display: flex; justify-content: space-between; gap: 10px; font-size: 0.78rem; color: var(--muted); }
.incident-kind { color: var(--text); font-weight: 750; }
.incident-message { margin-top: 8px; font-size: 0.88rem; line-height: 1.4; }
.incident-source { margin-top: 7px; color: var(--muted); font-size: 0.75rem; }
.ack-action { margin-top: 11px; border: 1px solid var(--accent); border-radius: 10px; padding: 8px 11px; background: transparent; color: var(--accent); font-weight: 700; cursor: pointer; }

.section-heading { display: flex; justify-content: space-between; align-items: end; margin-bottom: 17px; }
.section-heading h2, .dialog-heading h2 { margin-top: 4px; font-size: 1.35rem; letter-spacing: -0.025em; }
.count { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 0.86rem; }

.stack { display: grid; gap: 8px; }

.premise {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  gap: 12px;
  align-items: center;
  min-height: 68px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--bg);
}

.premise.own { border-color: color-mix(in srgb, var(--accent) 55%, transparent); background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.floor { color: var(--muted); font-size: 0.76rem; font-weight: 700; text-align: center; }
.floor strong { display: block; color: var(--text); font-size: 1.25rem; line-height: 1.05; }
.premise-name { font-weight: 700; font-size: 0.92rem; }
.premise-meta { margin-top: 4px; color: var(--muted); font-size: 0.76rem; }

.reachability {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #9a9d99;
  box-shadow: 0 0 0 4px color-mix(in srgb, #9a9d99 15%, transparent);
}

.reachability.available { background: #23a36a; box-shadow: 0 0 0 4px color-mix(in srgb, #23a36a 16%, transparent); }
.empty { padding: 38px 16px; color: var(--muted); text-align: center; line-height: 1.45; }

.primary-action, .submit-action {
  width: 100%;
  border: 0;
  border-radius: 16px;
  padding: 15px 18px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 750;
  cursor: pointer;
}

.primary-action { margin-top: 14px; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
.status { min-height: 1.4em; margin: 10px 4px 0; color: var(--muted); font-size: 0.82rem; text-align: center; }

dialog {
  width: min(calc(100% - 20px), 640px);
  max-height: calc(100vh - 18px);
  margin: auto auto 8px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 26px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 30px 80px rgb(0 0 0 / 24%);
}

dialog::backdrop { background: rgb(5 10 7 / 52%); backdrop-filter: blur(4px); }
dialog form { padding: 8px 18px calc(18px + var(--safe-bottom)); }
.dialog-handle { width: 38px; height: 4px; margin: 2px auto 14px; border-radius: 99px; background: var(--line); }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; }
.icon-button { border: 0; background: transparent; color: var(--muted); font-size: 1.9rem; line-height: 1; cursor: pointer; }
.kind-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 20px 0; padding: 0; border: 0; }
.kind-grid label { cursor: pointer; }
.kind-grid input { position: absolute; opacity: 0; }
.kind-grid span { display: block; padding: 12px; border: 1px solid var(--line); border-radius: 13px; text-align: center; font-size: 0.83rem; font-weight: 650; }
.kind-grid input:checked + span { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); color: var(--accent); }
.message-label { display: block; margin-bottom: 8px; font-size: 0.85rem; font-weight: 700; }
textarea { width: 100%; min-height: 110px; resize: vertical; border: 1px solid var(--line); border-radius: 14px; padding: 13px; background: var(--bg); color: var(--text); outline: none; }
textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 13%, transparent); }
.form-hint { margin: 8px 2px 16px; color: var(--muted); font-size: 0.76rem; line-height: 1.4; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (prefers-reduced-motion: no-preference) {
  .premise { animation: rise 180ms ease-out both; }
  @keyframes rise { from { opacity: 0; transform: translateY(5px); } }
}

@media (min-width: 600px) {
  .shell { padding-left: 28px; padding-right: 28px; }
  .stack-section { padding: 24px; }
}
