:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #efebe4;
  --text: #1f2421;
  --muted: #5f6a64;
  --border: #ddd6cc;
  --primary: #2f6f5e;
  --primary-text: #ffffff;
  --primary-soft: #dcebe5;
  --danger: #c0392b;
  --danger-soft: #f8e1dd;
  --warn: #b7791f;
  --ok: #2e8b57;
  --radius: 18px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 6px 20px rgb(0 0 0 / 0.06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101614;
    --surface: #18211e;
    --surface-2: #212c28;
    --text: #e9efec;
    --muted: #9aa8a1;
    --border: #2d3a35;
    --primary: #5fb39a;
    --primary-text: #0c1512;
    --primary-soft: #1f3a32;
    --danger: #ef6f5e;
    --danger-soft: #3a1f1b;
    --warn: #e0a84a;
    --ok: #5fcf8f;
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #101614;
  --surface: #18211e;
  --surface-2: #212c28;
  --text: #e9efec;
  --muted: #9aa8a1;
  --border: #2d3a35;
  --primary: #5fb39a;
  --primary-text: #0c1512;
  --primary-soft: #1f3a32;
  --danger: #ef6f5e;
  --danger-soft: #3a1f1b;
  --warn: #e0a84a;
  --ok: #5fcf8f;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body { min-height: 100dvh; }

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 88px);
}

h1 { font-size: 1.6rem; margin: 8px 0 16px; line-height: 1.2; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 16px 0 8px; }
p { margin: 0 0 12px; }
a { color: var(--primary); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 0.87rem; }
.center { text-align: center; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

button, .btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 14px;
  padding: 12px 16px;
  min-height: 48px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
}
button svg, .btn svg { width: 24px; height: 24px; flex: none; }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
button.ghost { background: transparent; border-color: transparent; color: var(--primary); }
button.block { width: 100%; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

.big-call {
  width: 100%;
  min-height: 140px;
  font-size: 1.5rem;
  border-radius: 28px;
  background: var(--primary);
  border: none;
  color: var(--primary-text);
  flex-direction: column;
  gap: 6px;
}
.big-call svg { width: 44px; height: 44px; }
.big-call small { font-size: 0.95rem; font-weight: 500; opacity: 0.9; }

label { display: block; font-weight: 600; margin-bottom: 6px; }
input[type="text"], input[type="password"], input[type="number"], input[type="time"], select {
  width: 100%;
  font: inherit;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  min-height: 48px;
}
.field { margin-bottom: 14px; }
.form-error { background: var(--danger-soft); color: var(--danger); font-weight: 600; padding: 12px 14px; border-radius: 12px; margin: 0 0 14px; }
.field .hint { font-size: 0.85rem; color: var(--muted); margin-top: 4px; }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.switch:last-child { border-bottom: none; }
.switch .text { flex: 1; }
.switch .text span { display: block; font-size: 0.85rem; color: var(--muted); font-weight: 400; }
.switch input[type="checkbox"] { width: 52px; height: 30px; appearance: none; background: var(--surface-2); border: 1px solid var(--border); border-radius: 30px; position: relative; cursor: pointer; flex: none; transition: background 0.15s; }
.switch input[type="checkbox"]::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / 0.3); transition: transform 0.15s; }
.switch input[type="checkbox"]:checked { background: var(--primary); border-color: var(--primary); }
.switch input[type="checkbox"]:checked::after { transform: translateX(22px); }

.status { display: flex; gap: 12px; align-items: center; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 25%, transparent); }
.dot.off { background: var(--danger); }
.dot.warn { background: var(--warn); }
.tablet-status h2 { margin-bottom: 6px; }
.tablet-status.alert { border-color: var(--danger); box-shadow: 0 0 0 2px color-mix(in srgb, var(--danger) 35%, transparent); }
.status-row { display: flex; gap: 12px; align-items: flex-start; padding: 8px 0; }
.status-row + .status-row { border-top: 1px solid var(--border); }
.status-row .dot { margin-top: 6px; }
.status-row.bad strong { color: var(--danger); }
.status-row.warn strong { color: var(--warn); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.chip { font-size: 0.85rem; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.chip.warn { background: var(--danger-soft); color: var(--danger); }

.banner { border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; background: var(--primary-soft); }
.banner.danger { background: var(--danger-soft); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 12px 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: none; }

.code { font: 700 2.4rem/1 ui-monospace, Menlo, Consolas, monospace; letter-spacing: 0.2em; text-align: center; padding: 14px; background: var(--surface-2); border-radius: 14px; }
.linkbox { word-break: break-all; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.85rem; background: var(--surface-2); padding: 10px; border-radius: 10px; }

nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: center;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 6px 8px calc(env(safe-area-inset-bottom) + 6px);
  z-index: 10;
}
nav.tabs .inner { display: flex; width: 100%; max-width: 640px; }
nav.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; color: var(--muted); text-decoration: none; font-size: 0.75rem; font-weight: 600; border-radius: 12px; }
nav.tabs a.active { color: var(--primary); background: var(--primary-soft); }
nav.tabs svg { width: 24px; height: 24px; }

