/* Remote Surveillance — modern light UI */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f5f7fa; --surface: #ffffff; --surface2: #f8fafc;
  --border: #e5e9f0; --border2: #d8dee9;
  --text: #101828; --muted: #667085;
  --primary: #2563eb; --primary-h: #1d4ed8; --primary-t: #eff4ff;
  --green: #16a34a; --green-t: #ecfdf3; --red: #dc2626; --red-t: #fef3f2;
  --amber: #d97706; --amber-t: #fffaeb;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 10px 30px -8px rgba(16,24,40,.12);
  --radius: 14px;
}
html { font-size: 14px; }
body {
  background: var(--bg); color: var(--text);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-weight: 400; }
.error { color: var(--red); margin-top: 10px; font-size: 13px; }

/* ---------- auth pages ---------- */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(37,99,235,.10), transparent 60%),
    radial-gradient(800px 500px at 110% 110%, rgba(37,99,235,.08), transparent 60%),
    var(--bg);
  padding: 20px;
}
.auth-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  box-shadow: var(--shadow); padding: 38px; width: 400px;
  display: flex; flex-direction: column; gap: 8px; text-align: center;
}
.auth-logo { font-size: 40px; }
.auth-card h1 { font-size: 21px; margin: 6px 0 2px; letter-spacing: -.02em; }
.auth-card p { margin-bottom: 14px; }
.auth-card input { margin-top: 8px; text-align: left; }

