/* Command Center dark theme for cmsv7 — overrides Bootstrap 5 variables. */
:root {
  --cc-bg: #0b0f19;
  --cc-surface: #111827;
  --cc-surface-2: #1f2937;
  --cc-surface-3: #243045;
  --cc-border: #1f2937;
  --cc-border-strong: #334155;
  --cc-text: #e5e7eb;
  --cc-text-dim: #cbd5e1;
  --cc-muted: #94a3b8;
  --cc-accent: #3b82f6;
  --cc-accent-hover: #60a5fa;
  --cc-success: #22c55e;
  --cc-warning: #f59e0b;
  --cc-danger: #ef4444;
  --cc-info: #06b6d4;
}

html, body {
  background: var(--cc-bg);
  color: var(--cc-text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  min-height: 100vh;
}

body * {
  -webkit-font-smoothing: antialiased;
}

/* Global text + link contrast */
h1, h2, h3, h4, h5, h6 {
  color: var(--cc-text);
}

p, span, div, li, td, th, label {
  color: inherit;
}

a {
  color: var(--cc-accent);
  text-decoration: none;
}

a:hover {
  color: var(--cc-accent-hover);
  text-decoration: underline;
}

/* Bootstrap overrides so legacy pages look native too */
.container, .container-fluid {
  color: var(--cc-text);
}

.text-muted {
  color: var(--cc-muted) !important;
}

.bg-dark, .navbar-dark.bg-dark {
  background: var(--cc-surface) !important;
  border-bottom: 1px solid var(--cc-border);
}

.navbar-brand, .nav-link {
  color: var(--cc-text) !important;
}

.nav-link:hover {
  color: var(--cc-accent-hover) !important;
}

.card, .list-group-item {
  background: var(--cc-surface);
  color: var(--cc-text);
  border-color: var(--cc-border);
}

.card-header, .card-footer {
  background: var(--cc-surface-2);
  border-color: var(--cc-border);
}

.table {
  color: var(--cc-text);
  --bs-table-bg: transparent;
  --bs-table-color: var(--cc-text);
  --bs-table-striped-color: var(--cc-text);
  --bs-table-striped-bg: rgba(255, 255, 255, 0.02);
  --bs-table-hover-bg: rgba(59, 130, 246, 0.08);
  --bs-table-hover-color: var(--cc-text);
  --bs-table-border-color: var(--cc-border);
}

.table thead th {
  color: var(--cc-muted);
  border-bottom: 1px solid var(--cc-border-strong);
  background: var(--cc-surface-2);
}

.alert {
  background: var(--cc-surface-2);
  border-color: var(--cc-border);
  color: var(--cc-text);
}

.alert-success { border-left: 3px solid var(--cc-success); }
.alert-warning { border-left: 3px solid var(--cc-warning); }
.alert-danger, .alert-error { border-left: 3px solid var(--cc-danger); }
.alert-info { border-left: 3px solid var(--cc-info); }

.btn-close {
  filter: invert(1) brightness(1.5);
}

/* Form controls — dark fill, white text */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="tel"],
input[type="url"],
input[type="search"],
input[type="date"],
input[type="time"],
input[type="datetime-local"],
textarea,
select,
.form-control,
.form-select {
  background: var(--cc-bg) !important;
  color: var(--cc-text) !important;
  border: 1px solid var(--cc-border-strong) !important;
  border-radius: 6px !important;
  padding: 8px 12px !important;
  width: 100%;
  font-size: 14px;
  box-sizing: border-box;
  box-shadow: none !important;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
textarea:focus,
select:focus,
.form-control:focus,
.form-select:focus {
  outline: none;
  border-color: var(--cc-accent) !important;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15) !important;
}

input::placeholder,
textarea::placeholder,
.form-control::placeholder {
  color: var(--cc-muted);
}

input[type="date"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator,
input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  filter: invert(1) brightness(0.8);
  cursor: pointer;
}

select option {
  background: var(--cc-surface);
  color: var(--cc-text);
}

input[type="checkbox"],
input[type="radio"] {
  width: auto !important;
  accent-color: var(--cc-accent);
  margin-right: 6px;
}

label {
  color: var(--cc-text-dim);
  font-size: 13px;
  display: block;
  margin-bottom: 4px;
}

/* Buttons — Bootstrap and custom */
.btn {
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 13px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: filter 0.15s ease, background 0.15s ease;
}