.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.photos figure { margin: 0; position: relative; border-radius: 12px; overflow: hidden; background: var(--surface-2); aspect-ratio: 1; }
.photos img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photos button { position: absolute; top: 6px; right: 6px; min-height: 36px; padding: 6px 10px; font-size: 0.8rem; background: rgb(0 0 0 / 0.55); color: #fff; border: none; }

/* ── Hovor ─────────────────────────────── */
.call {
  position: fixed; inset: 0; z-index: 50;
  background: #0b0f0e; color: #fff;
  display: flex; flex-direction: column;
}
.call .stage { flex: 1; display: grid; gap: 4px; padding: calc(env(safe-area-inset-top) + 4px) 4px 4px; min-height: 0; }
.call .stage.n1 { grid-template-columns: 1fr; }
.call .stage.n2 { grid-template-rows: 1fr 1fr; }
@media (orientation: landscape) { .call .stage.n2 { grid-template-rows: none; grid-template-columns: 1fr 1fr; } }
.call .stage.n3, .call .stage.n4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.call .tile { position: relative; background: #1b2320; border-radius: 14px; overflow: hidden; min-height: 0; }
.call .tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.call .tile .name { position: absolute; left: 10px; bottom: 10px; background: rgb(0 0 0 / 0.5); padding: 4px 10px; border-radius: 999px; font-size: 0.9rem; }
.call .tile .placeholder { position: absolute; inset: 0; display: grid; place-items: center; font-size: 3rem; font-weight: 700; color: #7fa596; }
.call .self { position: absolute; right: 12px; bottom: calc(env(safe-area-inset-bottom) + 104px); width: 28vw; max-width: 160px; aspect-ratio: 3 / 4; border-radius: 14px; overflow: hidden; background: #222; border: 2px solid rgb(255 255 255 / 0.3); z-index: 2; }
.call .self video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.call .self.back video { transform: none; }
.call .overlay { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 24px; background: rgb(11 15 14 / 0.75); z-index: 1; }
.call .overlay h2 { font-size: 1.5rem; margin-bottom: 6px; }
.call .controls { display: flex; justify-content: center; gap: 18px; padding: 14px 16px calc(env(safe-area-inset-bottom) + 16px); }
.call .controls button { width: 64px; height: 64px; border-radius: 50%; padding: 0; background: rgb(255 255 255 / 0.14); border: none; color: #fff; }
.call .controls button.off { background: #fff; color: #111; }
.call .controls button.hangup { background: #e0463a; width: 72px; height: 72px; }
.call .controls svg { width: 28px; height: 28px; }

.incoming { position: fixed; inset: 0; z-index: 60; background: var(--primary); color: var(--primary-text); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 24px; text-align: center; }
.incoming h1 { font-size: 2rem; }
.incoming .actions { display: flex; gap: 40px; margin-top: 30px; }
.incoming .actions button { width: 84px; height: 84px; border-radius: 50%; border: none; padding: 0; }
.incoming .actions .accept { background: #fff; color: var(--primary); }
.incoming .actions .decline { background: #e0463a; color: #fff; }
.incoming svg { width: 36px; height: 36px; }
.pulse { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.08); } }
@media (prefers-reduced-motion: reduce) { .pulse { animation: none; } }

.splash { min-height: 70dvh; display: grid; place-items: center; }
.spinner { width: 40px; height: 40px; border-radius: 50%; border: 4px solid var(--surface-2); border-top-color: var(--primary); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 90px); transform: translateX(-50%) translateY(20px); opacity: 0; transition: 0.2s; background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 14px; max-width: calc(100vw - 32px); z-index: 100; pointer-events: none; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--danger); color: #fff; }

.hero { text-align: center; padding: 30px 0 10px; }
.hero .logo { width: 84px; height: 84px; }
