:root {
  color-scheme: light;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #bfc4cd;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-900: #111827;
  --violet-50: #f1eeff;
  --violet-200: #d2cbff;
  --violet-600: #755ff8;
  --violet-700: #5d47de;
  --sky-50: #e3f3ff;
  --sky-700: #3193da;
  --green-50: #d2ffe2;
  --green-700: #239f52;
  --yellow-50: #fff2c9;
  --yellow-700: #bc9021;
  --red-50: #ffe8e8;
  --red-700: #e63939;
  --surface: #fff;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(17, 24, 39, 0.06), 0 5px 16px rgba(17, 24, 39, 0.05);
}

* { box-sizing: border-box; }

html { min-height: 100%; -webkit-text-size-adjust: 100%; }

body {
  min-height: 100vh;
  margin: 0;
  background: var(--gray-100);
  color: var(--gray-900);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
.is-hidden { display: none !important; }
.muted { color: var(--gray-500); font-size: .9rem; line-height: 1.45; }
.eyebrow { color: var(--violet-700); font-size: .69rem; font-weight: 800; text-transform: uppercase; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  min-height: calc(62px + env(safe-area-inset-top));
  align-items: center;
  gap: .65rem;
  padding: max(.5rem, env(safe-area-inset-top)) .75rem .5rem;
  border-bottom: 1px solid var(--gray-200);
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(16px);
}

.brand-mark { width: 44px; height: 44px; object-fit: contain; }
.brand-copy { display: grid; gap: .08rem; min-width: 0; }
.brand-copy strong { font-size: 1.12rem; line-height: 1.15; }
.brand-copy span { overflow: hidden; color: var(--gray-500); font-size: .75rem; text-overflow: ellipsis; white-space: nowrap; }

.icon-button {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--gray-700);
}
.icon-button svg, .bottom-nav svg, .status-hero-icon svg, .summary-icon svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; }
.icon-button.is-spinning svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.app-shell {
  width: min(100%, 780px);
  margin: 0 auto;
  padding: .8rem .7rem calc(6rem + env(safe-area-inset-bottom));
}
.view { display: grid; gap: .75rem; }

.status-hero {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) auto;
  align-items: center;
  gap: .8rem;
  min-height: 86px;
  padding: 1rem;
  border: 1px solid var(--gray-200);
  border-left: 4px solid var(--green-700);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.status-hero.is-alert { border-left-color: var(--red-700); }
.status-hero-icon { display: grid; width: 46px; height: 46px; place-items: center; border-radius: 50%; background: var(--green-50); color: var(--green-700); }
.status-hero.is-alert .status-hero-icon { background: var(--red-50); color: var(--red-700); }
.status-hero p { color: var(--gray-500); font-size: .75rem; font-weight: 700; }
.status-hero h1 { margin-top: .12rem; font-size: 1.36rem; line-height: 1.2; }
.status-hero time { color: var(--gray-500); font-size: .72rem; white-space: nowrap; }

.summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .65rem; }
.summary-card {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  min-width: 0;
  align-items: center;
  gap: .62rem;
  min-height: 78px;
  padding: .75rem;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  text-align: left;
  box-shadow: var(--shadow);
}
.summary-icon { display: grid; width: 40px; height: 40px; place-items: center; border-radius: 50%; }
.summary-icon.is-door { background: var(--yellow-50); color: var(--yellow-700); }
.summary-icon.is-bollard { background: var(--sky-50); color: var(--sky-700); }
.summary-card > span:nth-child(2) { display: grid; gap: .12rem; min-width: 0; }
.summary-card small { color: var(--gray-500); font-size: .7rem; }
.summary-card strong { overflow: hidden; font-size: .78rem; text-overflow: ellipsis; white-space: nowrap; }
.summary-card > b { font-size: 1.35rem; }

