@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;1,400&family=Roboto+Mono:ital,wght@0,300;0,400;0,500;0,600;0,700;1,400&family=Fira+Code:wght@300;400;500;600;700&display=swap');

:root {
  --font-mono: 'JetBrains Mono', 'Roboto Mono', 'Fira Code', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --font-sans: var(--font-mono);
  --font-display: var(--font-mono);

  /* Color Palette - Modern Dark Theme by default */
  --bg-main: #0b0f19;
  --bg-surface: #111827;
  --bg-surface-elevated: #1f2937;
  --bg-card: rgba(30, 41, 59, 0.7);
  --bg-input: #1e293b;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: #3b82f6;

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent-primary: #3b82f6;
  --accent-primary-hover: #2563eb;
  --accent-gradient: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
  --accent-success: #10b981;
  --accent-warning: #f59e0b;
  --accent-danger: #ef4444;
  --accent-info: #06b6d4;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.2), 0 2px 4px -2px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -4px rgba(0, 0, 0, 0.2);
  --shadow-glow: 0 0 20px rgba(59, 130, 246, 0.25);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;
}

[data-theme="light"] {
  --bg-main: #f1f5f9;
  --bg-surface: #ffffff;
  --bg-surface-elevated: #f8fafc;
  --bg-card: rgba(255, 255, 255, 0.85);
  --bg-input: #f8fafc;
  --border-color: #e2e8f0;
  --border-focus: #2563eb;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;

  --accent-primary: #2563eb;
  --accent-primary-hover: #1d4ed8;
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  --shadow-glow: 0 0 15px rgba(37, 99, 235, 0.15);
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-main);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}

/* App Layout Grid */
.app-container {
  display: grid;
  grid-template-rows: 68px 1fr;
  grid-template-columns: 280px 1fr;
  grid-template-areas:
    "header header"
    "sidebar main";
  height: 100vh;
  overflow: hidden;
}

/* Header */
.app-header {
  grid-area: header;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 100;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: auto;
  min-width: 42px;
  max-width: 240px;
  height: 38px;
  border-radius: var(--radius-md);
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3px 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.brand-logo img {
  max-height: 30px;
  max-width: 100%;
  width: auto;
  object-fit: contain;
  display: block;
}

.brand-section .brand-title,
.brand-section .brand-badge,
.brand-section #navbarBrandTitle,
.brand-section #navbarBrandSubtitle {
  display: none !important;
}

.brand-title {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: rgba(59, 130, 246, 0.15);
  color: var(--accent-primary);
  border: 1px solid rgba(59, 130, 246, 0.3);
  font-weight: 600;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.db-status-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.db-status-pill:hover {
  border-color: var(--accent-primary);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-success);
  box-shadow: 0 0 8px var(--accent-success);
}

.status-dot.disconnected {
  background: var(--accent-warning);
  box-shadow: 0 0 8px var(--accent-warning);
}

/* Sidebar */
.app-sidebar {
  grid-area: sidebar;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 18px 14px;
}

.nav-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin: 18px 10px 8px 10px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  margin-bottom: 3px;
}

.nav-item:hover {
  background: var(--bg-surface-elevated);
  color: var(--text-primary);
}

.nav-item.active {
  background: rgba(59, 130, 246, 0.12);
  color: var(--accent-primary);
  font-weight: 600;
  border-left: 3px solid var(--accent-primary);
}

.nav-item .icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
}

.nav-item .count-badge {
  margin-left: auto;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  background: var(--bg-surface-elevated);
  color: var(--text-muted);
}

/* Main Content Area */
.app-main {
  grid-area: main;
  overflow-y: auto;
  padding: 24px 32px;
  background: var(--bg-main);
}

/* View Sections */
.view-pane {
  display: none;
  animation: fadeIn 0.25s ease forwards;
}

.view-pane.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

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

.section-title {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.section-subtitle {
  font-size: 13.5px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* Glassmorphic Card Container */
.glass-card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-md);
}

/* Form Controls & Inputs */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-control {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  font-size: 13.5px;
  color: var(--text-primary);
  font-family: inherit;
  transition: all 0.2s ease;
  width: 100%;
}

.form-control:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

/* Filter Grid in Parameter Panel */
.compact-filter-card {
  padding: 10px 16px !important;
  margin-bottom: 12px !important;
  transition: all 0.2s ease;
}

