:root {
  color-scheme: dark;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #e9f1fb;
  background: #071522;
  --surface: #102235;
  --control: #173349;
  --border: #24475a;
  --muted: #a4b4c9;
  --accent: #37e0d0;
  --danger: #ffaaaa;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 0; }
body > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .75rem;
  padding: .8rem clamp(.75rem, 2vw, 2rem);
  border-bottom: 1px solid var(--border);
  background: #0b1c2d;
}
.brand { display: flex; align-items: center; gap: .7rem; font-size: 1.05rem; font-weight: 760; letter-spacing: .06em; }
.brand-logo { width: 2.5rem; height: 2.5rem; border-radius: .65rem; }
.brand small { display: block; color: var(--muted); font-size: .65rem; font-weight: 500; letter-spacing: .04em; }
main { padding: clamp(.75rem, 1.8vw, 1.75rem); }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(1.75rem, 3vw, 2.45rem); letter-spacing: -.035em; line-height: 1.1; }
h2 { font-size: 1.05rem; line-height: 1.25; overflow-wrap: anywhere; }
#status, .muted { color: var(--muted); font-size: .875rem; }
#status { margin-top: .35rem; }
.heading, .view-controls, .toolbar, .card-head, .dialog-head, .ptz {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .5rem;
}
.heading { justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.view-controls { gap: .75rem; max-width: 100%; }
.view-controls label { display: flex; align-items: center; gap: .5rem; min-width: 0; color: var(--muted); }
.view-controls select { max-width: min(100%, 16rem); min-width: 0; color: #e9f1fb; }
.segments { display: flex; flex-wrap: wrap; padding: .2rem; background: var(--surface); border: 1px solid var(--border); border-radius: .7rem; gap: .2rem; }
.segments button { border-color: transparent; background: transparent; }
button, select, input, summary {
  font: inherit;
  font-size: .875rem;
  color: inherit;
  background: var(--control);
  border: 1px solid var(--border);
  border-radius: .48rem;
}
button, select, summary { min-height: 2.65rem; padding: .45rem .7rem; }
button, summary, select { cursor: pointer; }
button:hover:not(:disabled), summary:hover { background: #22354e; }
button:disabled, select:disabled { opacity: .58; cursor: default; }
select {
  appearance: none;
  padding-right: 1.9rem;
  background-image: linear-gradient(45deg, transparent 50%, #b4c7dc 50%), linear-gradient(135deg, #b4c7dc 50%, transparent 50%);
  background-position: right 1rem center, right .75rem center;
  background-size: .25rem .25rem;
  background-repeat: no-repeat;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.primary, .segments button[aria-pressed="true"], #recordings button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #091b29; font-weight: 700; }
.primary:hover:not(:disabled), .segments button[aria-pressed="true"]:hover, #recordings button[aria-pressed="true"]:hover { background: #a1e4ff; }
.panel { border: 1px solid var(--border); border-radius: .8rem; background: var(--surface); min-width: 0; }
.tiles { display: grid; grid-template-columns: minmax(0, 1fr); gap: .8rem; align-items: start; }
@media (min-width: 650px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1100px) { .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1550px) { .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.tiles.single { grid-template-columns: minmax(0, 1fr); }
.card-head { min-height: 3rem; padding: .6rem .75rem; }
.card-head h2 { margin-right: auto; }
.camera-status, .recording-status { font-weight: 650; font-size: .875rem; color: var(--muted); }
.camera-status::before { content: ""; display: inline-block; width: .45rem; height: .45rem; border-radius: 50%; background: currentColor; margin-right: .38rem; vertical-align: .12em; }
.camera-status[data-state="Online"] { color: #76e4b7; }
.camera-status[data-state="Verbindet"] { color: #ffd18b; }
.camera-status[data-state="Fehler"], .recording-status { color: var(--danger); }
.screen { width: 100%; display: grid; place-items: center; position: relative; overflow: hidden; background: #03070e; aspect-ratio: 16 / 9; }
.screen[data-fit="original"], .screen[data-fit="fit"][data-lens="max"] { aspect-ratio: var(--video-ratio); }
.screen video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; transform: scale(var(--zoom, 1)); }
.screen[data-fit="fill"] video { object-fit: cover; }
.screen.zoomed video { touch-action: none; cursor: grab; }
.screen.zoomed video:active { cursor: grabbing; }
.placeholder, .play { position: relative; text-align: center; }
.placeholder { padding: 1rem; color: var(--muted); pointer-events: none; }
.single .screen { max-height: 76dvh; }
.single .screen:not([data-fit="original"]):not([data-lens="max"]), .single .screen[data-fit="fill"] {
  height: clamp(13rem, 69dvh, 85vw);
  aspect-ratio: auto;
}
.card-toolbar { padding: .55rem .65rem; }
.record[data-active="true"] { border-color: var(--danger); color: var(--danger); background: #382334; }
.camera-error, .camera-address { padding: 0 .75rem .65rem; font-size: .875rem; overflow-wrap: anywhere; }
.camera-error, #notice, #settings-error { color: var(--danger); }
.camera-address { color: var(--muted); user-select: all; }
.camera-menu { position: relative; margin-inline-start: auto; }
summary { display: grid; place-items: center; list-style: none; }
summary::-webkit-details-marker { display: none; }
.menu-items {
  display: grid;
  gap: .4rem;
  position: absolute;
  right: 0;
  top: calc(100% + .35rem);
  z-index: 3;
  width: min(15rem, 80vw);
  padding: .55rem;
  border: 1px solid var(--border);
  border-radius: .6rem;
  background: var(--surface);
  box-shadow: 0 .6rem 1.5rem #0009;
}
.ptz { border-top: 1px solid var(--border); padding-top: .45rem; }
.camera-card:fullscreen, .camera-card.expanded { display: flex; flex-direction: column; border: 0; border-radius: 0; }
.camera-card.expanded { position: fixed; inset: 0; z-index: 5; }
.has-expanded { overflow: hidden; }
.tiles .camera-card:is(:fullscreen, .expanded) .screen { flex: 1 1 0; min-height: 0; max-height: none; height: auto; aspect-ratio: auto; }
.camera-card:is(:fullscreen, .expanded) .menu-items { top: auto; bottom: calc(100% + .35rem); }
.manage, .empty, .login { padding: 1rem; }
.manage { margin-top: 1rem; }
.manage h2 { margin-bottom: .65rem; }
.login { max-width: 26rem; margin: 8vh auto; }
.login form { margin-top: 1rem; }
form, .camera-fields { display: grid; gap: .75rem; }
form label { display: grid; align-content: start; gap: .35rem; font-size: .875rem; }
input:not([type="checkbox"]):not([type="range"]) { width: 100%; padding: .65rem; }
input[type="range"], input[type="checkbox"] { accent-color: var(--accent); }
label.check, label:has(input[type="checkbox"]) { display: flex; align-items: center; }
#camera-form { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); max-width: 54rem; }
@media (min-width: 650px) { .camera-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
#notice:not(:empty), #discovery-status:not(:empty) { margin-top: .75rem; }
dialog {
  background: var(--surface);
  color: inherit;
  border: 1px solid var(--border);
  border-radius: .85rem;
  width: min(94vw, 35rem);
  max-height: 94dvh;
  padding: 1rem;
}
dialog::backdrop { background: #02060bc9; }
.dialog-head { justify-content: space-between; margin-bottom: .4rem; }
.dialog-head h2 { font-size: 1.2rem; }
#archive { width: min(94vw, 62rem); }
#archive-video { width: 100%; max-height: 58dvh; display: block; background: #03070e; margin-bottom: .6rem; }
#archive-status:not(:empty) { margin-top: .65rem; }
#recordings, #discoveries { list-style: none; margin: .55rem 0 0; padding: 0; display: grid; gap: .4rem; }
#recordings button { width: 100%; text-align: left; }

#ai-nav { width: fit-content; max-width: 100%; }
#ai-message { color: var(--muted); margin: .75rem 0; }
#ai-content, .ai-stack, .ai-tile, .ai-tile label { display: grid; gap: .75rem; }
.ai-stack > button, .ai-tile > button { justify-self: start; }
.ai-grid { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 19rem), 1fr)); align-items: start; }
.ai-tile { padding: .9rem; }
.ai-tile legend { padding: 0 .35rem; font-weight: 650; }
.ai-tile label { min-width: 0; gap: .3rem; }
.ai-tile label.check { display: flex; align-items: start; gap: .5rem; }
.ai-tile input:not([type="checkbox"]), .ai-tile textarea { width: 100%; min-width: 0; padding: .55rem; }
.ai-tile textarea { background: var(--control); border: 1px solid var(--border); border-radius: .48rem; color: inherit; font: inherit; }
.ai-tile summary { margin-bottom: .45rem; }
.ai-value { color: var(--accent); font-size: 1.15rem; }
.ai-tile a { color: var(--accent); }
.ai-photos { display: flex; flex-wrap: wrap; gap: .55rem; }
.ai-photo img { width: 6rem; height: 5rem; object-fit: cover; border-radius: .4rem; }
.ai-photo button { min-height: 2rem; }
.ai-capture { width: min(100%, 34rem); border-radius: .5rem; }
.ai-event { display: flex; flex-wrap: wrap; align-items: center; }
.ai-event img { width: min(15rem, 67vw); max-height: 12rem; object-fit: contain; border-radius: .4rem; }
.ai-live .manage { display: none; }
.ai-live-caption { color: var(--accent); flex-basis: 100%; font-size: .82rem; }
.ai-overlay { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.ai-marker { position: absolute; border: 2px solid #ffd18b; box-shadow: 0 0 0 1px #111; }
.ai-marker[data-status="known"] { border-color: #76e4b7; }
.ai-marker:is([data-status="dog"], [data-status="animal"]) { border-color: var(--accent); }
.card-toolbar button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }

body > header {
  padding-top: calc(.8rem + env(safe-area-inset-top));
  padding-left: max(.75rem, 2vw, env(safe-area-inset-left));
  padding-right: max(.75rem, 2vw, env(safe-area-inset-right));
}
main {
  padding-left: max(clamp(.75rem, 1.8vw, 1.75rem), env(safe-area-inset-left));
  padding-right: max(clamp(.75rem, 1.8vw, 1.75rem), env(safe-area-inset-right));
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
}
.startup { display: flex; gap: .9rem; align-items: center; flex-wrap: wrap; }
.startup h1 { font-size: 1.25rem; letter-spacing: .07em; }
.tagline { color: var(--accent); font-size: .8rem; letter-spacing: .04em; }
.login { text-align: center; }
.login-logo { display: block; margin: .25rem auto .7rem; border-radius: 1rem; box-shadow: 0 0 36px #37e0d022; }
.login > h1 { font-size: 1.35rem; letter-spacing: .08em; }
.login-heading { margin-top: 1.5rem; text-align: left; }
.login form { text-align: left; }
.startup p, #device-status { color: var(--muted); }
.startup img { border-radius: .85rem; }
.spinner { width: 1.25rem; height: 1.25rem; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; }
@media (prefers-reduced-motion: no-preference) {
  .spinner { animation: camera-spin .8s linear infinite; }
}
@keyframes camera-spin { to { transform: rotate(360deg); } }
#device-list { display: grid; gap: .75rem; padding: 0; list-style: none; }
#device-list li { display: grid; gap: .35rem; padding: .8rem; border: 1px solid var(--border); border-radius: .75rem; overflow-wrap: anywhere; }
#device-list button { justify-self: start; }
