﻿/* DASHBOARD STYLES - CSS Variables for easy theming */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --color-primary: #3b82f6;
  --color-primary-dark: #2563eb;
  --color-accent: #8b5cf6;
  --color-success: #22c55e;
  --color-warning: #f59e0b;
  --color-danger: #ef4444;
  --sidebar-width: 260px;
  --navbar-height: 60px;
  --sidebar-bg: #ffffff;
  --sidebar-text: #374151;
  --sidebar-text-muted: #9ca3af;
  --sidebar-hover: #f3f4f6;
  --sidebar-active: #eff6ff;
  --sidebar-active-text: #2563eb;
  --sidebar-border: #e5e7eb;
  --navbar-bg: #ffffff;
  --navbar-text: #1f2937;
  --navbar-border: #e5e7eb;
  --content-bg: #f8fafc;
  --card-bg: #ffffff;
  --card-border: #e5e7eb;
  --card-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
  --card-shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.1);
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --input-bg: #ffffff;
  --input-border: #d1d5db;
  --input-focus: #3b82f6;
  --auth-bg: linear-gradient(135deg, #eef2ff 0%, #f8fafc 60%, #f1f5f9 100%);
}

.dark {
  --sidebar-bg: #0f172a;
  --sidebar-text: #cbd5e1;
  --sidebar-text-muted: #64748b;
  --sidebar-hover: #1e293b;
  --sidebar-active: #1e3a5f;
  --sidebar-active-text: #60a5fa;
  --sidebar-border: #1e293b;
  --navbar-bg: #0f172a;
  --navbar-text: #f1f5f9;
  --navbar-border: #1e293b;
  --content-bg: #0f172a;
  --card-bg: #1e293b;
  --card-border: #334155;
  --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  --card-shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.4);
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --input-bg: #1e293b;
  --input-border: #475569;
  --input-focus: #60a5fa;
  --auth-bg: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
}

/* ─── Black-Grey Dark Theme (data-theme="black") ───────────────── */
[data-theme="black"] {
  --sidebar-bg: #0a0a0b;
  --sidebar-text: #d4d4d8;
  --sidebar-text-muted: #6f6f75;
  --sidebar-hover: #1c1c1f;
  --sidebar-active: #202024;
  --sidebar-active-text: #e8e8ea;
  --sidebar-border: #26262a;
  --navbar-bg: #0a0a0b;
  --navbar-text: #f3f3f5;
  --navbar-border: #26262a;
  --content-bg: #0f0f10;
  --card-bg: #17171a;
  --card-border: #2a2a2e;
  --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.55);
  --card-shadow-hover: 0 4px 14px rgba(0, 0, 0, 0.65);
  --text-primary: #ececef;
  --text-secondary: #9a9aa2;
  --text-muted: #6f6f75;
  --input-bg: #1c1c1f;
  --input-border: #3a3a40;
  --input-focus: var(--color-primary);
  --auth-bg: linear-gradient(135deg, #0a0a0b 0%, #17171a 50%, #0a0a0b 100%);
}

/* ─── Accent Colors (buttons / links / focus) - any mode ───────── */
[data-accent="green"] {
  --color-primary: #10b981;
  --color-primary-dark: #059669;
  --color-accent: #34d399;
  --input-focus: #10b981;
}

[data-accent="purple"] {
  --color-primary: #8b5cf6;
  --color-primary-dark: #7c3aed;
  --color-accent: #a78bfa;
  --input-focus: #8b5cf6;
}

[data-accent="orange"] {
  --color-primary: #f97316;
  --color-primary-dark: #ea580c;
  --color-accent: #fb923c;
  --input-focus: #f97316;
}

[data-accent="red"] {
  --color-primary: #ef4444;
  --color-primary-dark: #dc2626;
  --color-accent: #f87171;
  --input-focus: #ef4444;
}

/* Active sidebar state per accent (dark mode only, keeps light clean) */
.dark[data-accent="green"] {
  --sidebar-active: #064e3b;
  --sidebar-active-text: #34d399;
}

.dark[data-accent="purple"] {
  --sidebar-active: #581c87;
  --sidebar-active-text: #a78bfa;
}

.dark[data-accent="orange"] {
  --sidebar-active: #7c2d12;
  --sidebar-active-text: #fb923c;
}

