:root {
  color-scheme: light;
  --bg: #f5f2ea;
  --panel: rgba(255, 254, 250, 0.94);
  --panel-solid: #fffefa;
  --line: #dedbd2;
  --line-soft: #ebe8e0;
  --text: #29322e;
  --muted: #77807b;
  --accent: #587d6d;
  --accent-dark: #3f6354;
  --accent-soft: #e6efe9;
  --good: #2f8a5b;
  --good-soft: #e7f5ec;
  --warm: #d79a70;
  --danger: #b75e58;
  --radius: 20px;
  --shadow: 0 18px 50px rgba(68, 71, 64, 0.08);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 7% 8%, rgba(215, 154, 112, 0.13), transparent 27rem),
    radial-gradient(circle at 92% 14%, rgba(88, 125, 109, 0.12), transparent 30rem),
    var(--bg);
}
button, input, select { font: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgba(88, 125, 109, 0.2); outline-offset: 2px; }
.shell { width: min(1400px, 100%); min-height: 100vh; margin: auto; padding: 0 34px; }

.topbar {
  min-height: 86px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid rgba(132, 130, 119, 0.15);
}
.brand { display: inline-flex; align-items: center; gap: 13px; color: var(--text); text-decoration: none; }
.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  color: var(--accent-dark);
  border: 1px solid #cbd9d1;
  border-radius: 14px;
  background: linear-gradient(145deg, #f9fcf9, #dfece5);
  box-shadow: 0 7px 18px rgba(73, 105, 91, 0.12);
  font: 500 25px/1 Georgia, serif;
}
.brand strong, .brand small { display: block; }
.brand strong { font-size: 17px; letter-spacing: 0.02em; }
.brand small { margin-top: 3px; }
.brand small, .eyebrow {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: 0.13em;
}
.header-actions { display: flex; align-items: center; gap: 10px; }
.connection { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 13px; }
.connection-dot { width: 8px; height: 8px; border-radius: 50%; background: #a6aaa7; box-shadow: 0 0 0 5px rgba(120, 128, 123, 0.08); }
.connection.is-online .connection-dot { background: var(--good); box-shadow: 0 0 0 5px rgba(47, 138, 91, 0.1); }
.connection.is-offline .connection-dot { background: var(--danger); box-shadow: 0 0 0 5px rgba(183, 94, 88, 0.09); }

main { display: grid; grid-template-columns: minmax(0, 1fr) 350px; gap: 28px; padding: 34px 0 30px; }
.section-heading, .panel-title-row, .ai-card-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; }
.eyebrow { margin: 0 0 7px; color: var(--accent); }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 7px; font-size: clamp(27px, 3vw, 38px); line-height: 1.12; letter-spacing: -0.035em; }
h2 { margin-bottom: 18px; font-size: 18px; letter-spacing: -0.018em; }
.section-copy { max-width: 32rem; margin-bottom: 0; color: var(--muted); font-size: 14px; line-height: 1.65; }
.care-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  padding: 8px 12px;
  color: var(--good);
  border: 1px solid #cbe4d4;
  border-radius: 999px;
  background: var(--good-soft);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.care-badge i { width: 7px; height: 7px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 4px rgba(47, 138, 91, 0.1); }

