/* ═══════════════════════════════════════════════
   SMART BANDAGE AI — DASHBOARD LAYOUT (dashboard.css)
   ═══════════════════════════════════════════════ */

/* ── DASHBOARD GRID ────────────────────────── */
.dashboard {
  display: grid;
  grid-template-columns: 280px 1fr 320px;
  grid-template-rows: 1fr auto;
  grid-template-areas:
    "vitals center drug"
    "log    log    log";
  gap: 12px;
  padding: 12px;
  height: calc(100vh - var(--header-h));
  overflow: hidden;
}

.vitals-panel { grid-area: vitals; }
.center-col   { grid-area: center; display: flex; flex-direction: column; gap: 12px; overflow: hidden; min-height: 0; }
.drug-panel   { grid-area: drug; overflow-y: auto; }
.release-log-panel { grid-area: log; flex-direction: row !important; align-items: flex-start; gap: 16px; max-height: 160px; flex-shrink: 0; }

/* ── VITALS PANEL ──────────────────────────── */
.vitals-panel { display: flex; flex-direction: column; gap: 10px; overflow-y: auto; }

.gauges-grid { display: flex; flex-direction: column; gap: 8px; align-items: center; }

.gauge-wrap {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 10px; border-radius: var(--radius);
  background: var(--surface2); border: 1px solid var(--border);
  width: 100%; transition: border-color .3s, background .3s;
  position: relative; overflow: hidden;
}
.gauge-wrap::before {
  content: ''; position: absolute; inset: 0; opacity: 0;
  background: radial-gradient(ellipse at top, rgba(0,229,160,0.06), transparent 70%);
  transition: opacity .4s;
}
.gauge-wrap:hover::before { opacity: 1; }
.gauge-wrap:hover { border-color: var(--border2); }
.gauge-wrap.warning { border-color: rgba(245,158,11,0.45); background: rgba(245,158,11,0.05); }
.gauge-wrap.critical { border-color: rgba(239,68,68,0.45); background: rgba(239,68,68,0.06); animation: criticalPulse 2s ease infinite; }

.gauge-svg { width: 90px; height: 90px; transform: rotate(-90deg); }

