:root {
  --bg0: #0f1c14;
  --bg1: #163022;
  --ink: #e8f2e9;
  --muted: #9bb5a4;
  --accent: #d4a24c;
  --accent-ink: #1a1205;
  --ok: #3ecf8e;
  --bad: #e26a6a;
  --line: rgba(232, 242, 233, 0.12);
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --font-body: "Avenir Next", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  font-family: var(--font-body);
  background:
    radial-gradient(120% 80% at 10% -10%, #2a4a35 0%, transparent 55%),
    radial-gradient(90% 70% at 100% 0%, #3a2a12 0%, transparent 50%),
    linear-gradient(160deg, var(--bg0), var(--bg1) 60%, #0b1410);
}

body {
  min-height: 100dvh;
}

.shell {
  width: min(28rem, 100%);
  margin: 0 auto;
  padding: 1.75rem 1.25rem 2.5rem;
  display: grid;
  gap: 1.25rem;
  transition: width 0.2s ease;
}

body.video-wide .shell {
  width: min(56rem, 100%);
  padding-left: 0.75rem;
  padding-right: 0.75rem;
}

.brand h1 {
  margin: 0.15rem 0;
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 9vw, 3.2rem);
  letter-spacing: -0.03em;
  font-weight: 600;
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  font-size: 0.72rem;
  color: var(--accent);
}

.lede,
.status-meta,
label {
  color: var(--muted);
}

.lede {
  margin: 0;
  font-size: 1rem;
}

.clock {
  margin: 0.4rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.status-block,
.video-card,
.call-card,
.log-card {
  border: 1px solid var(--line);
  background: rgba(8, 16, 11, 0.45);
  backdrop-filter: blur(8px);
  border-radius: 1rem;
  padding: 1rem 1.1rem;
}

.video-card {
  padding: 0.75rem;
}

.video-wrap {
  position: relative;
  width: 100%;
  height: 11.5rem;
  border-radius: 0.75rem;
  overflow: hidden;
  background: #050807;
  transition: height 0.2s ease;
}

.video-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.video-hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 1rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.92rem;
  background: rgba(5, 8, 7, 0.55);
  pointer-events: none;
}

.video-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.65rem;
}

.video-card-title {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.size-toggle {
  display: inline-flex;
  padding: 0.15rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
  gap: 0.1rem;
}

.size-btn {
  width: auto;
  margin: 0;
  padding: 0.35rem 0.7rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.size-btn.is-active {
  background: rgba(212, 162, 76, 0.22);
  color: var(--ink);
}

.video-card.video-large .video-wrap {
  width: 100%;
  height: min(72dvh, 38rem);
}

.status-block {
  display: flex;
  gap: 0.85rem;
  align-items: center;
}

.dot {
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 50%;
  background: var(--bad);
  box-shadow: 0 0 0 4px rgba(226, 106, 106, 0.15);
}

.dot.online {
  background: var(--ok);
  box-shadow: 0 0 0 4px rgba(62, 207, 142, 0.18);
}

.status-label {
  margin: 0;
  font-weight: 600;
}

.status-meta {
  margin: 0.15rem 0 0;
  font-size: 0.9rem;
}

label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.85rem;
}

.dial-caption {
  margin: 0 0 0.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}

input {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  border-radius: 0.7rem;
  padding: 0.85rem 0.95rem;
  font-size: 1.35rem;
  letter-spacing: 0.04em;
  text-align: center;
  margin-bottom: 0.75rem;
}

.pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.55rem;
  margin: 0.25rem 0 1rem;
}

.pad button {
  width: 100%;
  margin: 0;
  min-height: 3.2rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  border: 1px solid var(--line);
  font-size: 1.25rem;
  font-weight: 600;
}

.pad button:active {
  background: rgba(212, 162, 76, 0.25);
}

button {
  width: 100%;
  border: 0;
  border-radius: 0.75rem;
  padding: 0.95rem 1rem;
  font-size: 1rem;
  font-weight: 650;
  cursor: pointer;
}

.call-card > button + button,
.auth-card > button + button {
  margin-top: 0.55rem;
}

.primary {
  background: var(--accent);
  color: var(--accent-ink);
}

.secondary,
.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

.primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.log-card h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  font-weight: 600;
}

#log {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.65rem;
}

#log li {
  border-top: 1px solid var(--line);
  padding-top: 0.65rem;
  font-size: 0.92rem;
}

#log .meta {
  color: var(--muted);
  font-size: 0.8rem;
}

