/* ───────── Tank Farm Monitor — Theme & Variables ───────── */
:root {
  /* Backgrounds */
  --bg-body: #0a0a0a;
  --bg-card: #1a1a2e;
  --bg-input: #0f0f23;
  --bg-hover: #16213e;
  --bg-dark: #111827;
  --bg-toast-error: rgba(127, 29, 29, 0.95);
  --bg-toast-success: rgba(20, 83, 45, 0.95);
  --bg-toast-info: rgba(30, 58, 95, 0.95);
  --bg-modal-overlay: rgba(0, 0, 0, 0.6);

  /* Borders */
  --border: #16213e;
  --border-hover: #b96a19;
  --border-error: #ef4444;

  /* Text */
  --text: #e0e0e0;
  --text-muted: #aaa;
  --text-dim: #8a8a8a;
  --text-accent: #b96a19;
  --text-accent-light: #f59e0b;
  --text-danger: #ef4444;
  --text-success: #22c55e;
  --text-blue: #3b82f6;

  /* Primary palette */
  --primary: #b96a19;
  --primary-hover: #8f4e12;
  --primary-light: #f59e0b;
  --primary-dark: #b45309;

  /* Semantic */
  --danger: #ef4444;
  --danger-hover: #b91c1c;
  --success: #22c55e;
  --running: #28a745;
  --completed: #0d6efd;
  --aborted: #dc3545;
  --blue: #3b82f6;

  /* Shadows */
  --shadow-glow: rgba(185, 106, 25, 0.15);
  --shadow-glow-strong: rgba(185, 106, 25, 0.3);
  --shadow-box: 0 4px 12px rgba(0, 0, 0, 0.5);

  /* Glass */
  --glass-bg: rgba(26, 26, 46, 0.7);
  --glass-border: rgba(255, 255, 255, 0.06);
  --glass-blur: 12px;

  /* Theme-aware surfaces */
  --body-atmosphere:
    radial-gradient(ellipse at 50% 0%, rgba(26, 26, 46, 0.6) 0%, transparent 70%),
    linear-gradient(rgba(185, 106, 25, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(185, 106, 25, 0.03) 1px, transparent 1px);
  --body-grid-size: 100% 100%, 60px 60px, 60px 60px;
  --operation-surface: linear-gradient(135deg, rgba(26, 26, 46, 0.88), rgba(15, 15, 35, 0.65));
  --diagnostics-surface: rgba(15, 15, 35, 0.45);
  --login-input-surface: rgba(15, 15, 35, 0.6);
  --user-input-surface: rgba(15, 15, 35, 0.6);
  --form-cluster-surface: rgba(15, 15, 35, 0.4);
  --mode-inactive-surface: #0a0a14;
  --mode-inactive-border: #0f0f23;
  --control-text: #ccc;
  --control-text-hover: #fff;
  --mobile-nav-surface: rgba(10, 10, 20, 0.96);
  --input-placeholder: #696b7e;
  --skeleton-shimmer: rgba(255, 255, 255, 0.04);
  --tank-shell-highlight: rgba(255, 255, 255, 0.07);
  --toast-text: #fff;
  --toast-dismiss: rgba(255, 255, 255, 0.5);
  --toast-dismiss-hover: #fff;
  --toast-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  --primary-action-text: #090909;
  --connection-banner-surface: rgba(127, 29, 29, 0.18);
  --connection-banner-border: rgba(239, 68, 68, 0.25);
  --connection-banner-heading: #fca5a5;
  --receiver-badge-surface: rgba(34, 197, 94, 0.14);
  --receiver-badge-text: #4ade80;

  /* Typography */
  --font-family: 'Space Grotesk', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Radii */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 10px;
  --radius-xl: 12px;
  --radius-full: 20px;

  /* Transitions */
  --transition-fast: 0.2s;
  --transition-normal: 0.3s;
  --transition-slow: 0.5s;
}

html[data-theme="light"] {
  --bg-body: #ffffff;
  --bg-card: #ffffff;
  --bg-input: #f8f9fa;
  --bg-hover: #f2e9df;
  --bg-dark: #f8f9fa;
  --bg-toast-error: #991b1b;
  --bg-toast-success: #166534;
  --bg-toast-info: #1e40af;
  --bg-modal-overlay: rgba(44, 36, 24, 0.42);
  --border: #ded7cf;
  --border-hover: #8b4513;
  --border-error: #dc2626;
  --text: #2c2418;
  --text-muted: #665b4e;
  --text-dim: #7a6852;
  --text-accent: #8b4513;
  --text-accent-light: #8b4513;
  --text-danger: #b91c1c;
  --text-success: #15803d;
  --text-blue: #1d4ed8;
  --primary: #8b4513;
  --primary-hover: #5d3a1a;
  --primary-light: #8b4513;
  --primary-dark: #5d3a1a;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --success: #15803d;
  --running: #15803d;
  --completed: #1d4ed8;
  --aborted: #b91c1c;
  --blue: #1d4ed8;
  --shadow-glow: rgba(139, 69, 19, 0.12);
  --shadow-glow-strong: rgba(139, 69, 19, 0.2);
  --shadow-box: 0 4px 16px rgba(44, 36, 24, 0.12);
  --glass-bg: rgba(255, 255, 255, 0.9);
  --glass-border: rgba(93, 58, 26, 0.16);
  --body-atmosphere:
    radial-gradient(ellipse at 50% 0%, rgba(248, 249, 250, 0.95) 0%, transparent 70%),
    linear-gradient(rgba(139, 69, 19, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(139, 69, 19, 0.035) 1px, transparent 1px);
  --operation-surface: linear-gradient(135deg, rgba(255, 255, 255, 0.98), rgba(248, 249, 250, 0.96));
  --diagnostics-surface: rgba(248, 249, 250, 0.9);
  --login-input-surface: rgba(248, 249, 250, 0.96);
  --user-input-surface: #f8f9fa;
  --form-cluster-surface: rgba(248, 249, 250, 0.96);
  --mode-inactive-surface: #f8f9fa;
  --mode-inactive-border: #95836e;
  --control-text: #665b4e;
  --control-text-hover: #5d3a1a;
  --mobile-nav-surface: rgba(255, 255, 255, 0.98);
  --input-placeholder: #7a6852;
  --skeleton-shimmer: rgba(93, 58, 26, 0.12);
  --tank-shell-highlight: rgba(93, 58, 26, 0.08);
  --toast-dismiss: #fff;
  --primary-action-text: #ffffff;
  --connection-banner-surface: #fef2f2;
  --connection-banner-border: #fca5a5;
  --connection-banner-heading: #991b1b;
  --receiver-badge-surface: #f0fdf4;
  --receiver-badge-text: #166534;
}

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

body {
  background: var(--bg-body);
  background-image: var(--body-atmosphere);
  background-size: var(--body-grid-size);
  color: var(--text);
  font-family: var(--font-family);
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
}
/* Industrial noise texture overlay */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.03;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 256px 256px;
}

button {
  font-family: inherit;
  font-weight: 700;
}

input, select, textarea {
  font-family: inherit;
}

/* ───────── Custom scrollbar ───────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-body); }
::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: var(--radius-sm); }
::-webkit-scrollbar-thumb:hover { background: var(--primary); }

/* ───────── Accessibility & utilities ───────── */
:focus-visible {
  outline: 2px solid var(--primary-light);
  outline-offset: 2px;
}

.is-hidden { display: none; }

.skip-link {
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 2000;
  padding: 0.65rem 1rem;
  border-radius: var(--radius-md);
  background: var(--primary-light);
  color: var(--primary-action-text);
  font-weight: 700;
  transform: translateY(-160%);
  transition: transform var(--transition-fast);
}

.skip-link:focus-visible { transform: translateY(0); }

/* ───────── Header ───────── */
.header {
  background: var(--bg-card);
  padding: 1rem 2rem;
  border-bottom: 2px solid var(--primary);
  box-shadow: 0 0 20px var(--shadow-glow), 0 4px 30px rgba(0,0,0,0.3);
  position: relative;
  z-index: 10;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1400px;
  margin: 0 auto;
  gap: 1rem;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.6);
  animation: statusPulse 2s ease-in-out infinite;
  flex-shrink: 0;
}
.header-live-status {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--text-muted);
  font-size: 0.78rem;
  white-space: nowrap;
}
.header-live-status.status-stale { color: var(--primary-light); }
.header-status-dot.status-offline {
  background: var(--danger);
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.6);
  animation: none;
}
@keyframes statusPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(0.85); }
}

