/* =========================================================
   SDE MONITOR — Modern Responsive Dashboard Theme
   High-performance, mobile-first design with dark mode
   ApexCharts optimized, responsive grid layout
   ========================================================= */

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600;700&family=IBM+Plex+Sans+Thai:wght@400;500;600;700;800&display=swap');

:root {
  color-scheme: dark;
  /* Color Palette — SD Blue Theme */
  --ink:        #0f1e3d;   /* main background - deep navy */
  --ink-2:      #131d3a;   /* topbar navy */
  --panel:      #162447;   /* card surface */
  --panel-2:    #1c2e58;   /* raised/hover card / input bg */
  --panel-3:    #223568;   /* elevated surface */
  --sidebar:    #0f1e3d;   /* sidebar background */
  --hairline:   #253d6e;   /* subtle border */
  --hairline-2: #2e4d7e;   /* stronger border */
  --paper:      #e8eef8;   /* primary text */
  --muted:      #7a94c0;   /* secondary text */
  --faint:      #4d6a96;   /* tertiary/placeholder text */
  --signal:     #2e6be6;   /* SD Blue — primary accent */
  --signal-dim: #5b8ef0;   /* lighter blue for hover */
  --green:      #34c97a;   /* success/online */
  --amber:      #f0a832;   /* warning/energy */
  --red:        #f05a5a;   /* error/offline */
  --blue:       #2e6be6;   /* primary button */
  --orange:     #f97316;   /* secondary accent */

  /* Typography */
  --font-ui:    'IBM Plex Sans Thai', system-ui, sans-serif;
  --font-mono:  'IBM Plex Mono', monospace;

  /* Spacing */
  --radius:     6px;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html, body {
  height: 100%;
  width: 100%;
}

body {
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  position: relative;
  overflow-x: hidden;
}

a {
  color: inherit;
  text-decoration: none;
  transition: color var(--transition);
}

a:hover {
  color: var(--signal);
}

::selection {
  background: var(--signal-dim);
  color: #fff;
}

:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 2px;
}

/* ==================== TOPBAR ==================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--ink-2);
  border-bottom: 1px solid var(--hairline);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

.topbar-inner {
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 16px;
  height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

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

.brand-logo {
  align-items: center;
  height: 48px;
  object-fit: contain;
}

.brand-word {
  font-family: var(--font-mono);
  font-weight: 700;
  letter-spacing: 0.08em;
  font-size: 13px;
  text-transform: uppercase;
  color: var(--paper);
  display: none;
}

.brand-word b {
  color: var(--signal);
}

@media (min-width: 768px) {
  .brand-word {
    display: block;
  }
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.nav-link {
  font-size: 13px;
  font-weight: 500;
  padding: 8px 12px;
  border-radius: var(--radius);
  color: var(--muted);
  transition: all var(--transition);
  white-space: nowrap;
}

.nav-link:hover {
  color: var(--signal);
  background: var(--panel-2);
}

.nav-link.active {
  color: #ffffff;
  background: rgba(46, 107, 230, 0.15);
}

.nav-dropdown {
  position: relative;
}

.nav-dropdown-toggle {
  border: 0;
  background: transparent;
  cursor: pointer;
}

.nav-dropdown-toggle::after {
  content: '▾';
  font-size: 11px;
  margin-left: 6px;
}

.nav-dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 180px;
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  display: none;
  padding: 6px;
  z-index: 70;
}

.nav-dropdown.open .nav-dropdown-menu {
  display: block;
}

.nav-dropdown-link {
  display: block;
  padding: 8px 10px;
  border-radius: 4px;
  color: var(--muted);
  font-size: 13px;
}

.nav-dropdown-link:hover,
.nav-dropdown-link.active {
  background: var(--panel-2);
  color: var(--signal);
}

.nav-dropdown-link.active {
  color: #ffffff;
}

.nav-cta {
  font-size: 12px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: var(--radius);
  background: var(--signal);
  color: white;
  transition: all var(--transition);
  display: inline-block;
}

.nav-cta:hover {
  background: var(--signal-dim);
  transform: translateY(-2px);
  box-shadow: 0 8px 16px rgba(46, 107, 230, 0.3);
  color: white;
}

.nav-cta-danger {
  background: var(--red);
  color: white;
}

.nav-cta-danger:hover {
  background: #d94444;
  color: white;
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--paper);
  cursor: pointer;
  font-size: 20px;
  padding: 8px;
  border-radius: var(--radius);
}

.menu-toggle:hover {
  background: var(--panel-2);
}

@media (max-width: 768px) {
  .menu-toggle {
    display: block;
  }

  .nav-links {
    display: none;
    position: absolute;
    top: 62px;
    left: 0;
    right: 0;
    background: var(--panel);
    border-bottom: 1px solid var(--hairline);
    flex-direction: column;
    gap: 0;
    padding: 8px;
    justify-content: flex-start;
    z-index: 40;
  }

  .nav-links.active {
    display: flex;
  }

  .nav-link, .nav-cta {
    width: 100%;
    text-align: left;
  }

  .nav-dropdown {
    width: 100%;
  }

  .nav-dropdown-toggle {
    width: 100%;
    text-align: left;
  }

  .nav-dropdown-menu {
    position: static;
    min-width: 0;
    margin-top: 6px;
    box-shadow: none;
  }
}

/* ==================== SIDEBAR ==================== */
.sidebar {
  display: none;
  flex-direction: column;
  width: 220px;
  background: var(--sidebar);
  border-right: 1px solid var(--hairline);
  padding: 24px 0;
  gap: 8px;
  position: sticky;
  top: 62px;
  height: calc(100vh - 62px);
  overflow-y: auto;
}