#log .ok {
  color: var(--ok);
}

#log .bad {
  color: var(--bad);
}

/* ── New elements (multi-device, audio, retry) ── */

.shell {
  width: min(60rem, 100%);
}

.video-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.vcard {
  flex: 1 1 28rem;
  min-width: 0;
  position: relative;
  border: 1px solid var(--line);
  background: rgba(8, 16, 11, 0.45);
  backdrop-filter: blur(8px);
  border-radius: 1rem;
  overflow: hidden;
  aspect-ratio: 16 / 9;
}

.vcard.is-offline { opacity: 0.4; }
.vcard.is-pinned {
  border-color: rgba(212,162,76,0.68);
  box-shadow: 0 0 0 1px rgba(212,162,76,0.18);
}

.vcard.vcard-expanded {
  flex: 1 1 100%;
  aspect-ratio: auto;
  min-height: 60vh;
}

/* когда одна карточка развёрнута — остальные не растягиваются */
.video-grid:has(.vcard-expanded) .vcard:not(.vcard-expanded) {
  flex: 0 0 auto;
  width: min(28rem, 100%);
}

.vcard-feed {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.3s;
}
.vcard-feed.visible { opacity: 1; }

.vcard-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.vcard-spinner {
  width: 1.4rem;
  height: 1.4rem;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.vcard-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background:
    linear-gradient(180deg, rgba(0,0,0,0.5) 0%, transparent 35%,
                    transparent 65%, rgba(0,0,0,0.6) 100%);
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}
.vcard:hover .vcard-overlay,
.vcard:focus-within .vcard-overlay {
  opacity: 1;
  pointer-events: auto;
}

.vcard-controls {
  display: flex;
  gap: 0.3rem;
  padding: 0.5rem;
  justify-content: flex-end;
}

.vcard-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(0,0,0,0.5);
  color: rgba(255,255,255,0.9);
  border-radius: 0.45rem;
  cursor: pointer;
  font-size: 0;
}
.vcard-btn:hover {
  background: rgba(255,255,255,0.15);
  border-color: rgba(255,255,255,0.4);
}
.vcard-btn.is-active {
  background: rgba(212,162,76,0.25);
  border-color: var(--accent);
  color: var(--accent);
}

.vcard-info {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.55rem;
}

.vcard-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ok);
  flex-shrink: 0;
}
.vcard.is-offline .vcard-status-dot { background: var(--bad); }

.vcard-name {
  font-size: 0.72rem;
  color: rgba(255,255,255,0.9);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.vcard-info .vcard-btn {
  width: 1.5rem;
  height: 1.5rem;
  border: 0;
  background: rgba(0,0,0,0.35);
  flex-shrink: 0;
}

.vcard-battery {
  font-size: 0.72rem;
  color: rgba(255,255,255,0.9);
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
}
.vcard-battery.low { color: #ff9d9d; }

.rename-input {
  flex: 1;
  min-width: 0;
  background: rgba(0,0,0,0.55);
  border: 1px solid var(--accent);
  color: var(--ink);
  border-radius: 0.3rem;
  padding: 0.15rem 0.4rem;
  font-size: 0.72rem;
  margin: 0;
  letter-spacing: normal;
  text-align: left;
}

.empty-hint {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--muted);
  font-size: 0.9rem;
  border: 1px solid var(--line);
  background: rgba(8,16,11,0.45);
  backdrop-filter: blur(8px);
  border-radius: 1rem;
}
.empty-hint p + p { margin-top: 0.25rem; font-size: 0.78rem; opacity: 0.6; }

.device-select {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.04);
  color: var(--ink);
  border-radius: 0.7rem;
  padding: 0.65rem 0.85rem;
  font-size: 0.9rem;
  cursor: pointer;
  appearance: none;
  font-family: inherit;
  margin-bottom: 0.55rem;
}

.retry-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: var(--muted);
  cursor: pointer;
  margin-bottom: 0;
}
.retry-label input[type="checkbox"] {
  width: auto;
  margin: 0;
  padding: 0;
  font-size: inherit;
  letter-spacing: normal;
  text-align: left;
  cursor: pointer;
  accent-color: var(--accent);
}

.hidden-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.hidden-chip {
  width: auto;
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255,255,255,0.04);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.hidden-chip:hover {
  background: rgba(255,255,255,0.09);
  color: var(--ink);
  border-color: rgba(232,242,233,0.25);
}

.apk-row {
  display: flex;
  gap: 0.5rem;
}

