/* ============================================================
   EIMS Platform – Design System
   Industrial/Utilitarian dark theme with electric accent
   ============================================================ */

/* ── Fonts ── */
@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── CSS Variables ── */
:root {
  /* Core palette - dark */
  --bg-canvas:    #0a0e17;
  --bg-surface:   #111827;
  --bg-elevated:  #1a2235;
  --bg-overlay:   #222d42;
  --border:       #2a3750;
  --border-focus: #00d4aa;

  /* Text */
  --text-primary:   #e8edf5;
  --text-secondary: #8899b4;
  --text-muted:     #4a5a72;
  --text-inverse:   #0a0e17;

  /* Brand */
  --accent:         #00d4aa;
  --accent-dim:     rgba(0, 212, 170, 0.15);
  --accent-hover:   #00f0c0;
  --brand-blue:     #0088ff;
  --brand-blue-dim: rgba(0, 136, 255, 0.15);

  /* Status colors */
  --status-online:   #10b981;
  --status-offline:  #6b7280;
  --status-warning:  #f59e0b;
  --status-critical: #ef4444;
  --status-info:     #3b82f6;

  /* Alarm severity */
  --alarm-critical: #ef4444;
  --alarm-major:    #f97316;
  --alarm-minor:    #eab308;
  --alarm-info:     #3b82f6;

  /* Sidebar */
  --sidebar-width:         240px;
  --sidebar-collapsed:     64px;
  --sidebar-bg:            #080d16;
  --sidebar-border:        #1a2235;

  /* Layout */
  --topbar-height: 60px;
  --radius-sm:     6px;
  --radius-md:     10px;
  --radius-lg:     16px;
  --radius-xl:     24px;

  /* Shadows */
  --shadow-sm:  0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md:  0 4px 16px rgba(0,0,0,0.5);
  --shadow-lg:  0 10px 40px rgba(0,0,0,0.6);
  --shadow-glow: 0 0 20px rgba(0, 212, 170, 0.2);

  /* Transitions */
  --t-fast: 120ms ease;
  --t-med:  200ms ease;
  --t-slow: 350ms ease;

  /* Typography */
  --font-sans: 'Space Grotesk', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

/* Light theme overrides */
[data-theme="light"] {
  --bg-canvas:    #f0f4fb;
  --bg-surface:   #ffffff;
  --bg-elevated:  #f8fafd;
  --bg-overlay:   #eef2f9;
  --border:       #dde3ef;
  --text-primary:   #0f1729;
  --text-secondary: #4a5a72;
  --text-muted:     #8899b4;
  --sidebar-bg:     #0a0e17;
  --shadow-sm:  0 1px 3px rgba(0,0,0,0.08);
  --shadow-md:  0 4px 16px rgba(0,0,0,0.1);
  --shadow-lg:  0 10px 40px rgba(0,0,0,0.15);
}

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; scroll-behavior: smooth; }

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

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: fixed;
  left: 0; top: 0;
  z-index: 200;
  transition: width var(--t-slow);
  overflow: hidden;
}

.sidebar.collapsed { width: var(--sidebar-collapsed); }
.sidebar.collapsed .logo-text,
.sidebar.collapsed .tenant-name,
.sidebar.collapsed .nav-item span,
.sidebar.collapsed .nav-badge { display: none; }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--sidebar-border);
  min-height: 60px;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-text {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--accent);
  text-transform: uppercase;
}

.sidebar-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: color var(--t-fast);
  line-height: 1;
}
.sidebar-toggle:hover { color: var(--text-primary); }

