/* ============================================================
   EAST SOLUTIONS SCADA PLATFORM — MAIN STYLESHEET
   Brand: Dark Navy / Charcoal + Orange Accent
   ============================================================ */

:root {
  /* Brand Colours */
  --brand-orange:       #E8620A;
  --brand-orange-light: #FF7A2F;
  --brand-orange-dark:  #C4520A;
  --brand-navy:         #0D1B2A;
  --brand-navy-mid:     #112233;
  --brand-navy-light:   #1A2E44;

  /* Dark Mode Surface */
  --bg-primary:         #0D1B2A;
  --bg-secondary:       #112233;
  --bg-tertiary:        #1A2E44;
  --bg-card:            #152030;
  --bg-card-hover:      #1E2F45;
  --bg-input:           #0A1520;
  --bg-overlay:         rgba(13, 27, 42, 0.95);

  /* Text */
  --text-primary:       #E8EDF2;
  --text-secondary:     #8FA3B8;
  --text-muted:         #5A7A96;
  --text-inverse:       #0D1B2A;

  /* Status Colours */
  --status-healthy:     #22C55E;
  --status-warning:     #F59E0B;
  --status-critical:    #EF4444;
  --status-advisory:    #3B82F6;
  --status-offline:     #6B7280;
  --status-unknown:     #8B5CF6;

  /* Electrical / SCADA */
  --el-live:            #22C55E;
  --el-dead:            #EF4444;
  --el-open:            #F59E0B;
  --el-closed:          #22C55E;
  --el-busbar:          #60A5FA;
  --el-cable:           #94A3B8;

  /* Borders */
  --border-primary:     #1E3A5A;
  --border-secondary:   #243D5A;
  --border-accent:      #E8620A;

  /* Sidebar */
  --sidebar-width:      260px;
  --sidebar-collapsed:  64px;
  --topbar-height:      60px;

  /* Shadows */
  --shadow-sm:          0 1px 3px rgba(0,0,0,0.4);
  --shadow-md:          0 4px 12px rgba(0,0,0,0.5);
  --shadow-lg:          0 8px 32px rgba(0,0,0,0.6);
  --shadow-glow-orange: 0 0 20px rgba(232,98,10,0.3);
  --shadow-glow-green:  0 0 12px rgba(34,197,94,0.4);
  --shadow-glow-red:    0 0 12px rgba(239,68,68,0.4);

  /* Transitions */
  --transition-fast:    0.15s ease;
  --transition-med:     0.25s ease;
  --transition-slow:    0.4s ease;

  /* Radius */
  --radius-sm:          4px;
  --radius-md:          8px;
  --radius-lg:          12px;
  --radius-xl:          16px;

  /* Typography */
  --font-sans:          'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono:          'JetBrains Mono', 'Courier New', monospace;
}

/* Light mode overrides */
body.light-mode {
  --bg-primary:         #F0F4F8;
  --bg-secondary:       #E2EAF0;
  --bg-tertiary:        #D4E0EC;
  --bg-card:            #FFFFFF;
  --bg-card-hover:      #F5F9FF;
  --bg-input:           #FFFFFF;
  --text-primary:       #0D1B2A;
  --text-secondary:     #3A5A7A;
  --text-muted:         #6A8AA8;
  --border-primary:     #C8D8E8;
  --border-secondary:   #B0C8DC;
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 14px;
  scroll-behavior: smooth;
}

/* Scale up on large screens */
@media (min-width: 1920px) {
  html { font-size: 16px; }
}
@media (min-width: 2560px) {
  html { font-size: 18px; }
}
@media (min-width: 3200px) {
  html { font-size: 20px; }
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--brand-orange);
  text-decoration: none;
  transition: color var(--transition-fast);
}
a:hover { color: var(--brand-orange-light); }

button {
  font-family: var(--font-sans);
  cursor: pointer;
  border: none;
  outline: none;
}

input, select, textarea {
  font-family: var(--font-sans);
  outline: none;
}

/* ============================================================
   APP LAYOUT
   ============================================================ */
#app {
  min-height: 100vh;
}

.app-layout {
  display: flex;
  min-height: 100vh;
}

.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  margin-top: var(--topbar-height);
  min-height: calc(100vh - var(--topbar-height));
  transition: margin-left var(--transition-med);
  background: var(--bg-primary);
}