/* ---------- inputs & buttons ---------- */
input, select {
  background: var(--surface); border: 1px solid var(--border2); color: var(--text);
  border-radius: 10px; padding: 10px 13px; font-size: 14px; width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
input[readonly] { background: var(--surface2); font-family: Consolas, monospace; font-size: 12.5px; }

.btn {
  background: var(--surface); color: var(--text); border: 1px solid var(--border2);
  border-radius: 10px; padding: 9px 15px; cursor: pointer; font-size: 13.5px;
  font-weight: 500; transition: all .15s; white-space: nowrap;
}
.btn:hover { background: var(--surface2); border-color: #c3cbd9; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--primary-h); }
.btn.danger { background: transparent; border-color: #f4b3b0; color: var(--red); }
.btn.danger:hover { background: var(--red-t); border-color: var(--red); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface2); color: var(--text); }
.btn.block { width: 100%; margin-top: 14px; padding: 11px; }
.btn.rec-active { background: var(--red-t); border-color: var(--red); color: var(--red); font-weight: 700; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- app layout ---------- */
#app-view { display: flex; min-height: 100vh; }
.sidebar {
  width: 250px; flex: none; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 20px 14px; position: sticky; top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 15.5px;
  letter-spacing: -.01em; padding: 4px 10px 18px; }
.brand-icon { font-size: 20px; }
.nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px;
  cursor: pointer; color: var(--muted); font-weight: 500; border: none; background: none;
  font-size: 14px; text-align: left; width: 100%; transition: all .12s;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--primary-t); color: var(--primary); font-weight: 600; }
.nav-ico { font-size: 16px; width: 22px; text-align: center; }
.sidebar-foot { border-top: 1px solid var(--border); padding-top: 14px; }
.userchip { display: flex; align-items: center; gap: 10px; padding: 0 8px 10px; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
}
.username { font-weight: 600; font-size: 13.5px; }
.userrole { color: var(--muted); font-size: 11.5px; }

.main { flex: 1; padding: 28px 34px; max-width: 1500px; }
.view { animation: fadein .18s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

.page-head { display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 22px; gap: 14px; flex-wrap: wrap; }
.page-head h2 { font-size: 21px; letter-spacing: -.02em; }
.page-actions { display: flex; gap: 10px; }
.back-link { color: var(--primary); font-size: 13px; font-weight: 600; margin-bottom: 4px; cursor: pointer; }

/* ---------- stats ---------- */
.stats-row { display: flex; gap: 14px; margin-bottom: 22px; flex-wrap: wrap; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 20px; display: flex; align-items: center; gap: 14px; min-width: 165px;
  box-shadow: 0 1px 2px rgba(16,24,40,.04); }
.stat-ico { width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center;
  justify-content: center; font-size: 18px; }
.stat-ico.blue { background: var(--primary-t); } .stat-ico.green { background: var(--green-t); }
.stat-ico.red { background: var(--red-t); } .stat-ico.amber { background: var(--amber-t); }
.stat span { font-size: 22px; font-weight: 700; letter-spacing: -.02em; display: block; }
.stat label { color: var(--muted); font-size: 12px; font-weight: 500; }

/* ---------- system cards ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 18px; }
.empty { color: var(--muted); padding: 70px 30px; text-align: center; grid-column: 1/-1;
  background: var(--surface); border: 1px dashed var(--border2); border-radius: var(--radius); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; display: flex; flex-direction: column; transition: all .15s; }
.card:hover { box-shadow: var(--shadow); border-color: #c9d2e1; transform: translateY(-1px); }
.thumb { position: relative; aspect-ratio: 16/9; background: #0e1116; cursor: pointer; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.noimg { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  color: #5b6572; font-size: 13px; background: var(--surface2); }
.badge { position: absolute; top: 10px; left: 10px; font-size: 10.5px; font-weight: 700;
  padding: 4px 10px; border-radius: 20px; text-transform: uppercase; letter-spacing: .6px;
  backdrop-filter: blur(4px); }
.badge.on { background: rgba(22,163,74,.85); color: #fff; }
.badge.off { background: rgba(102,112,133,.75); color: #fff; }
.badge.rec { position: absolute; top: 10px; right: 10px; left: auto;
  background: rgba(220,38,38,.9); color: #fff; animation: blink 1.5s infinite; }
@keyframes blink { 50% { opacity: .55; } }
.watch-btn { position: absolute; bottom: 10px; right: 10px; background: rgba(37,99,235,.92);
  color: #fff; border: none; border-radius: 8px; padding: 7px 14px; font-size: 12.5px;
  font-weight: 600; cursor: pointer; transition: background .15s; }
.watch-btn:hover { background: var(--primary-h); }
.meta { padding: 14px 16px 8px; }
.row1 { display: flex; gap: 12px; align-items: center; }
.card .avatar { width: 40px; height: 40px; font-size: 14px; }
.name { font-weight: 600; font-size: 14.5px; }
.sub { color: var(--muted); font-size: 12.5px; margin-top: 1px; }
.lines { margin-top: 10px; color: var(--muted); font-size: 12.5px; display: flex;
  flex-direction: column; gap: 3px; }
.actions { display: flex; gap: 8px; padding: 12px 16px 16px; }
.actions .btn { flex: 1; padding: 7px 0; font-size: 12.5px; }

/* ---------- live wall (CCTV-style dashboard) ---------- */
.seg { display: inline-flex; border: 1px solid var(--border2); border-radius: 10px;
  overflow: hidden; background: var(--surface); }
.seg-btn { border: none; background: none; padding: 8px 14px; font: inherit; font-size: 13px;
  color: var(--muted); cursor: pointer; }
.seg-btn + .seg-btn { border-left: 1px solid var(--border2); }
.seg-btn.active { background: var(--primary-t); color: var(--primary); font-weight: 600; }
.badge.live { background: rgba(22,163,74,.9); color: #fff; }
.wall-label { display: none; }
.grid.wall { grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr)); gap: 4px;
  background: #0b0d10; padding: 4px; border-radius: var(--radius); }
.grid.wall .card { border: none; border-radius: 0; background: #0e1116; }
.grid.wall .card:hover { transform: none; box-shadow: none;
  outline: 2px solid var(--red); outline-offset: -2px; z-index: 1; }
.grid.wall .meta, .grid.wall .actions, .grid.wall .watch-btn { display: none; }
.grid.wall .noimg { background: #0e1116; }
.grid.wall .wall-label { display: block; position: absolute; left: 0; right: 0; bottom: 0;
  padding: 22px 12px 8px; background: linear-gradient(transparent, rgba(0,0,0,.75));
  color: #fff; font-size: 13px; pointer-events: none; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.wall-label b { font-weight: 600; }
.wall-label span { opacity: .7; margin-left: 8px; font-size: 12px; }
/* fullscreen wall: tiles share the whole screen */
.grid.wall:fullscreen { width: 100vw; height: 100vh; border-radius: 0; grid-auto-rows: 1fr; }
.grid.wall.expanded { position: fixed; inset: 0; z-index: 40; border-radius: 0; grid-auto-rows: 1fr; }
.grid.wall:fullscreen .card, .grid.wall.expanded .card { min-height: 0; }
.grid.wall:fullscreen .thumb, .grid.wall.expanded .thumb { aspect-ratio: auto; flex: 1; min-height: 0; }

/* ---------- panels / tables ---------- */
.panel-list { background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; box-shadow: 0 1px 2px rgba(16,24,40,.04); }
.panel-row { display: flex; align-items: center; gap: 14px; padding: 15px 20px;
  border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.panel-row:last-child { border-bottom: none; }
.panel-row:hover { background: var(--surface2); }
.row-title { font-weight: 600; font-size: 14.5px; }
.row-sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.row-main { flex: 1; min-width: 220px; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { font-size: 11px; font-weight: 700; padding: 3px 10px; border-radius: 20px; }
.chip.green { background: var(--green-t); color: var(--green); }
.chip.red { background: var(--red-t); color: var(--red); }
.chip.blue { background: var(--primary-t); color: var(--primary); }
.chip.gray { background: var(--surface2); color: var(--muted); border: 1px solid var(--border); }
.panel-empty { padding: 60px; text-align: center; color: var(--muted); }
.mono { font-family: Consolas, monospace; font-size: 12px; }

/* ---------- modals ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(16,24,40,.45); z-index: 20;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  backdrop-filter: blur(2px); }
.modal-back.dark { background: rgba(16,24,40,.72); }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  padding: 26px; width: 500px; max-height: 92vh; overflow-y: auto; box-shadow: var(--shadow); }
.modal.small { width: 400px; }
.modal.wide { width: min(1500px, 96vw); }
.modal h2 { margin-bottom: 14px; font-size: 18px; letter-spacing: -.01em; }
.form-grid { display: flex; flex-direction: column; gap: 6px; }
.form-grid label { color: var(--muted); font-size: 12px; font-weight: 600; margin-top: 10px; }
.cfg-2, .cfg-3 { display: grid; gap: 10px; }
.cfg-2 { grid-template-columns: 1fr 1fr; }
.cfg-3 { grid-template-columns: 1fr 1fr 1fr; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.copy-row { display: flex; gap: 8px; margin-top: 4px; }
.slug-preview { font-size: 12px; margin-top: 3px; min-height: 15px; font-family: Consolas, monospace; }

/* ---------- live view ---------- */
.live-head { display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 14px; gap: 12px; flex-wrap: wrap; }
#live-modal .modal { max-height: calc(100dvh - 24px); }
#live-modal .live-head { position: sticky; top: -26px; z-index: 2;
  background: var(--surface); padding-top: 12px; padding-bottom: 10px; }
.live-sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.dot-label { font-weight: 700; }
.dot-label.on { color: var(--green); }
.dot-label.off { color: var(--red); }
.live-actions { display: flex; gap: 8px; }
.live-stage { position: relative; background: #0e1116; border-radius: 12px; overflow: hidden;
  height: min(70dvh, calc((100vw - 48px) * 9 / 16)); min-height: 280px;
  display: flex; align-items: center; justify-content: center; }
.live-stage img { width: 100%; height: 100%; object-fit: contain; }
.live-stage:fullscreen { aspect-ratio: auto; border-radius: 0; }
/* fullscreen the whole live view: image fills the screen, controls stay visible */
.modal:fullscreen { width: 100vw; height: 100vh; max-height: 100vh; border-radius: 0;
  overflow: hidden; display: flex; flex-direction: column; }
.modal:fullscreen .live-head { flex: none; }
.modal:fullscreen .live-stage { flex: 1; min-height: 0; aspect-ratio: auto; }
.modal:fullscreen .history-head, .modal:fullscreen .history-strip,
.modal:fullscreen .rec-list, .modal:fullscreen .rec-video,
.modal:fullscreen .live-history { display: none; }
.modal:-webkit-full-screen { width: 100vw; height: 100vh; max-height: 100vh; border-radius: 0;
  overflow: hidden; display: flex; flex-direction: column; }
.modal:-webkit-full-screen .live-head { flex: none; }
.modal:-webkit-full-screen .live-stage { flex: 1; min-height: 0; aspect-ratio: auto; }
.modal:-webkit-full-screen .history-head, .modal:-webkit-full-screen .history-strip,
.modal:-webkit-full-screen .rec-list, .modal:-webkit-full-screen .rec-video,
.modal:-webkit-full-screen .live-history { display: none; }
/* In-app iOS browsers often disallow the Fullscreen API for non-video elements. */
#live-modal.expanded { padding: 0; }
#live-modal.expanded .modal { width: 100vw; height: 100dvh; max-height: 100dvh;
  border-radius: 0; overflow: hidden; display: flex; flex-direction: column; }
#live-modal.expanded .live-head { flex: none; }
#live-modal.expanded .live-stage { flex: 1; min-height: 0; height: auto; }
#live-modal.expanded .live-history { display: none; }
.live-history { margin-top: 12px; border-top: 1px solid var(--border); }
.live-history summary { cursor: pointer; font-size: 13px; font-weight: 700;
  padding: 12px 0; color: var(--primary); }
.live-placeholder { position: absolute; color: #8b95a5; font-size: 14px; }
.history-head { margin: 18px 0 8px; font-weight: 700; font-size: 13.5px; }
.history-strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; }
.history-strip img { height: 70px; border-radius: 8px; border: 1px solid var(--border);
  cursor: pointer; flex: none; transition: border-color .12s; }
.history-strip img:hover { border-color: var(--primary); }
.history-strip .hnone { color: var(--muted); font-size: 12.5px; padding: 8px; }
.playback-modal { max-height: calc(100dvh - 24px); }
#playback-date { max-width: 220px; display: block; margin: 8px 0 12px; }
#playback-status { margin: 10px 0; min-height: 20px; }
.playback-video { display: block; width: 100%; max-height: 65dvh; margin-top: 12px;
  border-radius: 12px; background: #000; border: 1px solid var(--border); }

.sub-banner { background: var(--amber-t); border: 1px solid #f5dcc0; color: #92400e;
  border-radius: 12px; padding: 12px 18px; margin-bottom: 18px; font-size: 13.5px; font-weight: 600; }
.sub-banner.expired { background: var(--red-t); border-color: #f4b3b0; color: var(--red); }
.chip.amber { background: var(--amber-t); color: var(--amber); }

/* ---------- toast ---------- */
.toast { position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: #101828; color: #fff; padding: 11px 20px; border-radius: 10px; z-index: 50;
  font-size: 13.5px; box-shadow: var(--shadow); animation: fadein .2s ease; }
.toast.err { background: var(--red); }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  #app-view { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row;
    align-items: center; gap: 10px; padding: 10px 14px; flex-wrap: wrap; }
  .brand { padding: 0 6px 0 0; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-foot { border-top: none; padding-top: 0; margin-left: auto;
    display: flex; align-items: center; gap: 10px; }
  .userchip { padding: 0; }
  .main { padding: 18px; }
  .cfg-3, .cfg-2 { grid-template-columns: 1fr; }
  .page-actions { flex-wrap: wrap; }
}
@media (max-width: 600px) {
  .grid.wall:not(:fullscreen):not(.expanded) { grid-template-columns: 1fr; }
}