.sidebar-tenant {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--sidebar-border);
}
.tenant-logo { width: 20px; height: 20px; object-fit: contain; border-radius: 4px; }
.tenant-name { font-size: 12px; font-weight: 500; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.nav-divider {
  height: 1px;
  background: var(--sidebar-border);
  margin: 8px 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: all var(--t-fast);
  white-space: nowrap;
  position: relative;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.nav-item i { font-size: 16px; flex-shrink: 0; width: 18px; text-align: center; }
.nav-item:hover { background: rgba(255,255,255,0.05); color: var(--text-primary); }
.nav-item.active { background: var(--accent-dim); color: var(--accent); }
.nav-item.active i { color: var(--accent); }
.nav-item--logout:hover { color: var(--alarm-critical); background: rgba(239,68,68,0.08); }

.nav-badge {
  margin-left: auto;
  background: var(--alarm-critical);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  min-width: 18px;
  text-align: center;
}

.sidebar-footer {
  padding: 8px;
  border-top: 1px solid var(--sidebar-border);
}

/* ── Main Wrapper ── */
.main-wrapper {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left var(--t-slow);
}
.sidebar.collapsed ~ .main-wrapper { margin-left: var(--sidebar-collapsed); }

/* ── Topbar ── */
.topbar {
  height: var(--topbar-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 12px;
}

.topbar-left { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.btn-icon {
  background: none;
  border: 1px solid transparent;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 7px;
  border-radius: var(--radius-sm);
  transition: all var(--t-fast);
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-icon:hover { color: var(--text-primary); background: var(--bg-elevated); border-color: var(--border); }

/* Breadcrumb */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  min-width: 0;
}
.breadcrumb a { color: var(--text-secondary); text-decoration: none; }
.breadcrumb a:hover { color: var(--accent); }
.bc-sep { color: var(--text-muted); }
.bc-current { color: var(--text-primary); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Topbar search */
.topbar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 6px 12px;
  cursor: pointer;
  transition: border-color var(--t-fast);
  width: 220px;
}
.topbar-search:hover { border-color: var(--accent); }
.topbar-search i { color: var(--text-muted); font-size: 14px; }
.topbar-search input { background: none; border: none; outline: none; color: var(--text-secondary); font-family: var(--font-sans); font-size: 13px; width: 100%; cursor: pointer; }
.topbar-search input::placeholder { color: var(--text-muted); }
.topbar-search kbd { font-family: var(--font-mono); font-size: 10px; color: var(--text-muted); background: var(--bg-canvas); border: 1px solid var(--border); padding: 1px 5px; border-radius: 4px; white-space: nowrap; }

/* Alarm bell */
.topbar-alarm { position: relative; }
.alarm-badge {
  position: absolute;
  top: 2px; right: 2px;
  background: var(--alarm-critical);
  color: white;
  font-size: 9px;
  font-weight: 700;
  width: 16px; height: 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* User menu */
.user-menu { position: relative; }
.user-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: 1px solid transparent;
  padding: 5px 8px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--t-fast);
}
.user-trigger:hover { background: var(--bg-elevated); border-color: var(--border); }
.user-avatar {
  width: 30px; height: 30px;
  background: linear-gradient(135deg, var(--accent), var(--brand-blue));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-inverse);
  flex-shrink: 0;
}
.user-info { text-align: left; display: none; }
@media (min-width: 900px) { .user-info { display: block; } }
.user-name { display: block; font-size: 13px; font-weight: 600; color: var(--text-primary); line-height: 1.2; }
.user-role { display: block; font-size: 11px; color: var(--text-muted); }
.user-trigger i { color: var(--text-muted); font-size: 12px; }

.user-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  min-width: 180px;
  box-shadow: var(--shadow-lg);
  padding: 6px;
  display: none;
  z-index: 300;
}
.user-menu.open .user-dropdown { display: block; }
.user-dropdown a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  transition: all var(--t-fast);
}
.user-dropdown a:hover { background: var(--bg-canvas); color: var(--text-primary); }
.dropdown-divider { height: 1px; background: var(--border); margin: 4px 0; }