.main-content.sidebar-collapsed {
  margin-left: var(--sidebar-collapsed);
}

.page-content {
  padding: 24px;
  max-width: 2400px;
}

/* ============================================================
   SCROLLBAR
   ============================================================ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-secondary); }
::-webkit-scrollbar-thumb { background: var(--border-secondary); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--brand-orange); }

/* ============================================================
   TYPOGRAPHY
   ============================================================ */
h1 { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 1.375rem; font-weight: 600; letter-spacing: -0.01em; }
h3 { font-size: 1.125rem; font-weight: 600; }
h4 { font-size: 0.9375rem; font-weight: 600; }
h5 { font-size: 0.8125rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; }

.text-mono { font-family: var(--font-mono); }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-orange { color: var(--brand-orange); }
.text-green { color: var(--status-healthy); }
.text-red { color: var(--status-critical); }
.text-yellow { color: var(--status-warning); }
.text-blue { color: var(--status-advisory); }

/* ============================================================
   PAGE HEADER
   ============================================================ */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-primary);
}

.page-header-left { display: flex; flex-direction: column; gap: 4px; }
.page-header-right { display: flex; align-items: center; gap: 12px; }

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
}

.page-subtitle {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* Breadcrumbs */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.breadcrumb-sep { color: var(--border-secondary); }
.breadcrumb-item { cursor: pointer; transition: color var(--transition-fast); }
.breadcrumb-item:hover { color: var(--brand-orange); }
.breadcrumb-item.active { color: var(--text-secondary); cursor: default; }

/* ============================================================
   GRID LAYOUTS
   ============================================================ */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-5 { grid-template-columns: repeat(5, 1fr); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  padding: 20px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.card:hover {
  border-color: var(--border-secondary);
  box-shadow: var(--shadow-md);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-primary);
}

.card-title {
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
}

.card-accent {
  border-left: 3px solid var(--brand-orange);
}

/* KPI Cards */
.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
  overflow: hidden;
  transition: all var(--transition-fast);
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--brand-orange);
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.kpi-card:hover::before { opacity: 1; }
.kpi-card:hover { border-color: var(--border-secondary); box-shadow: var(--shadow-md); }

.kpi-label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.kpi-value {
  font-size: 1.875rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-primary);
  line-height: 1;
}

.kpi-unit {
  font-size: 0.875rem;
  font-weight: 400;
  color: var(--text-secondary);
  margin-left: 4px;
}

.kpi-trend {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

.kpi-icon {
  position: absolute;
  top: 16px; right: 16px;
  width: 36px; height: 36px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.125rem;
  background: rgba(232,98,10,0.12);
  color: var(--brand-orange);
}

/* ============================================================
   STATUS BADGES
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.badge-healthy  { background: rgba(34,197,94,0.15);  color: var(--status-healthy);  border: 1px solid rgba(34,197,94,0.3); }
.badge-warning  { background: rgba(245,158,11,0.15); color: var(--status-warning);  border: 1px solid rgba(245,158,11,0.3); }
.badge-critical { background: rgba(239,68,68,0.15);  color: var(--status-critical); border: 1px solid rgba(239,68,68,0.3); }
.badge-advisory { background: rgba(59,130,246,0.15); color: var(--status-advisory); border: 1px solid rgba(59,130,246,0.3); }
.badge-offline  { background: rgba(107,114,128,0.15);color: var(--status-offline);  border: 1px solid rgba(107,114,128,0.3); }
.badge-orange   { background: rgba(232,98,10,0.15);  color: var(--brand-orange);    border: 1px solid rgba(232,98,10,0.3); }

.badge-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge-dot.pulse {
  animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.8); }
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-size: 0.8125rem;
  font-weight: 600;
  transition: all var(--transition-fast);
  cursor: pointer;
  border: 1px solid transparent;
  white-space: nowrap;
}

.btn-primary {
  background: var(--brand-orange);
  color: #fff;
  border-color: var(--brand-orange);
}
.btn-primary:hover {
  background: var(--brand-orange-light);
  border-color: var(--brand-orange-light);
  box-shadow: var(--shadow-glow-orange);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--border-secondary);
}
.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: var(--brand-orange);
  color: var(--brand-orange);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}
.btn-ghost:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.btn-danger {
  background: rgba(239,68,68,0.15);
  color: var(--status-critical);
  border-color: rgba(239,68,68,0.3);
}
.btn-danger:hover {
  background: var(--status-critical);
  color: #fff;
}

.btn-success {
  background: rgba(34,197,94,0.15);
  color: var(--status-healthy);
  border-color: rgba(34,197,94,0.3);
}
.btn-success:hover {
  background: var(--status-healthy);
  color: #fff;
}

.btn-sm { padding: 5px 10px; font-size: 0.75rem; }
.btn-lg { padding: 12px 24px; font-size: 0.9375rem; }
.btn-icon { padding: 8px; width: 36px; height: 36px; justify-content: center; }
.btn-icon.btn-sm { padding: 5px; width: 28px; height: 28px; }

/* ============================================================
   FORMS
   ============================================================ */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.form-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

.form-control {
  background: var(--bg-input);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  padding: 9px 12px;
  font-size: 0.875rem;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  width: 100%;
}

.form-control:focus {
  border-color: var(--brand-orange);
  box-shadow: 0 0 0 3px rgba(232,98,10,0.15);
}

.form-control::placeholder { color: var(--text-muted); }

select.form-control {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%235A7A96' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

/* ============================================================
   TABLES
   ============================================================ */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-primary);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

thead tr {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-primary);
}

