:root{
  --bg1: #0f172a;
  --bg2: #07103a;
  --card: rgba(255,255,255,0.04); /* restored blue-ish card surface */
  --glass: rgba(255,255,255,0.04);
  --accent: #06B6D4;
  --accent-2: #ef4444;           /* red accent for charts / danger */
  --text: #f4f8ff;               /* brighter foreground text */
  --muted: #9fb0c6;              /* slightly brighter muted */
  --select-bg: rgba(255,255,255,0.03);

  --green: #22c55e;
  --orange: #f59e0b;
  --red: #ef4444;
  --shadow-1: 0 12px 36px rgba(2,6,23,0.55);

  /* layout tokens */
  --radius: 12px;
  --card-padding: 22px;
  --gap: 12px;
}

/* baseline */
*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  font-family: Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  color:var(--text);
  background: linear-gradient(180deg, var(--bg1) 0%, var(--bg2) 55%);
  -webkit-font-smoothing:antialiased;
  -moz-osx-font-smoothing:grayscale;
  display:flex;
  flex-direction:column;
  min-height:100vh;
}

/* When a modal is open, dim everything except the modal and modal-dropdowns */
body.modal-open > :not(.history-modal):not(.modal-dropdown):not(.login-modal) {
  transition: filter .28s ease, opacity .28s ease;
  filter: brightness(0.08) saturate(0.9);
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  opacity: 0.98;
}

/* keep modal-dropdowns interactive and visible */
.modal-dropdown {
  z-index: 10070 !important;
  position: fixed !important;
}

/* Header — inline logo + brand (refined to be more prominent but balanced) */
.topbar{
  display:flex;
  align-items:center;
  justify-content:center;
  padding:28px 32px;
  gap:18px;
  background: transparent;
  min-height:140px; /* slightly taller so logo breathes without pushing content */
}

/* container for logo + brand to keep them grouped */
.brand-with-logo{
  display:flex;
  align-items:center;
  gap:18px;
  width:100%;
  max-width:1200px;
}

/* stronger, more professional logo container */
.header-logo{
  display:flex;
  align-items:center;
  justify-content:center;
  flex:0 0 auto;
  background: linear-gradient(180deg, rgba(255,255,255,0.015), rgba(255,255,255,0.005));
  border-radius:12px;
  padding:10px;             /* breathing room around the mark */
  border:1px solid rgba(255,255,255,0.06);
  box-shadow: var(--shadow-1);
  transition: transform 160ms ease, box-shadow 160ms ease;
}

/* logo image refined to be more prominent but still harmonious */
.logo-img{
  width:140px;              /* larger for more presence */
  height:86px;
  object-fit:contain;
  display:block;
  border-radius:8px;
  background: transparent;
  transform-origin:center;
  transition: transform 180ms cubic-bezier(.2,.9,.2,1), box-shadow 180ms;
  -webkit-font-smoothing:antialiased;
}

/* hover/focus makes the logo subtly lift — noticeable but not overpowering */
.header-logo:hover .logo-img,
.header-logo:focus-within .logo-img{
  transform: translateY(-4px) scale(1.03);
  box-shadow: 0 18px 48px rgba(2,6,23,0.6);
}

/* brand text sits to the right of the logo */
.brand{
  display:flex;
  flex-direction:column;
  justify-content:center;
  gap:6px;
}
.brand h1{
  margin:0;
  font-size:30px; /* larger title */
  font-weight:700;
  letter-spacing:0.2px;
  line-height:1.02;
}
.subtitle{
  margin:0;
  font-size:14px; /* larger subtitle */
  color:var(--muted);
  line-height:1.05;
  opacity:0.95;
}

/* main container — moved down a bit so cards sit lower */
.container{
  width:100%;
  max-width:1200px;
  margin:36px auto 36px;
  padding:0 20px;
  flex:1 0 auto;
}

