:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --text: #18202b;
  --muted: #5f6d80;
  --primary: #006b5e;
  --accent: #f2b705;
  --danger: #ad1d23;
  --border: #d8dee8;
}

body.theme-dark {
  --bg: #0f1720;
  --surface: #131d28;
  --text: #e6edf6;
  --muted: #9eb0c6;
  --primary: #18a28f;
  --accent: #f2b705;
  --danger: #ff7378;
  --border: #2a3849;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  background: radial-gradient(circle at 10% 20%, #e8f6f3 0, var(--bg) 45%);
  color: var(--text);
}

body.theme-dark {
  background: radial-gradient(circle at 10% 20%, #1a2938 0, var(--bg) 50%);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1 {
  margin: 0;
  font-size: 1.3rem;
}

.topbar p {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.brand-logo {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  flex-wrap: wrap;
}

.layout {
  max-width: 1200px;
  margin: 1rem auto;
  padding: 0 1rem 2rem;
}

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

.hidden {
  display: none !important;
}

.form-grid {
  display: grid;
  gap: 0.7rem;
}

input,
select,
button {
  font: inherit;
}

.password-wrap {
  position: relative;
}

.password-wrap input {
  padding-right: 6.5rem;
}

.toggle-password {
  position: absolute;
  right: 0.35rem;
  top: 50%;
  transform: translateY(-50%);
  border: 1px solid var(--border);
  background: #fff;
  color: var(--primary);
  border-radius: 8px;
  width: 2.3rem;
  height: 2rem;
  padding: 0;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.toggle-password::before {
  content: "👁";
  font-size: 1rem;
  line-height: 1;
}

.toggle-password.is-visible::before {
  content: "🙈";
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

input,
select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.65rem;
}

.btn {
  border: 0;
  border-radius: 10px;
  padding: 0.6rem 0.9rem;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
}

.btn-outline {
  border: 1px solid var(--primary);
  background: var(--surface);
  color: var(--primary);
}

.badge {
  background: #e2f4f1;
  color: #084d44;
  border-radius: 999px;
  padding: 0.3rem 0.7rem;
  font-size: 0.83rem;
}

.tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.8rem;
}

.tab {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  padding: 0.4rem 0.75rem;
}

.tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr 160px 120px;
  gap: 0.6rem;
  margin-bottom: 0.7rem;
}

.video-list {
  display: grid;
  gap: 0.6rem;
}

.video-row,
.video-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.6rem;
}

.video-row {
  display: grid;
  grid-template-columns: 140px 1fr auto;
  gap: 0.7rem;
  align-items: center;
}

.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0.8rem;
}

.video-thumb {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #dce3ed;
  aspect-ratio: 16 / 9;
  object-fit: cover;
}

.video-meta p {
  margin: 0.15rem 0;
  color: var(--muted);
}

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

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.8rem;
}

#liveVideo,
#modalVideo {
  width: 100%;
  max-height: 70vh;
  border-radius: 10px;
  background: #000;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 20, 0.7);
  display: grid;
  place-items: center;
  padding: 1rem;
}

.modal-content {
  width: min(1000px, 100%);
  background: var(--surface);
  border-radius: 14px;
  padding: 1rem;
}

.error {
  color: var(--danger);
}

#usersTable {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
}

#usersTable th,
#usersTable td {
  border: 1px solid var(--border);
  padding: 0.45rem;
  text-align: left;
}

#auditLog {
  max-height: 260px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem;
  background: #f8fafc;
}

.ptz-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  gap: 0.6rem;
}

@media (max-width: 880px) {
  .toolbar {
    grid-template-columns: 1fr;
  }

  .video-row {
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.8rem;
  }

  .top-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .tabs {
    overflow-x: auto;
    padding-bottom: 0.2rem;
    -webkit-overflow-scrolling: touch;
  }

  .tab {
    white-space: nowrap;
    min-height: 2.4rem;
  }

  .card {
    padding: 0.8rem;
    border-radius: 12px;
  }

  .btn,
  .btn-outline,
  input,
  select {
    min-height: 2.6rem;
  }

  .actions {
    width: 100%;
  }

  .actions .btn,
  .actions a.btn {
    flex: 1 1 auto;
    text-align: center;
  }

  #usersTable {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
}

@media (max-width: 560px) {
  .layout {
    margin: 0.7rem auto;
    padding: 0 0.55rem 1.2rem;
  }

  .topbar {
    padding: 0.8rem;
  }

  .topbar h1 {
    font-size: 1.1rem;
  }

  .brand-logo {
    width: 50px;
    height: 50px;
  }

  .topbar p {
    font-size: 0.78rem;
  }

  .pagination {
    gap: 0.35rem;
  }

  .modal-content {
    padding: 0.7rem;
  }
}