.header-time {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-right: 1.5rem;
  white-space: nowrap;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.header-user-name {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-right: 1rem;
}

/* ───────── Logout button ───────── */
.logout-btn {
  flex: 0 0 auto;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.4rem 1rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 0.8rem;
  white-space: nowrap;
  transition: border-color var(--transition-fast), color var(--transition-fast);
}

.logout-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* ───────── Tab Bar ───────── */
.tab-bar {
  display: flex;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0 2rem;
  gap: 0;
}

.tab-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: var(--font-family);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.75rem 1.5rem;
  cursor: pointer;
  position: relative;
  transition: color var(--transition-fast);
  letter-spacing: 0.03em;
}

.tab-btn:hover {
  color: var(--text-accent);
}

.tab-btn.active {
  color: var(--text-accent-light);
}

.tab-btn::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
  box-shadow: 0 0 8px var(--shadow-glow-strong);
  transition: width var(--transition-normal) ease, left var(--transition-normal) ease;
}

.tab-btn.active::after {
  left: 0;
  width: 100%;
}

.tab-content {
  opacity: 0;
  transform: translateY(8px);
  transition: opacity var(--transition-normal) ease, transform var(--transition-normal) ease;
  pointer-events: none;
  display: none;
}

.tab-content.active {
  display: block;
}

.tab-content.active-in {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* ───────── Container ───────── */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem;
}

/* ───────── Tank Grid ───────── */
.tank-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  justify-content: center;
  align-items: start;
}

.tank-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  border-left: 4px solid var(--primary);
  transition: border-color var(--transition-normal), box-shadow var(--transition-normal), transform var(--transition-fast);
  cursor: pointer;
}

.tank-card:hover {
  border-color: var(--primary);
  box-shadow: 0 0 20px var(--shadow-glow);
  transform: translateY(-2px);
}

/* Product-based accent colors */
.tank-card[data-product="crude oil"] {
  border-left-color: var(--primary);
}
.tank-card[data-product="crude oil"]:hover {
  border-color: var(--primary);
  box-shadow: 0 0 20px rgba(185, 106, 25, 0.25);
}
.tank-card[data-product="crude oil"] .liquid {
  background:
    linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.05) 50%, transparent 100%) 0 0 / 200% 100% no-repeat,
    linear-gradient(180deg, #d4881e, #8b4a0b 60%, #3d1c00) 0 0 / 100% 100% no-repeat;
  border-top-color: rgba(245, 158, 11, 0.5);
  box-shadow: 0 -2px 12px rgba(185, 106, 25, 0.2);
}

.tank-card[data-product="diesel"] {
  border-left-color: #3b82f6;
}
.tank-card[data-product="diesel"]:hover {
  border-color: #3b82f6;
  box-shadow: 0 0 20px rgba(59, 130, 246, 0.25);
}
.tank-card[data-product="diesel"] .liquid {
  background:
    linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.05) 50%, transparent 100%) 0 0 / 200% 100% no-repeat,
    linear-gradient(180deg, #4a90d9, #1a4a8a 60%, #0a2240) 0 0 / 100% 100% no-repeat;
  border-top-color: rgba(59, 130, 246, 0.5);
  box-shadow: 0 -2px 12px rgba(59, 130, 246, 0.2);
}

.tank-card[data-product="gasoline"] {
  border-left-color: #22c55e;
}
.tank-card[data-product="gasoline"]:hover {
  border-color: #22c55e;
  box-shadow: 0 0 20px rgba(34, 197, 94, 0.25);
}
.tank-card[data-product="gasoline"] .liquid {
  background:
    linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.05) 50%, transparent 100%) 0 0 / 200% 100% no-repeat,
    linear-gradient(180deg, #4ade80, #15803d 60%, #064e1a) 0 0 / 100% 100% no-repeat;
  border-top-color: rgba(34, 197, 94, 0.5);
  box-shadow: 0 -2px 12px rgba(34, 197, 94, 0.2);
}

.tank-card[data-product="fuel oil"] {
  border-left-color: #dc2626;
}
.tank-card[data-product="fuel oil"]:hover {
  border-color: #dc2626;
  box-shadow: 0 0 20px rgba(220, 38, 38, 0.25);
}
.tank-card[data-product="fuel oil"] .liquid {
  background:
    linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.05) 50%, transparent 100%) 0 0 / 200% 100% no-repeat,
    linear-gradient(180deg, #e85d3a, #7a1a0a 60%, #3d0800) 0 0 / 100% 100% no-repeat;
  border-top-color: rgba(220, 38, 38, 0.5);
  box-shadow: 0 -2px 12px rgba(220, 38, 38, 0.2);
}

.tank-card h3 {
  color: var(--primary);
  margin-bottom: 1rem;
}

.tank-card.readonly {
  cursor: default;
}

.tank-visual {
  width: 100%;
  height: 180px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md) var(--radius-md) 35% 35%;
  position: relative;
  overflow: hidden;
  margin-bottom: 1rem;
  /* cylinder shading — darkens toward edges */
  box-shadow: inset 0 0 40px rgba(0,0,0,0.4);
}

/* Tick marks on the tank wall */
.tank-visual::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background:
    repeating-linear-gradient(
      to top,
      transparent 0px,
      transparent calc(25% - 1px),
      var(--tank-shell-highlight) calc(25% - 1px),
      var(--tank-shell-highlight) 25%
    );
  -webkit-mask-image: linear-gradient(to right, transparent 0%, rgba(0,0,0,0.3) 15%, rgba(0,0,0,0.3) 85%, transparent 100%);
  mask-image: linear-gradient(to right, transparent 0%, rgba(0,0,0,0.3) 15%, rgba(0,0,0,0.3) 85%, transparent 100%);
}

.liquid {
  position: absolute;
  bottom: 0;
  width: 100%;
  z-index: 1;
  /* Three-layer: shimmer sweep, oil body gradient, surface glint */
  background:
    linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.05) 50%, transparent 100%) 0 0 / 200% 100% no-repeat,
    linear-gradient(180deg, #d4881e, #8b4a0b 60%, #3d1c00) 0 0 / 100% 100% no-repeat;
  transition: height var(--transition-slow) ease;
  animation: waterSway 5s ease-in-out infinite, liquidShimmer 6s linear infinite;
  /* Surface glow line at the liquid top */
  border-top: 2px solid rgba(245, 158, 11, 0.5);
  box-shadow: 0 -2px 12px rgba(185, 106, 25, 0.2);
}

@keyframes waterSway {
  0%   { transform: skewX(-2deg) translateX(-2px); }
  25%  { transform: skewX(-1deg) translateX(-1px); }
  50%  { transform: skewX(2deg) translateX(2px); }
  75%  { transform: skewX(1deg) translateX(1px); }
  100% { transform: skewX(-2deg) translateX(-2px); }
}

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

/* Product-based sway speed — viscous products move slower */
.tank-card[data-product="gasoline"] .liquid  { animation-duration: 3.5s, 4s; }
.tank-card[data-product="diesel"] .liquid    { animation-duration: 5s, 6s; }
.tank-card[data-product="crude oil"] .liquid  { animation-duration: 7s, 8s; }
.tank-card[data-product="fuel oil"] .liquid   { animation-duration: 9s, 10s; }

.fill-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 28px;
  font-weight: bold;
  color: #fff;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.7), 0 0 12px rgba(0,0,0,0.5);
  z-index: 2;
  pointer-events: none;
}

.tank-info {
  padding-top: 1rem;
}