.viewer {
  position: relative;
  aspect-ratio: 4 / 3;
  min-height: 320px;
  margin-top: 23px;
  overflow: hidden;
  border: 6px solid rgba(255, 254, 250, 0.98);
  border-radius: 26px;
  background: linear-gradient(145deg, #29332f, #1d2522);
  box-shadow: 0 22px 60px rgba(48, 54, 50, 0.16);
}
.viewer::after {
  content: "";
  position: absolute;
  z-index: 3;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, transparent 72%, rgba(12, 17, 15, 0.28));
}
#stream { position: relative; z-index: 1; width: 100%; height: 100%; display: none; object-fit: contain; background: #18201d; }
.viewer.has-stream #stream { display: block; }
.stream-placeholder { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; padding: 30px; color: #f2f6f3; text-align: center; }
.viewer.has-stream .stream-placeholder { display: none; }
.stream-placeholder p { margin: 20px 0 6px; font-size: 16px; font-weight: 650; }
.stream-placeholder small { color: rgba(233, 240, 235, 0.62); }
.care-orb {
  width: 62px;
  height: 62px;
  display: grid;
  place-items: center;
  color: #d9eadf;
  border: 1px solid rgba(218, 235, 224, 0.27);
  border-radius: 22px;
  background: rgba(231, 245, 236, 0.08);
  font: 400 35px/1 Georgia, serif;
}
.viewer-meta { position: absolute; z-index: 4; right: 23px; bottom: 20px; left: 23px; display: flex; justify-content: space-between; color: rgba(255,255,255,.72); font-size: 10px; font-weight: 700; letter-spacing: .08em; text-shadow: 0 1px 5px #000; }
.viewer-actions { display: flex; flex-wrap: wrap; gap: 10px; padding-top: 15px; }

.button, .icon-button {
  color: var(--text);
  border: 1px solid var(--line);
  background: rgba(255, 254, 250, 0.82);
  cursor: pointer;
  transition: border-color 140ms, background 140ms, transform 140ms, box-shadow 140ms;
}
.button { min-height: 43px; padding: 0 17px; border-radius: 12px; font-size: 13px; font-weight: 700; }
.button:hover, .icon-button:hover { border-color: #bfcac3; background: #fff; box-shadow: 0 8px 20px rgba(65, 78, 70, 0.08); }
.button:active, .icon-button:active { transform: translateY(1px); }
.button-primary { color: #fff; border-color: var(--accent); background: var(--accent); }
.button-primary:hover { border-color: var(--accent-dark); background: var(--accent-dark); }
.button-quiet { margin-left: auto; color: var(--muted); border-color: transparent; background: transparent; }
.button-small { min-height: 38px; padding: 0 13px; }
.button-icon { margin-right: 8px; color: #d9eee2; font-size: 8px; }

.ai-card {
  margin-top: 25px;
  padding: 24px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}
.ai-card-header { align-items: flex-start; }
.ai-card-header h2 { margin-bottom: 0; font-size: 20px; }
.ai-state { display: inline-flex; align-items: center; gap: 8px; padding: 9px 12px; border-radius: 999px; font-size: 12px; white-space: nowrap; }
.ai-state span { width: 8px; height: 8px; border-radius: 50%; }
.ai-state.is-safe { color: var(--good); background: var(--good-soft); }
.ai-state.is-safe span { background: var(--good); box-shadow: 0 0 0 5px rgba(47, 138, 91, 0.1); }
.ai-state.is-attention { color: var(--danger); background: #faece9; }
.ai-state.is-attention span { background: var(--danger); }
.ai-feed {
  max-height: 234px;
  margin-top: 20px;
  overflow-y: auto;
  overscroll-behavior: contain;
  border-top: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
  scrollbar-width: thin;
  scrollbar-color: #bdc9c1 transparent;
}
.ai-event { display: grid; grid-template-columns: 30px minmax(0, 1fr) auto; gap: 11px; align-items: start; padding: 14px 3px; border-bottom: 1px solid var(--line-soft); }
.ai-event:last-child { border-bottom: 0; }
.ai-event-marker { width: 28px; height: 28px; display: grid; place-items: center; color: var(--accent); border-radius: 10px; background: var(--accent-soft); font-size: 13px; font-weight: 800; }
.ai-event-safe .ai-event-marker { color: var(--good); background: var(--good-soft); }
.ai-event p { margin: 0 0 3px; font-size: 13px; font-weight: 700; }
.ai-event small { display: block; color: var(--muted); font-size: 11px; line-height: 1.45; }
.ai-event time { padding-top: 4px; color: #9aa19d; font-size: 10px; font-variant-numeric: tabular-nums; }
.ai-empty { padding: 28px 4px; color: var(--muted); font-size: 13px; text-align: center; }
.ai-footer { display: flex; justify-content: space-between; gap: 15px; padding-top: 13px; color: var(--muted); font-size: 11px; }
.ai-pulse { display: inline-flex; align-items: center; gap: 7px; color: var(--accent-dark); font-weight: 700; }
.ai-pulse i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: breathe 1.8s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: .35; transform: scale(.75); } }

.side-panel { display: flex; flex-direction: column; gap: 16px; }
.panel { padding: 22px; border: 1px solid var(--line-soft); border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow); }
.panel label { display: block; margin-bottom: 8px; color: var(--muted); font-size: 12px; }
.input-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
input[type="text"], input[type="password"], select { width: 100%; min-width: 0; height: 40px; padding: 0 11px; color: var(--text); border: 1px solid var(--line); border-radius: 11px; outline: none; background: #fbfaf6; font-size: 12px; }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(88, 125, 109, 0.11); }
.panel-title-row { align-items: flex-start; }
.icon-button { width: 34px; height: 34px; border-radius: 50%; color: var(--accent-dark); font-size: 18px; }
.stats { margin: 0; }
.stats div { display: flex; align-items: baseline; justify-content: space-between; gap: 18px; padding: 13px 0; border-top: 1px solid var(--line-soft); }
.stats dt { color: var(--muted); font-size: 12px; }
.stats dd { margin: 0; font-size: 12px; font-weight: 700; text-align: right; }
.publisher-panel h2 { margin-bottom: 12px; }
#camera-preview { width: 100%; aspect-ratio: 4/3; display: block; margin-bottom: 14px; object-fit: cover; border: 1px solid var(--line); border-radius: 14px; background: #26302c; }
.publisher-row { display: grid; grid-template-columns: 1fr 110px; align-items: center; gap: 12px; margin: 12px 0; }
.publisher-row label { margin: 0; }
.publisher-button { width: 100%; }
.help-text { min-height: 2.8em; margin: 11px 0 0; color: var(--muted); font-size: 11px; line-height: 1.45; }

dialog { width: min(420px, calc(100% - 28px)); padding: 0; color: var(--text); border: 1px solid var(--line); border-radius: 24px; background: var(--panel-solid); box-shadow: 0 30px 100px rgba(58, 63, 59, 0.25); }
dialog::backdrop { background: rgba(47, 54, 50, 0.38); backdrop-filter: blur(7px); }
.login-card { display: grid; gap: 9px; padding: 30px; }
.login-card h2 { margin-bottom: 12px; font-size: 23px; }
.login-card label { color: var(--muted); font-size: 12px; }
.login-card .button { margin-top: 10px; }
.login-card small { margin-top: 5px; color: var(--muted); line-height: 1.5; }
.form-error { min-height: 1.4em; margin: 2px 0 0; color: var(--danger); font-size: 12px; }
footer { min-height: 68px; display: flex; align-items: center; justify-content: space-between; gap: 20px; color: #8b918d; border-top: 1px solid rgba(132, 130, 119, 0.15); font-size: 11px; }

@media (max-width: 960px) {
  .shell { padding: 0 20px; }
  main { grid-template-columns: 1fr; padding-top: 28px; }
  .side-panel { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .publisher-panel { grid-column: 1 / -1; }
}
@media (max-width: 650px) {
  .shell { padding: 0 14px; }
  .topbar { min-height: 76px; }
  .brand strong { font-size: 15px; }
  .brand small { display: none; }
  .connection { font-size: 11px; }
  main { gap: 18px; }
  .section-heading, .ai-card-header { align-items: flex-start; flex-direction: column; }
  .viewer { min-height: 230px; border-width: 4px; border-radius: 20px; }
  .side-panel { grid-template-columns: 1fr; }
  .publisher-panel { grid-column: auto; }
  .viewer-actions .button { flex: 1 1 auto; }
  .button-quiet { margin-left: 0; }
  .ai-card { padding: 19px; }
  .ai-event { grid-template-columns: 30px minmax(0, 1fr); }
  .ai-event time { grid-column: 2; padding-top: 0; }
  .ai-footer, footer { align-items: flex-start; flex-direction: column; justify-content: center; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }
