/* MARS SCADA Dashboard Theme */
:root {
  --bg-0: #050814;
  --bg-1: #0b1020;
  --bg-2: #121a33;
  --bg-3: #1a2449;
  --accent: #22d3ee;      /* cyan */
  --accent-2: #a78bfa;    /* violet */
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --border: rgba(56,189,248,0.18);
}

html, body { background: var(--bg-0); color: var(--text); font-family: 'Inter', system-ui, -apple-system, sans-serif; }

/* grid background like SCADA HMI */
.scada-bg {
  background-color: var(--bg-0);
  background-image:
    linear-gradient(rgba(56,189,248,0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(56,189,248,0.04) 1px, transparent 1px),
    radial-gradient(ellipse at top, rgba(34,211,238,0.08), transparent 60%),
    radial-gradient(ellipse at bottom right, rgba(167,139,250,0.08), transparent 60%);
  background-size: 40px 40px, 40px 40px, 100% 100%, 100% 100%;
}

/* glowing panel */
.panel {
  background: linear-gradient(180deg, rgba(18,26,51,0.85), rgba(11,16,32,0.85));
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 0 0 1px rgba(56,189,248,0.04) inset, 0 6px 24px -10px rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
}
.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  background: linear-gradient(90deg, rgba(34,211,238,0.08), transparent);
  font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase;
  color: #67e8f9;
}
.panel-body { padding: 14px; }

/* KPI tile */
.kpi {
  position: relative; overflow: hidden;
  border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 16px;
  background: linear-gradient(135deg, rgba(34,211,238,0.08), rgba(11,16,32,0.6));
}
.kpi::after {
  content: ''; position: absolute; inset: -1px; border-radius: 10px;
  background: linear-gradient(120deg, transparent 30%, rgba(56,189,248,0.25), transparent 70%);
  pointer-events: none; animation: shimmer 6s linear infinite;
}
@keyframes shimmer { 0%{transform:translateX(-100%);} 100%{transform:translateX(100%);} }