@media (min-width: 1024px) {
  .sidebar {
    display: flex;
  }
}

.sidebar-section {
  padding: 0 12px;
}

.sidebar-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--faint);
  padding: 8px 12px;
  margin-top: 12px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  margin: 0 4px;
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--muted);
  transition: all var(--transition);
  cursor: pointer;
}

.sidebar-link:hover {
  color: var(--signal);
  background: var(--panel-2);
}

.sidebar-link.active {
  color: #ffffff;
  background: rgba(46, 107, 230, 0.15);
  border-left: 2px solid var(--signal);
  padding-left: 10px;
}

.sidebar-submenu {
  margin-top: 8px;
}

.sidebar-submenu-label {
  cursor: default;
  margin-bottom: 4px;
}

.sidebar-sublink {
  display: flex;
  align-items: center;
  margin-left: 16px;
  margin-bottom: 6px;
  padding: 8px 10px;
  border-radius: var(--radius);
  color: var(--muted);
  border: 1px solid transparent;
  font-size: 13px;
  transition: all var(--transition);
}

.sidebar-sublink:hover {
  color: var(--signal);
  background: var(--panel-2);
}

.sidebar-sublink.active {
  color: #ffffff;
  background: rgba(46, 107, 230, 0.12);
  border-color: rgba(46, 107, 230, 0.25);
}

.sidebar-link i {
  font-size: 16px;
  flex-shrink: 0;
}

/* ==================== MAIN LAYOUT ==================== */
.app-container {
  display: flex;
  min-height: calc(100vh - 62px);
  position: relative;
  z-index: 1;
}

.app-content {
  flex: 1;
  overflow-y: auto;
  background: var(--ink);
}

.content-area {
  max-width: 1600px;
  margin: 0 auto;
  padding: 24px 16px;
}

@media (min-width: 768px) {
  .content-area {
    padding: 32px 24px;
  }
}

/* ==================== DASHBOARD GRID ==================== */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  margin-bottom: 24px;
}

@media (min-width: 768px) {
  .dashboard-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
  }
}

@media (min-width: 1024px) {
  .dashboard-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 1400px) {
  .dashboard-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.dashboard-grid.wide {
  grid-column: 1 / -1;
}

/* ==================== CARDS ==================== */
.card {
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.card:hover {
  border-color: var(--hairline-2);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.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(--paper);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0;
}

.card-subtitle {
  font-size: 11px;
  color: var(--muted);
  font-weight: 400;
  letter-spacing: 0.02em;
}

.card-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 2px;
  background: rgba(46, 107, 230, 0.15);
  color: var(--signal);
}

.card-status.online {
  background: rgba(52, 211, 153, 0.1);
  color: var(--green);
}

.card-status.offline {
  background: rgba(244, 104, 95, 0.1);
  color: var(--red);
}

.led {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 2s infinite;
  box-shadow: 0 0 8px currentColor;
}

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

/* ==================== READOUTS ==================== */
.readout {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 0;
}

.readout-label {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--faint);
  font-weight: 600;
}

.readout-value {
  font-family: var(--font-mono);
  font-size: 24px;
  font-weight: 700;
  color: var(--signal);
  letter-spacing: -0.02em;
}

.readout-unit {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  margin-left: 4px;
}

.readout-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-top: 12px;
}

