:root {
  --bg: #0b1016;
  --bg-elev: #151c26;
  --bg-card: #1b2430;
  --line: #2a3444;
  --text: #eef3f8;
  --muted: #8b97a8;
  --accent: #1ec8b8;
  --accent-dim: #129387;
  --danger: #ef5b6a;
  --ok: #3dd68c;
  --warn: #f0c14b;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: "SF Pro Text", "Segoe UI", "Noto Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); height: 100%; }
body { min-height: 100dvh; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; }

#app, .screen {
  min-height: 100dvh;
  min-height: 100svh;
}
.screen[hidden], .view[hidden], [hidden] { display: none !important; }

/* Login */
#screen-login {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(24px + var(--safe-top)) 24px calc(24px + var(--safe-bottom));
  background:
    radial-gradient(1200px 500px at 50% -10%, rgba(30, 200, 184, 0.18), transparent 55%),
    var(--bg);
}
.login-wrap { width: 100%; max-width: 380px; }
.brand { text-align: center; margin-bottom: 32px; }
.brand-logo {
  width: 84px; height: 84px; border-radius: 22px;
  box-shadow: var(--shadow), 0 0 0 1px rgba(30, 200, 184, 0.25);
}
.brand h1 { margin: 14px 0 6px; font-size: 28px; letter-spacing: 0.02em; }
.sub { margin: 0; color: var(--muted); font-size: 14px; }
#login-form label, .view label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 8px; }
input[type="password"], input[type="text"], input[type="date"], select {
  width: 100%;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 14px;
  outline: none;
  margin-bottom: 14px;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(30, 200, 184, 0.2); }
.btn {
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 14px 16px;
  font-weight: 650;
  margin-top: 4px;
}
.btn.primary { background: var(--accent); color: #04221f; }
.btn.primary:active { background: var(--accent-dim); }
.btn.secondary { background: var(--bg-card); border: 1px solid var(--line); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.danger { background: transparent; border: 1px solid var(--danger); color: var(--danger); margin-top: 12px; }
.btn[disabled] { opacity: 0.55; }
.error { color: var(--danger); font-size: 13px; margin: 0 0 12px; }
.ok { color: var(--ok); font-size: 13px; }
.hint { color: var(--muted); font-size: 12px; line-height: 1.5; margin-top: 16px; }

/* App chrome */
#screen-app {
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: calc(96px + var(--safe-bottom));
}
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  min-height: 56px;
  position: sticky;
  top: 0;
  background: rgba(11, 16, 22, 0.88);
  backdrop-filter: blur(12px);
  z-index: 5;
}
.topbar-title { flex: 1; min-width: 0; }
.topbar-title h1 { margin: 0; font-size: 18px; font-weight: 700; }
.icon-btn {
  background: transparent;
  border: 0;
  color: var(--text);
  width: 40px; height: 40px;
  border-radius: 12px;
  display: grid; place-items: center;
}
.icon-btn:active { background: var(--bg-elev); }
.icon-btn.glass { background: rgba(0,0,0,0.4); }

.view { padding: 8px 16px 32px; flex: 1; overflow-y: auto; }
.banner {
  background: rgba(240, 193, 75, 0.12);
  color: var(--warn);
  border: 1px solid rgba(240, 193, 75, 0.25);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 13px;
  margin: 0 0 14px;
}
.empty { color: var(--muted); text-align: center; padding: 40px 12px; }