.apk-link {
  flex: 1;
  display: block;
  text-align: center;
  padding: 0.6rem 1rem;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 550;
  text-decoration: none;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.apk-link:hover {
  background: rgba(255,255,255,0.05);
  color: var(--ink);
  border-color: rgba(232,242,233,0.25);
}

.apk-upload-label {
  flex: 1;
  display: block;
  text-align: center;
  padding: 0.6rem 1rem;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 550;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  margin-bottom: 0;
}
.apk-upload-label:hover {
  background: rgba(255,255,255,0.05);
  color: var(--ink);
  border-color: rgba(232,242,233,0.25);
}
.apk-upload-label input[type="file"] {
  display: none;
}

.upload-status {
  font-size: 0.78rem;
  color: var(--muted);
  text-align: center;
  margin-top: 0.25rem;
  padding: 0;
  border: none;
  background: none;
  width: auto;
  letter-spacing: normal;
}
.upload-status.ok  { color: var(--ok); }
.upload-status.bad { color: var(--bad); }

.log-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.15rem;
}

.log-number { font-size: 0.9rem; }

.log-status {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 0.15rem 0.45rem;
  border-radius: 0.3rem;
}
.log-status.ok   { background: rgba(62,207,142,0.12); color: var(--ok); }
.log-status.bad  { background: rgba(226,106,106,0.12); color: var(--bad); }
.log-status.warn { background: rgba(212,162,76,0.12);  color: var(--accent); }

.log-meta {
  font-size: 0.75rem;
  color: var(--muted);
}

/* ── Map section ── */

.map-card {
  border: 1px solid var(--line);
  background: rgba(8,16,11,0.45);
  backdrop-filter: blur(8px);
  border-radius: 1rem;
  overflow: hidden;
  padding: 0.75rem 0.75rem 0;
}

.map-card-title {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.map-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0 0 0.5rem;
}

.map-status {
  color: var(--muted);
  font-size: 0.72rem;
}

.map-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 15rem;
  gap: 0.75rem;
  padding-bottom: 0.75rem;
}

#map {
  height: 360px;
  border-radius: 0.7rem;
  overflow: hidden;
  margin-bottom: 0;
}

.map-device-list {
  display: grid;
  align-content: start;
  gap: 0.45rem;
  max-height: 360px;
  overflow-y: auto;
}

.map-device-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.7rem;
  border: 1px solid var(--line);
  border-radius: 0.65rem;
  background: rgba(255,255,255,0.035);
  color: var(--ink);
  text-align: left;
}

.map-device-item:not(:disabled):hover,
.map-device-item.selected {
  border-color: rgba(212,162,76,0.7);
  background: rgba(212,162,76,0.12);
}

.map-device-item:disabled { cursor: default; opacity: 0.55; }

.map-device-dot {
  width: 0.5rem;
  height: 0.5rem;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--bad);
}
.map-device-dot.online { background: var(--ok); }

.map-device-body { min-width: 0; display: grid; gap: 0.15rem; }
.map-device-body strong,
.map-device-body span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.map-device-body strong { font-size: 0.82rem; }
.map-device-body span { color: var(--muted); font-size: 0.68rem; }

.map-marker {
  background: var(--ok);
  color: #04200d;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  white-space: nowrap;
  border: 2px solid rgba(255,255,255,0.9);
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
  cursor: default;
  pointer-events: none;
}
.map-marker.offline {
  background: var(--bad);
  color: #fff;
}
.map-marker.selected {
  outline: 3px solid rgba(212,162,76,0.72);
  transform: scale(1.08);
}

@media (max-width: 700px) {
  .map-layout { grid-template-columns: 1fr; }
  #map { height: 320px; }
  .map-device-list {
    max-height: none;
    grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
  }
}

/* Leaflet popup dark theme */
.leaflet-popup-content-wrapper {
  background: #1a2e20;
  color: var(--ink);
  border: 1px solid var(--line);
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  border-radius: 0.5rem;
}
.leaflet-popup-tip { background: #1a2e20; }
.leaflet-popup-content {
  font-size: 0.8rem;
  line-height: 1.55;
  margin: 0.6rem 0.8rem;
}
.leaflet-popup-close-button { color: var(--muted) !important; }
.leaflet-control-zoom a {
  background: #1a2e20 !important;
  color: var(--ink) !important;
  border-color: var(--line) !important;
}
.leaflet-control-zoom a:hover {
  background: #2a4a35 !important;
}