.dark[data-accent="red"] {
  --sidebar-active: #7f1d1d;
  --sidebar-active-text: #f87171;
}

body {
  font-family: Inter, Segoe UI, system-ui, sans-serif;
  background: var(--content-bg);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 3px;
}

.d-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: var(--navbar-height) 1fr;
  min-height: 100vh;
  transition: grid-template-columns 0.3s ease;
}

.d-layout.sc {
  grid-template-columns: 60px 1fr;
}

.navbar {
  grid-column: 1 / -1;
  grid-row: 1;
  height: var(--navbar-height);
  background: var(--navbar-bg);
  border-bottom: 1px solid var(--navbar-border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--navbar-text);
  font-weight: 700;
  font-size: 1.1rem;
}

.navbar-brand img {
  height: 32px;
  width: auto;
}

.navbar-spacer {
  flex: 1;
}

.navbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.navbar-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1.15rem;
}

.navbar-btn:hover {
  background: var(--sidebar-hover);
  color: var(--text-primary);
}

.u-dropdown {
  position: relative;
}

.u-dropdown-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  font-size: .9rem;
  font-weight: 500;
}

.u-dropdown-btn:hover {
  background: var(--sidebar-hover);
}

.u-dropdown-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  min-width: 220px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  z-index: 200;
  overflow: hidden;
}

.u-dropdown:hover .u-dropdown-menu,
.u-dropdown-menu.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.u-dropdown-menu a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  color: var(--text-primary);
  text-decoration: none;
  font-size: .875rem;
}

.u-dropdown-menu a:hover {
  background: var(--sidebar-hover);
}

.u-dropdown-menu .divider {
  height: 1px;
  background: var(--sidebar-border);
  margin: 4px 0;
}

.u-dropdown-menu .danger {
  color: var(--color-danger);
}

.u-dropdown-menu i {
  width: 18px;
  text-align: center;
}

.sidebar {
  grid-column: 1;
  grid-row: 2;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 50;
  transition: width 0.3s ease;
}

.sidebar.collapsed {
  width: 60px;
}

.sidebar.collapsed .s-link span {
  display: none;
}

.sidebar.collapsed .s-section-title {
  display: none;
}

.sidebar.collapsed .s-link {
  justify-content: center;
  padding: 9px 0;
}

.sidebar.collapsed .s-link i {
  width: auto;
  font-size: 1.25rem;
}

.s-nav {
  padding: 12px 0;
}

.s-section {
  padding: 0 12px;
  margin-top: 8px;
}

.s-section:first-child {
  margin-top: 0;
}

.s-section-title {
  font-size: .65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--sidebar-text-muted);
  padding: 8px 12px 6px;
}

.s-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: .875rem;
  font-weight: 500;
  border-radius: 8px;
  margin-bottom: 1px;
}

.s-link:hover {
  background: var(--sidebar-hover);
}

.s-link.active {
  background: var(--sidebar-active);
  color: var(--sidebar-active-text);
}

.s-link i {
  width: 20px;
  text-align: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.main-content {
  grid-column: 2;
  grid-row: 2;
  padding: 24px;
  overflow-y: auto;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  box-shadow: var(--card-shadow);
}

.card-hover:hover {
  box-shadow: var(--card-shadow-hover);
  transform: translateY(-2px);
}

.card-body {
  padding: 20px;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--card-border);
  font-weight: 600;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 20px;
  min-width: 0;
  /* allow the card to shrink so a 4-per-row grid never overflows */
}

.stat-card-icon {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  flex-shrink: 0;
}

.stat-card-value {
  font-size: 1.5rem;
  font-weight: 700;
}

.stat-card-label {
  font-size: .8rem;
  color: var(--text-muted);
  font-weight: 500;
}

.form-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: .9rem;
  font-family: inherit;
  outline: none;
}

.form-input:focus {
  border-color: var(--input-focus);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.form-input[readonly] {
  cursor: default;
  opacity: .8;
}

.form-label {
  display: block;
  font-size: .85rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: .9rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
}

.btn-primary {
  background: var(--color-primary);
  color: white;
}

.btn-primary:hover {
  background: var(--color-primary-dark);
}

.btn-block {
  width: 100%;
  justify-content: center;
}

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--auth-bg);
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--card-bg);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  padding: 40px;
}