thead th {
  padding: 10px 14px;
  text-align: left;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--border-primary);
  transition: background var(--transition-fast);
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg-card-hover); }

tbody td {
  padding: 11px 14px;
  color: var(--text-primary);
  vertical-align: middle;
}

/* ============================================================
   TABS
   ============================================================ */
.tabs {
  display: flex;
  gap: 2px;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  padding: 3px;
  border: 1px solid var(--border-primary);
}

.tab-btn {
  padding: 7px 16px;
  border-radius: 6px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.tab-btn:hover { color: var(--text-primary); background: var(--bg-tertiary); }
.tab-btn.active {
  background: var(--brand-orange);
  color: #fff;
  font-weight: 600;
}

/* ============================================================
   MODALS
   ============================================================ */
.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;
  animation: fadeIn 0.2s ease;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-secondary);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.25s ease;
}

.modal-lg { max-width: 800px; }
.modal-xl { max-width: 1100px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-primary);
}

.modal-title { font-size: 1rem; font-weight: 600; }

.modal-body { padding: 24px; }
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--border-primary);
}

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-20px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.animate-fade { animation: fadeIn 0.3s ease; }
.animate-slide { animation: slideIn 0.3s ease; }
.animate-spin { animation: spin 1s linear infinite; }

/* ============================================================
   UTILITY
   ============================================================ */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.justify-end { justify-content: flex-end; }
.gap-4 { gap: 4px; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.gap-24 { gap: 24px; }
.w-full { width: 100%; }
.h-full { height: 100%; }
.relative { position: relative; }
.absolute { position: absolute; }
.hidden { display: none !important; }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.p-0 { padding: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cursor-pointer { cursor: pointer; }
.select-none { user-select: none; }
.opacity-50 { opacity: 0.5; }

/* Divider */
.divider {
  height: 1px;
  background: var(--border-primary);
  margin: 16px 0;
}

/* Loading spinner */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border-secondary);
  border-top-color: var(--brand-orange);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  color: var(--text-muted);
  gap: 12px;
}

.empty-state-icon { font-size: 3rem; opacity: 0.4; }
.empty-state-title { font-size: 1rem; font-weight: 600; color: var(--text-secondary); }
.empty-state-text { font-size: 0.8125rem; max-width: 320px; }

/* Desktop-only feature message (shown when a restricted page is opened on mobile) */
.desktop-only-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 16px;
  padding: 48px 20px;
  min-height: 60vh;
}

.desktop-only-icon {
  font-size: 3.5rem;
  opacity: 0.7;
}

.desktop-only-title {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text-primary);
  max-width: 420px;
}

.desktop-only-text {
  font-size: 0.875rem;
  color: var(--text-secondary);
  max-width: 420px;
  line-height: 1.6;
}

.desktop-only-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 320px;
  margin-top: 8px;
}

.desktop-only-actions .btn {
  width: 100%;
  justify-content: center;
}

/* Toast notifications */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border-secondary);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 280px;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.25s ease;
  font-size: 0.8125rem;
}