.btn-primary {
  background: var(--cc-accent);
  border-color: var(--cc-accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--cc-accent-hover);
  border-color: var(--cc-accent-hover);
  color: #fff;
}

.btn-secondary,
.btn-outline-secondary {
  background: var(--cc-surface-2);
  border-color: var(--cc-border-strong);
  color: var(--cc-text);
}

.btn-secondary:hover,
.btn-outline-secondary:hover {
  background: var(--cc-surface-3);
  color: var(--cc-text);
}

.btn-danger {
  background: var(--cc-danger);
  border-color: var(--cc-danger);
  color: #fff;
}

/* Sidebar */
.cc-sidebar {
  width: 220px;
  min-height: 100vh;
  background: var(--cc-surface);
  border-right: 1px solid var(--cc-border);
  padding: 16px 8px;
  position: fixed;
  top: 0;
  left: 0;
  overflow-y: auto;
  transition: transform 0.25s ease, width 0.25s ease;
  z-index: 100;
}

.cc-sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 16px;
  font-weight: 700;
  color: var(--cc-text);
}

.cc-sidebar .brand-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cc-sidebar .nav-label {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--cc-muted);
  padding: 10px 10px 4px;
  letter-spacing: 0.05em;
}

.cc-sidebar a.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--cc-text);
  text-decoration: none;
  font-size: 14px;
  white-space: nowrap;
}

.cc-sidebar a.nav-item:hover {
  background: var(--cc-surface-2);
  color: var(--cc-text);
  text-decoration: none;
}

.cc-sidebar a.nav-item.active {
  background: var(--cc-accent);
  color: #fff;
}

.cc-sidebar a.nav-item .icon {
  width: 16px;
  text-align: center;
  flex-shrink: 0;
}

body.cc-sidebar-collapsed .cc-sidebar {
  width: 64px;
}

body.cc-sidebar-collapsed .cc-sidebar .brand-text,
body.cc-sidebar-collapsed .cc-sidebar .nav-label,
body.cc-sidebar-collapsed .cc-sidebar a.nav-item .label,
body.cc-sidebar-collapsed .cc-sidebar .account-name {
  display: none;
}

body.cc-sidebar-collapsed .cc-sidebar a.nav-item {
  justify-content: center;
  padding: 10px 0;
}

body.cc-sidebar-collapsed .cc-main {
  margin-left: 64px;
}

/* Toggle button */
.cc-sidebar-toggle {
  position: fixed;
  top: 12px;
  left: 180px;
  width: 36px;
  height: 36px;
  background: var(--cc-surface-2);
  border: 1px solid var(--cc-border-strong);
  border-radius: 8px;
  color: var(--cc-text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 200;
  font-size: 18px;
  transition: left 0.25s ease, background 0.15s ease;
}

.cc-sidebar-toggle:hover {
  background: var(--cc-surface-3);
}

body.cc-sidebar-collapsed .cc-sidebar-toggle {
  left: 24px;
}

/* Main content area */
.cc-main {
  margin-left: 220px;
  padding: 20px 28px;
  transition: margin-left 0.25s ease;
}

.cc-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0 16px;
  border-bottom: 1px solid var(--cc-border);
  margin-bottom: 20px;
}

.cc-topbar .title {
  font-size: 20px;
  font-weight: 600;
  color: var(--cc-text);
}

.cc-topbar .subtitle {
  color: var(--cc-muted);
  font-size: 13px;
}

.cc-tile {
  background: var(--cc-surface);
  border: 1px solid var(--cc-border);
  border-radius: 10px;
  padding: 18px;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.cc-tile:hover {
  border-color: var(--cc-border-strong);
}

.cc-tile .label {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--cc-muted);
  letter-spacing: 0.05em;
  font-weight: 600;
}

.cc-tile .value {
  font-size: 28px;
  font-weight: 700;
  margin-top: 6px;
  color: var(--cc-text);
}

.cc-tile.success .value { color: var(--cc-success); }
.cc-tile.warning .value { color: var(--cc-warning); }
.cc-tile.danger .value { color: var(--cc-danger); }
.cc-tile.info .value { color: var(--cc-info); }

.cc-card {
  background: var(--cc-surface);
  border: 1px solid var(--cc-border);
  border-radius: 10px;
  padding: 18px;
  color: var(--cc-text);
}

.cc-card h3 {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 12px;
  color: var(--cc-text);
}

.cc-card .text-muted,
.cc-card p {
  color: var(--cc-text-dim);
}