.auth-logo {
  text-align: center;
  margin-bottom: 8px;
}

.auth-logo img {
  height: 48px;
  width: auto;
}

.auth-title {
  text-align: center;
  font-size: 1.5rem;
  font-weight: 700;
}

.auth-subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: .9rem;
  margin-bottom: 24px;
}

.auth-error {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.2);
  color: var(--color-danger);
  padding: 12px 16px;
  border-radius: 8px;
  font-size: .85rem;
  margin-bottom: 16px;
}

.spinner {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 9999;
  display: flex;
  gap: 6px;
}

.spinner-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--color-primary);
  animation: sb 1.2s ease-in-out infinite;
}

.spinner-dot:nth-child(2) {
  animation-delay: .2s;
}

.spinner-dot:nth-child(3) {
  animation-delay: .4s;
}

@keyframes sb {

  0%,
  80%,
  100% {
    opacity: .3;
    transform: scale(.8);
  }

  40% {
    opacity: 1;
    transform: scale(1.2);
  }
}

.spinner-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 9998;
}

.hidden {
  display: none !important;
}

.amcharts-amexport-menu,
.amcharts-amexport-icon,
a[href*="amcharts.com"] {
  display: none !important;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 40;
}

/* Modal Overlay */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 20px;
}

.modal {
  background: var(--card-bg);
  border-radius: 16px;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.25);
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--card-border);
}

.modal-header h3 {
  font-size: 1.1rem;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0 4px;
}

.modal-close:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: 20px 24px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 24px;
  border-top: 1px solid var(--card-border);
}

@media (max-width: 768px) {
  .d-layout {
    grid-template-columns: 1fr;
    grid-template-rows: var(--navbar-height) 1fr;
  }

  .sidebar {
    position: fixed;
    top: var(--navbar-height);
    left: 0;
    height: calc(100vh - var(--navbar-height));
    transform: translateX(-100%);
    z-index: 50;
    grid-column: auto;
    grid-row: auto;
  }

  .sidebar.mobile-open {
    transform: translateX(0);
  }

  .sidebar-backdrop.mobile-open {
    display: block;
  }

  .main-content {
    grid-column: 1;
    grid-row: 2;
    width: 100%;
    min-width: 0;
    padding: 16px;
  }

  .navbar-brand span {
    display: none;
  }
}

@media (min-width: 769px) {
  .sidebar-backdrop {
    display: none !important;
  }
}

/* ─── Stat Cards Responsive Grid ─────────────────────────────────── */
.stat-cards-grid {
  display: grid;
  gap: 14px;
}

/* Mobile (≤479px): 2 cards per row */
@media (max-width: 479px) {
  .stat-cards-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .stat-card {
    padding: 12px 14px;
    gap: 10px;
  }

  .stat-card-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
  }

  .stat-card-icon i {
    font-size: 0.95rem;
  }

  .stat-card-value {
    font-size: 1.15rem;
  }

  .stat-card-label {
    font-size: 0.7rem;
  }

  .main-content {
    padding: 12px;
  }

  /* Filter form stacks vertically */
  .card form {
    flex-direction: column;
  }

  .card form input[type="date"] {
    width: 100% !important;
  }

  /* Chart scales down */
  #stat-chart {
    min-height: 180px;
    height: auto;
  }

  .navbar {
    padding: 0 12px;
  }

  .card-body {
    padding: 12px;
  }

  .card-header {
    padding: 12px 14px;
  }

  /* Touch-friendly buttons */
  .btn {
    min-height: 44px;
    min-width: 44px;
    padding: 10px 16px;
    font-size: 0.85rem;
  }

  .navbar-btn {
    width: 44px;
    height: 44px;
  }

  h2 {
    font-size: 1.25rem !important;
    margin-bottom: 16px !important;
  }

  /* Most/Least Active stack on mobile */
  .user-stats-grid {
    grid-template-columns: 1fr !important;
  }
}

/* Small tablet (480px – 639px): 3 cards per row */
@media (min-width: 480px) and (max-width: 639px) {
  .stat-cards-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .stat-card-value {
    font-size: 1.3rem;
  }

  .stat-card {
    padding: 14px 16px;
  }

  .stat-card-icon {
    width: 38px;
    height: 38px;
  }
}