@media (min-width: 768px) {
  .readout-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* ==================== GAUGES ==================== */
.gauge-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 240px;
  position: relative;
}

.gauge-value {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  z-index: 10;
}

.gauge-value-number {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 700;
  color: var(--signal);
  line-height: 1;
}

.gauge-value-unit {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ==================== CHARTS ==================== */
.chart-container {
  position: relative;
  width: 100%;
  min-height: 300px;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--hairline);
  justify-content: center;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* ==================== TABLES ==================== */
.table-wrapper {
  overflow-x: auto;
  margin: 0 -20px -20px -20px;
  border-top: 1px solid var(--hairline);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead {
  background: var(--panel-2);
  border-bottom: 1px solid var(--hairline);
}

th {
  padding: 12px 20px;
  text-align: left;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 11px;
  color: var(--faint);
}

td {
  padding: 12px 20px;
  border-bottom: 1px solid var(--hairline);
  color: var(--paper);
}

tbody tr:hover {
  background: var(--panel-2);
}

/* ==================== BUTTONS ==================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  font-family: var(--font-ui);
  white-space: nowrap;
}

.btn-primary {
  background: var(--signal);
  color: white;
  border: 1px solid var(--signal);
}

.btn-primary:hover {
  background: var(--signal-dim);
  border-color: var(--signal-dim);
  transform: translateY(-2px);
  box-shadow: 0 8px 16px rgba(46, 107, 230, 0.3);
}

.btn-secondary {
  background: var(--panel-2);
  color: var(--signal);
  border: 1px solid var(--hairline-2);
}

.btn-secondary:hover {
  border-color: var(--signal);
  background: rgba(46, 107, 230, 0.15);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--hairline);
}

.btn-ghost:hover {
  color: var(--signal);
  border-color: var(--signal);
  background: rgba(46, 107, 230, 0.1);
}

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

/* ==================== FORMS ==================== */
.form-group {
  margin-bottom: 20px;
}

label {
  display: block;
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 8px;
  color: var(--paper);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
textarea,
select {
  width: 100%;
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  color: var(--paper);
  font-family: var(--font-ui);
  font-size: 13px;
  transition: all var(--transition);
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--signal);
  background: var(--panel-3);
  box-shadow: 0 0 0 3px rgba(46, 107, 230, 0.18);
}

/* ==================== ALERTS ==================== */
.alert {
  padding: 16px;
  border-radius: var(--radius);
  border-left: 4px solid;
  margin-bottom: 16px;
}

.alert-info {
  background: rgba(46, 107, 230, 0.15);
  border-color: var(--signal);
  color: #93c5fd;
}

.alert-success {
  background: rgba(52, 211, 153, 0.1);
  border-color: var(--green);
  color: #86efac;
}

.alert-warning {
  background: rgba(245, 166, 35, 0.1);
  border-color: var(--amber);
  color: #fcd34d;
}

.alert-error {
  background: rgba(244, 104, 95, 0.1);
  border-color: var(--red);
  color: #f87171;
}

/* ==================== LOADING STATES ==================== */
.skeleton {
  background: linear-gradient(90deg, var(--panel-2) 0%, var(--panel-3) 50%, var(--panel-2) 100%);
  background-size: 200% 100%;
  animation: loading 1.5s infinite;
  border-radius: var(--radius);
}

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

.skeleton-text {
  height: 14px;
  width: 100%;
  margin-bottom: 8px;
}

.skeleton-text.short {
  width: 60%;
}

.skeleton-chart {
  height: 300px;
}

/* ==================== UTILITIES ==================== */
.container {
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 16px;
}

@media (min-width: 768px) {
  .container {
    padding: 0 24px;
  }
}

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

.text-muted {
  color: var(--muted);
}

.text-faint {
  color: var(--faint);
}

.text-error {
  color: var(--red);
}

.text-success {
  color: var(--green);
}

.mt-8 {
  margin-top: 32px;
}

.mb-8 {
  margin-bottom: 32px;
}

.gap-2 {
  gap: 8px;
}

.gap-4 {
  gap: 16px;
}

/* ==================== RESPONSIVE ==================== */
@media (max-width: 640px) {
  .topbar-inner {
    padding: 0 12px;
  }

  .content-area {
    padding: 16px 12px;
  }

  .card {
    padding: 16px;
  }

  .readout-value {
    font-size: 20px;
  }

  .card-title {
    font-size: 12px;
  }

  .dashboard-grid {
    gap: 16px;
  }
}

/* ==================== ACCESSIBILITY ==================== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .led {
    animation: none;
    box-shadow: none;
  }
}