/* Card base — slightly larger for better readability */
.card{
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01));
  /* use var(--card) as underlying surface color (subtle blue-ish) */
  background-color: var(--card);
  border: 1px solid rgba(255,255,255,0.04);
  padding:var(--card-padding);
  border-radius:14px;
  box-shadow: var(--shadow-1);
  min-height:150px;
  display:flex;
  flex-direction:column;
  justify-content:space-between;
  position:relative;
  transition: transform 160ms cubic-bezier(.2,.9,.2,1), box-shadow 160ms;
  will-change: transform;
  user-select: none;
}

/* Hover / focus lift and show controls */
.card:hover,
.card:focus-within{
  transform: translateY(-6px) scale(1.02);
  box-shadow: 0 18px 40px rgba(2,6,23,0.55);
}

/* Selected card (keyboard) */
.card.selected{
  outline: none;
  box-shadow: 0 22px 48px rgba(2,6,23,0.6);
  transform: translateY(-6px) scale(1.02);
}

/* Grid for tanks — larger cards and spacing */
.tanks-grid{
  display:grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap:20px;
}

/* top row in card: name + spinner */
.card-top{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
}

/* result / card content */
.result-header{
  display:flex;
  align-items:center;
  justify-content:flex-start;
  gap:12px;
  margin-top:6px;
}

/* Value block */
.value-unit{display:flex;align-items:center;gap:10px}
.value-box{
  display:flex;
  align-items:center;
  gap:10px;
}

/* status dot left of number */
.status-dot{
  width:12px;
  height:12px;
  border-radius:50%;
  flex:0 0 auto;
  box-shadow: 0 0 18px rgba(0,0,0,0.25) inset;
  opacity:0.98;
}

/* color classes */
.status-green{ background: var(--green); box-shadow: 0 0 8px rgba(34,197,94,0.25); }
.status-orange{ background: var(--orange); box-shadow: 0 0 8px rgba(245,158,11,0.22); }
.status-red{ background: var(--red); box-shadow: 0 0 8px rgba(239,68,68,0.20); }

/* numeric value */
.value{font-size:52px;font-weight:800;line-height:1;color:#fff; transition: color 180ms ease, transform 160ms ease;}
.value.muted{ color:var(--muted); font-weight:700; }

/* unit */
.unit{font-size:14px;color:var(--muted)}

/* metadata and footer */
.meta{margin-top:12px;color:var(--muted);font-size:13px;display:flex;gap:18px;flex-wrap:wrap}
.card-footer{margin-top:16px;display:flex;align-items:center;gap:12px;flex-direction:column}

/* spinner — moved to card top-right */
.card .card-spinner{
  width:14px;
  height:14px;
  border-radius:50%;
  border:2px solid rgba(255,255,255,0.18);
  border-top-color:#fff;
  animation: spin 1s linear infinite;
  display:inline-block;
  flex:0 0 auto;
}

/* Keep a smaller animation for a subtle look */
@keyframes spin{to{transform:rotate(360deg)}}

/* value change pulse */
@keyframes pulse-scale {
  0% { transform: scale(1); text-shadow: 0 0 0 rgba(0,0,0,0); }
  30% { transform: scale(1.06); text-shadow: 0 6px 26px rgba(0,0,0,0.35); }
  100% { transform: scale(1); text-shadow: none; }
}
.value.pulse{
  animation: pulse-scale 520ms ease;
}

/* loading skeleton for value */
.skeleton {
  background: linear-gradient(90deg, rgba(255,255,255,0.03), rgba(255,255,255,0.06), rgba(255,255,255,0.03));
  border-radius:8px;
  min-width:84px;
  height:56px;
  display:inline-block;
  animation: shimmer 1.2s linear infinite;
  background-size: 240px 100%;
}
@keyframes shimmer {
  0% { background-position: -160px 0; }
  100% { background-position: 160px 0; }
}
.skeleton.small { min-width:48px; height:30px; border-radius:6px; }

/* error */
.error{
  margin-top:16px;
  color:#ffdede;
  background: rgba(255,0,0,0.06);
  border:1px solid rgba(255,255,255,0.02);
  padding:12px;
  border-radius:8px;
}

/* inline card error */
.card-error{
  width:100%;
  color:#ffdede;
  background: rgba(255,0,0,0.06);
  border:1px solid rgba(255,255,255,0.02);
  padding:10px;
  border-radius:8px;
  font-size:13px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
}

/* refresh button (initially hidden, appears on hover) */
.card .controls {
  position:absolute;
  top:12px;
  right:12px;
  display:flex;
  gap:8px;
  align-items:center;
}
.refresh-btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:6px;
  width:36px;
  height:36px;
  background: rgba(255,255,255,0.02);
  color:var(--muted);
  border:1px solid rgba(255,255,255,0.03);
  border-radius:8px;
  cursor:pointer;
  transition: background 120ms, transform 120ms, color 120ms, box-shadow 120ms;
  opacity:0;
  transform: translateY(-6px) scale(0.98);
  pointer-events:none;
  font-size:14px;
}
.card:hover .refresh-btn,
.card:focus-within .refresh-btn{
  opacity:1;
  transform: translateY(0) scale(1);
  pointer-events:auto;
}
.refresh-btn svg { display:block; color:var(--muted); }
.refresh-btn:active{ transform: translateY(0) scale(.98); }
.refresh-btn:focus{ outline:2px solid rgba(99,102,241,0.18); }