/* Tablet (640px – 899px): 4 cards per row (1st row: 4, 2nd row: 3) */
@media (min-width: 640px) and (max-width: 899px) {
  .stat-cards-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .stat-card-value {
    font-size: 1.35rem;
  }

  /* Two-column dashboard layout */
  .dashboard-columns {
    grid-template-columns: 1fr !important;
  }
}

/* Desktop (900px – 1199px): 4 cards per row */
@media (min-width: 900px) and (max-width: 1199px) {
  .stat-cards-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  /* Two columns on wide tablets / small desktops */
  .dashboard-columns {
    grid-template-columns: 1fr 1fr !important;
  }
}

/* Large desktop (≥1200px): 4 cards per row */
@media (min-width: 1200px) {
  .stat-cards-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .dashboard-columns {
    grid-template-columns: 1fr 1fr !important;
  }
}

/* ─── Smooth mobile scrolling for DataTables ───────────────────── */
.dataTables_wrapper {
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 768px) {
  .dataTables_wrapper .dt-buttons {
    margin-bottom: 8px;
  }

  .dataTables_wrapper .dt-buttons .btn {
    padding: 6px 10px;
    font-size: 0.75rem;
    min-height: 36px;
    min-width: 36px;
  }

  /* Modal mobile padding */
  .modal {
    max-width: 95vw;
    border-radius: 12px;
  }

  .modal-header {
    padding: 14px 16px;
  }

  .modal-body {
    padding: 14px 16px;
  }

  .modal-footer {
    padding: 12px 16px;
  }
}

/* ─── Device Cards ──────────────────────────────────────────────── */
.device-cards-grid {
  display: grid;
  gap: 14px;
  /* Auto-fill as many equal columns as fit and wrap the rest, so cards
     always fit the viewport instead of overflowing it. */
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}

.device-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  /* allow the card to shrink below its content width */
  transition: box-shadow 0.2s, transform 0.2s;
}

.device-card:hover {
  box-shadow: var(--card-shadow-hover);
  transform: translateY(-2px);
}

.device-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.device-card-name {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  /* let the name shrink so long names truncate with "…" */
}

.device-card-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  flex-shrink: 0;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.online {
  background: #22c55e;
}

.status-dot.offline {
  background: #ef4444;
}

.status-dot.unknown {
  background: #9ca3af;
}

.device-card-details {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.device-card-details span {
  display: flex;
  align-items: center;
  gap: 4px;
}

.device-card-details i {
  font-size: 0.85rem;
  opacity: 0.7;
}

.device-card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 4px;
  border-top: 1px solid var(--card-border);
}

/* ─── Toggle Switch ─────────────────────────────────────────────── */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.toggle-label {
  font-size: 0.78rem;
  color: var(--text-secondary);
  flex: 1;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 24px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--text-muted);
  border-radius: 24px;
  transition: 0.2s;
}

.toggle-slider::before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: 0.2s;
}

.toggle-switch input:checked+.toggle-slider {
  background: var(--color-primary);
}

.toggle-switch input:checked+.toggle-slider::before {
  transform: translateX(18px);
}

/* ─── Modal Device Form ─────────────────────────────────────────── */
.modal-form-group {
  margin-bottom: 14px;
}

.modal-form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.modal-form-group select,
.modal-form-group input {
  width: 100%;
  padding: 10px 12px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
}

.modal-form-group select:focus,
.modal-form-group input:focus {
  border-color: var(--input-focus);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

/* ─── Device Card Action Buttons ────────────────────────────────── */
.device-card-actions .btn {
  font-size: 0.78rem;
  padding: 6px 12px;
  min-height: 34px;
  gap: 5px;
}

.device-card-actions .btn-sm {
  font-size: 0.75rem;
  padding: 5px 10px;
  min-height: 32px;
  border-radius: 6px;
}

.btn-danger {
  background: var(--color-danger);
  color: white;
}

.btn-danger:hover {
  opacity: 0.9;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--input-border);
  color: var(--text-primary);
}

.btn-outline:hover {
  background: var(--sidebar-hover);
}

/* ─── Confirm Dialog ────────────────────────────────────────────── */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 20px;
}

.confirm-dialog {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 24px;
  max-width: 380px;
  width: 100%;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
  text-align: center;
}

