:root {
  --bg: #070b13;
  --bg-gradient: radial-gradient(circle at 50% 50%, #0d1527 0%, #060911 100%);
  --panel: rgba(13, 20, 38, 0.45);
  --panel-hover: rgba(19, 29, 54, 0.6);
  --panel-border: rgba(255, 255, 255, 0.06);
  --text: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --accent: #3b82f6;
  --accent-glow: rgba(59, 130, 246, 0.25);
  --good: #10b981;
  --good-glow: rgba(16, 185, 129, 0.2);
  --warn: #f59e0b;
  --warn-glow: rgba(245, 158, 11, 0.2);
  --bad: #ef4444;
  --bad-glow: rgba(239, 68, 68, 0.3);
  --color-temp: #f97316;
  --color-water: #06b6d4;
  --color-rpm: #10b981;
  --color-power: #eab308;
  --font-main: 'Be Vietnam Pro', sans-serif;
  --font-code: 'JetBrains Mono', monospace;
}

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

body {
  background-color: var(--bg);
  background-image: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font-main);
  min-height: 100vh;
  display: flex;
  overflow-x: hidden;
}

/* App Layout */
.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  width: 100vw;
  min-height: 100vh;
}

/* Sidebar */
aside {
  background: rgba(4, 7, 15, 0.8);
  border-right: 1px solid var(--panel-border);
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  backdrop-filter: blur(20px);
}

.brand { margin-bottom: 35px; }
.brand h2 {
  font-size: 20px; font-weight: 800; letter-spacing: -0.5px;
  background: linear-gradient(135deg, #60a5fa 0%, #3b82f6 50%, #a855f7 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.brand small {
  display: block; font-size: 11px; color: var(--text-secondary);
  font-weight: 500; text-transform: uppercase; letter-spacing: 1px; margin-top: 5px;
}

nav { flex-grow: 1; }
nav div {
  padding: 12px 14px; border-radius: 10px; margin-bottom: 8px;
  color: var(--text-secondary); font-size: 14px; font-weight: 500;
  cursor: pointer; transition: all 0.2s ease;
  display: flex; align-items: center; gap: 12px; border: 1px solid transparent;
}
nav div:hover { background: rgba(255, 255, 255, 0.03); color: var(--text); border-color: rgba(255, 255, 255, 0.02); }
nav div.active {
  background: rgba(59, 130, 246, 0.15); color: #93c5fd; font-weight: 600;
  border-color: rgba(59, 130, 246, 0.3); box-shadow: 0 4px 15px rgba(59, 130, 246, 0.1);
}

.aside-footer { border-top: 1px solid var(--panel-border); padding-top: 20px; }
.status-panel {
  font-size: 12px; background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--panel-border); border-radius: 12px; padding: 12px;
}
.status-line { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.status-line:last-child { margin-bottom: 0; }
.dot-indicator {
  width: 8px; height: 8px; border-radius: 50%; background: var(--good);
  box-shadow: 0 0 8px var(--good); display: inline-block;
}
.dot-indicator.flash-error {
  background: var(--bad); box-shadow: 0 0 10px var(--bad);
  animation: flash-red 1s infinite alternate;
}
@keyframes flash-red { 0% { opacity: 0.3; } 100% { opacity: 1; } }

/* Main */
main { padding: 30px; overflow-y: auto; max-width: 1600px; width: 100%; margin: 0 auto; }

.top-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.top-bar h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.5px; }
.top-bar-left { display: flex; align-items: center; gap: 12px; }

/* Hamburger */
.hamburger {
  display: none; width: 40px; height: 40px; border: none; background: rgba(255,255,255,0.05);
  border-radius: 10px; cursor: pointer; flex-direction: column; justify-content: center;
  align-items: center; gap: 5px; padding: 0; transition: background 0.2s;
}
.hamburger:hover { background: rgba(255,255,255,0.1); }
.hamburger span { display: block; width: 20px; height: 2px; background: var(--text); border-radius: 2px; transition: all 0.3s; }

/* Mobile overlay backdrop */
.sidebar-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  z-index: 998; backdrop-filter: blur(2px); opacity: 0; transition: opacity 0.3s;
}
.sidebar-backdrop.open { display: block; opacity: 1; }
.clock-display {
  font-size: 14px; font-family: var(--font-code);
  background: rgba(255, 255, 255, 0.03); border: 1px solid var(--panel-border);
  padding: 8px 16px; border-radius: 10px; color: #93c5fd;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.2);
}

/* Panel */
.panel {
  background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: 16px; padding: 20px; backdrop-filter: blur(10px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2); transition: border-color 0.3s ease;
}
.panel:hover { border-color: rgba(255, 255, 255, 0.1); }