.tank-info p {
  margin: 0.3rem 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.tank-actions {
  display: flex;
  gap: 0.5rem;
  padding-top: 0.75rem;
}

.tank-btn {
  flex: 1;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  cursor: pointer;
  background: transparent;
  font-family: inherit;
  font-weight: 700;
  transition: border-color var(--transition-fast), color var(--transition-fast);
}

.tank-btn-empty {
  color: var(--primary-light);
}

.tank-btn-empty:hover {
  border-color: var(--primary-light);
  background: rgba(245, 158, 11, 0.1);
}

.tank-btn-delete {
  color: var(--danger);
}

.tank-btn-delete:hover {
  border-color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}

/* ───────── Injection Form ───────── */
.injection-form {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 1.5rem 1.5rem 2.5rem;
  margin-top: 2.5rem;
  position: relative;
}

/* Form field clusters — visually group related inputs */
.form-cluster {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  background: var(--form-cluster-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.5rem;
}

.form-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.dest-section {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.dest-section select,
.dest-section input { min-width: 0; }

.form-row select,
.form-row input {
  flex: 1;
  min-width: 150px;
  padding: 0.6rem 1rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: 0.9rem;
}

.form-row select:focus,
.form-row input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 12px rgba(185, 106, 25, 0.2);
}

.input-group {
  display: flex;
  flex: 1;
  min-width: 150px;
  position: relative;
}

.input-group input {
  flex: 1;
  min-width: 0;
  padding: 0.6rem 2.8rem 0.6rem 1rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: 0.9rem;
}

.input-group input:focus {
  outline: none;
  border-color: var(--primary);
}

.input-max {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  padding: 0.2rem 0.6rem;
  background: transparent;
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  color: var(--primary-light);
  font-size: 0.7rem;
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
  opacity: 1;
  transition: opacity var(--transition-fast), background var(--transition-fast);
}

.input-max:hover {
  opacity: 1;
  background: rgba(185, 106, 25, 0.2);
}

.input-group.error input {
  border-color: var(--border-error);
}

/* Per-field error highlight */
select.is-error,
input.is-error {
  border-color: var(--border-error) !important;
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.25);
}

.field-wrap {
  flex: 1;
  min-width: 150px;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.field-wrap label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field-wrap select,
.field-wrap input {
  width: 100%;
}

.form-error {
  display: none;
  color: var(--text-danger);
  font-size: 0.7rem;
  position: absolute;
  bottom: 0.75rem;
  left: 1.5rem;
  right: 1.5rem;
}

.form-error.visible {
  display: block;
}

/* ───────── Mode toggle ───────── */
.mode-toggle {
  display: flex;
  gap: 1px;
  flex-shrink: 0;
}

.mode-btn {
  padding: 0.6rem 1.2rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.85rem;
  font-family: inherit;
  font-weight: 700;
  transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
}

.mode-btn:first-child {
  border-radius: var(--radius-md) 0 0 var(--radius-md);
}

.mode-btn:last-child {
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

.mode-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: inset 0 -2px 0 0 #fff;
}

.mode-btn:not(.active) {
  background: var(--mode-inactive-surface);
  border-color: var(--mode-inactive-border);
  color: var(--text-dim);
}

.mode-btn:not(.active):hover {
  background: var(--bg-hover);
  border-color: var(--bg-hover);
  color: var(--text-muted);
}

/* ───────── Form Submit Button ───────── */
.form-row button[type="button"] {
  padding: 0.6rem 1.5rem;
  background: var(--primary);
  border: none;
  border-radius: var(--radius-md);
  color: #fff;
  font-weight: 700;
  font-family: var(--font-mono);
  cursor: pointer;
  transition: background var(--transition-fast), transform 0.1s, box-shadow var(--transition-fast);
}

.form-row button[type="button"]:hover {
  background: var(--primary-hover);
  box-shadow: 0 0 16px var(--shadow-glow-strong);
}

.form-row button[type="button"]:active {
  transform: scale(0.97);
}

/* ───────── Injection Dashboard ───────── */
.injection-dashboard {
  margin-top: 2rem;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1rem;
  text-align: center;
  position: relative;
  overflow: hidden;
  transition: transform var(--transition-fast) ease, box-shadow var(--transition-fast) ease;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--stat-accent, var(--primary));
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: 0 0 10px var(--stat-accent, var(--primary));
}

.stat-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.5rem;
  color: var(--stat-accent, var(--primary));
  opacity: 0.8;
}

.stat-icon svg {
  width: 26px;
  height: 26px;
  filter: drop-shadow(0 0 6px var(--stat-accent, var(--primary)));
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-bottom: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat-value {
  font-size: 1.8rem;
  font-weight: bold;
  color: var(--stat-accent, var(--primary));
  font-family: var(--font-mono);
  line-height: 1.2;
  transition: color 0.3s ease;
}
.stat-value.pulse {
  animation: statPulse 0.4s ease-out;
}
@keyframes statPulse {
  0%   { transform: scale(1); }
  30%  { transform: scale(1.08); color: var(--primary-light); }
  100% { transform: scale(1); }
}

.stat-unit {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 0.15rem;
}

/* Per-stat accent colors */
.stat-card[data-stat="volume"] { --stat-accent: var(--primary); }
.stat-card[data-stat="flow"]    { --stat-accent: var(--primary-light); }
.stat-card[data-stat="pressure"] { --stat-accent: var(--danger); }
.stat-card[data-stat="temp"]    { --stat-accent: var(--blue); }
.stat-card[data-stat="stdvol"] { --stat-accent: #06b6d4; }
.stat-card[data-stat="vcf"]    { --stat-accent: #8b5cf6; }

.progress-section {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 1.25rem 1.5rem;
  margin-bottom: 0;
  border-bottom: none;
}

.progress-bar-bg {
  width: 100%;
  height: 22px;
  background: var(--bg-input);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
  border-radius: var(--radius-lg);
  transition: width var(--transition-slow) ease;
}

.dashboard-info {
  display: none;
  justify-content: center;
  align-items: center;
  gap: 2rem;
  padding: 0.75rem 1.5rem;
  margin-bottom: 0;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-top: none;
  border-bottom: none;
  border-radius: 0;
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--text);
  text-align: center;
  flex-wrap: wrap;
  box-shadow: 0 0 12px var(--shadow-glow);
  transition: box-shadow var(--transition-normal);
}

.info-segment {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.info-label {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.85rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.info-value {
  color: var(--primary-light);
  font-weight: 600;
  font-family: var(--font-mono);
}

.info-segment + .info-segment::before {
  content: '';
  display: inline-block;
  width: 1px;
  height: 1.2rem;
  background: var(--border);
  margin-right: 0.5rem;
}

/* ───────── Timeline ───────── */
.timeline-row {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 0;
  margin-bottom: 1.25rem;
  padding: 0.75rem 0.5rem 0.5rem;
  position: relative;
  /* Continuation of the progress card — no top border, rounded bottom only */
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-top: none;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* Connecting track */
.timeline-row::before {
  content: '';
  position: absolute;
  top: calc(0.75rem + 5.5px);
  left: 15%;
  right: 15%;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  z-index: 0;
}

/* Fill track */
.timeline-row::after {
  content: '';
  position: absolute;
  top: calc(0.75rem + 5.5px);
  left: 15%;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
  border-radius: 2px;
  z-index: 1;
  transition: width var(--transition-slow) ease;
  width: var(--tl-progress, 0%);
  box-shadow: 0 0 8px var(--shadow-glow-strong);
}

.tl-item {
  flex: 1;
  text-align: center;
  position: relative;
  z-index: 2;
}

.tl-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--bg-body);
  border: 3px solid var(--border);
  margin: 0 auto 0.5rem;
  transition: border-color var(--transition-normal), box-shadow var(--transition-normal), background var(--transition-normal);
  position: relative;
}

.tl-dot.tl-dot--active {
  border-color: var(--primary);
  box-shadow: 0 0 12px var(--shadow-glow-strong);
  background: var(--primary);
}

.tl-dot.tl-dot--done {
  border-color: var(--primary);
  background: var(--primary);
}

.tl-label {
  display: block;
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-bottom: 0.15rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.tl-value {
  display: block;
  font-size: 0.85rem;
  color: var(--text);
  font-family: var(--font-mono);
}

/* ───────── Session Controls ───────── */
.session-controls {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  justify-content: center;
}

.ctrl-btn {
  padding: 0.6rem 1.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast);
  background: var(--bg-input);
  color: var(--control-text);
}

.ctrl-btn:hover {
  border-color: var(--primary);
  color: var(--control-text-hover);
}

.ctrl-pause:hover {
  border-color: var(--primary-light);
  background: rgba(245, 158, 11, 0.1);
}

.ctrl-resume:hover {
  border-color: var(--success);
  background: rgba(34, 197, 94, 0.1);
}

.ctrl-abort:hover {
  border-color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}

/* ───────── Charts ───────── */
.charts-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  margin-bottom: 1rem;
}

.chart-card {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: 0.75rem;
  height: 240px;
  display: flex;
  flex-direction: column;
  transition: box-shadow var(--transition-fast);
}

.chart-card:hover {
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.chart-card h3 {
  color: var(--primary-light);
  margin-bottom: 0.5rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}

.chart-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
}

.chart-wrap canvas {
  width: 100% !important;
  height: 100% !important;
  position: absolute;
  top: 0;
  left: 0;
}

/* Full-width chart variant (primary chart) */
.charts-row.charts-primary {
  grid-template-columns: 1fr;
}
.chart-card.chart-full {
  height: 260px;
}
/* Secondary charts: 3+2 layout on wider screens */
.charts-row.charts-secondary {
  grid-template-columns: repeat(3, 1fr);
}
.charts-row.charts-secondary:last-child {
  grid-template-columns: repeat(2, 1fr);
}

/* Colored dot before chart title matching the chart line color */
.chart-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 0.4rem;
  vertical-align: middle;
  box-shadow: 0 0 6px currentColor;
}

/* ───────── Sessions List ───────── */
.sessions-list {
  margin-top: 2rem;
}

.section-title {
  color: var(--primary);
  margin-bottom: 1rem;
}

.empty-state {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
  margin-top: 2rem;
  text-align: center;
  color: var(--text-muted);
}

.empty-state-icon {
  width: 40px;
  height: 40px;
  margin: 0 auto 0.75rem;
  color: var(--text-dim);
  opacity: 0.5;
}

.empty-state-icon svg {
  width: 100%;
  height: 100%;
}

.empty-state-title {
  color: var(--text);
  font-weight: 600;
  font-size: 1rem;
  margin-bottom: 0.3rem;
}

.empty-state-sub {
  color: var(--text-dim);
  font-size: 0.85rem;
}

.session-card {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.5rem;
  margin-bottom: 0.75rem;
  display: flex;
  gap: 1rem;
  align-items: center;
  cursor: pointer;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.session-card:hover {
  border-color: var(--primary);
}

.session-card.active {
  border-color: var(--primary);
  background: var(--bg-hover);
  box-shadow: 0 0 20px var(--shadow-glow);
}

.session-card.completing {
  animation: slideOutUp 0.4s ease-in forwards;
  pointer-events: none;
}

.session-card.entering {
  animation: slideInDown 0.3s ease-out;
}

/* ───────── User idle message ───────── */
.user-idle-msg {
  display: flex;
  justify-content: center;
  padding: 2rem 1rem;
}

.user-idle-card {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-xl);
  padding: 2.5rem 3rem;
  text-align: center;
  max-width: 420px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

.user-idle-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 0 0.75rem;
  color: var(--text-dim);
  opacity: 0.5;
}

.user-idle-icon svg {
  width: 40px;
  height: 40px;
}

.user-idle-title {
  color: var(--text);
  font-weight: 600;
  font-size: 1rem;
  margin: 0 0 0.4rem;
}

.user-idle-sub {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin: 0;
}

.session-info {
  flex: 1;
}

.session-info h4 {
  color: var(--text);
  font-size: 0.95rem;
}

.session-info p {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 0.2rem;
}

.session-status {
  flex-shrink: 0;
  padding: 0.3rem 0.8rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: bold;
}

.status-queued {
  background: rgba(108, 117, 125, 0.3);
  color: var(--text-muted);
}

.status-running {
  background: rgba(40, 167, 69, 0.2);
  color: var(--running);
  animation: pulse 1.5s infinite;
  box-shadow: 0 0 8px rgba(40, 167, 69, 0.3);
}

.status-completed {
  background: rgba(13, 110, 253, 0.2);
  color: var(--completed);
}

.status-aborted {
  background: rgba(220, 53, 69, 0.2);
  color: var(--aborted);
}

/* ───────── Session History ───────── */
.session-history-section {
  margin-top: 2rem;
}

.history-date-group {
  color: var(--text-dim);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 1rem 0 0.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.5rem;
}

.history-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-accent);
  font-family: var(--font-family);
  font-size: 0.85rem;
  padding: 0.5rem 1.2rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, box-shadow 0.2s;
  width: 100%;
  text-align: center;
}

