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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #0f172a;
  color: #e2e8f0;
  min-height: 100vh;
}

/* Top Bar */
.topbar {
  background: #1e293b;
  border-bottom: 1px solid #334155;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.topbar-left h1 {
  font-size: 18px;
  color: #38bdf8;
  font-weight: 700;
}

.topbar-stats {
  display: flex;
  gap: 12px;
}

.stat-badge {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.stat-badge.online { background: #065f46; color: #34d399; }
.stat-badge.offline { background: #7f1d1d; color: #fca5a5; }
.stat-badge.total { background: #1e3a5f; color: #93c5fd; }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-right a, .topbar-right button {
  color: #94a3b8;
  text-decoration: none;
  font-size: 13px;
  cursor: pointer;
  background: none;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
}

.topbar-right a:hover, .topbar-right button:hover {
  background: #334155;
  color: #e2e8f0;
}

.user-info {
  color: #94a3b8;
  font-size: 12px;
}

/* Main Layout */
.main {
  padding: 20px 24px;
}

/* PLC Cards Row */
.plc-cards {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 20px;
}

.plc-card {
  min-width: 160px;
  background: #1e293b;
  border: 2px solid #334155;
  border-radius: 10px;
  padding: 12px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  flex-shrink: 0;
}

.plc-card:hover { border-color: #475569; }
.plc-card.selected { border-color: #38bdf8; background: #1e3a5f; }
.plc-card.offline { opacity: 0.6; }

.plc-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.online { background: #34d399; box-shadow: 0 0 6px #34d399; }
.status-dot.offline { background: #6b7280; }

.plc-card-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.plc-card-meta {
  font-size: 11px;
  color: #94a3b8;
}

.plc-card-meta span { display: block; }

/* Tank Section */
.tank-section {
  background: #1e293b;
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 20px;
}

.tank-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.tank-section-header h2 {
  font-size: 16px;
  color: #e2e8f0;
}

.view-toggle {
  display: flex;
  gap: 4px;
}

.view-toggle button {
  padding: 4px 10px;
  border: 1px solid #475569;
  background: transparent;
  color: #94a3b8;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
}

.view-toggle button.active {
  background: #38bdf8;
  color: #0f172a;
  border-color: #38bdf8;
}

/* Tank Grid */
.tank-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}

.tank-tile {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 10px 12px;
}

.tank-tile-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.tank-tile-name {
  font-size: 13px;
  font-weight: 600;
  color: #f1f5f9;
}

.badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
}

.badge.flow { background: #065f46; color: #34d399; }
.badge.suspicious { background: #713f12; color: #fbbf24; }

.tank-level-bar {
  height: 6px;
  background: #334155;
  border-radius: 3px;
  margin-bottom: 8px;
  overflow: hidden;
}

.tank-level-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s;
}

.tank-level-fill.low { background: #ef4444; }
.tank-level-fill.mid { background: #f59e0b; }
.tank-level-fill.high { background: #22c55e; }

.tank-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  font-size: 11px;
}

.tank-stat {
  display: flex;
  justify-content: space-between;
}

.tank-stat-label { color: #64748b; }
.tank-stat-value { color: #cbd5e1; font-weight: 500; }

/* Tank Table */
.tank-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.tank-table th {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 2px solid #334155;
  color: #94a3b8;
  font-weight: 600;
  white-space: nowrap;
}

.tank-table td {
  padding: 6px 10px;
  border-bottom: 1px solid #1e293b;
  color: #e2e8f0;
}

.tank-table tr:hover td { background: #1e293b; }
.tank-table td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Events Section */
.events-section {
  background: #1e293b;
  border-radius: 10px;
  padding: 16px;
}

.events-toggle {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.events-toggle h2 { font-size: 16px; }
.events-toggle .chevron { transition: transform 0.2s; font-size: 12px; color: #64748b; }
.events-toggle .chevron.collapsed { transform: rotate(-90deg); }

.event-list {
  max-height: 300px;
  overflow-y: auto;
}

.event-item {
  display: flex;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid #0f172a;
  font-size: 12px;
}

.event-time { color: #64748b; white-space: nowrap; flex-shrink: 0; }
.event-type { font-weight: 600; width: 120px; flex-shrink: 0; }
.event-type.received { color: #34d399; }
.event-type.online { color: #22d3ee; }
.event-type.offline { color: #f87171; }
.event-type.error { color: #fbbf24; }
.event-msg { color: #cbd5e1; }

/* No Selection */
.no-selection {
  text-align: center;
  padding: 60px 20px;
  color: #64748b;
}

.no-selection .icon { font-size: 48px; margin-bottom: 12px; }
.no-selection p { font-size: 14px; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #0f172a; }
::-webkit-scrollbar-thumb { background: #475569; border-radius: 3px; }