.device-grid { display: grid; gap: 14px; }
.device-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  text-align: left;
  padding: 0;
  width: 100%;
  box-shadow: var(--shadow);
}
.device-thumb {
  position: relative;
  aspect-ratio: 16 / 10;
  background: #0e1620;
  overflow: hidden;
}
.device-thumb img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.device-thumb .placeholder {
  width: 100%; height: 100%;
  display: grid; place-items: center;
  color: var(--muted);
  background: linear-gradient(160deg, #1a2430, #0d131b);
  font-size: 13px;
}
.badge {
  position: absolute;
  top: 10px; left: 10px;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(0,0,0,0.55);
}
.badge.online { color: var(--ok); }
.badge.offline { color: #ff9aa3; }
.device-meta { padding: 12px 14px 14px; }
.device-meta h2 { margin: 0 0 4px; font-size: 16px; }
.device-meta p { margin: 0; color: var(--muted); font-size: 12px; }

/* Live player */
#view-live { padding: 0 0 24px; }
.player-shell {
  position: relative;
  background: #000;
  aspect-ratio: 16 / 10;
  overflow: hidden;
}
.player-shell.compact { margin-top: 16px; border-radius: 12px; }
.player-shell video { width: 100%; height: 100%; object-fit: contain; background: #000; display: block; }
.player-shell .ezuikit-box { position: absolute; inset: 0; width: 100%; height: 100%; background: #000; z-index: 1; }
.player-shell .ezuikit-box[hidden] { display: none !important; }
.player-shell .ezuikit-box > * { width: 100% !important; height: 100% !important; }
.player-top-actions, .player-overlay { z-index: 4; }
.player-shell:fullscreen, .player-shell:-webkit-full-screen { aspect-ratio: auto; width: 100%; height: 100%; }
.player-overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 10px;
  background: rgba(0,0,0,0.35);
  color: var(--text);
  font-size: 13px;
  pointer-events: none;
}
.player-overlay[hidden] { display: none !important; }
.spinner {
  width: 28px; height: 28px;
  border: 3px solid rgba(255,255,255,0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.player-top-actions {
  position: absolute; top: 10px; right: 10px;
  display: flex; gap: 8px;
}
.chip {
  border: 0;
  background: rgba(0,0,0,0.5);
  color: #fff;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
}
.live-tools {
  display: flex; gap: 10px;
  padding: 14px 16px 0;
}
.tool-btn {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 8px;
  font-size: 13px;
}
.tool-icon { display: block; font-size: 18px; margin-bottom: 4px; }

.ptz-wrap { padding: 8px 16px 0; text-align: center; }
.ptz-label { color: var(--muted); font-size: 12px; margin: 8px 0 12px; }
.ptz-pad {
  width: 220px;
  height: 220px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  grid-template-areas:
    "ul up ur"
    "left mid right"
    "dl down dr";
  gap: 8px;
}
.ptz {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 14px;
  font-size: 16px;
  color: var(--text);
}
.ptz:active, .ptz.held { background: var(--accent); color: #04221f; }
.ptz-center {
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #2a3646, #121820);
  border: 1px solid var(--line);
}

/* Settings / playback */
.section-label {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 20px 0 8px;
}
.row { display: flex; gap: 10px; }
.row .field { flex: 1; min-width: 0; }
.check { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; color: var(--muted); font-size: 13px; }
.check input { width: auto; margin: 0; }
.version { text-align: center; }

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  background: rgba(15, 20, 28, 0.96);
  border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + var(--safe-bottom));
  z-index: 8;
}
.tabbar[hidden] { display: none !important; }
.tab {
  flex: 1;
  background: none;
  border: 0;
  color: var(--muted);
  padding: 8px 4px;
  font-size: 11px;
}
.tab .tab-ico { display: block; font-size: 18px; margin-bottom: 2px; }
.tab.active { color: var(--accent); }

@media (min-width: 720px) {
  .device-grid { grid-template-columns: 1fr 1fr; }
  #screen-app { max-width: 860px; margin: 0 auto; }
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  margin: 8px 0 10px;
  color: var(--text);
}
.toggle-row strong { display: block; font-size: 14px; }
.toggle-row small { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; font-weight: 400; }
.toggle-row input[type="checkbox"] {
  width: 22px; height: 22px; margin: 0; accent-color: var(--accent);
  flex: 0 0 auto;
  align-self: center;
}

/* Hide official-player HUD; HomeCam already has HD / fullscreen / sound. */
.player-shell .ezuikit-box .ezplayer-footer,
.player-shell .ezuikit-box .ezplayer-header,
.player-shell .ezuikit-box .ezplayer-controls,
.player-shell .ezuikit-box [class*="ezplayer-footer"],
.player-shell .ezuikit-box [class*="ezplayer-header"],
.player-shell .ezuikit-box [class*="ezplayer-toolbar"],
.player-shell .ezuikit-box [class*="ezplayer-mobile-control"],
.player-shell .ezuikit-box [class*="ezplayer-control-bar"] {
  display: none !important;
}