.history-toggle:hover {
  background: var(--bg-hover);
  border-color: var(--border-hover);
  box-shadow: 0 0 8px var(--shadow-glow);
}

.history-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  padding: 0.6rem 1rem;
  margin-bottom: 0.5rem;
  transition: border-color 0.2s;
}

.history-card:hover {
  border-color: var(--border-hover);
}

.history-card .hc-info {
  flex: 1;
  min-width: 0;
}

.history-card .hc-info h4 {
  color: var(--text);
  font-size: 0.85rem;
  margin: 0;
}

.history-card .hc-info p {
  color: var(--text-dim);
  font-size: 0.75rem;
  margin: 0.15rem 0 0 0;
}

.hc-delete {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0 0.2rem;
  line-height: 1;
  transition: color var(--transition-fast);
  flex-shrink: 0;
}

.hc-delete:hover {
  color: var(--danger);
}

.hc-meta {
  display: flex;
  gap: 1.5rem;
  font-size: 0.75rem;
  color: var(--text-dim);
  flex-shrink: 0;
}

.hc-meta span {
  white-space: nowrap;
}

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

.hc-status {
  flex-shrink: 0;
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-full);
  font-size: 0.7rem;
  font-weight: bold;
}

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

@keyframes slideOutUp {
  0% {
    opacity: 1;
    transform: translateY(0);
    max-height: 120px;
    margin-bottom: 0.75rem;
  }
  100% {
    opacity: 0;
    transform: translateY(-100%);
    max-height: 0;
    margin-bottom: 0;
    padding: 0 1.5rem;
  }
}

@keyframes slideInDown {
  0% {
    opacity: 0;
    transform: translateY(-20px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ───────── Ring Gauge ───────── */
.ring-gauge {
  flex: 0 0 48px;
  width: 48px;
  height: 48px;
}

.ring-bg {
  fill: none;
  stroke: var(--bg-input);
  stroke-width: 4;
}

.ring-fill {
  fill: none;
  stroke: var(--primary);
  stroke-width: 4;
  stroke-linecap: round;
  transition: stroke-dasharray 0.6s ease, stroke 0.6s ease;
  filter: drop-shadow(0 0 4px var(--shadow-glow));
}

/* Ring color by progress thresholds */
.ring-fill.ring-low    { stroke: #22c55e; }
.ring-fill.ring-medium { stroke: var(--primary-light); }
.ring-fill.ring-high   { stroke: #dc2626; filter: drop-shadow(0 0 8px rgba(220, 38, 38, 0.5)); }

.ring-text {
  fill: var(--primary);
  font-size: 11px;
  font-weight: bold;
  text-anchor: middle;
}

/* ───────── Skeleton Loading ───────── */
.loading-container {
  position: relative;
  min-height: 120px;
}

.skeleton {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  overflow: hidden;
  position: relative;
}
.skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, var(--skeleton-shimmer) 50%, transparent 100%);
  animation: skeletonShimmer 1.8s ease-in-out infinite;
}
@keyframes skeletonShimmer {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

.skeleton-tank-card {
  height: 340px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  border-left: 4px solid var(--border);
}
.skeleton-session-card {
  height: 56px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  margin-bottom: 0.75rem;
}
.skeleton-chart {
  height: 240px;
}

/* Hide old spinner when skeleton is active */
.loading-container.loading .skeleton-preload { display: block; }
.loading-container:not(.loading) .skeleton-preload { display: none; }

/* Keep old spinner for backward compatibility on elements without skeleton */
.loading-container.loading-spinner.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 28px;
  height: 28px;
  margin: -14px 0 0 -14px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  z-index: 3;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-container .error-msg {
  display: none;
  color: var(--text-danger);
  font-size: 0.85rem;
  text-align: center;
  padding: 2rem;
}

.loading-container.error .error-msg {
  display: block;
}

.loading-container.error::after {
  display: none;
}

/* ───────── Confirm Modal ───────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-modal-overlay);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-box {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-xl);
  padding: 2rem;
  min-width: 400px;
  max-width: 90vw;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  border-top: 3px solid var(--primary);
}

.modal-title {
  color: var(--primary);
  margin-bottom: 1rem;
}

.modal-details {
  margin-bottom: 1.5rem;
  line-height: 1.8;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}

.modal-actions button {
  padding: 0.5rem 1.2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: border-color var(--transition-fast), background var(--transition-fast);
}

#confirmCancel {
  background: transparent;
  color: var(--text-muted);
}

#confirmCancel:hover {
  border-color: var(--text-dim);
  color: var(--text);
}

#confirmOk {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

#confirmOk:hover {
  background: var(--primary-hover);
}

#confirmOk.ok-danger {
  background: #b91c1c;
  border-color: #b91c1c;
  color: #fff;
}

#confirmOk.ok-danger:hover {
  background: #991b1b;
}

/* ───────── Add Tank Section ───────── */
.add-tank-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-top: 2rem;
  border-left: 4px solid var(--primary);
}

/* ───────── Toast Notifications ───────── */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.65rem 1.1rem;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  color: var(--toast-text);
  pointer-events: auto;
  animation: toastIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  max-width: 380px;
  box-shadow: var(--toast-shadow);
  border-left: 3px solid transparent;
}

.toast .toast-icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toast .toast-icon svg {
  width: 18px;
  height: 18px;
}

.toast .toast-msg {
  flex: 1;
  line-height: 1.4;
}

.toast-dismiss {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--toast-dismiss);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0 0.2rem;
  line-height: 1;
  transition: color var(--transition-fast);
}
.toast-dismiss:hover {
  color: var(--toast-dismiss-hover);
}

.toast.toast-error {
  background: var(--bg-toast-error);
  border-left-color: var(--danger);
}

.toast.toast-success {
  background: var(--bg-toast-success);
  border-left-color: var(--success);
}

.toast.toast-info {
  background: var(--bg-toast-info);
  border-left-color: var(--blue);
}

@keyframes toastIn {
  0% { opacity: 0; transform: translateX(100%) scale(0.9); }
  100% { opacity: 1; transform: translateX(0) scale(1); }
}

.toast.toast-out {
  animation: toastOut 0.3s ease-in forwards;
}

@keyframes toastOut {
  0% { opacity: 1; transform: translateX(0) scale(1); }
  100% { opacity: 0; transform: translateX(100%) scale(0.9); }
}

/* ───────── Tank Card Expand ───────── */
.tank-expand {
  overflow: hidden;
  transition: max-height 0.35s ease;
}

.expand-content {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  padding-top: 0.75rem;
  flex-wrap: wrap;
  position: relative;
}

.expand-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.75rem 0 0;
}