.filter-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
}

.btn-collapse-toggle {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-collapse-toggle:hover {
  background: var(--bg-input);
  border-color: var(--accent-primary);
}

.compact-filter-card.collapsed #parameterCardBody {
  display: none !important;
}

.filter-card-body {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border-color);
}

.parameters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px 14px;
  align-items: flex-end;
}

.parameters-grid .form-group {
  gap: 3px;
}

.parameters-grid .form-label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-secondary);
}

.parameters-grid .form-control {
  padding: 4px 10px;
  font-size: 12.5px;
  height: 32px;
}

/* Reduced Section Header Margin in Report Viewer for maximum data height */
#viewReports .section-header {
  margin-bottom: 10px;
}

#viewReports .section-title {
  font-size: 20px;
}

#viewReports .section-subtitle {
  font-size: 12px;
  margin-top: 2px;
}

/* Expand Table Container for Maximum Vertical Height */
#viewReports .table-container {
  max-height: calc(100vh - 275px);
}

.compact-filter-card.collapsed ~ #gridWrapper .table-container,
.compact-filter-card.collapsed ~ #chartWrapper {
  max-height: calc(100vh - 215px);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
  font-family: inherit;
}

.btn-primary {
  background: var(--accent-gradient);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.35);
}

.btn-primary:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: var(--bg-input);
  border-color: var(--text-muted);
}

.btn-success {
  background: #059669;
  color: #fff;
}

.btn-success:hover {
  background: #047857;
}

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

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

/* KPI Summary Cards Row */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
}

.kpi-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.kpi-value {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  margin-top: 6px;
}

.kpi-sub {
  font-size: 11.5px;
  color: var(--accent-success);
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Toolbar & View Modes */
.report-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 12px;
}

.view-mode-tabs {
  display: flex;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 3px;
}

.view-tab-btn {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
  border: none;
  background: transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  gap: 6px;
}

.view-tab-btn.active {
  background: var(--accent-primary);
  color: #fff;
}

.export-group {
  display: flex;
  gap: 8px;
}

/* High-Performance Table Container */
.table-container {
  width: 100%;
  overflow-x: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  max-height: 580px;
  position: relative;
}

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
  text-align: left;
}

.data-table thead th {
  position: sticky;
  top: 0;
  background: var(--bg-surface-elevated);
  color: var(--text-secondary);
  font-weight: 600;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
  user-select: none;
  cursor: pointer;
  z-index: 10;
}

.data-table thead th:hover {
  color: var(--text-primary);
}

.data-table tbody td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
  white-space: nowrap;
}

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

.data-table tfoot td {
  position: sticky;
  bottom: 0;
  background: var(--bg-surface-elevated);
  font-weight: 700;
  padding: 12px 16px;
  border-top: 2px solid var(--border-color);
  color: var(--text-primary);
  z-index: 9;
}

.align-right { text-align: right; }
.align-center { text-align: center; }

/* Status Badges */
.badge-pill {
  display: inline-block;
  padding: 3px 9px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
}

.badge-success { background: rgba(16, 185, 129, 0.15); color: #10b981; }
.badge-warning { background: rgba(245, 158, 11, 0.15); color: #f59e0b; }
.badge-info { background: rgba(6, 182, 212, 0.15); color: #06b6d4; }
.badge-danger { background: rgba(239, 68, 68, 0.15); color: #ef4444; }

/* Chart Container */
.chart-container {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  height: 420px;
  position: relative;
  display: none;
}

.chart-container.active {
  display: block;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-backdrop.active {
  display: flex;
}

.modal-dialog {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 620px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: modalScale 0.2s ease;
}

@keyframes modalScale {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-title {
  font-size: 17px;
  font-weight: 700;
}

.modal-body {
  padding: 20px 24px;
  max-height: 70vh;
  overflow-y: auto;
}

.modal-footer {
  padding: 14px 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: var(--bg-surface-elevated);
}

/* Notice Bar */
.notice-bar {
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.3);
  color: #fbbf24;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 12.5px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ============================================================================ */
/* Toast Notification System */
/* ============================================================================ */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 999999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast-item {
  pointer-events: auto;
  min-width: 320px;
  max-width: 440px;
  background: var(--bg-surface-elevated);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.4), 0 4px 10px -2px rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: flex-start;
  gap: 12px;
  border-left: 4px solid var(--accent-info);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border-color);
  border-right: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
  animation: slideInRight 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  transition: all 0.3s ease;
}

.toast-item.toast-success {
  border-left-color: var(--accent-success);
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.15) 0%, var(--bg-surface-elevated) 100%);
}

.toast-item.toast-fail, .toast-item.toast-danger, .toast-item.toast-error {
  border-left-color: var(--accent-danger);
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.15) 0%, var(--bg-surface-elevated) 100%);
}