.toast-success { border-left: 3px solid var(--status-healthy); }
.toast-error   { border-left: 3px solid var(--status-critical); }
.toast-warning { border-left: 3px solid var(--status-warning); }
.toast-info    { border-left: 3px solid var(--status-advisory); }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1200px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-5 { grid-template-columns: repeat(3, 1fr); }
}

/* ── Tablet ── */
@media (max-width: 900px) {
  :root {
    --sidebar-width: 0px;
  }

  .main-content {
    margin-left: 0 !important;
  }

  .topbar {
    left: 0 !important;
  }

  /* Sidebar becomes an overlay drawer — styles in components.css */

  .sidebar.mobile-open {
    transform: translateX(0) !important;
  }

  /* Overlay backdrop */
  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
    backdrop-filter: blur(2px);
  }

  .sidebar-backdrop.active {
    display: block;
  }

  /* Hamburger button in topbar */
  .mobile-menu-btn {
    display: flex !important;
  }

  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .page-content { padding: 16px; }

  /* Topbar adjustments */
  .topbar-search {
    display: none;
  }

  .site-selector {
    min-width: unset;
    max-width: 200px;
  }

  .user-info {
    display: none;
  }

  /* Sidebar footer toggle not needed on mobile */
  .sidebar-footer {
    display: none;
  }
}