/* glowing buttons */
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 6px; font-weight: 500; transition: all .15s; cursor: pointer; font-size: 14px; border: 1px solid transparent; }
.btn-primary { background: linear-gradient(135deg, #06b6d4, #0ea5e9); color: white; box-shadow: 0 0 20px rgba(6,182,212,0.35); }
.btn-primary:hover { box-shadow: 0 0 30px rgba(6,182,212,0.6); transform: translateY(-1px); }
.btn-ghost { background: rgba(34,211,238,0.08); color: #67e8f9; border-color: var(--border); }
.btn-ghost:hover { background: rgba(34,211,238,0.18); }
.btn-danger { background: linear-gradient(135deg, #dc2626, #ef4444); color: white; }

/* Inputs */
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.input, textarea.input, select.input {
  width: 100%; padding: 9px 11px; border-radius: 6px;
  background: rgba(5,8,20,0.7); border: 1px solid var(--border);
  color: var(--text); font-size: 14px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(34,211,238,0.15); }

/* Status pills */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.pill-open { background: rgba(245,158,11,0.2); color: #fbbf24; border: 1px solid rgba(245,158,11,0.4); }
.pill-progress { background: rgba(59,130,246,0.2); color: #60a5fa; border: 1px solid rgba(59,130,246,0.4); }
.pill-resolved { background: rgba(34,197,94,0.2); color: #4ade80; border: 1px solid rgba(34,197,94,0.4); }
.pill-closed { background: rgba(100,116,139,0.2); color: #94a3b8; border: 1px solid rgba(100,116,139,0.4); }
.pill-low { background: rgba(34,197,94,0.15); color: #4ade80; }
.pill-medium { background: rgba(245,158,11,0.15); color: #fbbf24; }
.pill-high { background: rgba(239,68,68,0.15); color: #f87171; }
.pill-critical { background: rgba(239,68,68,0.35); color: #fecaca; border: 1px solid rgba(239,68,68,0.6); }

/* Drag-drop zone */
.dropzone {
  border: 2px dashed rgba(56,189,248,0.35); border-radius: 10px;
  padding: 22px; text-align: center; cursor: pointer; transition: all .2s;
  background: rgba(34,211,238,0.04); color: var(--muted);
}
.dropzone.drag { border-color: var(--accent); background: rgba(34,211,238,0.15); color: var(--accent); transform: scale(1.01); }
.dropzone.has-file { border-style: solid; border-color: var(--ok); color: var(--ok); background: rgba(34,197,94,0.05); }

/* Table */
.tbl { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.tbl thead th { position: sticky; top: 0; background: rgba(11,16,32,0.98); backdrop-filter: blur(4px); color: #67e8f9; text-transform: uppercase; font-size: 11px; letter-spacing: 0.06em; padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; }
.tbl tbody td { padding: 10px 12px; border-bottom: 1px solid rgba(56,189,248,0.08); }
.tbl tbody tr:hover { background: rgba(34,211,238,0.04); }

/* sidebar nav */
.nav-item { display: flex; align-items: center; gap: 10px; padding: 10px 14px; color: var(--muted); border-left: 3px solid transparent; cursor: pointer; transition: all .15s; }
.nav-item:hover { color: var(--text); background: rgba(34,211,238,0.05); }
.nav-item.active { color: var(--accent); background: linear-gradient(90deg, rgba(34,211,238,0.15), transparent); border-left-color: var(--accent); }

/* blinking indicator */
.blink { animation: blink 1.4s infinite; }
@keyframes blink { 0%,100%{opacity:1;} 50%{opacity:0.4;} }

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: rgba(0,0,0,0.2); }
::-webkit-scrollbar-thumb { background: rgba(56,189,248,0.25); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: rgba(56,189,248,0.45); }

/* modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.7); backdrop-filter: blur(4px); z-index: 40; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { max-width: 960px; width: 100%; max-height: 90vh; overflow-y: auto; }

/* toast */
#toasts { position: fixed; top: 20px; right: 20px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast { background: rgba(11,16,32,0.95); border-left: 3px solid var(--accent); padding: 10px 14px; border-radius: 6px; min-width: 280px; animation: slidein .2s; box-shadow: 0 8px 24px rgba(0,0,0,0.5); }
.toast.success { border-left-color: var(--ok); }
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }
@keyframes slidein { from{transform:translateX(100%);opacity:0;} to{transform:translateX(0);opacity:1;} }

/* machine tiles on overview */
.machine-tile { position: relative; border: 1px solid var(--border); border-radius: 8px; padding: 10px; background: rgba(18,26,51,0.6); cursor: pointer; transition: all .15s; font-size: 12px; }
.machine-tile:hover { border-color: var(--accent); box-shadow: 0 0 14px rgba(34,211,238,0.3); transform: translateY(-2px); }
.machine-tile.hot { border-color: var(--danger); }
.machine-tile.warm { border-color: var(--warn); }
.machine-tile .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-green { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot-yellow { background: var(--warn); box-shadow: 0 0 8px var(--warn); }
.dot-red { background: var(--danger); box-shadow: 0 0 8px var(--danger); animation: blink 1.2s infinite; }

/* Login card */
.auth-card {
  width: 100%; max-width: 440px;
  border: 1px solid var(--border); border-radius: 14px; padding: 28px;
  background: linear-gradient(180deg, rgba(18,26,51,0.85), rgba(11,16,32,0.85));
  box-shadow: 0 0 40px rgba(34,211,238,0.15), 0 20px 60px rgba(0,0,0,0.6);
}

/* typeahead dropdown */
.type-list { position: absolute; z-index: 30; left: 0; right: 0; top: 100%; max-height: 240px; overflow-y: auto; background: rgba(5,8,20,0.98); border: 1px solid var(--border); border-radius: 6px; margin-top: 2px; }
.type-item { padding: 8px 12px; font-size: 13px; cursor: pointer; }
.type-item:hover, .type-item.active { background: rgba(34,211,238,0.12); color: var(--accent); }

/* draggable activity card (Kanban) */
.kanban-col { min-height: 400px; padding: 10px; border-radius: 8px; background: rgba(11,16,32,0.6); border: 1px dashed rgba(56,189,248,0.15); }
.kanban-col.drag-over { border-color: var(--accent); background: rgba(34,211,238,0.1); }
.kanban-card { background: rgba(18,26,51,0.9); border: 1px solid var(--border); border-radius: 8px; padding: 10px; margin-bottom: 8px; cursor: grab; }
.kanban-card:active { cursor: grabbing; }
.kanban-card.dragging { opacity: 0.4; }

/* image preview */
.img-preview { max-height: 160px; border-radius: 6px; border: 1px solid var(--border); }

/* === Additional utility classes used by app.js === */
.topbar {
  background: linear-gradient(180deg, rgba(11,16,32,0.95), rgba(11,16,32,0.75));
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}

.scada-input {
  background: rgba(5,8,20,0.8);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.scada-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(34,211,238,0.15);
}
textarea.scada-input { resize: vertical; font-family: inherit; }
select.scada-input { appearance: none; background-image: linear-gradient(45deg, transparent 50%, #94a3b8 50%), linear-gradient(135deg, #94a3b8 50%, transparent 50%); background-position: calc(100% - 14px) center, calc(100% - 9px) center; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 26px; }

.btn-primary {
  display: inline-flex; align-items: center; justify-content: center;
  background: linear-gradient(180deg, #22d3ee, #0ea5b7);
  color: #05070f; font-weight: 600; font-size: 13px;
  padding: 8px 14px; border-radius: 7px;
  border: 1px solid rgba(34,211,238,0.5);
  box-shadow: 0 0 14px rgba(34,211,238,0.3), inset 0 1px 0 rgba(255,255,255,0.2);
  cursor: pointer; transition: transform .08s, box-shadow .15s, filter .15s;
}
.btn-primary:hover { filter: brightness(1.1); box-shadow: 0 0 20px rgba(34,211,238,0.5); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-ghost {
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.04);
  color: var(--text); font-size: 12px;
  padding: 7px 12px; border-radius: 7px;
  border: 1px solid var(--border);
  cursor: pointer; transition: background .15s, border-color .15s;
}
.btn-ghost:hover { background: rgba(34,211,238,0.12); border-color: rgba(34,211,238,0.35); }

.fld-label {
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 4px;
}

/* Drag & drop zone */
.drop-zone {
  min-height: 180px;
  border: 2px dashed rgba(34,211,238,0.35);
  border-radius: 10px;
  background: rgba(5,8,20,0.4);
  padding: 18px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .15s;
  flex-direction: column;
}
.drop-zone:hover { background: rgba(34,211,238,0.06); border-color: var(--accent); }
.drop-zone.drag-over { background: rgba(34,211,238,0.15); border-color: var(--accent); transform: scale(1.01); }
.drop-zone img { max-height: 200px; object-fit: contain; }

/* Animations */
@keyframes fadeIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: #050814; }
::-webkit-scrollbar-thumb { background: #1a2449; border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #22d3ee; }

/* Tables — subtle hover */
table tbody tr td { transition: background .1s; }

/* Chart wrapper — fixes Chart.js infinite-resize bug inside flex/grid panels */
.chart-wrap {
  position: relative;
  width: 100%;
  /* height set inline per chart */
}
.chart-wrap > canvas {
  position: absolute !important;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
}

/* NOW chip button next to datetime inputs */
.now-btn {
  background: rgba(34,211,238,0.12);
  border: 1px solid rgba(34,211,238,0.35);
  color: #22d3ee;
  font-size: 10px;
  padding: 4px 8px;
  border-radius: 5px;
  cursor: pointer;
  font-weight: 600;
  letter-spacing: 0.06em;
  transition: background .12s;
}
.now-btn:hover { background: rgba(34,211,238,0.25); }
.dt-with-now { display: flex; gap: 6px; align-items: stretch; }
.dt-with-now > input { flex: 1; }

/* Chip button for recent machines / quick pickers */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.chip:hover { background: rgba(34,211,238,0.12); border-color: rgba(34,211,238,0.5); color: var(--accent); }
.chip .chip-badge { font-size: 9px; opacity: 0.6; }

/* Keyboard hint */
kbd {
  background: #0b1020;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 6px;
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 10px;
  color: var(--accent);
}

/* Suggestion card */
.suggest-card {
  border: 1px solid rgba(34,211,238,0.2);
  background: rgba(34,211,238,0.04);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: background .12s, border-color .12s, transform .1s;
}
.suggest-card:hover { background: rgba(34,211,238,0.1); border-color: rgba(34,211,238,0.5); }
.suggest-card:active { transform: scale(0.99); }

/* Quick-mode compact form */
.quick-mode {
  position: fixed; bottom: 20px; right: 20px; z-index: 90;
  background: linear-gradient(180deg, rgba(18,26,51,0.98), rgba(11,16,32,0.98));
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  width: 360px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6), 0 0 40px rgba(34,211,238,0.15);
}

/* ============================================================================
   Chart containers — CRITICAL FIX for "chart keeps zooming downwards":
   Chart.js with maintainAspectRatio:false shrinks forever unless the parent
   has an explicit height. These classes guarantee that height.
   ============================================================================ */
.chart-box { position: relative; width: 100%; }
.chart-box canvas { position: absolute !important; inset: 0; width: 100% !important; height: 100% !important; }
.chart-h-sm { height: 220px; }
.chart-h-md { height: 260px; }
.chart-h-lg { height: 340px; }
@media (max-width: 640px) {
  .chart-h-sm, .chart-h-md { height: 200px; }
  .chart-h-lg { height: 260px; }
}

/* "Now" datetime button */
.now-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 5px;
  background: linear-gradient(180deg, #22d3ee, #0ea5b7);
  color: #05070f;
  font-weight: 700;
  border: 1px solid rgba(34,211,238,0.5);
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  box-shadow: 0 0 8px rgba(34,211,238,0.25);
  transition: filter .15s, transform .08s;
}
.now-btn:hover { filter: brightness(1.15); }
.now-btn:active { transform: translateY(-50%) scale(0.94); }

/* Overdue row highlight */
.row-overdue {
  background: linear-gradient(90deg, rgba(244,63,94,0.08), transparent 40%) !important;
  box-shadow: inset 4px 0 0 #f43f5e;
}

/* Theme picker buttons */
.theme-pick {
  padding: 8px 16px;
  border-radius: 8px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  transition: all .15s;
}
.theme-pick.active {
  background: linear-gradient(180deg, rgba(34,211,238,0.25), rgba(34,211,238,0.1));
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 10px rgba(34,211,238,0.25);
}

/* keyboard key */
kbd {
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 11px;
  font-family: 'JetBrains Mono', Menlo, monospace;
  color: var(--accent);
}

/* Alarm pulse on badge */
@keyframes alarmPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(244,63,94, 0.7); transform: scale(1); }
  50% { box-shadow: 0 0 0 8px rgba(244,63,94, 0); transform: scale(1.08); }
}
.alarm-pulse { animation: alarmPulse 1.5s infinite; }

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

/* ============================================================================
   LIGHT THEME OVERRIDES
   ============================================================================ */
html[data-theme="light"] {
  --bg-0: #f0f4fb;
  --bg-1: #ffffff;
  --bg-2: #eef2f9;
  --bg-3: #e1e8f3;
  --text: #1e293b;
  --muted: #64748b;
  --border: rgba(2,132,199,0.18);
}
html[data-theme="light"] body { background: #f0f4fb; color: #1e293b; }
html[data-theme="light"] .scada-bg {
  background-color: #f0f4fb;
  background-image:
    linear-gradient(rgba(14,165,183,0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(14,165,183,0.06) 1px, transparent 1px),
    radial-gradient(ellipse at top, rgba(34,211,238,0.10), transparent 60%),
    radial-gradient(ellipse at bottom right, rgba(167,139,250,0.10), transparent 60%);
}
html[data-theme="light"] .panel {
  background: linear-gradient(180deg, #ffffff, #f6f9ff);
  border: 1px solid rgba(2,132,199,0.18);
  box-shadow: 0 2px 12px rgba(30,41,59,0.06), 0 1px 0 rgba(255,255,255,0.9) inset;
}
html[data-theme="light"] .panel-header {
  border-bottom: 1px solid rgba(2,132,199,0.12);
  color: #1e293b;
}
html[data-theme="light"] .topbar {
  background: linear-gradient(180deg, rgba(255,255,255,0.95), rgba(255,255,255,0.75));
  border-bottom: 1px solid rgba(2,132,199,0.18);
}
html[data-theme="light"] .scada-input {
  background: #ffffff;
  border: 1px solid rgba(2,132,199,0.22);
  color: #1e293b;
}
html[data-theme="light"] .scada-input:focus {
  border-color: #0ea5b7;
  box-shadow: 0 0 0 3px rgba(14,165,183,0.15);
}
html[data-theme="light"] .btn-ghost {
  background: rgba(2,132,199,0.05);
  border: 1px solid rgba(2,132,199,0.18);
  color: #1e293b;
}
html[data-theme="light"] .btn-ghost:hover { background: rgba(14,165,183,0.12); }
html[data-theme="light"] thead.text-muted,
html[data-theme="light"] thead { background: rgba(2,132,199,0.06) !important; }
html[data-theme="light"] thead th { color: #475569 !important; }
html[data-theme="light"] table tbody tr { border-color: rgba(2,132,199,0.08); }
html[data-theme="light"] table tbody tr:hover { background: rgba(14,165,183,0.05); }
html[data-theme="light"] .divide-white\/5 > * + * { border-color: rgba(2,132,199,0.08); }
html[data-theme="light"] ::-webkit-scrollbar-track { background: #eef2f9; }
html[data-theme="light"] ::-webkit-scrollbar-thumb { background: #cbd5e1; }
html[data-theme="light"] ::-webkit-scrollbar-thumb:hover { background: #0ea5b7; }
html[data-theme="light"] .text-slate-200,
html[data-theme="light"] .text-slate-300 { color: #1e293b !important; }
html[data-theme="light"] .text-slate-400,
html[data-theme="light"] .text-slate-500 { color: #64748b !important; }
html[data-theme="light"] .bg-white\/5 { background: rgba(2,132,199,0.05) !important; }
html[data-theme="light"] .border-white\/5 { border-color: rgba(2,132,199,0.10) !important; }
html[data-theme="light"] .drop-zone { background: #ffffff; border-color: rgba(14,165,183,0.4); }
html[data-theme="light"] .drop-zone:hover { background: rgba(14,165,183,0.05); }
html[data-theme="light"] kbd { background: rgba(2,132,199,0.08); color: #0ea5b7; border-color: rgba(2,132,199,0.18); }
html[data-theme="light"] .btn-primary { color: #ffffff; background: linear-gradient(180deg, #0ea5b7, #0891a3); }
html[data-theme="light"] .btn-primary:hover { filter: brightness(1.05); }
html[data-theme="light"] .theme-pick { background: #ffffff; color: #1e293b; border-color: rgba(2,132,199,0.18); }
html[data-theme="light"] footer { color: #64748b; }

