/* ─── Reset & base ──────────────────────────────────────────────────────── */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg:          #0f1117;
  --surface:     #1c1f26;
  --border:      #2a2d35;
  --text:        #e2e8f0;
  --text-muted:  #718096;
  --primary:     #3b82f6;
  --primary-dk:  #2563eb;
  --danger:      #ef4444;
  --success:     #22c55e;
  --sidebar-w:   280px;
  --topbar-h:    48px;
  --font:        system-ui, -apple-system, sans-serif;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
}

/* ─── Login page ────────────────────────────────────────────────────────── */

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}

.login-logo h1 {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 4px;
}

.login-subtitle {
  color: var(--text-muted);
  margin-bottom: 28px;
}

.login-note {
  margin-top: 16px;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

/* ─── Forms ─────────────────────────────────────────────────────────────── */

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 6px;
}

.form-group input,
.form-group select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 9px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
}

.form-group input:focus,
.form-group select:focus {
  border-color: var(--primary);
}

/* ─── Buttons ────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  padding: 8px 14px;
  transition: background .15s, opacity .15s;
}

.btn:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.btn-primary   { background: var(--primary);  color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dk); }

.btn-outline   { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover:not(:disabled) { background: var(--border); }

.btn-danger    { background: var(--danger);   color: #fff; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }

.btn-sm        { padding: 5px 10px; font-size: 12px; }
.btn-full      { width: 100%; }

/* ─── Alerts ─────────────────────────────────────────────────────────────── */

.alert {
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 12px;
}

.alert-error   { background: rgba(239,68,68,.15);  border: 1px solid rgba(239,68,68,.4);  color: #fca5a5; }
.alert-success { background: rgba(34,197,94,.12);  border: 1px solid rgba(34,197,94,.35); color: #86efac; }

/* ─── Dashboard layout ──────────────────────────────────────────────────── */

.dashboard-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Top bar */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  flex-shrink: 0;
}

.topbar-brand {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
  margin-right: 12px;
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-right: auto;
}

.topbar-link {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  padding: 4px 10px;
  border-radius: 5px;
  transition: background .15s, color .15s;
}

.topbar-link:hover { background: var(--border); color: var(--text); }
.topbar-link.active { color: var(--text); background: rgba(255,255,255,.05); }

.topbar-account {
  position: relative;
  margin-left: auto;
}

.topbar-account-btn {
  font-size: 13px;
  color: var(--text-muted);
  background: none;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 4px 10px;
  cursor: pointer;
  white-space: nowrap;
}
.topbar-account-btn:hover { border-color: var(--border); color: var(--text); }

.topbar-account-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  min-width: 170px;
  z-index: 200;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
  overflow: hidden;
}

.topbar-account-item {
  display: block;
  width: 100%;
  padding: 9px 14px;
  background: none;
  border: none;
  text-align: left;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}
.topbar-account-item:hover { background: var(--border); }

/* Main two-column layout */
.dashboard-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ─── Sidebar ────────────────────────────────────────────────────────────── */

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.panel {
  border-bottom: 1px solid var(--border);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 8px;
}

.panel-header h2 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
}

/* Channel list */
.item-list {
  list-style: none;
  padding-bottom: 6px;
}

.item-list li {
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.item-list li:last-child  { border-bottom: none; }
.item-list li.placeholder { color: var(--text-muted); font-style: italic; }

.channel-name {
  flex: 1;
  font-weight: 500;
}

/* User table */
.user-table {
  width: 100%;
  border-collapse: collapse;
}

.user-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  padding: 6px 14px;
  border-bottom: 1px solid var(--border);
}

.user-table td {
  padding: 7px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.user-table tr:last-child td { border-bottom: none; }

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
}