.section-block, .channel-row, .source-error, .account-card, .account-details {
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.section-title { display: flex; min-height: 48px; align-items: center; justify-content: space-between; padding: .7rem .85rem; border-bottom: 1px solid var(--gray-200); }
.section-title h2 { font-size: .98rem; }
.section-title span { color: var(--gray-500); font-size: .78rem; font-weight: 700; }
.event-list { display: grid; }
.event-row, .history-row {
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr) auto;
  align-items: center;
  gap: .72rem;
  min-height: 66px;
  padding: .72rem .85rem;
  border: 0;
  border-top: 1px solid var(--gray-200);
  background: transparent;
  color: inherit;
  text-align: left;
}
.event-row:first-child, .history-row:first-child { border-top: 0; }
.event-row > span:nth-child(2), .history-row > span:nth-child(2) { display: grid; gap: .08rem; min-width: 0; }
.event-row small, .history-row small { color: var(--gray-500); font-size: .68rem; font-style: normal; font-weight: 700; }
.event-row strong, .history-row strong { font-size: .88rem; }
.event-row em, .history-row em { overflow: hidden; color: var(--gray-500); font-size: .74rem; font-style: normal; line-height: 1.35; text-overflow: ellipsis; }
.event-row > b { color: var(--gray-300); font-size: 1.4rem; }
.history-row time { color: var(--gray-500); font-size: .7rem; text-align: right; }
.event-marker { width: 8px; height: 32px; border-radius: 4px; background: var(--gray-300); }
.event-marker.is-alert { background: var(--red-700); }
.event-marker.is-ok { background: var(--green-700); }
.empty-state { padding: 1.15rem; color: var(--gray-500); font-size: .82rem; line-height: 1.45; text-align: center; }
.source-error { padding: .8rem; border-color: #ffb2b2; background: var(--red-50); color: #941818; }
.source-error p { margin-top: .35rem; font-size: .78rem; }

.view-head { display: flex; min-height: 58px; align-items: center; justify-content: space-between; gap: .8rem; padding: .18rem .15rem; }
.view-head h1 { margin-top: .08rem; font-size: 1.35rem; }
.count-badge, .status-chip { padding: .25rem .48rem; border-radius: 5px; background: var(--gray-100); color: var(--gray-600); font-size: .7rem; font-weight: 800; white-space: nowrap; }
.count-badge.is-alert, .status-chip.is-alert { background: var(--red-50); color: var(--red-700); }
.count-badge.is-ok, .status-chip.is-ok { background: var(--green-50); color: var(--green-700); }
.count-badge.is-warning, .status-chip.is-warning { background: var(--yellow-50); color: #816316; }

.metric-strip { display: grid; grid-template-columns: repeat(4, 1fr); overflow: hidden; border: 1px solid var(--gray-200); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.metric-strip.is-three { grid-template-columns: repeat(3, 1fr); }
.metric-strip div { display: grid; gap: .12rem; padding: .68rem .4rem; border-left: 1px solid var(--gray-200); text-align: center; }
.metric-strip div:first-child { border-left: 0; }
.metric-strip small { color: var(--gray-500); font-size: .65rem; }
.metric-strip strong { font-size: 1.05rem; }

.channel-row { display: flex; min-height: 66px; align-items: center; justify-content: space-between; gap: .65rem; padding: .75rem .85rem; }
.channel-row > span { display: grid; gap: .1rem; min-width: 0; }
.channel-row strong { font-size: .82rem; }
.channel-row small { color: var(--gray-500); font-size: .7rem; }
.channel-row a, .channel-row button { min-height: 34px; padding: 0 .65rem; border: 1px solid var(--violet-200); border-radius: 6px; background: var(--violet-50); color: var(--violet-700); font-size: .75rem; font-weight: 800; text-decoration: none; }
.channel-row a { display: inline-flex; align-items: center; }
.channel-actions { display: flex; gap: .35rem; }

.room-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .55rem; padding: .65rem; }
.room-card { display: grid; gap: .55rem; min-width: 0; padding: .72rem; border: 1px solid var(--gray-200); border-top: 3px solid var(--gray-300); border-radius: var(--radius); background: var(--gray-50); transition: box-shadow .2s, border-color .2s; }
.room-card.is-alert { border-top-color: var(--red-700); }
.room-card.is-warning { border-top-color: var(--yellow-700); }
.room-card.is-ok { border-top-color: var(--green-700); }
.room-card-head { display: flex; align-items: start; justify-content: space-between; gap: .45rem; }
.room-card-head > span { display: grid; gap: .08rem; min-width: 0; }
.room-card-head small { color: var(--gray-500); font-size: .64rem; }
.room-card-head strong { font-size: .9rem; }
.room-card-head b { color: var(--gray-600); font-size: .66rem; white-space: nowrap; }
.room-card p { color: var(--gray-600); font-size: .73rem; line-height: 1.4; }
.room-card footer { display: flex; justify-content: space-between; gap: .5rem; padding-top: .48rem; border-top: 1px solid var(--gray-200); color: var(--gray-500); font-size: .68rem; }
.is-highlighted { border-color: var(--violet-600) !important; box-shadow: 0 0 0 3px rgba(117, 95, 248, .2) !important; }

.camera-list { display: grid; gap: .7rem; padding: .65rem; }
.monitor-list { display: grid; }
.monitor-summary-card {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr) auto;
  min-width: 0;
  align-items: center;
  gap: .72rem;
  width: 100%;
  min-height: 92px;
  padding: .58rem .7rem;
  border: 0;
  border-top: 1px solid var(--gray-200);
  background: transparent;
  color: inherit;
  text-align: left;
}
.monitor-summary-card:first-child { border-top: 0; }
.monitor-summary-card:active { background: var(--gray-50); }
.monitor-preview { position: relative; display: grid; overflow: hidden; width: 112px; aspect-ratio: 16 / 9; place-items: center; border-radius: 5px; background: var(--gray-900); color: var(--gray-300); font-size: .65rem; }
.monitor-preview img { width: 100%; height: 100%; object-fit: fill; }
.monitor-summary-copy { display: grid; min-width: 0; gap: .12rem; }
.monitor-summary-copy small, .monitor-summary-copy time { color: var(--gray-500); font-size: .65rem; }
.monitor-summary-copy strong { overflow: hidden; font-size: .86rem; text-overflow: ellipsis; white-space: nowrap; }
.monitor-summary-state { display: grid; justify-items: end; gap: .25rem; }
.monitor-summary-state i { color: var(--gray-300); font-size: 1.4rem; font-style: normal; line-height: 1; }
.camera-card { overflow: hidden; border: 1px solid var(--gray-200); border-radius: var(--radius); background: var(--surface); }
.camera-card > header { display: flex; align-items: center; justify-content: space-between; gap: .7rem; padding: .7rem .75rem; }
.camera-card > header > span { display: grid; min-width: 0; }
.camera-card > header small { color: var(--gray-500); font-size: .65rem; }
.camera-card > header strong { font-size: .88rem; }
.image-modes { display: flex; overflow-x: auto; gap: .28rem; padding: 0 .75rem .65rem; }
.image-modes button { min-height: 31px; padding: 0 .58rem; border: 1px solid var(--gray-200); border-radius: 5px; background: var(--gray-50); color: var(--gray-600); font-size: .69rem; font-weight: 700; white-space: nowrap; }
.image-modes button.is-active { border-color: var(--violet-200); background: var(--violet-50); color: var(--violet-700); }
.image-compare { position: relative; overflow: hidden; aspect-ratio: var(--image-aspect); background: var(--gray-900); }
.image-compare img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; }
.latest-layer { position: absolute; inset: 0; }
.reference-label, .latest-label { position: absolute; top: .45rem; z-index: 2; padding: .18rem .38rem; border-radius: 4px; background: rgba(17, 24, 39, .82); color: #fff; font-size: .63rem; font-weight: 700; }
.reference-label { left: .45rem; }
.latest-label { right: .45rem; }
.compare-footer { display: grid; grid-template-columns: minmax(0, 1fr) 110px minmax(0, 1fr); align-items: center; gap: .5rem; padding: .55rem .7rem; border-top: 1px solid var(--gray-200); }
.compare-footer > time { color: var(--gray-500); font-size: .6rem; }
.compare-footer > time:last-child { text-align: right; }
.compare-footer label { display: grid; gap: .16rem; color: var(--gray-600); font-size: .64rem; text-align: center; }
.compare-footer input { width: 100%; accent-color: var(--violet-600); }
.inline-error { padding: .6rem .75rem; background: var(--red-50); color: #941818; font-size: .72rem; }
.camera-card.is-detail { box-shadow: var(--shadow); }
.camera-card.is-detail .image-modes { padding-top: .75rem; }

.detail-toolbar { display: flex; min-height: 42px; align-items: center; justify-content: space-between; gap: .65rem; }
.detail-back-button {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  gap: .3rem;
  padding: 0 .58rem;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--violet-700);
  font-size: 1.2rem;
  font-weight: 800;
}
.detail-back-button span { font-size: .78rem; }
.monitor-pager { display: grid; grid-template-columns: 36px auto 36px; align-items: center; gap: .3rem; }
.monitor-pager button { width: 36px; height: 36px; padding: 0; border: 1px solid var(--gray-200); border-radius: 6px; background: var(--surface); color: var(--gray-700); font-size: 1.25rem; }
.monitor-pager span { color: var(--gray-500); font-size: .7rem; font-weight: 700; white-space: nowrap; }
.monitor-detail-head { min-height: 48px; padding-top: 0; padding-bottom: 0; }
.monitor-detail-head h1 { font-size: 1.18rem; }
.monitor-detail-metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); overflow: hidden; border: 1px solid var(--gray-200); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.monitor-detail-metrics div { display: grid; min-width: 0; gap: .16rem; padding: .62rem .45rem; border-left: 1px solid var(--gray-200); text-align: center; }
.monitor-detail-metrics div:first-child { border-left: 0; }
.monitor-detail-metrics small { color: var(--gray-500); font-size: .61rem; }
.monitor-detail-metrics strong { overflow-wrap: anywhere; font-size: .72rem; font-variant-numeric: tabular-nums; }

