/* ================================================================
   base.css — CSS variables, reset, body, layout, sidebar, topbar, buttons, controls bar
   ================================================================ */

:root {
  /* Light theme */
  --bg: #ffffff;
  --surface: #ffffff;
  --surface2: #f1f5f9;
  --surface3: #f8fafc;
  --border: rgba(15,23,42,0.10);
  --border2: rgba(15,23,42,0.18);
  --accent: #2563eb;
  --accent2: #0891b2;
  --accent3: #d97706;
  --green: #059669;
  --red: #dc2626;
  --orange: #ea580c;
  --text: #0f172a;
  --muted: #64748b;
  --muted2: #334155;
  --hover: rgba(15,23,42,0.05);
  --hover2: rgba(37,99,235,0.08);
}

html[data-theme="dark"] {
  /* Dark theme */
  --bg: #060b16;
  --surface: #0b1222;
  --surface2: #0f1b33;
  --surface3: #0a1326;
  --border: rgba(148,163,184,0.14);
  --border2: rgba(148,163,184,0.22);
  --accent: #38bdf8;
  --accent2: #22c55e;
  --accent3: #f59e0b;
  --green: #22c55e;
  --red: #f87171;
  --orange: #fb923c;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --muted2: #cbd5e1;
  --hover: rgba(255,255,255,0.06);
  --hover2: rgba(56,189,248,0.14);
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(37,99,235,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(37,99,235,0.03) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
  z-index: 0;
}

/* ── LAYOUT ── */
.app {
  display: flex;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

/* ── SIDEBAR ── */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-logo {
  display: grid;
  grid-template-columns: 44px 1fr;
  /* Row 1 matches logo height so text can align with it */
  grid-template-rows: 44px auto;
  column-gap: 12px;
  row-gap: 2px;
  align-items: start;
  padding: 0 20px 18px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
  position: relative;
}

.sidebar-logo .logo-stack {
  grid-column: 1;
  grid-row: 1;
  align-self: center;
}

.logo-mark {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'DM Mono', monospace;
  font-size: 13px;
  color: white;
  font-weight: 500;
  box-shadow: 0 0 20px rgba(59,130,246,0.3);
  flex-shrink: 0;
}

.logo-mark--img {
  background: transparent;
  box-shadow: none;
}

.logo-stack {
  width: 44px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.logo-caption {
  position: static;
  width: 44px;
  margin-top: 3px;
  font-family: 'DM Mono', monospace;
  font-size: 7px;
  line-height: 1.1;
  color: var(--accent3);
  text-align: center;
  letter-spacing: 0.4px;
  text-transform: initial;
  word-break: break-word;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.logo-caption--full {
  width: 100%;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  text-align: left;
  letter-spacing: 0.5px;
}

/* Payoff under the logo */
.sidebar-caption {
  grid-column: 1 / -1;
  grid-row: 2;
  margin-top: 0;
  width: 100%;
  font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
  font-size: 7px;
  line-height: 1.2;
  /* In light theme the yellow is not readable on white */
  color: var(--muted2);
  font-weight: bold;
  text-shadow: none;
  text-transform: uppercase;
  text-align: left;
  letter-spacing: 0.5px; /* moderate spacing so it still fits */
  word-spacing: 1px;     /* gentle gap between words */
  white-space: nowrap;   /* force single line */
  overflow: hidden;
  text-overflow: clip;
}

/* Keep the MAE-like yellow in dark theme */
html[data-theme="dark"] .sidebar-caption {
  color: #f8d200;
}

.caption-advanced { letter-spacing: inherit; }
.app-logo {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 10px;
  display: block;
}

.sidebar-logo-text {
  font-family: 'Syne', sans-serif;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.2;
  grid-column: 2;
  grid-row: 1;
  margin-top: 0;
  width: 100%;
  align-self: center; /* vertically align with logo */
}

.sidebar-logo-text small {
  display: block;
  font-family: 'DM Mono', monospace;
  font-size: 9px;
  color: var(--muted);
  font-weight: 400;
  letter-spacing: 1px;
}

.nav-section {
  padding: 8px 20px 4px;
  font-family: 'DM Mono', monospace;
  font-size: 9px;
  letter-spacing: 2px;
  color: var(--muted);
  text-transform: uppercase;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  font-size: 13px;
  color: var(--muted2);
  cursor: pointer;
  border-left: 2px solid transparent;
  transition: all 0.15s;
}

.nav-item:hover {
  color: var(--text);
  background: var(--hover);
}

.nav-item.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--hover2);
}

.nav-item svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.device-list {
  padding: 8px 12px;
  margin-top: 16px;
  border-top: 1px solid var(--border);
}

.device-section-label {
  font-family: 'DM Mono', monospace;
  font-size: 9px;
  letter-spacing: 2px;
  color: var(--muted);
  text-transform: uppercase;
  padding: 8px 8px 6px;
}

.device-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
  border: 1px solid transparent;
}

.device-item:hover {
  background: var(--hover);
}

.device-item.active {
  background: var(--hover2);
  border-color: rgba(37,99,235,0.2);
}

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

.device-info {
  flex: 1;
  min-width: 0;
}

.device-name {
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-transform: uppercase;
}

.device-serial {
  font-family: 'DM Mono', monospace;
  font-size: 9px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-transform: uppercase;
}

.device-status {
  font-family: 'DM Mono', monospace;
  font-size: 9px;
}

/* ── MAIN CONTENT ── */
.main {
  flex: 1;
  min-width: 0;
  padding: 28px;
  overflow-x: hidden;
}

/* ── TOP BAR ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
}

.topbar-left {
  flex: 1;
  min-width: 0;
}

.topbar-left h1 {
  font-family: 'Syne', sans-serif;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-left .subtitle {
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 1px;
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-right {
  flex-shrink: 0;
}

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

.status-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 14px;
  background: rgba(16,185,129,0.1);
  border: 1px solid rgba(16,185,129,0.2);
  border-radius: 100px;
  font-size: 11px;
  color: var(--green);
  font-family: 'DM Mono', monospace;
}

.status-dot {
  width: 6px;
  height: 6px;
  background: var(--green);
  border-radius: 50%;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(16,185,129,0.4);
  }
  50% {
    box-shadow: 0 0 0 4px rgba(16,185,129,0);
  }
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  border-radius: 9px;
  font-size: 12px;
  font-family: 'DM Mono', monospace;
  cursor: pointer;
  transition: all 0.15s;
  border: 1px solid var(--border2);
  background: var(--surface2);
  color: var(--muted2);
}

.btn:hover {
  color: var(--text);
  border-color: rgba(255,255,255,0.24);
}

.btn.btn-primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.btn.btn-primary:hover {
  background: #2563eb;
}

.btn.btn-danger {
  background: rgba(239,68,68,0.1);
  color: var(--red);
  border-color: rgba(239,68,68,0.2);
}

.btn.active {
  color: var(--accent);
  border-color: rgba(37,99,235,0.4);
  background: rgba(37,99,235,0.08);
}

.btn svg {
  width: 13px;
  height: 13px;
}

/* ── CONTROLS BAR ── */
.controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.controls-label {
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 1px;
  text-transform: uppercase;
  white-space: nowrap;
}

.date-input {
  background: var(--surface2);
  border: 1px solid var(--border2);
  color: var(--text);
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  padding: 7px 10px;
  border-radius: 8px;
  outline: none;
}

.date-input:focus {
  border-color: var(--accent);
}

.select-input {
  background: var(--surface2);
  border: 1px solid var(--border2);
  color: var(--muted2);
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  padding: 7px 10px;
  border-radius: 8px;
  outline: none;
  cursor: pointer;
}

.select-input:focus {
  border-color: var(--accent);
}

.controls-sep {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 4px;
}

#refreshCountdown {
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  color: var(--muted);
  min-width: 60px;
}