.status-dot.online          { background: var(--success); }
.status-dot.recently-active { background: #f59e0b; }
.status-dot.offline         { background: var(--text-muted); }

.device-info {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ─── Map ────────────────────────────────────────────────────────────────── */

.map-container {
  flex: 1;
  position: relative;
}

#map {
  position: absolute;
  inset: 0;
}

/* ─── Leaflet popup override ─────────────────────────────────────────────── */

.leaflet-popup-content-wrapper {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.leaflet-popup-tip {
  background: var(--surface);
}

.marker-label {
  font-weight: 600;
  font-size: 13px;
}

.marker-channel {
  font-size: 11px;
  color: var(--text-muted);
}

/* ─── Modals (simple inline prompt alternative) ──────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px;
  width: 340px;
  max-width: 95vw;
}

.modal-box h3 { margin-bottom: 16px; font-size: 1rem; }

/* ─── Sidebar resize handle ──────────────────────────────────────────────── */

.sidebar-resize {
  width: 4px;
  flex-shrink: 0;
  cursor: col-resize;
  background: transparent;
  transition: background .15s;
  position: relative;
  z-index: 10;
}

.sidebar-resize:hover,
.sidebar-resize.dragging { background: var(--primary); }

/* ─── Channel connected-user pills ───────────────────────────────────────── */

.item-list li.channel-item {
  flex-direction: column;
  align-items: stretch;
  gap: 5px;
}

.channel-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.channel-users {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  min-height: 18px;
}

.channel-users-empty {
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
}

.user-pill {
  background: rgba(59,130,246,.12);
  border: 1px solid rgba(59,130,246,.28);
  color: #93c5fd;
  font-size: 11px;
  font-weight: 500;
  border-radius: 10px;
  padding: 1px 8px;
  white-space: nowrap;
}

/* ─── Administration page ────────────────────────────────────────────────── */

.admin-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.admin-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
}

/* Tabs */
.tab-bar {
  display: flex;
  border-bottom: 2px solid var(--border);
  margin-bottom: 24px;
}

.tab-btn {
  padding: 10px 22px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .15s;
}

.tab-btn.active  { color: var(--text); border-bottom-color: var(--primary); }
.tab-btn:hover:not(.active) { color: var(--text); }

/* Section */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-header h2 { font-size: 1rem; font-weight: 600; }

/* Data table */
.data-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 24px;
}

.data-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  padding: 8px 12px;
  border-bottom: 2px solid var(--border);
}

.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: rgba(255,255,255,.02); }

.actions-cell { display: flex; gap: 6px; align-items: center; }

/* Tags */
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.tag-admin      { background: rgba(239,68,68,.15);    color: #fca5a5; }
.tag-dispatcher { background: rgba(59,130,246,.15);   color: #93c5fd; }
.tag-user       { background: rgba(113,128,150,.15);  color: var(--text-muted); }
.tag-active     { background: rgba(34,197,94,.12);    color: #86efac; }
.tag-inactive   { background: rgba(113,128,150,.12);  color: var(--text-muted); }

/* Channel member chips */
.member-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  max-width: 400px;
}

.member-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 12px;
}

.member-chip .remove-btn {
  cursor: pointer;
  color: var(--text-muted);
  font-size: 10px;
  line-height: 1;
}

.member-chip .remove-btn:hover { color: var(--danger); }

/* ─── Settings page ──────────────────────────────────────────────────────── */

.settings-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.settings-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
  max-width: 640px;
}

.settings-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 24px;
  overflow: hidden;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.settings-row:last-child { border-bottom: none; }

.settings-label {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.settings-input {
  width: 72px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 6px 10px;
  font-size: 13px;
  text-align: right;
  outline: none;
  transition: border-color .15s;
}

.settings-input:focus { border-color: var(--primary); }

/* ─── Map unit markers ────────────────────────────────────────────────────── */

/* Override Leaflet's default white background on divIcon */
.unit-icon.leaflet-div-icon {
  background: none;
  border: none;
}

/* ─── Utilities ──────────────────────────────────────────────────────────── */

.placeholder { color: var(--text-muted); font-style: italic; }
.text-danger  { color: var(--danger); }
.text-muted   { color: var(--text-muted); }
.mt-8  { margin-top: 8px; }
.gap-8 { gap: 8px; }
