:root {
  --sidebar-bg: #0f172a;
  --sidebar-width: 230px;
  --accent: #0d9488;
  --accent-soft: #ccfbf1;
  --content-bg: #f1f5f9;
  --card-border: #e2e8f0;
  --text-muted: #64748b;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
  background: var(--content-bg);
}

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  z-index: 100;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px;
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
  border-bottom: 1px solid #1e293b;
}
.sidebar-brand i { color: #2dd4bf; font-size: 1.3rem; }

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 10px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 11px 14px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: #94a3b8;
  font-size: 0.95rem;
  text-align: left;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.nav-item i { font-size: 1.1rem; width: 20px; text-align: center; }
.nav-item:hover { background: #1e293b; color: #e2e8f0; }
.nav-item.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 12px rgba(13, 148, 136, .35);
}

.sidebar-footer { padding: 12px 10px; border-top: 1px solid #1e293b; }

/* ---------- Main / Topbar ---------- */
.main {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 18px 22px 26px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.topbar-title h1 { font-size: 1.35rem; margin: 0 0 8px; font-weight: 700; color: #0f172a; }
.device-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.device-chip {
  background: #e2e8f0;
  color: #334155;
  font-size: .78rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
}
.device-chip.sel { background: var(--accent); color: #fff; }

.topbar-actions { display: flex; align-items: center; gap: 10px; }
.status-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #94a3b8;
  display: inline-block;
}
.status-dot.online { background: #22c55e; box-shadow: 0 0 0 4px rgba(34,197,94,.15); }
.status-dot.error { background: #ef4444; box-shadow: 0 0 0 4px rgba(239,68,68,.15); }
.status-text { font-size: .82rem; color: var(--text-muted); }

#banner { margin-bottom: 14px; }

/* ---------- Panels ---------- */
.panel { display: none; }
.panel.active { display: block; animation: fadeIn .18s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.panel-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.search-group { max-width: 420px; }
.count-badge {
  background: #e0f2fe;
  color: #0369a1;
  font-size: .8rem;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 999px;
}

/* Tables */
.table-wrap {
  background: #fff;
  border: 1px solid var(--card-border);
  border-radius: 14px;
  overflow: auto;
  max-height: calc(100vh - 190px);
}
.table { margin: 0; }
.table thead th {
  position: sticky;
  top: 0;
  background: #f8fafc;
  color: #475569;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--card-border);
  z-index: 1;
}
.table td { font-size: .9rem; color: #334155; }
.row-hidden { display: none; }

.type-badge {
  display: inline-block;
  font-size: .72rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
}
.type-incoming { background: #dcfce7; color: #15803d; }
.type-outgoing { background: #dbeafe; color: #1d4ed8; }
.type-missed  { background: #fee2e2; color: #b91c1c; }
.type-rejected{ background: #fef3c7; color: #b45309; }
.tb-unknown   { background: #e2e8f0; color: #475569; }

/* ---------- Map ---------- */
#map {
  width: 100%;
  height: calc(100vh - 185px);
  border-radius: 14px;
  border: 1px solid var(--card-border);
  z-index: 1;
}
.legend { display: flex; flex-wrap: wrap; gap: 10px; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: .82rem; color: #334155; }
.legend-dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }

/* ---------- Social (chat) ---------- */
.chat-list { max-height: calc(100vh - 190px); overflow-y: auto; padding-right: 4px; }

.chat-card {
  display: flex;
  gap: 12px;
  background: #fff;
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 10px;
}
.chat-app {
  flex: 0 0 46px;
  height: 46px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: #fff;
  font-size: .95rem;
}
.chat-body { min-width: 0; flex: 1; }
.chat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.chat-appname { font-size: .85rem; font-weight: 700; color: #0f172a; }
.chat-sender { font-size: .84rem; font-weight: 600; color: var(--accent); }
.chat-time { font-size: .75rem; color: var(--text-muted); margin-left: auto; }
.chat-msg {
  font-size: .92rem;
  color: #334155;
  background: #f8fafc;
  border-radius: 10px;
  padding: 8px 12px;
  white-space: pre-wrap;
  word-break: break-word;
}
.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 10px;
  background: #fff;
  border: 1px dashed #cbd5e1;
  border-radius: 14px;
}
.empty-state i { font-size: 2rem; display: block; margin-bottom: 8px; opacity: .5; }

/* ---------- Media ---------- */
.media-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.media-col { min-width: 0; }
.media-heading {
  font-size: .95rem;
  color: #334155;
  font-weight: 700;
  margin: 0 0 10px;
}
.media-heading i { color: var(--accent); }

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}
.photo-tile {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: 12px;
  overflow: hidden;
  background: #e2e8f0;
  cursor: zoom-in;
  border: 1px solid var(--card-border);
}
.photo-tile img { width: 100%; height: 100%; object-fit: cover; transition: transform .2s; }
.photo-tile video { width: 100%; height: 100%; object-fit: cover; background: #0f172a; }
.photo-tile:hover img { transform: scale(1.06); }
.photo-meta {
  position: absolute;
  inset: auto 0 0 0;
  background: linear-gradient(transparent, rgba(15,23,42,.75));
  color: #fff;
  font-size: .72rem;
  padding: 14px 8px 6px;
}

.audio-list { display: flex; flex-direction: column; gap: 10px; }
.audio-card {
  background: #fff;
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 10px 12px;
}
.audio-head {
  display: flex;
  justify-content: space-between;
  font-size: .78rem;
  color: #475569;
  margin-bottom: 6px;
}
.audio-card audio { width: 100%; height: 36px; }

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, .92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1050;
  padding: 30px;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 10px; }
.lightbox-close {
  position: absolute;
  top: 16px;
  right: 20px;
  background: none;
  border: none;
  color: #fff;
  font-size: 1.6rem;
  cursor: pointer;
}

/* ---------- Device status chips ---------- */
.device-chip.online { background: var(--accent-soft); color: #0f766e; }
.device-chip.offline { background: #e2e8f0; color: #94a3b8; }

/* ---------- Login ---------- */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(160deg, #0f172a 0%, #134e4a 100%);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: #fff;
  border-radius: 16px;
  padding: 28px 26px;
  box-shadow: 0 20px 50px rgba(2, 6, 23, .45);
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.15rem;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 6px;
}
.login-brand i { color: var(--accent); font-size: 1.4rem; }
.login-title { font-size: 1.1rem; font-weight: 600; color: #334155; margin: 0 0 18px; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .sidebar { width: 64px; }
  .brand-text, .nav-label { display: none; }
  .main { margin-left: 64px; padding: 14px 12px 20px; }
  .media-columns { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .topbar-actions { width: 100%; justify-content: flex-end; }
  .search-group { max-width: 100%; }
}