.confirm-dialog i {
  font-size: 2.5rem;
  color: var(--color-danger);
  margin-bottom: 12px;
}

.confirm-dialog p {
  color: var(--text-secondary);
  margin: 8px 0 16px;
  font-size: 0.9rem;
}

.confirm-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

/* ─── Device Cards Grid Responsive ──────────────────────────────── */
@media (max-width: 479px) {
  .device-cards-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 10px;
  }

  .device-card {
    padding: 12px;
    gap: 8px;
  }

  .device-card-name {
    font-size: 0.88rem;
  }

  .device-card-details {
    font-size: 0.72rem;
    gap: 4px 10px;
  }

  .device-card-actions .btn {
    font-size: 0.72rem;
    padding: 5px 10px;
    min-height: 32px;
  }
}

@media (min-width: 480px) and (max-width: 639px) {
  .device-cards-grid {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  }
}

@media (min-width: 640px) and (max-width: 899px) {
  .device-cards-grid {
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  }
}

@media (min-width: 900px) {
  .device-cards-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* ─── Empty State ───────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-state i {
  font-size: 3rem;
  margin-bottom: 12px;
  opacity: 0.5;
}

.empty-state p {
  font-size: 0.95rem;
}

/* ─── Spinner Mini ──────────────────────────────────────────────── */
.spinner-mini {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--card-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ─── Modal Tabs ────────────────────────────────────────────────── */
.modal-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--card-border);
  margin-bottom: 16px;
}

.modal-tab-btn {
  padding: 10px 20px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: -2px;
}

.modal-tab-btn:hover {
  color: var(--text-primary);
}

.modal-tab-btn.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

.modal-tab-panel {
  display: none;
}

.modal-tab-panel.active {
  display: block;
}

/* ─── Alarm Table ───────────────────────────────────────────────── */
.alarm-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.alarm-table th {
  background: var(--sidebar-hover);
  color: var(--text-secondary);
  font-weight: 600;
  padding: 10px 12px;
  text-align: left;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.alarm-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--card-border);
  color: var(--text-primary);
}

.alarm-table .alarm-active {
  color: #22c55e;
  font-weight: 600;
}

.alarm-table .alarm-disabled {
  color: #9ca3af;
}

/* ─── Notification User Table ───────────────────────────────────── */
.notif-usertable {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.notif-usertable th {
  background: var(--sidebar-hover);
  padding: 8px 10px;
  text-align: left;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.notif-usertable td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--card-border);
}

/* ─── Chart in Modal ────────────────────────────────────────────── */
.edit-chart {
  width: 100%;
  min-height: 350px;
  background: var(--content-bg);
  border-radius: 8px;
  border: 1px solid var(--card-border);
}

@media (max-width: 479px) {
  .modal-tab-btn {
    padding: 8px 12px;
    font-size: 0.78rem;
  }

  .edit-chart {
    min-height: 250px;
  }

  .alarm-table th,
  .alarm-table td {
    padding: 6px 8px;
    font-size: 0.72rem;
  }
}

/* ─── Settings page: theme & accent pickers ───────────────────── */
.theme-picker {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 8px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  cursor: pointer;
  color: var(--text-primary);
  font-size: 0.85rem;
  font-weight: 500;
}

.theme-picker:hover {
  border-color: var(--color-primary);
}

.theme-picker.selected {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px var(--color-primary);
}

.theme-swatch {
  width: 100%;
  height: 44px;
  border-radius: 8px;
  display: block;
}

.accent-picker {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
}

.accent-picker.selected {
  box-shadow: 0 0 0 3px #ffffff, 0 0 0 6px var(--card-border);
  transform: scale(1.15);
}

.mqtt-tab-btn {
  color: #14b8a6;
}

.mqtt-tab-btn i {
  margin-right: 4px;
}

/* ── MQTT view ─────────────────────────────────────────────────── */
.mqtt-console {
  height: 420px;
  overflow-y: auto;
  padding: 12px 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .8rem;
  line-height: 1.5;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 8px;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-break: break-all;
}

.mqtt-line {
  padding: 2px 0;
}

.mqtt-line.mqtt-retained {
  color: #f59e0b;
}

.mqtt-line.mqtt-muted {
  color: var(--text-muted);
}

.mqtt-time {
  color: var(--text-muted);
  display: inline-block;
  min-width: 74px;
}

