:root {
  --ap: #003b75;
  --ap2: #005ea8;
  --bg: #f1f5f9;
  --gold: #d8b14a;
  --ink: #0f172a;
  --muted: #64748b;
  --brand: #2566da;
  --accent: #ef4444;
  --success: #10a33a;
  --warning: #e08300;
  --card: #fff;
  --line: #cbd5e1;
  --shadow: 0 4px 20px rgba(15, 23, 42, .06);
  --sidebar-width: 260px;
}

* { box-sizing: border-box; }
html { min-width: 320px; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
}
a { color: var(--brand); }
button, input, select, textarea { font: inherit; }

.top {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(300px, 2fr) minmax(220px, 1fr);
  align-items: center;
  gap: 16px;
  padding: 12px 24px;
  color: #fff;
  background: linear-gradient(90deg, var(--ap), var(--ap2));
  box-shadow: 0 2px 10px rgba(0, 0, 0, .1);
}
.logos { display: flex; align-items: center; gap: 14px; }
.logos.left { justify-content: flex-start; }
.logos.right { justify-content: flex-end; }
.logo, .logo-card img {
  width: 56px;
  height: 56px;
  padding: 4px;
  object-fit: contain;
  border-radius: 50%;
  background: #fff;
}
.logo-card { min-width: 82px; text-align: center; }
.logo-title, .logo-subtitle { display: block; margin-top: 3px; color: #d9e8ff; font-size: 8px; line-height: 1.2; }
.logo-title { color: #fff; font-weight: 700; }
.title { text-align: center; }
.title h1 { margin: 0; font: 700 clamp(18px, 2vw, 24px) Merriweather, Georgia, serif; letter-spacing: .5px; }
.title h2 { margin: 4px 0 2px; color: #e2e8f0; font-size: clamp(14px, 1.4vw, 16px); font-weight: 500; }
.title p { margin: 0; color: #ffd875; font-size: 12px; font-weight: 600; letter-spacing: 1px; text-transform: uppercase; }

.info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 48px;
  padding: 9px 24px;
  border-bottom: 3px solid var(--gold);
  background: #fff;
  box-shadow: var(--shadow);
}
.info-left { display: flex; align-items: center; gap: 16px; min-width: 0; }
.info strong { overflow: hidden; color: var(--ap); font-size: 15px; letter-spacing: .5px; text-overflow: ellipsis; text-transform: uppercase; white-space: nowrap; }
.timestamp { color: var(--muted); font-size: 13px; white-space: nowrap; }
.sidebar-toggle { display: flex; flex-direction: column; justify-content: space-between; width: 24px; height: 18px; padding: 0; border: 0; background: none; cursor: pointer; }
.sidebar-toggle span { width: 100%; height: 3px; border-radius: 2px; background: var(--ap); }

.wrap { display: grid; flex: 1; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); min-height: 0; transition: grid-template-columns .25s ease; }
.side { z-index: 90; display: flex; flex-direction: column; gap: 6px; padding: 24px 16px 80px; overflow: hidden auto; border-right: 1px solid #1e293b; background: #0f172a; }
.side a, .logout-link {
  display: flex;
  align-items: center;
  width: 100%;
  gap: 12px;
  padding: 12px 16px;
  border: 0;
  border-radius: 8px;
  color: #94a3b8;
  background: transparent;
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}
.side a:hover, .logout-link:hover { color: #fff; background: #1e293b; }
.side a.active { color: #fff; background: var(--brand); font-weight: 600; box-shadow: 0 4px 12px rgba(37, 102, 218, .2); }
.nav-section { margin: 14px 12px 2px; color: #64748b; font-size: 10px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.logout-form { margin: 0; }
.wrap.sidebar-collapsed { grid-template-columns: 0 minmax(0, 1fr); }
.wrap.sidebar-collapsed .side { padding-right: 0; padding-left: 0; opacity: 0; pointer-events: none; }

.page { width: 100%; max-width: 1600px; margin: 0 auto; padding: 30px 30px 92px; overflow: hidden; }
.page-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 22px; }
.page-heading h2 { margin: 0; color: var(--ap); font-size: clamp(21px, 3vw, 28px); }
.page-heading p { margin: 6px 0 0; color: var(--muted); }
.page-actions { display: flex; flex-wrap: wrap; gap: 10px; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(175px, 1fr)); gap: 16px; margin: 20px 0 28px; }
.stat-card, .card { border: 1px solid #e2e8f0; border-radius: 16px; background: var(--card); box-shadow: var(--shadow); }
.stat-card { min-width: 0; padding: 22px 18px; text-align: center; transition: transform .2s ease, box-shadow .2s ease; }
.stat-card:hover { transform: translateY(-3px); box-shadow: 0 12px 24px rgba(37, 102, 218, .08); }
.stat-circle { width: 50px; height: 50px; margin: 0 auto 12px; border-radius: 50%; background: #e8f0ff; }
.stat-card:nth-child(2n) .stat-circle { background: #e9f8ec; }
.stat-card:nth-child(3n) .stat-circle { background: #fff4de; }
.stat-card h3 { margin: 0 0 4px; color: var(--brand); font-size: 29px; }
.stat-card p { margin: 0; color: #627089; font-size: 14px; font-weight: 500; }
.card { padding: 22px; }
.card + .card { margin-top: 20px; }
.card h3 { margin-top: 0; color: var(--ap); }

.filter-card { margin-bottom: 20px; padding: 18px; }
.filter-grid, .form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.form-row { display: grid; gap: 7px; min-width: 0; }
.form-row label { color: #334155; font-size: 13px; font-weight: 700; }
.form-control, input[type="text"], input[type="password"], input[type="email"], input[type="date"], input[type="number"], select, textarea {
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--ink);
  background: #fff;
}
select[multiple] { min-height: 120px; }
textarea { resize: vertical; }
.helptext { color: var(--muted); font-size: 12px; }
.errorlist { margin: 4px 0 0; padding-left: 18px; color: #b91c1c; font-size: 13px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 40px; padding: 9px 16px; border: 1px solid transparent; border-radius: 999px; font-size: 14px; font-weight: 600; line-height: 1; text-decoration: none; cursor: pointer; }
.btn-primary { color: #fff; background: linear-gradient(120deg, var(--brand), #0ea5e9); box-shadow: 0 8px 18px rgba(14, 165, 233, .2); }
.btn-secondary { color: #155e75; border-color: rgba(21, 94, 117, .35); background: rgba(21, 94, 117, .07); }
.btn-danger { color: #b91c1c; border-color: #fecaca; background: #fff1f2; }
.btn-small { min-height: 32px; padding: 6px 11px; font-size: 12px; }

.table-wrap { width: 100%; overflow-x: auto; border: 1px solid #e2e8f0; border-radius: 12px; background: #fff; box-shadow: var(--shadow); }
table { width: 100%; min-width: 760px; border-collapse: collapse; }
th, td { padding: 12px 14px; border-bottom: 1px solid #edf2f7; text-align: left; vertical-align: top; }
th { color: var(--ap); background: #f8fafc; font-size: 12px; letter-spacing: .04em; text-transform: uppercase; }
td { color: #334155; font-size: 14px; }
tr:last-child td { border-bottom: 0; }
.table-actions { display: flex; gap: 7px; white-space: nowrap; }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 4px 9px; border-radius: 20px; color: #475569; background: #f1f5f9; font-size: 11px; font-weight: 700; }
.badge-live, .badge-active { color: #166534; background: #dcfce7; }
.badge-inactive { color: #991b1b; background: #fee2e2; }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: #ef4444; animation: pulse-live 1.5s infinite; }

.stream-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 22px; }
.video-card { overflow: hidden; border: 1px solid #e2e8f0; border-radius: 14px; background: #fff; box-shadow: var(--shadow); }
.video-card-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 13px 16px; }
.video-card-header h4 { margin: 0; color: #1e293b; }
.video-container { position: relative; width: 100%; padding-top: 56.25%; overflow: hidden; background: #111827; }
.drone-stream { position: absolute; inset: 0; display: none; width: 100%; height: 100%; object-fit: contain; background: #000; }
.stream-fallback { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #9ca3af; }
.stream-fallback strong { margin-top: 8px; color: #ef4444; font-size: 12px; letter-spacing: .08em; }
.empty-state { padding: 50px 20px; border: 2px dashed #cbd5e1; border-radius: 12px; color: var(--muted); background: #fff; text-align: center; }

.messages { display: grid; gap: 8px; margin-bottom: 16px; }
.message { padding: 11px 14px; border: 1px solid #bfdbfe; border-radius: 9px; color: #1e3a8a; background: #eff6ff; }
.message.success { color: #166534; border-color: #bbf7d0; background: #f0fdf4; }
.message.error { color: #991b1b; border-color: #fecaca; background: #fff1f2; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.detail-item { min-width: 0; padding: 12px 14px; border: 1px solid #edf2f7; border-radius: 9px; background: #f8fafc; }
.detail-item small { display: block; margin-bottom: 5px; color: var(--muted); font-weight: 700; text-transform: uppercase; }
.detail-item div { overflow-wrap: anywhere; }
.pagination { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 8px; margin-top: 18px; }

footer { position: fixed; z-index: 999; right: 0; bottom: 0; left: 0; padding: 12px 20px; color: rgba(255, 255, 255, .85); background: #02294f; box-shadow: 0 -2px 10px rgba(0, 0, 0, .15); font-size: 13px; text-align: center; }

.login-page { width: min(920px, 100%); margin: 0 auto; padding: 42px 20px 90px; }
.login-intro { margin-bottom: 18px; text-align: center; }
.login-card { max-width: 600px; margin: 0 auto; padding: 28px; border: 1px solid rgba(148, 163, 184, .18); border-radius: 20px; background: #fff; box-shadow: 0 20px 60px rgba(15, 23, 42, .12); }
.dialog-backdrop { position: fixed; z-index: 2000; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(15, 23, 42, .45); }
.dialog { width: min(360px, 100%); padding: 24px; border-radius: 20px; background: #fff; box-shadow: 0 20px 60px rgba(15, 23, 42, .2); text-align: center; }
.dialog-icon { display: grid; place-items: center; width: 54px; height: 54px; margin: 0 auto 12px; border-radius: 50%; color: #dc2626; background: rgba(220, 38, 38, .12); font-size: 26px; font-weight: 700; }

@keyframes pulse-live { 50% { transform: scale(1.35); opacity: .4; } }

@media (max-width: 1100px) {
  .top { grid-template-columns: 1fr 1.5fr 1fr; padding: 12px 16px; }
  .logo, .logo-card img { width: 48px; height: 48px; }
  .logo-card { min-width: 65px; }
}

@media (max-width: 900px) {
  .top { grid-template-columns: 1fr; gap: 14px; padding: 16px; text-align: center; }
  .logos { justify-content: center !important; flex-wrap: wrap; }
  .logo-card { display: none; }
  .info { padding: 9px 14px; }
  .timestamp { display: none; }
  .wrap { grid-template-columns: 0 minmax(0, 1fr); }
  .side { position: fixed; top: 0; bottom: 44px; left: calc(-1 * var(--sidebar-width)); width: var(--sidebar-width); padding-top: 20px; opacity: 1; transition: left .25s ease; }
  .wrap:not(.sidebar-collapsed) .side { left: 0; box-shadow: 8px 0 30px rgba(15, 23, 42, .25); }
  .wrap.sidebar-collapsed .side { padding-right: 16px; padding-left: 16px; opacity: 1; }
  .page { padding: 22px 16px 82px; }
  .page-heading { align-items: stretch; flex-direction: column; }
  .stream-grid { grid-template-columns: 1fr; }
  footer { padding: 9px 12px; font-size: 11px; }
}

@media (max-width: 560px) {
  .logo { width: 44px; height: 44px; }
  .title p { font-size: 10px; }
  .info strong { font-size: 12px; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat-card { padding: 16px 8px; }
  .stat-card h3 { font-size: 24px; }
  .card, .login-card { padding: 18px; }
  .filter-grid, .form-grid { grid-template-columns: 1fr; }
  .btn { width: 100%; }
  .table-actions .btn { width: auto; }
}