.expand-content input {
  flex: 1;
  min-width: 100px;
  padding: 0.5rem 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: 0.8rem;
}

.expand-content input:focus {
  outline: none;
  border-color: var(--primary);
}

.expand-content input.error {
  border-color: var(--border-error);
}

.expand-content .vol-set-btn {
  padding: 0.5rem 1rem;
  background: var(--primary);
  border: none;
  border-radius: var(--radius-md);
  color: #fff;
  font-size: 0.8rem;
  font-family: inherit;
  font-weight: bold;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.expand-content .vol-set-btn:hover {
  background: var(--primary-hover);
}

.expand-error {
  flex: 0 0 100%;
  color: var(--text-danger);
  font-size: 0.7rem;
  min-height: 0;
  display: none;
}

.expand-error.visible {
  display: block;
}

/* ───────── Login Screen ───────── */
#loginScreen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 2rem;
  position: fixed;
  inset: 0;
  z-index: 1000;
}

.login-box {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-xl);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
  text-align: center;
  position: relative;
  overflow: hidden;
  box-shadow: 0 0 60px var(--shadow-glow), 0 8px 32px rgba(0,0,0,0.4);
}

.login-box::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--primary-light), var(--primary));
  background-size: 200% 100%;
  animation: shimmer 3s ease-in-out infinite;
  box-shadow: 0 0 20px var(--shadow-glow-strong);
}

@keyframes shimmer {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

.login-title {
  color: var(--primary);
  margin-bottom: 0.5rem;
  font-size: 1.4rem;
  letter-spacing: 0.03em;
}

.login-subtitle {
  color: var(--text-dim);
  margin-bottom: 1.5rem;
  font-size: 0.85rem;
}

.login-box form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.login-box label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.login-box input {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--login-input-surface);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.login-box input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 16px rgba(185, 106, 25, 0.25);
}

#loginBtn {
  padding: 0.75rem 1.5rem;
  background: var(--primary);
  border: none;
  border-radius: var(--radius-md);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--transition-fast), box-shadow var(--transition-fast);
}

#loginBtn:hover {
  background: var(--primary-hover);
  box-shadow: 0 0 16px var(--shadow-glow-strong);
}

#loginBtn:active {
  transform: scale(0.97);
}

#loginBtn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.login-error {
  color: var(--text-danger);
  font-size: 0.8rem;
  min-height: 1.2rem;
}

/* ───────── Unit Select ───────── */
#unitSelect {
  flex: 0 0 auto;
  width: auto;
  min-width: 0;
  padding: 0.6rem 0.5rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--primary);
  font-size: 0.85rem;
  cursor: pointer;
}

#unitSelect:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 12px rgba(185, 106, 25, 0.25);
}

#unitSelect option {
  background: var(--bg-card);
  color: var(--text);
}

/* ───────── User Management Tab ───────── */
.users-tab-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.users-tab-header .section-title {
  margin-bottom: 0;
}

.users-add-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 0.5rem 1.2rem;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background var(--transition-fast), box-shadow var(--transition-fast);
}

.users-add-btn:hover {
  background: var(--primary-hover);
  box-shadow: 0 0 16px var(--shadow-glow-strong);
}

.user-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  margin-bottom: 0.65rem;
  transition: border-color var(--transition-fast);
}

.user-card:hover {
  border-color: var(--glass-border);
}

.user-card-avatar {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}