/* ── Mobile ── */
@media (max-width: 600px) {
  html {
    font-size: 13px;
  }

  .grid-2, .grid-3, .grid-4, .grid-5 {
    grid-template-columns: 1fr;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .page-header-right {
    width: 100%;
    flex-wrap: wrap;
  }

  .page-content {
    padding: 12px;
  }

  /* Topbar compact */
  .topbar {
    padding: 0 12px;
    height: 52px;
  }

  .main-content {
    margin-top: 52px;
    min-height: calc(100vh - 52px);
  }

  .site-selector {
    padding: 4px 8px;
    font-size: 0.75rem;
    max-width: 160px;
  }

  .site-selector span:first-child {
    display: none;
  }

  .topbar-btn {
    width: 44px;
    height: 44px;
    min-height: 44px;
    font-size: 0.875rem;
  }

  .user-menu {
    padding: 4px 6px;
    gap: 4px;
  }

  .user-avatar {
    width: 24px;
    height: 24px;
    font-size: 0.5625rem;
  }

  .live-indicator {
    display: none;
  }

  /* Cards compact */
  .card {
    padding: 14px;
  }

  .kpi-card {
    padding: 14px;
  }

  .kpi-value {
    font-size: 1.5rem;
  }

  /* Modals full-screen on mobile */
  .modal-overlay {
    padding: 0;
    align-items: flex-end;
  }

  .modal, .modal-lg, .modal-xl {
    max-width: 100%;
    max-height: 100vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    animation: slideUpMobile 0.25s ease;
  }

  .modal-header {
    padding: 16px;
    position: sticky;
    top: 0;
    background: var(--bg-card);
    z-index: 10;
  }

  .modal-body {
    padding: 16px;
  }

  .modal-footer {
    padding: 12px 16px;
    position: sticky;
    bottom: 0;
    background: var(--bg-card);
    z-index: 10;
    flex-direction: column;
    gap: 10px;
  }

  /* On mobile, modal action buttons go full-width and stacked in natural DOM
     order. Modal footers are built [secondary…, primary], so the primary
     action lands at the bottom where the thumb naturally rests — the
     conventional, learnable pattern. Large 48px targets throughout. */
  .modal-footer .btn {
    width: 100%;
    justify-content: center;
    min-height: 48px;
    font-size: 0.9375rem;
  }

  /* Confirm dialog (Helpers.confirm — used by the CB Open/Close two-step flow).
     Make Confirm the large, prominent bottom action and de-emphasise Cancel as
     a lighter ghost-style link above it. The big primary target plus a visually
     distinct, smaller Cancel makes the intended action obvious and reduces the
     chance of an accidental breaker operation. */
  .confirm-footer #confirm-btn {
    order: 2;
    min-height: 54px;
    font-size: 1rem;
    font-weight: 700;
  }

  .confirm-footer .confirm-cancel {
    order: 1;
    background: transparent;
    border-color: transparent;
    color: var(--text-secondary);
    min-height: 40px;
    font-weight: 500;
  }

  /* Buttons touch-friendly */
  .btn {
    min-height: 40px;
    padding: 10px 16px;
  }

  .btn-sm {
    min-height: 34px;
    padding: 6px 12px;
  }

  /* Tables scroll horizontally */
  .table-wrapper {
    -webkit-overflow-scrolling: touch;
  }

  table {
    font-size: 0.75rem;
  }

  thead th, tbody td {
    padding: 8px 10px;
  }

  /* ── Card-per-row table pattern ──
     Reusable: add class "table-cards" to a <table> and give each <td> a
     data-label="…" attribute. On mobile the table header is hidden and every
     row becomes a self-contained card with the column label shown beside each
     value. Used for alarms, audit log, recent alarms, etc. — avoids the
     horizontal-scroll-a-wide-table experience on small screens. */
  .table-cards {
    border-collapse: separate;
    border-spacing: 0;
  }

  .table-wrapper:has(.table-cards) {
    border: none;
    border-radius: 0;
    overflow: visible;
  }

  .table-cards thead {
    /* Visually hidden but kept for accessibility/screen readers */
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .table-cards,
  .table-cards tbody,
  .table-cards tr,
  .table-cards td {
    display: block;
    width: 100%;
  }

  .table-cards tbody tr {
    background: var(--bg-card);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    padding: 8px 14px;
    margin-bottom: 10px;
  }

  .table-cards tbody tr:last-child { margin-bottom: 0; }
  .table-cards tbody tr:hover { background: var(--bg-card); }

  .table-cards td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 7px 0;
    border: none;
    border-bottom: 1px solid var(--border-primary);
    text-align: right;
    min-height: 36px;
  }

  .table-cards td:last-child { border-bottom: none; }

  .table-cards td::before {
    content: attr(data-label);
    font-size: 0.625rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    text-align: left;
    flex-shrink: 0;
  }

  /* Cells flagged as the row's primary content span full width, label above */
  .table-cards td.cell-primary {
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
    white-space: normal;
  }

  /* Toast at top on mobile */
  .toast-container {
    bottom: auto;
    top: 60px;
    right: 12px;
    left: 12px;
  }

  .toast {
    min-width: unset;
    max-width: 100%;
    width: 100%;
  }

  /* Tabs scrollable */
  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
  }

  .tab-btn {
    flex-shrink: 0;
    min-height: 44px;
  }

  /* Power flow scroll */
  .power-flow {
    padding: 16px 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    justify-content: flex-start;
  }

  /* Form controls larger touch targets */
  .form-control {
    padding: 11px 12px;
    font-size: 1rem;
  }

  /* Page title smaller */
  .page-title {
    font-size: 1.25rem;
  }

  h1 { font-size: 1.375rem; }
  h2 { font-size: 1.125rem; }

  /* Breadcrumb wrap */
  .breadcrumb {
    flex-wrap: wrap;
  }

  /* Alarm banner compact */
  .alarm-banner {
    padding: 8px 12px;
    gap: 8px;
    font-size: 0.75rem;
  }

  /* Empty state compact */
  .empty-state {
    padding: 40px 16px;
  }

  /* Stat rows */
  .stat-row {
    font-size: 0.75rem;
    padding: 6px 0;
  }

  /* Site cards */
  .site-card {
    padding: 16px;
  }

  .site-card-kpis {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  /* Asset items */
  .asset-item {
    padding: 10px 12px;
    gap: 10px;
  }

  .asset-item-values {
    flex-direction: column;
    gap: 4px;
    align-items: flex-end;
  }

  /* Gateway cards */
  .card-accent > div:first-child {
    flex-direction: column;
    gap: 8px;
  }
}

/* ── Small phones ── */
@media (max-width: 380px) {
  html {
    font-size: 12px;
  }

  .page-content {
    padding: 8px;
  }

  .kpi-value {
    font-size: 1.25rem;
  }

  .site-card-kpis {
    grid-template-columns: 1fr;
  }
}

/* Mobile slide-up animation */
@keyframes slideUpMobile {
  from { opacity: 0; transform: translateY(100%); }
  to { opacity: 1; transform: translateY(0); }
}

/* Hamburger button — hidden on desktop */
.mobile-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: transparent;
  border: 1px solid var(--border-primary);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1.25rem;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.mobile-menu-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--brand-orange);
}

/* Sidebar backdrop — only exists on mobile */
.sidebar-backdrop {
  display: none;
}