/* unified .btn used in modal controls - prominent */
.btn {
  display:inline-flex;
  align-items:center;
  justify-content:center;
  height:36px;
  padding:0 12px;
  border-radius:8px;
  border: none;
  background: var(--accent);
  color: #041226;
  font-weight:700;
  cursor:pointer;
  box-shadow: 0 8px 20px rgba(3,7,18,0.5);
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 12px 30px rgba(3,7,18,0.55); }
.btn:active { transform: translateY(0); box-shadow: 0 6px 16px rgba(3,7,18,0.45); }

/* Close button: make red and prominent */
.history-close {
  background: var(--accent-2);
  color: #fff;
  border-radius:8px;
  padding:8px 12px;
  border: none;
  font-weight:700;
  cursor:pointer;
}
.history-close:hover { transform: translateY(-2px); }

/* footer */
.footer{
  text-align:center;
  padding:14px 8px;
  color:var(--muted);
  font-size:13px;
  border-top: 1px solid rgba(255,255,255,0.02);
}

/* Modal / history styles (enlarged) */
.history-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.88);
  z-index: 1200;
  padding: 32px;
}
.history-panel {
  width: 100%;
  max-width: 1200px; /* increased width */
  background: linear-gradient(180deg, rgba(255,255,255,0.015), rgba(255,255,255,0.01));
  border-radius: 12px;
  padding: 20px;
  color: var(--text);
  box-shadow: 0 30px 80px rgba(2,6,23,0.6);
  border: 1px solid rgba(255,255,255,0.02);
  overflow: hidden;
}

/* Header area inside modal: organized three-column layout */
.history-actions {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 16px;
  align-items: center;
  margin-bottom: 14px;
}

/* Left column: device title */
.history-actions > div:first-child {
  display:flex;
  flex-direction:column;
  gap:8px;
}
.history-actions strong {
  font-size:16px;
  letter-spacing:0.3px;
}

/* Middle column: range inputs and apply */
.history-range {
  display:flex;
  align-items:center;
  gap:10px;
  background: transparent;
}

/* Inputs: graph title, range inputs */
.graph-title-input,
.history-panel input[type="datetime-local"] {
  display:inline-block;
  padding:10px 12px;
  border-radius:8px;
  border:1px solid rgba(255,255,255,0.04);
  background: rgba(255,255,255,0.015);
  color: var(--text);
  font-size:14px;
  outline:none;
  min-width:200px;
  box-shadow: inset 0 -1px 0 rgba(0,0,0,0.15);
}
.graph-title-input::placeholder { color: rgba(255,255,255,0.45); }
.history-panel input[type="datetime-local"]::-webkit-calendar-picker-indicator { filter: invert(1) hue-rotate(180deg) brightness(2); }

/* Apply button next to inputs */
.apply-range { height:36px; padding:0 14px; }

/* Right column: actions stacked vertically for compactness */
.history-actions > div:last-child {
  display:flex;
  flex-direction:column;
  align-items:flex-end;
  gap:10px;
}
.history-controls { display:flex; gap:10px; align-items:center; }
.history-controls .btn { min-width:86px; }