/* Hue variants for avatar — applied via data-hue attribute */
.user-card-avatar[data-hue="200"] { background: linear-gradient(135deg, #3b82f6, #1e40af); }
.user-card-avatar[data-hue="140"] { background: linear-gradient(135deg, #22c55e, #166534); }
.user-card-avatar[data-hue="330"] { background: linear-gradient(135deg, #ec4899, #9d174d); }
.user-card-avatar[data-hue="30"]  { background: linear-gradient(135deg, #f59e0b, #b45309); }
.user-card-avatar[data-hue="270"] { background: linear-gradient(135deg, #a855f7, #6b21a8); }
.user-card-avatar[data-hue="180"] { background: linear-gradient(135deg, #06b6d4, #155e75); }

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

.user-card-info h4 {
  color: var(--text);
  font-size: 0.95rem;
  margin: 0 0 0.15rem;
}

.user-card-email {
  color: var(--text-dim);
  font-size: 0.8rem;
  margin: 0 0 0.1rem;
}

.user-card-meta {
  color: var(--text-dim);
  font-size: 0.7rem;
  margin: 0;
}

.user-card-role {
  flex-shrink: 0;
}

.user-role-badge {
  display: inline-block;
  padding: 0.25rem 0.7rem;
  border-radius: var(--radius-full);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.role-admin {
  background: rgba(185, 106, 25, 0.2);
  color: var(--primary-light);
}

.role-user {
  background: rgba(59, 130, 246, 0.15);
  color: var(--blue);
}

.user-card-actions {
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
}

.user-btn-edit,
.user-btn-delete {
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  background: transparent;
  transition: border-color var(--transition-fast), color var(--transition-fast);
}

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

.user-btn-edit:hover {
  border-color: var(--primary);
  color: var(--primary);
}

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

.user-btn-delete:hover {
  border-color: var(--danger);
  color: var(--danger);
}

/* User form modal */
.user-form-box {
  max-width: 420px;
}

.user-form-fields {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.user-form-fields label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.user-form-fields input[type="text"],
.user-form-fields input[type="email"],
.user-form-fields input[type="password"] {
  width: 100%;
  padding: 0.7rem 0.9rem;
  background: var(--user-input-surface);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.user-form-fields input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 12px rgba(185, 106, 25, 0.2);
}

.user-form-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
}

.user-form-check input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}

.user-form-error {
  color: var(--text-danger);
  font-size: 0.8rem;
  min-height: 1.2rem;
}

.field-hint {
  font-size: 0.75rem;
  min-height: 1rem;
  margin: -0.35rem 0 0;
}

/* Responsive: phone */
@media (max-width: 480px) {
  .user-card { flex-wrap: wrap; gap: 0.5rem; }
  .user-card-role { order: -1; }
  .user-card-actions { width: 100%; justify-content: flex-end; }
}

/* ───────── Connection Lost Banner ───────── */
.connection-banner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0.75rem 2rem 0.5rem;
  animation: bannerSlideIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.connection-banner-inner {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.75rem 1.25rem;
  background: var(--connection-banner-surface);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--connection-banner-border);
  border-left: 4px solid var(--danger);
  border-radius: var(--radius-lg);
  box-shadow: 0 0 24px rgba(239, 68, 68, 0.12), 0 4px 16px rgba(0,0,0,0.3);
}

.connection-banner-icon {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  color: var(--danger);
  opacity: 0.9;
}

.connection-banner-icon svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 0 6px rgba(239, 68, 68, 0.4));
}

.connection-banner-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.connection-banner-body strong {
  color: var(--connection-banner-heading);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.connection-banner-body span {
  color: var(--text-muted);
  font-size: 0.8rem;
  line-height: 1.4;
}

.connection-banner-out .connection-banner-inner {
  animation: bannerSlideOut 0.35s ease-in forwards;
}

@keyframes bannerSlideIn {
  0% { opacity: 0; transform: translateY(-12px); }
  100% { opacity: 1; transform: translateY(0); }
}

@keyframes bannerSlideOut {
  0% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-12px); }
}

/* ───────── Industrial Wave redesign ───────── */
html {
  color-scheme: dark;
}

html[data-theme="light"] {
  color-scheme: light;
}

.section-heading-row {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.section-heading-row .section-title { margin-bottom: 0; }

.inventory-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.55rem;
}

.inventory-actions .secondary-action { white-space: nowrap; }

.tilt-motion-btn[aria-pressed="true"] {
  border-color: var(--primary-light);
  background: rgba(245, 158, 11, 0.18);
  box-shadow: inset 0 0 0 1px rgba(245, 158, 11, 0.12);
}

.tilt-motion-btn:disabled {
  cursor: not-allowed;
  opacity: 0.68;
}

.section-kicker {
  margin: 0 0 0.25rem;
  color: var(--text-dim);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

#dashboardTab { --dashboard-section-gap: 2.5rem; }

.operation-region,
.inventory-section,
#adminSections { margin-bottom: var(--dashboard-section-gap); }

.operation-region {
  padding: 1.25rem;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-xl);
  background: var(--operation-surface);
  box-shadow: 0 10px 35px rgba(0,0,0,0.28);
}

.operation-region.has-active-operation {
  border-color: rgba(245, 158, 11, 0.28);
  box-shadow: 0 12px 40px rgba(0,0,0,0.35), 0 0 24px var(--shadow-glow);
}

.operation-region .sessions-list { margin-top: 0; }
.operation-region .injection-dashboard { margin-top: 1.5rem; }
.operation-empty { padding: 1.25rem; }

.secondary-action,
.tank-details-toggle,
.session-view {
  min-height: 38px;
  padding: 0.45rem 0.85rem;
  border: 1px solid var(--border-hover);
  border-radius: var(--radius-md);
  background: rgba(185, 106, 25, 0.08);
  color: var(--primary-light);
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}

.secondary-action:hover,
.tank-details-toggle:hover,
.session-view:hover {
  background: rgba(245, 158, 11, 0.15);
  border-color: var(--primary-light);
}

.tank-card {
  cursor: default;
  overflow: hidden;
  --react-angle: var(--motion-angle, 0deg);
  --react-bob: var(--motion-bob, 0px);
  --react-wave-scale: var(--motion-wave-scale, 1);
  --liquid-top: #d4881e;
  --liquid-mid: #8b4a0b;
  --liquid-bottom: #3d1c00;
  --wave-front: #e39a2d;
  --wave-back: #a65c12;
  --wave-speed: 8s;
  --wave-front-speed: 6.4s;
}

.tank-card:hover { transform: none; }
.tank-card.is-selected-operation { box-shadow: 0 0 0 1px var(--primary-light), 0 0 24px var(--shadow-glow-strong); }
.tank-card.is-source { border-top-color: var(--primary-light); }
.tank-card.is-receiver { border-top-color: #22c55e; }

.tank-card[data-product="diesel"] {
  --liquid-top: #4a90d9;
  --liquid-mid: #1a4a8a;
  --liquid-bottom: #0a2240;
  --wave-front: #60a5fa;
  --wave-back: #2563a8;
  --wave-speed: 6s;
  --wave-front-speed: 4.8s;
}
.tank-card[data-product="gasoline"] {
  --liquid-top: #4ade80;
  --liquid-mid: #15803d;
  --liquid-bottom: #064e1a;
  --wave-front: #6ee7a0;
  --wave-back: #1e9b4d;
  --wave-speed: 4.5s;
  --wave-front-speed: 3.6s;
}
.tank-card[data-product="fuel oil"] {
  --liquid-top: #e85d3a;
  --liquid-mid: #7a1a0a;
  --liquid-bottom: #3d0800;
  --wave-front: #f27755;
  --wave-back: #9f2f1a;
  --wave-speed: 10s;
  --wave-front-speed: 8s;
}

.tank-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: 4.15rem;
  margin-bottom: 0.85rem;
}
.tank-card-header h3 { margin: 0 0 0.15rem; }
.tank-product {
  color: var(--text-muted);
  font-size: 0.78rem;
  text-transform: capitalize;
}
.tank-card-header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.45rem;
  flex-wrap: wrap;
}
.tank-role-badge {
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-full);
  background: rgba(245, 158, 11, 0.14);
  color: var(--primary-light);
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}
.tank-card.is-receiver .tank-role-badge {
  background: var(--receiver-badge-surface);
  color: var(--receiver-badge-text);
}

.tank-visual { height: 172px; }
.liquid-level {
  position: absolute;
  inset: 0;
  z-index: 1;
  transform: translateY(var(--level-offset, 100%));
  transition: transform var(--transition-slow) ease;
  will-change: transform;
}
.liquid-motion {
  position: absolute;
  inset: 0;
  transform: translateY(var(--react-bob)) rotate(var(--react-angle));
  transform-origin: 50% 10px;
  will-change: transform;
}
.liquid-body {
  position: absolute;
  top: 10px;
  right: -5%;
  bottom: -8%;
  left: -5%;
  background:
    linear-gradient(105deg, transparent 30%, rgba(255,255,255,0.08) 50%, transparent 70%) calc(50% + var(--motion-highlight, 0px)) 0 / 42% 100% no-repeat,
    linear-gradient(180deg, var(--liquid-top), var(--liquid-mid) 58%, var(--liquid-bottom));
  box-shadow: inset 0 8px 18px rgba(255,255,255,0.05), 0 -4px 18px color-mix(in srgb, var(--wave-front) 28%, transparent);
}
.tank-wave {
  position: absolute;
  top: -1px;
  left: -4%;
  width: 208%;
  height: 24px;
  z-index: 2;
  pointer-events: none;
  filter: drop-shadow(0 -2px 5px rgba(255,255,255,0.08));
  transform-origin: 50% 50%;
  will-change: transform;
}
.tank-wave--back { color: var(--wave-back); opacity: 0.72; transform: translateX(-18%) scaleY(var(--react-wave-scale)); }
.tank-wave--front { color: var(--wave-front); opacity: 0.9; transform: translateX(-42%) scaleY(var(--react-wave-scale)); }
.tank-wave path { fill: currentColor; }
.tank-card.is-operating .tank-wave--back { animation: waveTravel var(--wave-speed) linear infinite; }
.tank-card.is-operating .tank-wave--front { animation: waveTravelReverse var(--wave-front-speed) linear infinite; }
.tank-card.is-operating .liquid-body { box-shadow: inset 0 8px 22px rgba(255,255,255,0.08), 0 -5px 22px color-mix(in srgb, var(--wave-front) 42%, transparent); }

.tank-card.is-operating {
  --react-angle: var(--motion-angle-active, 0deg);
  --react-bob: var(--motion-bob-active, 0px);
  --react-wave-scale: var(--motion-wave-scale-active, 1);
}

@keyframes waveTravel {
  from { transform: translateX(-18%) scaleY(var(--react-wave-scale)); }
  to { transform: translateX(-68%) scaleY(var(--react-wave-scale)); }
}
@keyframes waveTravelReverse {
  from { transform: translateX(-42%) scaleY(var(--react-wave-scale)); }
  to { transform: translateX(8%) scaleY(var(--react-wave-scale)); }
}

.fill-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  width: max-content;
  max-width: 90%;
}
.fill-percentage { font-size: 1.75rem; line-height: 1; }
.fill-volume { font-size: 0.72rem; font-family: var(--font-mono); color: rgba(255,255,255,0.9); }
.tank-expand[hidden] { display: none; }
.tank-expand { transition: none; }
.tank-card.is-expanded { grid-column: span 1; }

.session-card { cursor: default; }
.session-view { flex-shrink: 0; }
.session-view[aria-pressed="true"] {
  background: var(--primary-light);
  color: var(--primary-action-text);
}

.injection-form { margin-top: 0; padding: 1.5rem; }
.operation-form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
}
.form-cluster {
  min-width: 0;
  align-items: stretch;
  padding: 0.85rem;
}
.form-cluster legend {
  padding: 0 0.35rem;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.direction-cluster { grid-column: span 1; }
.tank-cluster,
.quantity-cluster,
.assignment-cluster { display: grid; }
.tank-cluster { grid-column: span 3; grid-template-columns: minmax(140px, 0.7fr) minmax(220px, 1.3fr); }
.quantity-cluster { grid-column: span 3; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.quantity-cluster .input-group { flex: 0 0 auto; }
.dest-section { display: grid; grid-template-columns: repeat(3, minmax(130px, 1fr)); }
.assignment-cluster { grid-column: span 1; grid-template-columns: minmax(0, 1fr); align-items: end; }
.operation-form-grid select,
.operation-form-grid input { min-height: 44px; }
#operationForm input,
#operationForm select {
  box-sizing: border-box;
  width: 100%;
  height: 44px;
  padding: 0 0.85rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}
#operationForm select { padding-right: 2.25rem; }
#operationForm input::placeholder {
  color: var(--input-placeholder);
  opacity: 1;
}
#operationForm .input-group input { padding-right: 3.25rem; }
#operationForm input:focus,
#operationForm select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 12px rgba(185, 106, 25, 0.2);
}
#operationForm .mode-toggle {
  display: grid;
  grid-template-columns: repeat(2, 80px);
  width: 160px;
  height: 44px;
  gap: 0;
}
#operationForm .mode-btn {
  box-sizing: border-box;
  display: grid;
  place-items: center;
  width: 80px;
  height: 44px;
  padding: 0;
}
#startBtn { min-height: 44px; }
.assignment-cluster #startBtn { width: 100%; }
#startBtn,
#addTankBtn,
#userFormSave {
  padding: 0.65rem 1.2rem;
  border: 1px solid var(--primary-light);
  border-radius: var(--radius-md);
  background: var(--primary-light);
  color: var(--primary-action-text);
  font-weight: 800;
  cursor: pointer;
}
#tankFormCancel,
#userFormCancel {
  background: transparent;
  color: var(--text-muted);
}
.form-error { position: static; min-height: 1.1rem; margin-top: 0.75rem; }