.account-card { display: flex; align-items: center; gap: .8rem; padding: .9rem; }
.account-initial { display: grid; width: 48px; height: 48px; place-items: center; border-radius: 50%; background: var(--violet-50); color: var(--violet-700); font-size: 1.1rem; font-weight: 800; }
.account-card > div { display: grid; }
.account-card strong { font-size: 1rem; }
.account-card small { color: var(--gray-500); font-size: .78rem; }
.account-details { margin: 0; padding: 0 .85rem; }
.account-details div { display: flex; justify-content: space-between; gap: 1rem; padding: .75rem 0; border-top: 1px solid var(--gray-200); }
.account-details div:first-child { border-top: 0; }
.account-details dt, .account-details dd { margin: 0; font-size: .8rem; }
.account-details dt { color: var(--gray-500); }
.account-details dd { font-weight: 700; text-align: right; }
.logout-button { width: 100%; min-height: 46px; border: 1px solid var(--red-700); border-radius: var(--radius); background: var(--surface); color: var(--red-700); font-weight: 800; }

.app-message { position: fixed; right: .75rem; bottom: calc(5.2rem + env(safe-area-inset-bottom)); left: .75rem; z-index: 30; max-width: 520px; margin: 0 auto; padding: .65rem .8rem; border-radius: var(--radius); background: var(--gray-900); color: #fff; font-size: .78rem; text-align: center; box-shadow: var(--shadow); }
.app-message:empty { display: none; }
.app-message.is-error { background: #941818; }

.bottom-nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  min-height: calc(64px + env(safe-area-inset-bottom));
  padding: .28rem max(.35rem, env(safe-area-inset-right)) max(.28rem, env(safe-area-inset-bottom)) max(.35rem, env(safe-area-inset-left));
  border-top: 1px solid var(--gray-200);
  background: rgba(255, 255, 255, .97);
  backdrop-filter: blur(16px);
}
.bottom-nav button { display: grid; min-width: 0; place-items: center; align-content: center; gap: .15rem; border: 0; border-radius: 6px; background: transparent; color: var(--gray-500); font-size: .64rem; font-weight: 700; }
.bottom-nav button.is-active { background: var(--violet-50); color: var(--violet-700); }
.bottom-nav svg { width: 20px; height: 20px; }

.login-body { background: var(--gray-100); }
.login-screen { display: grid; width: min(100%, 430px); min-height: 100vh; align-content: center; gap: .8rem; margin: 0 auto; padding: 1rem; }
.login-logo { width: 66px; height: 66px; margin: 0 auto; object-fit: contain; }
.login-panel { display: grid; gap: .8rem; padding: 1rem; border: 1px solid var(--gray-200); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.login-panel h1 { font-size: 1.45rem; }
.login-form { display: grid; gap: .75rem; }
.login-form label { display: grid; gap: .3rem; color: var(--gray-700); font-size: .78rem; font-weight: 700; }
.login-form input { min-height: 46px; padding: 0 .72rem; border: 1px solid var(--gray-300); border-radius: 6px; outline: 0; }
.login-form input:focus { border-color: var(--violet-600); box-shadow: 0 0 0 3px rgba(117, 95, 248, .16); }
.login-form button { min-height: 46px; border: 0; border-radius: 6px; background: var(--violet-600); color: #fff; font-weight: 800; }
.login-error { padding: .65rem; border-radius: 6px; background: var(--red-50); color: #941818; font-size: .78rem; }

button:focus-visible, a:focus-visible, input:focus-visible { outline: 3px solid rgba(117, 95, 248, .35); outline-offset: 2px; }

@media (max-width: 520px) {
  .summary-grid { grid-template-columns: 1fr; }
  .status-hero { grid-template-columns: 42px minmax(0, 1fr); }
  .status-hero time { grid-column: 2; }
  .room-grid { grid-template-columns: 1fr 1fr; }
  .history-row { grid-template-columns: 7px minmax(0, 1fr); }
  .history-row time { grid-column: 2; text-align: left; }
  .monitor-summary-card { grid-template-columns: 96px minmax(0, 1fr) auto; }
  .monitor-preview { width: 96px; }
}

@media (max-width: 370px) {
  .room-grid { grid-template-columns: 1fr; }
  .metric-strip small { font-size: .58rem; }
  .compare-footer { grid-template-columns: 1fr; }
  .compare-footer > time { text-align: center !important; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; }
}