/* Make stats/export buttons more compact and consistent */
.stats-btn, .export-btn { min-width:86px; }

/* Chart container styling — increased height to make modal taller */
.history-panel > div[position="chart"],
.history-panel > div[style*="height:"] {
  border-radius:8px;
  overflow:hidden;
  background: transparent;
  padding: 8px 4px 4px 4px;
}

/* Message below chart */
.history-msg { margin-top:10px; color:var(--muted); font-size:13px; }

/* Make graph/context dropdowns solid black and clearly visible */
.dropdown {
  position: absolute;
  background: #000000 !important;
  color: #ffffff !important;
  border: 1px solid rgba(255,255,255,0.06);
  padding:8px;
  border-radius:8px;
  min-width:160px;
  box-shadow: 0 14px 40px rgba(0,0,0,0.6);
  z-index: 1300;
  opacity: 1 !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

/* Dropdown buttons inside modal use subtle transparent style */
.dropdown .btn { width:100%; justify-content:flex-start; gap:8px; background: transparent; color: var(--text); border: 1px solid rgba(255,255,255,0.04); box-shadow:none; padding:8px; border-radius:6px; }
.dropdown .btn:hover { background: rgba(255,255,255,0.02); }

/* Graph title input field (modal) — kept consistent with other inputs */
.graph-title-input {
  display:inline-block;
  min-width:220px;
  max-width:420px;
  padding:8px 10px;
  border-radius:8px;
  border:1px solid rgba(255,255,255,0.06);
  background: rgba(255,255,255,0.02);
  color: var(--text);
  font-size:14px;
  outline: none;
  transition: box-shadow .12s ease, transform .08s ease;
}
.graph-title-input::placeholder { color: rgba(255,255,255,0.45); }
.graph-title-input:focus { box-shadow: 0 6px 20px rgba(6,11,26,0.6); transform: translateY(-2px); }

/* Ensure inner elements inherit visible color/opacity */
.chart-menu * ,
.graph-context-menu * {
  color: inherit !important;
  opacity: 1 !important;
}

/* Safety-net: override inline opacity styles */
.chart-menu[style*="opacity"],
.graph-context-menu[style*="opacity"],
.menu[style*="opacity"] {
  opacity: 1 !important;
}

/* Responsive tweaks */
@media (max-width:900px){
  .value{font-size:46px}
  .tanks-grid{grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));}
  .logo-img{ width:108px; height:66px; }
  .brand h1{ font-size:22px; }
  .topbar{ min-height:120px; padding:22px 20px; }
  .graph-title-input { min-width:160px; }
  .history-actions { grid-template-columns: 1fr; }
  .history-actions > div:last-child { align-items:flex-start; flex-direction:row; gap:8px; }
}
@media (max-width:640px){
  .value{font-size:38px}
  .tanks-grid{grid-template-columns: 1fr;}
  .brand-with-logo{gap:10px}
  .logo-img{ width:88px; height:56px; }
  .brand h1{font-size:18px}
  .subtitle{font-size:12px}
  .topbar{ min-height:96px; padding:14px 12px; }
  .graph-title-input{ min-width:120px; font-size:13px; padding:8px 10px; }
  .btn { height:44px; padding:0 16px; }
  .history-controls .btn, .history-close { min-width:72px; }
}

/* -----------------------------
   LOGIN MODAL STYLES (simple)
   ----------------------------- */
.login-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(2,6,23,0.88);
  z-index: 2000;
  padding: 20px;
}
.login-panel {
  width: 100%;
  max-width: 460px;
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01));
  border-radius: 12px;
  padding: 18px;
  color: var(--text);
  box-shadow: 0 24px 60px rgba(2,6,23,0.6);
  border: 1px solid rgba(255,255,255,0.03);
}
.login-panel h2 { font-size:20px; margin-bottom:4px; }
.login-panel input[type="text"],
.login-panel input[type="password"] {
  width:100%;
  box-sizing:border-box;
  padding:10px 12px;
  border-radius:8px;
  border:1px solid rgba(255,255,255,0.04);
  background: rgba(255,255,255,0.015);
  color: var(--text);
}