.tank-form-box { width: min(760px, 92vw); }
.tank-form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.tank-location-field { grid-column: 1 / -1; }
.tank-form-grid input,
.tank-form-grid select { min-height: 44px; padding: 0.65rem 0.8rem; background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius-md); color: var(--text); }

.diagnostics-panel {
  margin-top: 1rem;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  background: var(--diagnostics-surface);
}
.diagnostics-panel > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 48px;
  padding: 0.75rem 1rem;
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
}
.diagnostics-panel > summary::marker { color: var(--primary-light); }
.diagnostics-summary-copy { color: var(--text-muted); font-size: 0.78rem; font-weight: 400; }
.diagnostic-metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; padding: 0 1rem 1rem; }
.diagnostic-picker { display: none; padding: 0 1rem 1rem; }
.diagnostics-panel .charts-row { padding: 0 1rem; }

.header-time,
.fill-text,
.stat-value,
.progress-bar-bg,
.ring-text,
.tl-value,
.dashboard-info { font-variant-numeric: tabular-nums; }

.history-toggle { transition: background 0.2s, border-color 0.2s, box-shadow 0.2s; }
.history-toggle { color: var(--primary-light); }

.mode-btn.active,
.form-row button[type="button"],
#startBtn,
#confirmOk:not(.ok-danger),
#addTankBtn,
.users-add-btn,
#loginBtn,
.expand-content .vol-set-btn { color: var(--primary-action-text); }

input:focus-visible,
select:focus-visible,
button:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--primary-light) !important;
  outline-offset: 2px;
}

.ceres-lockup {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
}

.ceres-mark {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.ceres-relationship {
  display: block;
  color: var(--text-dim);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  line-height: 1.2;
}

.ceres-lockup-header .header-title {
  display: block;
}

.ceres-lockup-login {
  justify-content: center;
  margin-bottom: 0.9rem;
}

.login-theme-control {
  display: flex;
  justify-content: flex-end;
  margin: -1rem -0.5rem 0.5rem;
}

.theme-toggle {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border: 1px solid var(--border-hover);
  border-radius: 50%;
  background: var(--bg-input);
  color: var(--primary-light);
  font: inherit;
  font-size: 1rem;
  cursor: pointer;
}

.theme-toggle:hover {
  border-color: var(--primary-light);
  background: var(--bg-hover);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--primary-light);
  outline-offset: 3px;
}

[data-theme-icon] {
  display: block;
  position: relative;
  width: 16px;
  height: 16px;
  font-size: 0;
  line-height: 0;
  pointer-events: none;
}

[data-theme-icon]::before,
[data-theme-icon]::after {
  content: '';
  position: absolute;
}