.toast-item.toast-warning {
  border-left-color: var(--accent-warning);
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.15) 0%, var(--bg-surface-elevated) 100%);
}

.toast-item.toast-info {
  border-left-color: var(--accent-info);
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.15) 0%, var(--bg-surface-elevated) 100%);
}

.toast-icon {
  font-size: 20px;
  line-height: 1;
}

.toast-content {
  flex: 1;
}

.toast-title {
  font-weight: 700;
  font-size: 13.5px;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.toast-msg {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.toast-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.toast-close:hover {
  color: var(--text-primary);
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Button Busy Loading Animation */
.btn-spinner {
  display: inline-block;
  width: 13px;
  height: 13px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

.btn-secondary .btn-spinner, .btn-light .btn-spinner {
  border-color: rgba(255, 255, 255, 0.25);
  border-top-color: var(--text-primary);
}

.btn-busy {
  opacity: 0.85 !important;
  cursor: wait !important;
  pointer-events: none !important;
}

/* Drill-Down Interactive Hyperlinks */
.drilldown-link {
  color: var(--accent-primary);
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
  transition: color 0.15s ease, text-shadow 0.15s ease;
}

.drilldown-link:hover {
  color: #60a5fa;
  text-decoration: none;
  text-shadow: 0 0 8px rgba(96, 165, 250, 0.4);
}

/* Application Settings Tabs & Logo Dropzone */
.settings-tab-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  padding: 6px 14px;
  border-radius: var(--radius-md);
  font-weight: 500;
  cursor: pointer;
  font-size: 12.5px;
  transition: all 0.15s ease;
}

.settings-tab-btn:hover {
  background: var(--bg-surface-elevated);
  color: var(--text-primary);
}

.settings-tab-btn.active {
  background: var(--accent-primary);
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.35);
}

#logoDropZone.dragover {
  border-color: #10b981 !important;
  background: rgba(16, 185, 129, 0.08) !important;
}

/* ============================================================================
   KPI DASHBOARDS & WIDGETS
   ============================================================================ */
.dashboard-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 12px 18px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

.dash-controls-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.dash-controls-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 18px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-md);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s ease, border-color 0.2s ease;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.kpi-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: rgba(59, 130, 246, 0.4);
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--accent-gradient);
  opacity: 0.8;
}