/* Grid Rows */
.grid-row-top { display: grid; grid-template-columns: 1.8fr 1.2fr; gap: 20px; margin-bottom: 20px; }

/* Machine Status */
.machine-status { display: flex; flex-direction: column; justify-content: space-between; }
.machine-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.machine-title { display: flex; align-items: center; gap: 12px; }
.machine-title h3 { font-size: 18px; font-weight: 800; }
.badge-status {
  font-size: 11px; font-weight: 700; background: var(--good-glow); border: 1px solid var(--good);
  color: var(--good); padding: 4px 10px; border-radius: 20px;
  text-transform: uppercase; letter-spacing: 0.5px;
}
.badge-status.error { background: var(--bad-glow); border-color: var(--bad); color: var(--bad); animation: blink 1s infinite alternate; }
@keyframes blink { 0% { opacity: 0.6; } 100% { opacity: 1; } }

.meta-badges span {
  background: rgba(255, 255, 255, 0.03); border: 1px solid var(--panel-border);
  font-size: 11px; font-weight: 600; color: var(--text-secondary);
  padding: 4px 10px; border-radius: 6px; margin-left: 6px;
}

.progress-bar-container { margin-top: 15px; }
.progress-track {
  height: 8px; background: rgba(255, 255, 255, 0.03); border: 1px solid var(--panel-border);
  border-radius: 99px; overflow: hidden; margin-top: 8px;
}
.progress-fill {
  height: 100%; background: linear-gradient(90deg, var(--accent) 0%, #60a5fa 100%);
  width: 0%; transition: width 0.3s linear; box-shadow: 0 0 10px var(--accent-glow);
}
.progress-fill.error { background: var(--bad); box-shadow: 0 0 10px var(--bad-glow); }

.phase-details {
  margin-top: 18px; font-size: 13.5px; line-height: 1.6; color: var(--text-secondary);
  border-top: 1px solid rgba(255, 255, 255, 0.04); padding-top: 14px;
}
.phase-details strong { color: var(--text); }

/* Drum SVG */
.drum-container { display: flex; justify-content: center; align-items: center; position: relative; }
.drum-svg { width: 200px; height: 200px; }
.drum-casing { fill: #1e293b; stroke: #475569; stroke-width: 4; filter: drop-shadow(0 0 10px rgba(0,0,0,0.5)); }
.drum-door-ring { fill: none; stroke: #64748b; stroke-width: 6; }
.drum-inner-rotator { transform-origin: 100px 100px; transition: transform 0.1s linear; }
.drum-basket { fill: #0f172a; stroke: #334155; stroke-width: 2; }
.drum-vane { fill: #334155; }
.drum-perforations { fill: #475569; opacity: 0.4; }
.water-body { fill: rgba(6, 182, 212, 0.3); }
.water-wave { fill: none; stroke: rgba(6, 182, 212, 0.7); stroke-width: 2; }
.heat-wave { stroke: var(--color-temp); stroke-width: 2.5; fill: none; opacity: 0; transition: opacity 0.5s ease; stroke-linecap: round; }
.heat-wave-active { opacity: 0.8; animation: wavy-heat 1.5s infinite linear; }
@keyframes wavy-heat {
  0% { stroke-dashoffset: 0; transform: translateY(0); }
  50% { transform: translateY(-3px); }
  100% { stroke-dashoffset: 15; transform: translateY(0); }
}
.drum-error-icon { fill: var(--bad); opacity: 0; transition: opacity 0.3s; }
.drum-error-active { opacity: 1; animation: alert-blink 0.8s infinite alternate; }
@keyframes alert-blink { 0% { opacity: 0.2; } 100% { opacity: 1; } }
.vibrate-heavy { animation: vibrate-heavy-keyframes 0.15s infinite linear; }
@keyframes vibrate-heavy-keyframes {
  0% { transform: translate(1px, 1px) rotate(0deg); }
  10% { transform: translate(-1px, -1.5px) rotate(-0.5deg); }
  20% { transform: translate(-2px, 0px) rotate(0.5deg); }
  30% { transform: translate(1.5px, 1.5px) rotate(0deg); }
  40% { transform: translate(1px, -1px) rotate(0.5deg); }
  50% { transform: translate(-1px, 1.5px) rotate(-0.5deg); }
  60% { transform: translate(-2px, 1px) rotate(0deg); }
  70% { transform: translate(1.5px, 0.5px) rotate(-0.5deg); }
  80% { transform: translate(-1px, -1px) rotate(0.5deg); }
  90% { transform: translate(1px, 1.5px) rotate(0deg); }
  100% { transform: translate(1px, -1px) rotate(-0.5deg); }
}

/* Telemetry Cards */
.telemetry-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.tel-card { position: relative; overflow: hidden; }
.tel-card::before { content: ''; position: absolute; top: 0; left: 0; width: 4px; height: 100%; background: var(--card-accent); }
.tel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.tel-label { font-size: 11px; font-weight: 800; color: var(--text-secondary); letter-spacing: 1px; text-transform: uppercase; }
.tel-value { font-size: 28px; font-weight: 800; margin: 8px 0 4px; display: flex; align-items: baseline; gap: 4px; color: var(--text); }
.tel-unit { font-size: 14px; color: var(--text-secondary); font-weight: 500; }
.tel-footer { font-size: 12px; color: var(--text-secondary); line-height: 1.5; border-top: 1px solid rgba(255, 255, 255, 0.04); padding-top: 8px; margin-top: 8px; }

/* Chart & PLC Registers */
.grid-row-bottom { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; margin-bottom: 20px; }
.chart-panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.chart-tabs { display: flex; gap: 6px; }
.chart-tabs button {
  background: rgba(255,255,255,0.02); border: 1px solid var(--panel-border);
  color: var(--text-secondary); padding: 6px 12px; border-radius: 8px;
  font-size: 11px; font-weight: 600; cursor: pointer; transition: all 0.2s;
}
.chart-tabs button.active { background: rgba(59, 130, 246, 0.15); border-color: rgba(59, 130, 246, 0.4); color: #60a5fa; }
.chart-wrapper { position: relative; height: 260px; width: 100%; }

.plc-title {
  font-size: 13px; font-weight: 800; letter-spacing: 0.5px; margin-bottom: 12px;
  text-transform: uppercase; color: #93c5fd; border-bottom: 1px solid rgba(255, 255, 255, 0.05); padding-bottom: 6px;
}
.register-list { display: flex; flex-direction: column; gap: 6px; max-height: 250px; overflow-y: auto; padding-right: 4px; }
.reg-item {
  display: grid; grid-template-columns: 60px 1fr 60px 65px; align-items: center;
  font-family: var(--font-code); font-size: 11.5px; padding: 6px 8px;
  background: rgba(255, 255, 255, 0.01); border: 1px solid rgba(255, 255, 255, 0.03);
  border-radius: 6px; transition: background 0.2s;
}
.reg-item:hover { background: rgba(255, 255, 255, 0.03); }
.reg-name { font-weight: 700; color: #60a5fa; }
.reg-desc { color: var(--text-secondary); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 10px; }
.reg-val { text-align: right; font-weight: 700; color: var(--text); }
.reg-hex { text-align: right; color: var(--text-muted); font-size: 10px; }

/* S-Relays */
.s-relays-title { font-size: 11px; font-weight: 800; color: var(--text-secondary); margin-top: 12px; margin-bottom: 6px; text-transform: uppercase; }
.s-relays-grid { display: grid; grid-template-columns: repeat(9, 1fr); gap: 4px; }
.s-bit {
  display: flex; flex-direction: column; align-items: center; padding: 4px 2px;
  background: rgba(255,255,255,0.01); border: 1px solid var(--panel-border);
  border-radius: 4px; font-family: var(--font-code); font-size: 10px;
}
.s-bit span:first-child { font-weight: 700; color: var(--text-muted); margin-bottom: 2px; }
.s-bit span:last-child {
  width: 8px; height: 8px; border-radius: 50%; background: rgba(255,255,255,0.08);
  display: inline-block; transition: background 0.2s, box-shadow 0.2s;
}
.s-bit.active span:first-child { color: #93c5fd; }
.s-bit.active span:last-child { background: var(--good); box-shadow: 0 0 6px var(--good); }

/* Console & History */
.grid-row-bottom-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.section-title {
  font-size: 14px; font-weight: 800; color: var(--text); text-transform: uppercase;
  letter-spacing: 0.5px; margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center;
}
.console-box {
  background: #020408; border: 1px solid rgba(255, 255, 255, 0.05); border-radius: 12px;
  padding: 12px; height: 180px; overflow-y: auto; font-family: var(--font-code);
  font-size: 11px; line-height: 1.6; box-shadow: inset 0 4px 12px rgba(0,0,0,0.8);
  display: flex; flex-direction: column; gap: 4px;
}
.console-line { word-break: break-all; }
.console-time { color: var(--text-muted); }
.console-event { color: #eab308; }
.console-tx { color: #60a5fa; }
.console-rx { color: #34d399; }
.console-err { color: #ef4444; font-weight: 700; animation: blink-soft 1s infinite alternate; }
@keyframes blink-soft { 0% { opacity: 0.7; } 100% { opacity: 1; } }

/* Timeline */
.timeline-bar { display: flex; gap: 4px; height: 28px; margin-bottom: 16px; }
.timeline-seg {
  background: rgba(255, 255, 255, 0.03); border: 1px solid var(--panel-border); border-radius: 5px;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 600; color: var(--text-secondary); flex: 1;
}
.timeline-seg.done { background: rgba(16, 185, 129, 0.08); border-color: rgba(16, 185, 129, 0.2); color: #6ee7b7; }
.timeline-seg.live {
  background: rgba(59, 130, 246, 0.15); border-color: rgba(59, 130, 246, 0.4);
  color: #93c5fd; font-weight: 800; animation: pulse-border 1.5s infinite alternate;
}
@keyframes pulse-border { 0% { border-color: rgba(59, 130, 246, 0.2); } 100% { border-color: rgba(59, 130, 246, 0.7); } }

/* Table */
table { width: 100%; border-collapse: collapse; font-size: 11.5px; text-align: left; }
th, td { padding: 8px 10px; border-top: 1px solid rgba(255,255,255,0.04); }
th { color: var(--text-muted); font-weight: 700; text-transform: uppercase; font-size: 10px; letter-spacing: 0.5px; }
td { color: var(--text-secondary); }
tr:hover td { color: var(--text); background: rgba(255,255,255,0.01); }
.color-good { color: var(--good); font-weight: 700; }
.color-warn { color: var(--warn); font-weight: 700; }
.color-bad { color: var(--bad); font-weight: 700; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: rgba(0,0,0,0.2); border-radius: 3px; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* Responsive — Tablet & Mobile shared */
@media (max-width: 1150px) {
  .app { grid-template-columns: 1fr; }
  .hamburger { display: flex; }
  aside {
    display: flex; position: fixed; left: -280px; top: 0; bottom: 0;
    width: 260px; z-index: 999; transition: left 0.3s ease;
    box-shadow: 4px 0 20px rgba(0,0,0,0.4);
  }
  aside.open { left: 0; }
  .telemetry-row { grid-template-columns: repeat(2, 1fr); }
  .grid-row-top, .grid-row-bottom, .grid-row-bottom-2 { grid-template-columns: 1fr; }
}

/* Responsive — Mobile */
@media (max-width: 600px) {
  .app { grid-template-columns: 1fr; }
  main { padding: 14px; }

  /* Top bar */
  .top-bar { flex-direction: column; align-items: flex-start; gap: 8px; margin-bottom: 16px; }
  .top-bar h1 { font-size: 18px; }
  .clock-display { font-size: 13px; padding: 6px 12px; }

  /* Machine status */
  .machine-status { padding: 14px; }
  .machine-head { flex-direction: column; align-items: flex-start; gap: 8px; }
  .machine-title h3 { font-size: 16px; }
  .meta-badges { flex-wrap: wrap; }
  .meta-badges span { font-size: 11px; padding: 4px 8px; }
  .phase-details { font-size: 12px; padding: 10px; }

  /* Drum */
  .drum-container { display: flex; justify-content: center; padding: 16px; }
  .drum-svg { width: 160px; height: 160px; }

  /* Grids → single column */
  .grid-row-top,
  .grid-row-bottom,
  .grid-row-bottom-2 { grid-template-columns: 1fr; gap: 12px; }

  /* Telemetry cards → 2 columns */
  .telemetry-row { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
  .tel-card { padding: 14px; }
  .tel-value { font-size: 24px; }
  .tel-unit { font-size: 12px; }
  .tel-footer { font-size: 11px; }
  .tel-label { font-size: 10px; }

  /* Chart */
  .chart-panel-header { flex-direction: column; align-items: flex-start; gap: 8px; }
  .chart-tabs { flex-wrap: wrap; gap: 4px; }
  .chart-tabs button { font-size: 11px; padding: 5px 8px; }
  .chart-wrapper { height: 220px; }

  /* Section titles */
  .section-title { font-size: 12px; }

  /* Assessment panel */
  .assess-row { font-size: 12px !important; padding: 9px 0 !important; }

  /* Timeline */
  .timeline-bar { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .timeline-seg { min-width: 50px; font-size: 10px; }

  /* Table */
  table { font-size: 11px; }
  th, td { padding: 8px 6px; }
  table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  thead, tbody, tr { min-width: 500px; }

  /* Panels */
  .panel { padding: 14px; border-radius: 12px; margin-bottom: 12px; }

  /* Progress bar */
  .progress-bar-container { font-size: 12px; }
}