:root[data-theme="light"] [data-theme-icon]::before {
  inset: 1px;
  border-radius: 50%;
  background: currentColor;
  -webkit-mask: radial-gradient(circle at 68% 32%, transparent 0 43%, #000 46%);
  mask: radial-gradient(circle at 68% 32%, transparent 0 43%, #000 46%);
}

:root[data-theme="dark"] [data-theme-icon]::before {
  inset: 4px;
  border: 2px solid currentColor;
  border-radius: 50%;
}

:root[data-theme="dark"] [data-theme-icon]::after {
  top: 0;
  left: 7px;
  width: 2px;
  height: 2px;
  border-radius: 50%;
  background: currentColor;
  box-shadow:
    0 14px currentColor,
    -7px 7px currentColor,
    7px 7px currentColor,
    -5px 2px currentColor,
    5px 2px currentColor,
    -5px 12px currentColor,
    5px 12px currentColor;
}

@media (max-width: 480px) {
  .ceres-relationship {
    letter-spacing: 0.08em;
  }

  .ceres-mark {
    width: 34px;
    height: 34px;
    flex-basis: 34px;
  }

}

/* ───────── Responsive: Tablet ───────── */
@media (max-width: 768px) {
  .container { padding: 1rem; }
  .header { padding: 0.75rem 1rem; }
  .header-title { font-size: 1.2rem; }
  .tank-grid { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }
  .charts-row { grid-template-columns: 1fr; }
  .charts-row.charts-secondary,
  .charts-row.charts-secondary:last-child { grid-template-columns: 1fr; }
  .injection-form { padding: 1rem; }
  .form-row { gap: 0.6rem; }
  .timeline-row { gap: 0.5rem; }
  .modal-box { min-width: 0; width: 90%; padding: 1.2rem 1.5rem; }
  .session-card { padding: 0.8rem 1rem; gap: 0.6rem; }
  .tab-bar { padding: 0 1rem; overflow-x: auto; }
  .tab-btn { padding: 0.7rem 1rem; font-size: 0.8rem; white-space: nowrap; }
  .history-card { flex-wrap: wrap; gap: 0.5rem; }
  .hc-meta { flex-wrap: wrap; gap: 0.75rem; }
  .operation-form-grid { grid-template-columns: 1fr; }
  .direction-cluster,
  .tank-cluster,
  .quantity-cluster,
  .assignment-cluster { grid-column: auto; }
  .operation-region { padding: 1rem; }
  .diagnostic-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ───────── Responsive: Phone ───────── */
@media (max-width: 480px) {
  .container { padding: 0.5rem; }
  #dashboardTab { --dashboard-section-gap: 1.5rem; }

  /* #1 Compact header */
  .header { padding: 0.5rem 0.75rem; }
  .header-title { font-size: 1rem; }
  .header-left {
    min-width: 0;
    flex: 1 1 auto;
    flex-wrap: nowrap;
    gap: 0.45rem;
  }
  .header-live-status {
    flex: 0 0 auto;
    gap: 0;
    font-size: 0.68rem;
  }
  #headerStatusText {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
  }
  .theme-toggle-header {
    width: 44px;
    height: 44px;
    flex-basis: 44px;
  }
  .header-user-name, .header-time { display: none; }
  .logout-btn { padding: 0.3rem 0.7rem; font-size: 0.75rem; }

  /* #6 Full-viewport modals */
  .modal-overlay {
    align-items: flex-end;
    padding:
      max(0.5rem, env(safe-area-inset-top))
      env(safe-area-inset-right)
      env(safe-area-inset-bottom)
      env(safe-area-inset-left);
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .modal-box {
    min-width: 0;
    width: 100%;
    max-width: 100%;
    max-height: calc(100dvh - max(0.5rem, env(safe-area-inset-top)) - env(safe-area-inset-bottom));
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 1.25rem;
  }
  .modal-actions { flex-direction: column; }
  .modal-actions button { width: 100%; }

  /* Tank cards & buttons */
  .tank-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.65rem; }
  .tank-card { padding: 0.7rem; border-left-width: 3px; }
  .tank-card-header { display: block; min-height: 0; margin-bottom: 0.55rem; }
  .tank-card-header h3 { font-size: 0.92rem; }
  .tank-card-header-actions { justify-content: space-between; margin-top: 0.45rem; }
  .tank-details-toggle { min-height: 44px; padding: 0.35rem 0.6rem; font-size: 0.72rem; }
  .tank-visual { height: 116px; margin-bottom: 0.35rem; }
  .fill-percentage { font-size: 1.25rem; }
  .fill-volume { font-size: 0.68rem; }
  .tank-card.is-expanded { grid-column: 1 / -1; }
  .tank-card.is-expanded .tank-visual { height: 150px; }

  /* #3 Tank card buttons stacked */
  .tank-actions { flex-direction: column; gap: 0.35rem; }

  /* Injection form */
  .form-row { flex-direction: column; }
  .form-row select, .form-row input, .field-wrap { min-width: 0; width: 100%; }
  #unitSelect { width: auto; align-self: flex-start; }
  .injection-form { padding: 0.75rem 0.75rem 2rem; margin-top: 1rem; }
  .form-error { left: 0.75rem; right: 0.75rem; bottom: 0.5rem; }
  .operation-form-grid,
  .tank-cluster,
  .quantity-cluster,
  .assignment-cluster,
  .dest-section { grid-template-columns: 1fr; }
  .form-cluster { display: grid; }
  .tank-form-grid { grid-template-columns: 1fr; }
  .tank-location-field { grid-column: auto; }
  .section-heading-row { align-items: center; }
  .section-kicker { font-size: 0.64rem; }
  .operation-region { padding: 0.65rem; }
  .operation-region.has-active-operation .sessions-list {
    padding: 0.55rem;
    margin: -0.55rem -0.55rem 0;
    background: var(--mobile-nav-surface);
    border-bottom: 1px solid var(--glass-border);
  }
  .operation-heading { margin-bottom: 0.45rem; }
  .operation-heading .section-kicker { display: none; }
  .operation-heading .section-title { font-size: 1rem; }

  /* Stats */
  .stats-row { grid-template-columns: repeat(2, 1fr); gap: 0.5rem; }
  .stat-value { font-size: 1.3rem; }
  .stat-card { padding: 1rem 0.75rem; }

  .progress-section { padding: 1rem; }
  .session-controls { flex-wrap: wrap; }

  /* #4 Session cards vertical */
  .session-card { flex-direction: column; align-items: stretch; gap: 0.4rem; padding: 0.75rem 1rem; }
  .session-card .session-info { min-width: 0; }
  .session-status { align-self: flex-start; }
  .session-view { width: 100%; min-height: 44px; }

  /* #5 Simplified timeline */
  .timeline-row { padding: 0.75rem 0.25rem 0.25rem; }
  .timeline-row::before,
  .timeline-row::after { top: calc(0.75rem + 5.5px); }
  .tl-dot { width: 10px; height: 10px; border-width: 2px; }
  .tl-label { font-size: 0.68rem; }
  .tl-value { font-size: 0.75rem; }
  .tl-item { padding-top: 0; }

  /* History cards */
  .history-card { flex-wrap: wrap; gap: 0.5rem; padding: 0.5rem 0.75rem; }
  .hc-meta { flex-wrap: wrap; gap: 0.5rem; }

  /* #7 Chart cards */
  .chart-card { height: 180px; }
  .chart-card.chart-full { height: 220px; }
  .chart-card h3 { font-size: 0.7rem; margin-bottom: 0.35rem; }
  .diagnostics-summary-copy { display: none; }
  .diagnostic-metrics { grid-template-columns: 1fr 1fr; padding: 0 0.65rem 0.65rem; gap: 0.5rem; }
  .diagnostic-picker { display: flex; padding: 0 0.65rem 0.65rem; }
  .diagnostic-picker select { min-height: 44px; padding: 0.55rem; background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius-md); color: var(--text); }
  .diagnostics-panel .charts-row { display: block; padding: 0 0.65rem; }
  .diagnostics-panel [data-diagnostic-chart] { display: none; }
  .diagnostics-panel [data-diagnostic-chart].diagnostic-selected { display: flex; }

  /* Connection banner compact */
  .connection-banner { padding: 0.5rem 0.5rem 0.35rem; }
  .connection-banner-inner { padding: 0.6rem 1rem; gap: 0.6rem; }
  .connection-banner-icon { width: 22px; height: 22px; }
  .connection-banner-body strong { font-size: 0.8rem; }
  .connection-banner-body span { font-size: 0.75rem; }

  /* #1 Touch-friendly targets (44px min height) */
  .tab-btn { min-height: 44px; padding: 0.6rem 0.75rem; font-size: 0.75rem; }
  .secondary-action,
  .mode-btn,
  .tank-details-toggle,
  .session-view { min-height: 44px; }
  .ctrl-btn { min-height: 44px; padding: 0.5rem 1rem; }
  .tank-btn { min-height: 44px; padding: 0.5rem; font-size: 0.85rem; }
  .session-card { min-height: 44px; }
  .logout-btn { min-height: 44px; }
  .history-toggle { min-height: 44px; padding: 0.6rem 1rem; }
  .hc-delete { min-height: 44px; min-width: 44px; padding: 0; }
  .modal-actions button { min-height: 44px; }
  .form-row button[type="button"] { min-height: 44px; }
  #loginBtn { min-height: 44px; }
  .injection-form .input-group button { min-height: 44px; }

  /* User idle card */
  .user-idle-card { padding: 1.5rem 1.5rem; }
  .user-idle-icon svg { width: 32px; height: 32px; }
}

@media (max-width: 360px) {
  .tank-grid { grid-template-columns: 1fr; }
  .tank-card.is-expanded { grid-column: auto; }
  .tank-visual { height: 140px; }
}

@media (max-width: 390px) {
  .header { padding: 0.5rem; }
  .header-inner { gap: 0.5rem; }
  .header-left {
    min-width: 0;
    flex: 1 1 auto;
    flex-wrap: nowrap;
  }
  .ceres-lockup-header {
    min-width: 0;
    gap: 0.4rem;
  }
  .ceres-lockup-header > div { min-width: 0; }
  .ceres-lockup-header .ceres-mark {
    width: 30px;
    height: 30px;
    flex-basis: 30px;
    font-size: 0.72rem;
  }
  .ceres-lockup-header .ceres-relationship {
    font-size: 0.48rem;
    letter-spacing: 0.04em;
    white-space: nowrap;
  }
  .ceres-lockup-header .header-title {
    font-size: 0.82rem;
    letter-spacing: 0;
    white-space: nowrap;
  }
  .header-right {
    flex: 0 0 auto;
    gap: 0.25rem;
  }
  .logout-btn {
    min-width: 60px;
    padding: 0.3rem 0.5rem;
    font-size: 0.7rem;
  }
}

/* ───────── Backdrop-filter fallback ───────── */
@supports not ((backdrop-filter: blur(12px)) or (-webkit-backdrop-filter: blur(12px))) {
  .stat-card, .chart-card, .modal-box, .session-card, .login-box, .toast {
    background: var(--bg-card);
  }
}

/* ───────── Reduced motion ───────── */
@media (prefers-reduced-motion: reduce) {
  .theme-toggle {
    transition: none;
  }

  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .tank-wave { display: none; }
  .liquid-level { transition: none !important; }
  .liquid-motion { transform: none !important; }
  .liquid-body { top: 0; }
  .tilt-motion-btn { display: none !important; }
}