/* ── Flash Messages ── */
.flash {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  margin: 12px 20px 0;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  font-weight: 500;
  border-left: 3px solid;
  animation: slideIn 0.2s ease;
}
.flash--success { background: rgba(16,185,129,0.1); border-color: var(--status-online); color: #6ee7b7; }
.flash--error   { background: rgba(239,68,68,0.1);  border-color: var(--alarm-critical); color: #fca5a5; }
.flash--warning { background: rgba(245,158,11,0.1); border-color: var(--status-warning); color: #fcd34d; }
.flash--info    { background: rgba(59,130,246,0.1); border-color: var(--status-info);    color: #93c5fd; }
.flash-close { margin-left: auto; background: none; border: none; cursor: pointer; color: inherit; opacity: 0.6; padding: 2px; line-height: 1; }
.flash-close:hover { opacity: 1; }
@keyframes slideIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

/* ── Page Content ── */
.page-content {
  flex: 1;
  padding: 24px;
  max-width: 1600px;
  width: 100%;
}

/* ── Page Header ── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.page-header-left {}
.page-title { font-size: 22px; font-weight: 700; color: var(--text-primary); line-height: 1.2; }
.page-subtitle { font-size: 13px; color: var(--text-secondary); margin-top: 3px; }
.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ── Cards ── */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
}
.card-title { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.card-actions { display: flex; align-items: center; gap: 8px; }

/* ── KPI Cards ── */
.kpi-grid {
  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);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
  transition: border-color var(--t-med), transform var(--t-fast);
}
.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--kpi-color, var(--accent));
}
.kpi-card:hover { border-color: var(--kpi-color, var(--accent)); transform: translateY(-1px); }

.kpi-label { font-size: 11.5px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 8px; }
.kpi-value { font-size: 28px; font-weight: 700; color: var(--text-primary); line-height: 1; margin-bottom: 6px; font-variant-numeric: tabular-nums; }
.kpi-value--mono { font-family: var(--font-mono); }
.kpi-meta { font-size: 12px; color: var(--text-secondary); display: flex; align-items: center; gap: 4px; }
.kpi-meta .trend-up   { color: var(--status-online); }
.kpi-meta .trend-down { color: var(--alarm-critical); }
.kpi-icon {
  position: absolute;
  top: 16px; right: 16px;
  width: 36px; height: 36px;
  background: rgba(var(--kpi-rgb, 0,212,170), 0.12);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--kpi-color, var(--accent));
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 18px;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--t-fast);
  border: 1px solid transparent;
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.4;
}
.btn i { font-size: 15px; }

.btn-primary {
  background: var(--accent);
  color: var(--text-inverse);
  border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); box-shadow: 0 0 16px rgba(0,212,170,0.35); }

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--bg-overlay); border-color: var(--accent); color: var(--accent); }

.btn-danger {
  background: rgba(239,68,68,0.1);
  color: var(--alarm-critical);
  border-color: rgba(239,68,68,0.3);
}
.btn-danger:hover { background: var(--alarm-critical); color: white; }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--bg-elevated); color: var(--text-primary); }

.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }
.btn-icon-only { padding: 8px; }

/* ── Tables ── */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.data-table thead th {
  background: var(--bg-elevated);
  padding: 11px 16px;
  text-align: left;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr { transition: background var(--t-fast); }
.data-table tbody tr:hover { background: var(--bg-elevated); }

/* ── Status Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}
.badge::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.badge-online    { background: rgba(16,185,129,0.12); color: #10b981; }
.badge-offline   { background: rgba(107,114,128,0.12); color: #9ca3af; }
.badge-warning   { background: rgba(245,158,11,0.12); color: #f59e0b; }
.badge-critical  { background: rgba(239,68,68,0.12);  color: #ef4444; }
.badge-info      { background: rgba(59,130,246,0.12); color: #60a5fa; }
.badge-maintenance { background: rgba(139,92,246,0.12); color: #a78bfa; }

.severity-critical { background: rgba(239,68,68,0.12); color: #ef4444; border: 1px solid rgba(239,68,68,0.25); }
.severity-major    { background: rgba(249,115,22,0.12); color: #f97316; border: 1px solid rgba(249,115,22,0.25); }
.severity-minor    { background: rgba(234,179,8,0.12); color: #eab308; border: 1px solid rgba(234,179,8,0.25); }
.severity-info     { background: rgba(59,130,246,0.12); color: #3b82f6; border: 1px solid rgba(59,130,246,0.25); }

/* ── Forms ── */
.form-group { margin-bottom: 18px; }
.form-label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}
.form-label .required { color: var(--alarm-critical); margin-left: 3px; }

.form-control {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 9px 12px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13.5px;
  transition: border-color var(--t-fast);
  outline: none;
  appearance: none;
}
.form-control:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0,212,170,0.1); }
.form-control::placeholder { color: var(--text-muted); }
.form-control:disabled { opacity: 0.5; cursor: not-allowed; }