.kpi-card.tone-success::before { background: linear-gradient(90deg, #10b981, #059669); }
.kpi-card.tone-warning::before { background: linear-gradient(90deg, #f59e0b, #d97706); }
.kpi-card.tone-danger::before { background: linear-gradient(90deg, #ef4444, #dc2626); }
.kpi-card.tone-cyan::before { background: linear-gradient(90deg, #06b6d4, #0284c7); }
.kpi-card.tone-purple::before { background: linear-gradient(90deg, #8b5cf6, #6366f1); }

.kpi-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 12px;
}

.kpi-title-box {
  flex: 1;
  padding-right: 8px;
}

.kpi-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.kpi-icon-box {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}

.kpi-icon-box.tone-primary { background: rgba(59, 130, 246, 0.15); color: #60a5fa; border: 1px solid rgba(59, 130, 246, 0.3); }
.kpi-icon-box.tone-success { background: rgba(16, 185, 129, 0.15); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.3); }
.kpi-icon-box.tone-warning { background: rgba(245, 158, 11, 0.15); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.3); }
.kpi-icon-box.tone-danger { background: rgba(239, 68, 68, 0.15); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.3); }
.kpi-icon-box.tone-cyan { background: rgba(6, 182, 212, 0.15); color: #38bdf8; border: 1px solid rgba(6, 182, 212, 0.3); }
.kpi-icon-box.tone-purple { background: rgba(139, 92, 246, 0.15); color: #a78bfa; border: 1px solid rgba(139, 92, 246, 0.3); }

.kpi-value-container {
  margin-bottom: 12px;
}

.kpi-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.1;
  font-family: var(--font-mono);
  letter-spacing: -0.5px;
}

.kpi-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
}

.kpi-trend-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-mono);
}

.kpi-trend-badge.trend-up {
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.kpi-trend-badge.trend-down {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.kpi-trend-badge.trend-neutral {
  background: rgba(148, 163, 184, 0.15);
  color: var(--text-muted);
  border: 1px solid rgba(148, 163, 184, 0.3);
}

.kpi-progress-bar-bg {
  width: 100%;
  height: 6px;
  background: var(--bg-surface-elevated);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-top: 8px;
}

.kpi-progress-bar-fill {
  height: 100%;
  background: var(--accent-gradient);
  border-radius: var(--radius-full);
  transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ============================================================================
   GRAFANA-STYLE DYNAMIC CANVAS & WIDE DASHBOARD LAYOUT
   ============================================================================ */

/* Wide Mode Layout */
.app-container.wide-mode {
  grid-template-columns: 60px 1fr !important;
  transition: grid-template-columns 0.25s ease;
}

.app-container.wide-mode .app-sidebar {
  padding: 16px 8px;
  overflow: visible;
}

.app-container.wide-mode .nav-section-title {
  display: none;
}

.app-container.wide-mode .nav-item {
  justify-content: center;
  padding: 10px 0;
  position: relative;
}

.app-container.wide-mode .nav-item span:not(.icon) {
  display: none;
}

.app-container.wide-mode .nav-item .count-badge {
  display: none;
}

.app-container.wide-mode .app-main {
  padding: 16px 20px !important;
}

/* Grafana 12-Column Responsive Dynamic Canvas */
.grafana-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 16px;
  width: 100%;
  margin-bottom: 24px;
}

.grafana-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  position: relative;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  min-width: 0;
}

.grafana-panel:hover {
  border-color: rgba(59, 130, 246, 0.45);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

/* Dynamic Grafana ColSpans (1 to 12) */
.grafana-panel.col-span-1  { grid-column: span 1; }
.grafana-panel.col-span-2  { grid-column: span 2; }
.grafana-panel.col-span-3  { grid-column: span 3; }
.grafana-panel.col-span-4  { grid-column: span 4; }
.grafana-panel.col-span-5  { grid-column: span 5; }
.grafana-panel.col-span-6  { grid-column: span 6; }
.grafana-panel.col-span-7  { grid-column: span 7; }
.grafana-panel.col-span-8  { grid-column: span 8; }
.grafana-panel.col-span-9  { grid-column: span 9; }
.grafana-panel.col-span-10 { grid-column: span 10; }
.grafana-panel.col-span-11 { grid-column: span 11; }
.grafana-panel.col-span-12 { grid-column: span 12; }

@media (max-width: 1280px) {
  .grafana-panel.col-span-3 { grid-column: span 6; }
  .grafana-panel.col-span-4 { grid-column: span 6; }
}

@media (max-width: 860px) {
  .grafana-panel { grid-column: span 12 !important; }
}

/* Panel Header */
.grafana-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
  gap: 8px;
}

.grafana-panel-title-area {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.grafana-panel-drag-handle {
  cursor: grab;
  color: var(--text-muted);
  font-size: 13px;
  user-select: none;
  opacity: 0.6;
}

.grafana-panel-title {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.2px;
}

.grafana-panel-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Drag & Drop Feedback */
.grafana-panel.dragging {
  opacity: 0.35 !important;
  border: 2px dashed var(--accent-primary) !important;
  transform: scale(0.98);
}

.grafana-panel.drag-over {
  border: 2px solid #3b82f6 !important;
  box-shadow: 0 0 20px rgba(59, 130, 246, 0.45) !important;
  transform: scale(1.02);
}

/* Panel Actions Toolbar */
.grafana-panel-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.panel-btn {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  font-size: 11.5px;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  user-select: none;
}

.panel-btn:hover {
  background: rgba(59, 130, 246, 0.15);
  color: var(--accent-primary);
  border-color: rgba(59, 130, 246, 0.4);
}

/* Panel Resize Grip */
.panel-resize-grip {
  position: absolute;
  bottom: 4px;
  right: 6px;
  width: 18px;
  height: 18px;
  cursor: se-resize;
  color: var(--text-muted);
  font-size: 12px;
  user-select: none;
  opacity: 0.4;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  z-index: 10;
}

.panel-resize-grip:hover {
  opacity: 1;
  color: var(--accent-primary);
  transform: scale(1.25);
}

/* Panel Body */
.grafana-panel-body {
  flex: 1;
  position: relative;
  min-height: 140px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.grafana-panel-body canvas {
  width: 100% !important;
  height: 100% !important;
}

/* View Mode vs Design Mode Visibility */
.view-mode-active .dashboard-design-only {
  display: none !important;
}

.view-mode-active .panel-resize-grip,
.view-mode-active .grafana-panel-drag-handle {
  display: none !important;
}

.design-mode-active .grafana-panel {
  border-style: solid;
  cursor: grab;
}

.design-mode-banner {
  background: rgba(59, 130, 246, 0.12);
  border: 1px dashed rgba(59, 130, 246, 0.4);
  color: #60a5fa;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12.5px;
}

/* Charts Grid Legacy/Compatibility */
.dash-charts-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 20px;
  margin-bottom: 24px;
}

.dash-chart-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
}

.dash-chart-card.col-span-12 { grid-column: span 12; }
.dash-chart-card.col-span-8 { grid-column: span 8; }
.dash-chart-card.col-span-6 { grid-column: span 6; }
.dash-chart-card.col-span-4 { grid-column: span 4; }

@media (max-width: 1024px) {
  .dash-chart-card.col-span-8,
  .dash-chart-card.col-span-6,
  .dash-chart-card.col-span-4 {
    grid-column: span 12;
  }
}

.dash-chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-color);
}

.dash-chart-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.dash-chart-subtitle {
  font-size: 11.5px;
  color: var(--text-muted);
}

.dash-chart-body {
  position: relative;
  flex: 1;
  min-height: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ============================================================================
   PLAYLIST PRESENTATION MODE (KIOSK / TV SLIDESHOW)
   ============================================================================ */
.playlist-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-main);
  z-index: 99999;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.playlist-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.playlist-progress-line {
  position: fixed;
  top: 0;
  left: 0;
  height: 4px;
  background: linear-gradient(90deg, #3b82f6, #10b981, #8b5cf6);
  z-index: 100000;
  transition: width 0.25s linear;
  box-shadow: 0 0 10px rgba(59, 130, 246, 0.6);
}

.playlist-controls-bar {
  position: sticky;
  top: 12px;
  margin: 12px 24px 0 24px;
  width: calc(100% - 48px);
  max-width: 100%;
  background: rgba(17, 24, 39, 0.88);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-lg);
  padding: 8px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  z-index: 10000;
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.playlist-controls-bar.fade-out {
  opacity: 0.15;
  transform: translateY(-8px);
}

.playlist-controls-bar:hover {
  opacity: 1 !important;
  transform: translateY(0) !important;
}

.playlist-info-pill {
  display: flex;
  align-items: center;
  gap: 10px;
}

.playlist-indicator-badge {
  background: var(--accent-primary);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: var(--radius-full);
}

.playlist-container-body {
  padding: 16px 24px 32px 24px;
  max-width: 100%;
  width: 100%;
  box-sizing: border-box;
  flex: 1;
}

/* Wide TV Canvas / Wallboard Mode */
.wide-tv-canvas {
  width: 100% !important;
  max-width: 100% !important;
  gap: 16px !important;
}

/* Modal Nav Tabs (e.g. User Permissions Report vs Dashboard) */
.modal-nav-tab {
  padding: 7px 16px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-weight: 600;
  font-size: 12.5px;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.modal-nav-tab:hover {
  color: var(--text-primary);
  background: var(--bg-surface-elevated);
}
.modal-nav-tab.active {
  background: var(--bg-surface-elevated);
  border-color: var(--border-color);
  color: var(--accent-primary);
  box-shadow: var(--shadow-sm);
}

/* Profile Section Permission Switch */
.switch-control {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.switch-control input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  transition: .25s ease;
  border-radius: 24px;
}

.switch-slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  transition: .25s ease;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

input:checked + .switch-slider {
  background-color: #10b981;
  border-color: #10b981;
}

input:focus + .switch-slider {
  box-shadow: 0 0 1px #10b981;
}

input:checked + .switch-slider:before {
  transform: translateX(20px);
}