.cc-btn-primary {
  background: var(--cc-accent);
  color: #fff;
  border: none;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}

.cc-btn-primary:hover {
  background: var(--cc-accent-hover);
  color: #fff;
  text-decoration: none;
}

.cc-btn-ghost {
  background: transparent;
  color: var(--cc-text);
  border: 1px solid var(--cc-border-strong);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}

.cc-btn-ghost:hover {
  background: var(--cc-surface-2);
  color: var(--cc-text);
  border-color: var(--cc-accent);
  text-decoration: none;
}

.cc-table {
  width: 100%;
  border-collapse: collapse;
}

.cc-table th,
.cc-table td {
  padding: 12px;
  border-bottom: 1px solid var(--cc-border);
  text-align: left;
  font-size: 13px;
  color: var(--cc-text);
}

.cc-table th {
  color: var(--cc-muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--cc-surface-2);
}

.cc-table tbody tr:hover {
  background: rgba(59, 130, 246, 0.05);
}

.cc-table a {
  color: var(--cc-text);
}

.cc-table a:hover {
  color: var(--cc-accent-hover);
  text-decoration: none;
}

.cc-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.cc-badge.active { background: rgba(34, 197, 94, 0.15); color: var(--cc-success); }
.cc-badge.paused { background: rgba(245, 158, 11, 0.15); color: var(--cc-warning); }
.cc-badge.ended { background: rgba(148, 163, 184, 0.2); color: var(--cc-muted); }

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

.cc-dot.online { background: var(--cc-success); box-shadow: 0 0 6px rgba(34, 197, 94, 0.6); }
.cc-dot.offline { background: var(--cc-danger); }

/* Leaflet map (light tiles) */
.leaflet-container {
  background: #e5e9ef !important;
  border-radius: 8px;
}

.leaflet-popup-content-wrapper {
  background: var(--cc-surface-2);
  color: var(--cc-text);
}

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

.leaflet-control-attribution {
  background: rgba(17, 24, 39, 0.8) !important;
  color: var(--cc-muted) !important;
}

.leaflet-control-attribution a {
  color: var(--cc-accent);
}

.leaflet-bar a {
  background: var(--cc-surface-2) !important;
  color: var(--cc-text) !important;
  border-bottom: 1px solid var(--cc-border) !important;
}

.leaflet-bar a:hover {
  background: var(--cc-surface-3) !important;
}

/* Login and legacy pages */
.login-container, .login-box {
  background: var(--cc-surface);
  border: 1px solid var(--cc-border);
  border-radius: 12px;
  padding: 32px;
}

/* Bootstrap bg/text utility overrides so legacy templates blend in */
.bg-light {
  background: var(--cc-surface-2) !important;
  color: var(--cc-text) !important;
}

.text-dark {
  color: var(--cc-text) !important;
}

.bg-secondary {
  background: var(--cc-surface-3) !important;
}

.table-dark {
  background: var(--cc-surface-2) !important;
  color: var(--cc-text) !important;
}

.badge {
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 12px;
}

.badge.bg-light,
.badge.bg-light.text-dark {
  background: var(--cc-surface-3) !important;
  color: var(--cc-text) !important;
}

.badge.bg-primary { background: var(--cc-accent) !important; }
.badge.bg-success { background: var(--cc-success) !important; }
.badge.bg-danger { background: var(--cc-danger) !important; }
.badge.bg-warning { background: var(--cc-warning) !important; color: #000 !important; }

.form-label {
  color: var(--cc-text-dim);
  font-weight: 500;
  font-size: 13px;
  margin-bottom: 4px;
}

.form-check-label {
  color: var(--cc-text);
}

.form-text {
  color: var(--cc-muted) !important;
}

code {
  background: var(--cc-surface-2);
  color: var(--cc-accent-hover);
  padding: 2px 6px;
  border-radius: 4px;
}

.card.shadow {
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4) !important;
}

hr {
  border-color: var(--cc-border);
}

/* Ensure h4, h5 legacy headings have proper color */
h4, h5 {
  color: var(--cc-text);
}

/* Responsive: mobile sidebar collapses automatically */
@media (max-width: 768px) {
  .cc-sidebar {
    transform: translateX(-100%);
  }
  body.cc-sidebar-open .cc-sidebar {
    transform: translateX(0);
  }
  .cc-main {
    margin-left: 0;
  }
  .cc-sidebar-toggle {
    left: 12px;
  }
}