select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }

.form-mono { font-family: var(--font-mono); font-size: 12.5px; }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.form-error { font-size: 12px; color: var(--alarm-critical); margin-top: 4px; }

.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* Toggles */
.toggle-group {
  display: flex;
  gap: 4px;
  background: var(--bg-canvas);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 4px;
}
.toggle-option {
  flex: 1;
  text-align: center;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all var(--t-fast);
  border: none;
  background: none;
}
.toggle-option.active { background: var(--accent); color: var(--text-inverse); }

/* Switch */
.switch-wrap { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.switch {
  position: relative;
  width: 40px; height: 22px;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 999px;
  transition: background var(--t-fast);
}
.switch-slider::before {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  left: 3px; top: 3px;
  background: white;
  border-radius: 50%;
  transition: transform var(--t-fast);
}
.switch input:checked + .switch-slider { background: var(--accent); }
.switch input:checked + .switch-slider::before { transform: translateX(18px); }
.switch-label { font-size: 13.5px; color: var(--text-primary); }

/* ── Pagination ── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-secondary);
  flex-wrap: wrap;
  gap: 12px;
}
.pagination-pages { display: flex; gap: 4px; }
.page-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  transition: all var(--t-fast);
}
.page-link:hover { border-color: var(--accent); color: var(--accent); }
.page-link.active { background: var(--accent); border-color: var(--accent); color: var(--text-inverse); font-weight: 700; }
.page-link.disabled { opacity: 0.3; pointer-events: none; }

/* ── Filters Bar ── */
.filters-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.filter-search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 7px 12px;
  flex: 1;
  min-width: 200px;
}
.filter-search i { color: var(--text-muted); font-size: 14px; flex-shrink: 0; }
.filter-search input { background: none; border: none; outline: none; color: var(--text-primary); font-family: var(--font-sans); font-size: 13.5px; width: 100%; }
.filter-select {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 7px 12px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13.5px;
  outline: none;
  cursor: pointer;
  min-width: 140px;
}
.filter-select:focus { border-color: var(--accent); }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-med);
}
.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  transform: translateY(20px);
  transition: transform var(--t-med);
}
.modal-overlay.open .modal { transform: translateY(0); }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 16px; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 4px; border-radius: var(--radius-sm); }
.modal-close:hover { color: var(--text-primary); }
.modal-body { padding: 20px 24px; }
.modal-footer { display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding: 16px 24px; border-top: 1px solid var(--border); }

/* Modal sizes */
.modal-lg { max-width: 900px; }
.modal-xl { max-width: 1100px; }

