/* =================================================================
   RoboBurger Platform — Design System
   ================================================================= */

:root {
  /* Brand colors */
  --rb-red:       #D32F2F;
  --rb-red-dark:  #B71C1C;
  --rb-red-light: #FFCDD2;
  --rb-orange:    #FF6F00;
  --rb-yellow:    #FFC107;
  --rb-green:     #43A047;
  --rb-green-light: #C8E6C9;
  --rb-blue:      #1976D2;
  --rb-blue-light: #BBDEFB;

  /* Neutrals */
  --bg-primary:   #0F1117;
  --bg-secondary: #1A1D27;
  --bg-card:      #22252F;
  --bg-card-hover:#2A2D3A;
  --border:       #333642;
  --text-primary: #EAEDF3;
  --text-secondary:#8B90A0;
  --text-muted:   #5A5E6E;

  /* Layout */
  --sidebar-width: 240px;
  --header-height: 56px;
  --radius:        8px;
  --radius-sm:     4px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--rb-blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* =================================================================
   Layout
   ================================================================= */
.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: var(--header-height) 1fr;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  grid-row: 1 / -1;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  padding: 16px 0;
  display: flex;
  flex-direction: column;
}

.sidebar-brand {
  padding: 0 20px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

.sidebar-brand h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--rb-red);
  letter-spacing: -0.5px;
}

.sidebar-brand p {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.sidebar-nav { flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 14px;
  transition: all 0.15s;
  border-left: 3px solid transparent;
}

.nav-item:hover {
  background: var(--bg-card);
  color: var(--text-primary);
  text-decoration: none;
}

.nav-item.active {
  background: var(--bg-card);
  color: var(--text-primary);
  border-left-color: var(--rb-red);
}

.nav-item .icon { font-size: 18px; width: 24px; text-align: center; }

/* Header */
.header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
}

.header-title {
  font-size: 16px;
  font-weight: 600;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--rb-green);
}

.status-dot.offline { background: var(--text-muted); }
.status-dot.error   { background: var(--rb-red); }

/* Main content */
.main-content {
  padding: 24px;
  overflow-y: auto;
}

/* =================================================================
   Cards
   ================================================================= */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* =================================================================
   Stat Cards Row
   ================================================================= */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.stat-card .label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.stat-card .value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
}

.stat-card .sub {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 6px;
}

.stat-card.green .value { color: var(--rb-green); }
.stat-card.red .value   { color: var(--rb-red); }
.stat-card.blue .value  { color: var(--rb-blue); }
.stat-card.orange .value{ color: var(--rb-orange); }
.stat-card.yellow .value{ color: var(--rb-yellow); }

/* =================================================================
   Tables
   ================================================================= */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  text-align: left;
  padding: 10px 12px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}

.data-table tr:hover td {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.data-table tr:last-child td { border-bottom: none; }

/* =================================================================
   Unit Cards Grid
   ================================================================= */
.units-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.unit-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: all 0.15s;
}

.unit-card:hover {
  border-color: var(--rb-blue);
  background: var(--bg-card-hover);
}

.unit-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.unit-card-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.unit-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.unit-badge.online  { background: rgba(67, 160, 71, 0.15); color: var(--rb-green); }
.unit-badge.offline { background: rgba(90, 94, 110, 0.2); color: var(--text-muted); }
.unit-badge.error   { background: rgba(211, 47, 47, 0.15); color: var(--rb-red); }

.unit-card-stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
}

.unit-card-stat .label {
  font-size: 11px;
  color: var(--text-muted);
}

.unit-card-stat .value {
  font-size: 18px;
  font-weight: 700;
  margin-top: 2px;
}

/* =================================================================
   Badges & Tags
   ================================================================= */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
}

.badge-green  { background: rgba(67, 160, 71, 0.15); color: var(--rb-green); }
.badge-red    { background: rgba(211, 47, 47, 0.15); color: var(--rb-red); }
.badge-yellow { background: rgba(255, 193, 7, 0.15); color: var(--rb-yellow); }
.badge-blue   { background: rgba(25, 118, 210, 0.15); color: var(--rb-blue); }
.badge-orange { background: rgba(255, 111, 0, 0.15); color: var(--rb-orange); }

/* =================================================================
   Buttons
   ================================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn:hover { background: var(--bg-card-hover); }

.btn-primary {
  background: var(--rb-red);
  border-color: var(--rb-red);
  color: white;
}

.btn-primary:hover { background: var(--rb-red-dark); }

/* =================================================================
   Loading & Empty States
   ================================================================= */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: 14px;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--rb-red);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 12px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

/* =================================================================
   Charts (simple bar chart)
   ================================================================= */
.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 120px;
  padding-top: 8px;
}

.bar-chart .bar {
  flex: 1;
  background: var(--rb-blue);
  border-radius: 2px 2px 0 0;
  min-height: 2px;
  transition: height 0.3s;
  position: relative;
}

.bar-chart .bar:hover {
  background: var(--rb-red);
}

.bar-chart .bar .tooltip {
  display: none;
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  white-space: nowrap;
  z-index: 10;
}

.bar-chart .bar:hover .tooltip { display: block; }

