/* ============================================================
   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;
}

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: 1600px;
}

/* ============================================================
   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; }

/* 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); }
}

@media (max-width: 900px) {
  .main-content { margin-left: 0; }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .page-content { padding: 16px; }
}

@media (max-width: 600px) {
  .grid-2, .grid-3, .grid-4, .grid-5 { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; gap: 12px; }
}