/* ── Tabs ── */
.tabs { border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tabs-list { display: flex; gap: 0; }
.tab-btn {
  padding: 10px 18px;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all var(--t-fast);
}
.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Device / Status indicators ── */
.status-dot {
  display: inline-flex;
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot--online   { background: var(--status-online); box-shadow: 0 0 0 3px rgba(16,185,129,0.2); animation: pulse 2s infinite; }
.status-dot--offline  { background: var(--status-offline); }
.status-dot--warning  { background: var(--status-warning); box-shadow: 0 0 0 3px rgba(245,158,11,0.2); }
.status-dot--critical { background: var(--alarm-critical); box-shadow: 0 0 0 3px rgba(239,68,68,0.2); animation: pulse 1s infinite; }

@keyframes pulse {
  0%,100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ── Section headers ── */
.section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.section-title { font-size: 14px; font-weight: 700; color: var(--text-primary); }
.section-title-accent { color: var(--accent); }

/* ── Progress / Gauge bars ── */
.progress-bar {
  height: 6px;
  background: var(--bg-canvas);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.5s ease;
}
.progress-fill--warning { background: var(--status-warning); }
.progress-fill--critical { background: var(--alarm-critical); }

/* ── Port type chips ── */
.port-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-family: var(--font-mono);
}
.port-rs232  { background: rgba(139,92,246,0.15); color: #a78bfa; border: 1px solid rgba(139,92,246,0.3); }
.port-rs485  { background: rgba(0,136,255,0.15);  color: #60a5fa; border: 1px solid rgba(0,136,255,0.3); }
.port-lan    { background: rgba(0,212,170,0.15);  color: #00d4aa; border: 1px solid rgba(0,212,170,0.3); }
.port-wifi   { background: rgba(245,158,11,0.15); color: #f59e0b; border: 1px solid rgba(245,158,11,0.3); }
.port-digital_io { background: rgba(249,115,22,0.15); color: #f97316; border: 1px solid rgba(249,115,22,0.3); }
.port-analog_in  { background: rgba(16,185,129,0.15); color: #10b981; border: 1px solid rgba(16,185,129,0.3); }

/* ── Code / Mono display ── */
.mono-value {
  font-family: var(--font-mono);
  font-size: 12.5px;
  background: var(--bg-canvas);
  border: 1px solid var(--border);
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  color: var(--accent);
}

/* ── Telemetry value cards ── */
.telemetry-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}
.telemetry-item {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  transition: border-color var(--t-fast);
}
.telemetry-item:hover { border-color: var(--accent); }
.telemetry-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-muted); margin-bottom: 6px; }
.telemetry-value { font-size: 22px; font-weight: 700; font-family: var(--font-mono); color: var(--text-primary); line-height: 1; }
.telemetry-unit  { font-size: 11.5px; color: var(--text-secondary); margin-top: 3px; }

/* ── Search overlay ── */
.search-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  backdrop-filter: blur(6px);
  z-index: 2000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 80px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-med);
}
.search-overlay.open { opacity: 1; pointer-events: all; }
.search-modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 580px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.search-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.search-header i { color: var(--text-muted); font-size: 16px; }
.search-header input { flex: 1; background: none; border: none; outline: none; color: var(--text-primary); font-family: var(--font-sans); font-size: 15px; }
.search-esc { font-family: var(--font-mono); font-size: 11px; color: var(--text-muted); background: var(--bg-elevated); border: 1px solid var(--border); padding: 2px 7px; border-radius: 4px; cursor: pointer; }
.search-results { padding: 8px; max-height: 400px; overflow-y: auto; }
.search-hint { padding: 20px; text-align: center; color: var(--text-muted); font-size: 13px; }
.search-result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--t-fast);
  text-decoration: none;
  color: var(--text-primary);
}
.search-result-item:hover { background: var(--bg-elevated); }
.search-result-icon { width: 32px; height: 32px; background: var(--bg-elevated); border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center; color: var(--accent); font-size: 15px; flex-shrink: 0; }
.search-result-text .name { font-size: 13.5px; font-weight: 500; }
.search-result-text .meta { font-size: 12px; color: var(--text-secondary); }

/* ── Responsive ── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.mobile-open { transform: translateX(0); }
  .main-wrapper { margin-left: 0 !important; }
  .page-content { padding: 16px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row-2, .form-row-3 { grid-template-columns: 1fr; }
  .topbar-search { display: none; }
}

/* ── Utility classes ── */
.text-muted     { color: var(--text-muted) !important; }
.text-secondary { color: var(--text-secondary) !important; }
.text-accent    { color: var(--accent) !important; }
.text-success   { color: var(--status-online) !important; }
.text-warning   { color: var(--status-warning) !important; }
.text-danger    { color: var(--alarm-critical) !important; }
.font-mono      { font-family: var(--font-mono) !important; }
.font-bold      { font-weight: 700 !important; }
.truncate       { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.gap-3 { gap: 24px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* ── Scrollbar styling ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Loading spinner */
.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-secondary);
}
.empty-state i { font-size: 40px; color: var(--text-muted); margin-bottom: 12px; display: block; }
.empty-state h3 { font-size: 16px; font-weight: 600; margin-bottom: 8px; color: var(--text-primary); }
.empty-state p { font-size: 13.5px; max-width: 320px; margin: 0 auto 20px; }

/* Tooltip */
[data-tooltip] { position: relative; }
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-overlay);
  color: var(--text-primary);
  font-size: 12px;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--t-fast);
  z-index: 100;
}
[data-tooltip]:hover::after { opacity: 1; }