/* =================================================================
   Responsive
   ================================================================= */
@media (max-width: 768px) {
  .app-layout {
    grid-template-columns: 1fr;
  }
  .sidebar { display: none; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
}

/* =================================================================
   Tab Navigation
   ================================================================= */
.tab-nav {
  display: flex;
  gap: 2px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 16px;
}

.tab-btn {
  padding: 10px 20px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.2s, border-color 0.2s;
}

.tab-btn:hover {
  color: var(--text-primary);
  background: var(--bg-card);
}

.tab-btn.active {
  color: var(--rb-red);
  border-bottom-color: var(--rb-red);
}

/* =================================================================
   Timeline
   ================================================================= */
.time-selector {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 11px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
}

.btn-sm:hover, .btn-sm.active {
  background: var(--rb-red);
  color: #fff;
  border-color: var(--rb-red);
}

.timeline-list {
  max-height: 500px;
  overflow-y: auto;
  padding-right: 8px;
}

.timeline-event {
  display: grid;
  grid-template-columns: 90px 12px 1fr;
  gap: 8px;
  align-items: start;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.timeline-event:last-child { border-bottom: none; }

.tl-time {
  font-size: 11px;
  color: var(--text-muted);
  text-align: right;
  white-space: nowrap;
}

.tl-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 3px;
}

.tl-body { font-size: 13px; }

.tl-name {
  font-weight: 500;
  margin-bottom: 2px;
}

.tl-meta {
  font-size: 11px;
  color: var(--text-muted);
}

.tl-critical .tl-dot { background: var(--rb-red); }
.tl-warning  .tl-dot { background: var(--rb-orange); }
.tl-info     .tl-dot { background: var(--rb-blue); }
.tl-order    .tl-dot { background: var(--rb-green); }
.tl-critical .tl-name { color: var(--rb-red); }
.tl-warning  .tl-name { color: var(--rb-orange); }
.tl-order    .tl-name { color: var(--rb-green); }

/* =================================================================
   Heatmap
   ================================================================= */
.heatmap-grid {
  display: grid;
  grid-template-columns: 50px repeat(24, 1fr);
  gap: 2px;
}

.hm-cell {
  aspect-ratio: 1;
  border-radius: 2px;
  min-height: 16px;
  cursor: default;
}

.hm-label {
  font-size: 10px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* =================================================================
   Module Health Cards
   ================================================================= */
.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.module-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.module-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.module-header h4 {
  font-size: 13px;
  font-weight: 600;
}

.health-score {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}

.health-green  { background: rgba(67,160,71,0.15); color: var(--rb-green); }
.health-yellow { background: rgba(255,193,7,0.15); color: var(--rb-yellow); }
.health-red    { background: rgba(211,47,47,0.15); color: var(--rb-red); }

.module-stats {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.module-bar-track {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.module-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s;
}

/* =================================================================
   Order Flow Visualization
   ================================================================= */
.flow-bars {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.flow-bar {
  display: grid;
  grid-template-columns: 120px 1fr 50px;
  align-items: center;
  gap: 10px;
}

.flow-label {
  font-size: 12px;
  color: var(--text-secondary);
  text-align: right;
}

.flow-track {
  height: 20px;
  background: var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.flow-fill {
  height: 100%;
  border-radius: var(--radius-sm);
  background: var(--rb-blue);
  transition: width 0.5s;
}

.flow-value {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
}

/* =================================================================
   Alerts Banner
   ================================================================= */
.alerts-banner {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.alert-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 500;
}

.alert-critical {
  background: rgba(211,47,47,0.12);
  border: 1px solid rgba(211,47,47,0.3);
  color: var(--rb-red);
}

.alert-warning {
  background: rgba(255,111,0,0.12);
  border: 1px solid rgba(255,111,0,0.3);
  color: var(--rb-orange);
}

/* =================================================================
   Economics & Compact Stats
   ================================================================= */
.econ-metric {
  text-align: center;
  padding: 16px;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.econ-metric .value { font-size: 28px; font-weight: 700; }
.econ-metric .label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.stats-row.compact { gap: 8px; }
.stats-row.compact .stat-card { padding: 12px 16px; }
.stats-row.compact .stat-card .value { font-size: 20px; }

/* =================================================================
   Event Lab — Operational Phases Timeline
   ================================================================= */
.phases-timeline {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.phase-block {
  flex: 1;
  min-width: 60px;
  max-width: 80px;
  padding: 6px;
  border-radius: var(--radius-sm);
  text-align: center;
  font-size: 10px;
  border: 1px solid var(--border);
}

.phase-normal {
  background: rgba(67,160,71,0.1);
  border-color: rgba(67,160,71,0.3);
}

.phase-high-error {
  background: rgba(211,47,47,0.1);
  border-color: rgba(211,47,47,0.3);
}

.phase-offline {
  background: rgba(90,94,110,0.15);
  border-color: rgba(90,94,110,0.3);
}

.phase-label {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.phase-stats {
  color: var(--text-secondary);
}

.phase-dt {
  color: var(--rb-orange);
  font-weight: 500;
  margin-top: 2px;
}