.mqtt-kind {
  display: inline-block;
  min-width: 58px;
  padding: 0 6px;
  border-radius: 4px;
  font-size: .7rem;
  font-weight: 600;
  text-align: center;
  margin-right: 4px;
}

.mqtt-kind-data {
  color: #1f2937;
  background: #dcfce7;
}

.mqtt-kind-command {
  color: #fff;
  background: #6366f1;
}

.dark .mqtt-kind-data {
  color: #e5e7eb;
  background: rgba(16, 203, 134, .18);
}

.mqtt-topic {
  color: #06b6d4;
  margin-right: 6px;
}

.mqtt-payload {
  color: var(--text-primary);
}

/* ─── History Range Control (docked wide & slim bottom bar) ───────── */
.history-ctl {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  background: var(--card-bg);
  border-top: 1px solid var(--card-border);
  box-shadow: 0 2px 8px -2px rgba(0, 0, 0, .18);
  color: var(--text-primary);
  font-size: 0.8rem;
}

.history-ctl[data-hidden="true"] {
  display: none;
}

/* Collapsed: one slim centered row */
.history-ctl-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  color: var(--text-secondary);
  font-weight: 600;
  padding: 6px 0;
}

.history-ctl-toggle i {
  color: var(--color-primary);
}

.history-ctl-summary {
  color: var(--text-muted);
  font-weight: 400;
  margin-left: 6px;
}

.history-ctl[data-state="open"] .history-ctl-toggle {
  display: none;
}

.history-ctl[data-state="collapsed"] .history-ctl-body {
  display: none;
}

/* Expanded: one slim horizontal row */
.history-ctl[data-state="open"] .history-ctl-body {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 5px 10px;
}

.history-ctl-tabs {
  display: flex;
  gap: 2px;
  margin: 0;
  list-style: none;
}

.history-ctl-tabs button {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 0.72rem;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
}

.history-ctl-tabs button.active {
  background: var(--sidebar-active);
  color: var(--sidebar-active-text);
}

.history-ctl-slider-pane {
  position: relative;
  width: 380px;
  height: 20px;
}

.history-ctl-slider-pane::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 6px;
  height: 5px;
  border-radius: 3px;
  background: var(--input-border);
  z-index: 0;
}

.history-ctl-range-fill {
  position: absolute;
  top: 6px;
  height: 5px;
  border-radius: 3px;
  background: var(--color-primary);
  z-index: 1;
}

.history-range-slider {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 20px;
  margin: 0;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  z-index: 2;
}

/* End handle underneath; Start handle on top, intercepting only at its thumb. */
#historyCtlEnd {
  z-index: 2;
}

#historyCtlStart {
  z-index: 3;
  pointer-events: none;
}

#historyCtlStart::-webkit-slider-thumb {
  pointer-events: auto;
}

#historyCtlStart::-moz-range-thumb {
  pointer-events: auto;
}

.history-range-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  height: 14px;
  width: 14px;
  margin-top: -4px;
  background: var(--color-primary);
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: var(--card-shadow);
  cursor: pointer;
}

.history-range-slider::-moz-range-thumb {
  height: 14px;
  width: 14px;
  background: var(--color-primary);
  border: 2px solid #fff;
  border-radius: 50%;
  cursor: pointer;
}

.history-ctl-label {
  font-size: 0.72rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* Floating show/hide button (only visible while the dock is hidden) */
.history-ctl-fab {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 70;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  border: none;
  font-size: 1.3rem;
  box-shadow: var(--card-shadow-hover);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.history-ctl-fab[data-hidden="false"] {
  display: none;
}

/* Expanded picker / actions (remainder) */
.history-ctl-picker-pane {
  display: flex;
  align-items: center;
  gap: 6px;
}

.history-ctl-picker-label {
  color: var(--text-secondary);
  font-size: 0.72rem;
}

.history-ctl-date {
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 0.78rem;
  padding: 2px 4px;
}

.history-ctl-picker-sep {
  color: var(--text-muted);
}

.history-ctl-all {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
}

.history-ctl-all input {
  accent-color: var(--color-primary);
  cursor: pointer;
}

.history-ctl-close {
  background: transparent;
  border: none;
  font-size: 1.1rem;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 2px;
}

.history-ctl-close:hover {
  color: var(--text-primary);
}