.g-track { fill: none; stroke: rgba(255,255,255,0.06); stroke-width: 8; stroke-linecap: round; }
.g-fill  {
  fill: none; stroke-width: 8; stroke-linecap: round;
  stroke-dasharray: 301.6;
  stroke-dashoffset: 301.6;
  transition: stroke-dashoffset .8s cubic-bezier(.4,0,.2,1), stroke .4s;
  filter: drop-shadow(0 0 4px currentColor);
}
.g-temp { stroke: #f87171; }
.g-spo2 { stroke: var(--green); }
.g-h2o2 { stroke: #a78bfa; }
.g-hr   { stroke: #fb7185; }
.g-ph   { stroke: #22d3ee; }

/* ── Beat Detected Indicator ──────────────── */
.beat-indicator {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 8px 14px; border-radius: var(--radius);
  background: var(--surface2); border: 1px solid var(--border);
  opacity: 0.35; transition: opacity .3s, border-color .3s, background .3s;
}
.beat-indicator.active {
  opacity: 1;
  border-color: rgba(251,113,133,0.5);
  background: rgba(251,113,133,0.06);
}
.beat-heart {
  font-size: 20px; display: inline-block;
}
.beat-heart.pulse {
  animation: heartPulse 0.6s ease;
}
.beat-text {
  font-size: 12px; font-weight: 600; color: var(--text-muted);
  letter-spacing: 0.3px;
}
.beat-indicator.active .beat-text {
  color: #fb7185;
}
@keyframes heartPulse {
  0%   { transform: scale(1); }
  25%  { transform: scale(1.35); }
  50%  { transform: scale(1); }
  75%  { transform: scale(1.2); }
  100% { transform: scale(1); }
}

.g-val  {
  font-family: var(--font-head); font-size: 20px; font-weight: 700;
  fill: var(--text); transform: rotate(90deg); transform-box: fill-box; dominant-baseline: middle;
}
.g-unit { font-size: 10px; fill: var(--text-muted); transform: rotate(90deg); transform-box: fill-box; }

.gauge-label { font-size: 11px; font-weight: 500; color: var(--text-muted); margin-top: 1px; }
.gauge-badge {
  font-size: 10px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase;
  padding: 2px 9px; border-radius: 99px;
}
.gauge-badge.normal   { background: var(--ok-dim);     color: var(--ok); }
.gauge-badge.warning  { background: var(--warn-dim);   color: var(--warn); }
.gauge-badge.critical { background: var(--danger-dim); color: var(--danger); }

.vitals-stats {
  display: flex; flex-direction: column; gap: 7px;
  margin-top: auto; border-top: 1px solid var(--border); padding-top: 12px;
}
.stat-row {
  display: flex; justify-content: space-between; align-items: center; font-size: 12px;
}
.stat-row span:first-child { color: var(--text-muted); }
.stat-row span:last-child  { font-weight: 600; color: var(--text); font-family: var(--font-head); }

/* ── CHART PANEL ───────────────────────────── */
.chart-panel {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
}
.chart-box {
  flex: 1;
  min-height: 220px; /* fallback so Chart.js always has space */
  position: relative;
  width: 100%;
}
.chart-box canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; }

.chart-toggles { display: flex; gap: 6px; }
.ctoggle {
  padding: 4px 10px; border-radius: 99px;
  font-size: 11px; font-weight: 600;
  border: 1px solid var(--border);
  color: var(--text-dim); background: transparent;
  transition: all .2s; cursor: pointer;
}
.ctoggle.active[data-ds="0"] { color: #f87171; border-color: #f87171; background: rgba(248,113,113,0.1); }
.ctoggle.active[data-ds="1"] { color: var(--green); border-color: var(--green); background: var(--green-dim); }
.ctoggle.active[data-ds="2"] { color: #a78bfa; border-color: #a78bfa; background: rgba(167,139,250,0.1); }
.ctoggle.active[data-ds="3"] { color: #fb7185; border-color: #fb7185; background: rgba(251,113,133,0.1); }
.ctoggle.active[data-ds="4"] { color: #22d3ee; border-color: #22d3ee; background: rgba(34,211,238,0.1); }

/* ── WOUND PANEL ───────────────────────────── */
.wound-panel { flex-shrink: 0; }
.wound-actions { display: flex; gap: 8px; align-items: center; }

.wound-body { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; min-height: 140px; }

.wound-drop-zone {
  border: 2px dashed var(--border2); border-radius: var(--radius);
  position: relative; overflow: hidden;
  background: var(--surface2); min-height: 140px;
  transition: border-color .2s, background .2s;
  display: flex; align-items: center; justify-content: center;
}
.wound-drop-zone.dragover { border-color: var(--green); background: var(--green-dim); }

.drop-placeholder {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  color: var(--text-dim); font-size: 12px; text-align: center; padding: 12px;
}
.drop-placeholder svg { opacity: .35; }

.wound-img { width: 100%; height: 100%; object-fit: cover; border-radius: var(--radius-sm); position: absolute; inset: 0; }

.wound-result { display: flex; flex-direction: column; gap: 10px; justify-content: center; }
.wound-type-row { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.result-label { font-size: 11px; color: var(--text-muted); font-weight: 500; }
.result-chip {
  padding: 3px 10px; border-radius: 99px;
  background: var(--purple-dim); color: #c4b5fd;
  font-size: 11px; font-weight: 600; border: 1px solid rgba(124,58,237,0.3);
}
.wound-severity-bar { display: flex; flex-direction: column; gap: 5px; }
.severity-track { height: 6px; border-radius: 99px; background: var(--surface2); }
.severity-fill {
  height: 100%; border-radius: 99px;
  background: linear-gradient(90deg, var(--ok), var(--warn), var(--danger));
  transition: width 1s cubic-bezier(.4,0,.2,1);
}
.severity-pct { font-size: 11px; color: var(--text-muted); font-weight: 600; }
.wound-ai-text {
  font-size: 11px; color: var(--text-dim); line-height: 1.6;
  padding: 8px; border-radius: var(--radius-sm);
  background: var(--surface2); border: 1px solid var(--border);
}

/* ── DRUG PANEL ────────────────────────────── */
.drug-panel { display: flex; flex-direction: column; gap: 10px; }

.drug-section-label {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .8px; color: var(--text-dim);
}

.drug-suggestions { display: flex; flex-direction: column; gap: 8px; }
.drug-empty { font-size: 12px; color: var(--text-dim); padding: 10px 0; }

.drug-card {
  padding: 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface2);
  display: flex; flex-direction: column; gap: 6px;
  /* NO animation here — prevents glitch on refresh */
}
.drug-card-hdr { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.drug-name   { font-size: 13px; font-weight: 600; color: var(--text); font-family: var(--font-head); }
.drug-urgency {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px;
  padding: 2px 7px; border-radius: 99px;
}
.drug-urgency.high   { background: var(--danger-dim); color: var(--danger); border: 1px solid rgba(239,68,68,0.3); }
.drug-urgency.medium { background: var(--warn-dim);   color: var(--warn);   border: 1px solid rgba(245,158,11,0.3); }
.drug-urgency.low    { background: var(--ok-dim);     color: var(--ok);     border: 1px solid rgba(34,197,94,0.3); }

.drug-meta   { font-size: 11px; color: var(--text-muted); }
.drug-reason {
  font-size: 11px; color: var(--text-dim);
  background: var(--surface); border-radius: 6px; padding: 6px 8px;
  border-left: 2px solid var(--green);
}
.drug-apply-btn {
  align-self: flex-end; padding: 4px 10px; border-radius: 6px;
  font-size: 11px; font-weight: 600;
  background: var(--purple-dim); color: #c4b5fd;
  border: 1px solid rgba(124,58,237,0.35); transition: all .2s; cursor: pointer;
}
.drug-apply-btn:hover { background: rgba(124,58,237,0.3); }

/* ── RELEASE CONTROLS ──────────────────────── */
.release-controls { display: flex; flex-direction: column; gap: 10px; }
.dose-calc { display: flex; flex-direction: column; gap: 8px; }
.dose-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.dose-field { display: flex; flex-direction: column; }

/* ── RELEASE LOG PANEL (bottom, full-width) ─ */
.release-log-panel .panel-hdr { flex-shrink: 0; }
.release-log-panel .log-scroll {
  display: flex; gap: 10px; overflow-x: auto; flex: 1;
  padding-bottom: 4px;
}
.release-log-panel .log-scroll::-webkit-scrollbar { height: 3px; }

.log-entry {
  display: flex; flex-direction: column; gap: 3px; flex-shrink: 0;
  min-width: 180px; padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--surface2); border: 1px solid var(--border);
  animation: fadeIn .3s ease;
}
.log-entry-top { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.log-drug  { font-size: 12px; font-weight: 600; color: var(--text); }
.log-dose  { font-size: 11px; color: #c4b5fd; font-weight: 500; }
.log-time  { font-size: 10px; color: var(--text-dim); }
.log-mode  { font-size: 10px; color: var(--text-muted); }
.log-empty { font-size: 12px; color: var(--text-dim); }

/* ── ANIMATIONS ────────────────────────────── */
@keyframes criticalPulse {
  0%,100% { border-color: rgba(239,68,68,0.4); box-shadow: none; }
  50%     { border-color: rgba(239,68,68,0.9); box-shadow: 0 0 16px rgba(239,68,68,0.3); }
}
@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }

/* ══════════════════════════════════════════
   TABLET (≤ 1100px)
   ══════════════════════════════════════════ */
@media (max-width: 1100px) {
  .dashboard { grid-template-columns: 240px 1fr 280px; }
}

/* ══════════════════════════════════════════
   MOBILE (≤ 768px)
   NOTE: font-size is NEVER changed on mobile
   ══════════════════════════════════════════ */
@media (max-width: 768px) {
  :root { --header-h: 56px; }

  .dashboard {
    display: block;
    height: auto; overflow: auto;
    padding: 10px;
    padding-bottom: calc(var(--mobile-nav-h) + 10px);
    grid-template-areas: none;
  }

  /* All panels hidden by default; shown by JS */
  .panel { display: none; }
  .panel.mob-active { display: flex; }
  .center-col .panel { display: none; }
  .center-col .panel.mob-active { display: flex; }

  .mobile-nav { display: flex; }

  /* Gauges: 2-col grid to show all 5 vitals */
  .gauges-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .gauge-wrap  { width: 100%; padding: 8px; min-width: 0; }
  .gauge-wrap:last-child { grid-column: 1 / -1; max-width: 50%; justify-self: center; }

  .wound-body { grid-template-columns: 1fr; }

  .patient-info .patient-name { display: none; }

  .vitals-stats { flex-direction: row; flex-wrap: wrap; gap: 8px; }
  .stat-row { flex: 1 1 48%; }

  .chart-panel { min-height: 280px; }
  .chart-box   { min-height: 200px; }

  /* Release log panel: vertical on mobile */
  .release-log-panel { flex-direction: column !important; max-height: none; }
  .release-log-panel .log-scroll { flex-direction: column; overflow-x: hidden; overflow-y: auto; max-height: 220px; }
  .log-entry { min-width: unset; }
}

@media (max-width: 420px) {
  .header-left { gap: 8px; }
  .logo-sub    { display: none; }
  .conn-status { display: none; }
  .patient-chip { padding: 4px 8px; }
}
