/* ═══════════════════════════════════════════════════════════
   ECMO Sentinel v1.0 — Clinical UI
   ═══════════════════════════════════════════════════════════ */

:root {
  --navy:        #0d1b2e;
  --navy-mid:    #152540;
  --navy-light:  #1e3a5f;
  --accent:      #2563eb;
  --accent-glow: #3b82f6;
  --bg:          #f0f4f8;
  --bg-card:     #ffffff;
  --text:        #1a202c;
  --text-muted:  #718096;
  --border:      #e2e8f0;

  --stable:  #059669;
  --monitor: #d97706;
  --alert:   #dc2626;

  --sidebar-w:     230px;
  --right-panel-w: 240px;
  --topbar-h:      72px;
  --footer-h:      40px;

  --font-ui:   'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Courier New', monospace;
}

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

html, body {
  height: 100%;
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* ── Top Bar ───────────────────────────────────────────────── */
#top-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  min-height: var(--topbar-h);
  background: var(--navy);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 8px 16px 6px;
  z-index: 100;
  border-bottom: 1px solid var(--navy-light);
  box-sizing: border-box;
}

.top-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.top-left  { display: flex; align-items: center; }
.top-center { display: flex; align-items: center; justify-content: center; flex: 1; padding: 0 8px; }
.top-right  { display: flex; align-items: center; }

.logo {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 15px;
  color: #fff;
  letter-spacing: -0.3px;
  line-height: 1.2;
  white-space: nowrap;
}

.top-sub {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 4px;
}

.version {
  font-size: 10px;
  color: #475569;
  font-family: var(--font-mono);
}

.top-sub-dot {
  color: #334155;
  font-size: 10px;
  font-family: var(--font-mono);
}

#clock {
  font-family: var(--font-mono);
  font-size: 10px;
  color: #475569;
}

.top-btn {
  background: rgba(255,255,255,0.08);
  color: #e2e8f0;
  border: 1px solid rgba(255,255,255,0.12);
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-family: var(--font-ui);
  cursor: pointer;
  transition: background 0.15s;
}
.top-btn:hover { background: rgba(255,255,255,0.15); }

/* ── Risk Badge ─────────────────────────────────────────────── */
.risk-badge {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 14px;
  padding: 6px 20px;
  border-radius: 20px;
  letter-spacing: 0.4px;
  transition: all 0.3s ease;
  white-space: nowrap;
}

.risk-badge.stable  { background: rgba(5,150,105,0.15); color: #34d399; border: 1px solid rgba(52,211,153,0.3); }
.risk-badge.monitor { background: rgba(217,119,6,0.15);  color: #fbbf24; border: 1px solid rgba(251,191,36,0.3); }
.risk-badge.alert {
  background: rgba(220,38,38,0.2); color: #f87171; border: 1px solid rgba(248,113,113,0.4);
  animation: pulse-alert 1.2s ease-in-out infinite;
}

@keyframes pulse-alert {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220,38,38,0); }
  50%       { box-shadow: 0 0 0 6px rgba(220,38,38,0.2); }
}

/* ── App Layout ─────────────────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
  padding-top: var(--topbar-h);
}

/* ── Left Sidebar ───────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--navy);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  border-right: 1px solid var(--navy-light);
}

#sidebar::-webkit-scrollbar { width: 4px; }
#sidebar::-webkit-scrollbar-track { background: transparent; }
#sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

.sidebar-section { padding: 14px; border-bottom: 1px solid rgba(255,255,255,0.06); }
.sidebar-spacer  { flex: 1; }

.section-title {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: #4b6cb7;
  margin-bottom: 10px;
}

.info-grid { display: flex; flex-direction: column; gap: 6px; }

.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

.info-label { font-size: 10px; color: #64748b; white-space: nowrap; flex-shrink: 0; }

.info-val {
  font-family: var(--font-mono);
  font-size: 10px;
  color: #cbd5e1;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 120px;
}

/* ── Close Case Button ──────────────────────────────────────── */
.sidebar-footer {
  border-bottom: none;
  padding-top: 12px;
}

.close-case-btn {
  display: block;
  width: 100%;
  padding: 10px 12px;
  background: rgba(220, 38, 38, 0.12);
  color: #fca5a5;
  border: 1px solid rgba(220, 38, 38, 0.3);
  border-radius: 8px;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
  margin-bottom: 12px;
}

.close-case-btn:hover {
  background: rgba(220, 38, 38, 0.25);
  border-color: rgba(220, 38, 38, 0.5);
  color: #f87171;
}

.privacy-note {
  font-size: 9px;
  color: #334155;
  text-align: center;
  padding: 4px 0;
  margin-bottom: 8px;
}

.copyright-note {
  font-size: 9px;
  color: #475569;
  text-align: center;
  line-height: 1.6;
  border-top: 1px solid rgba(255,255,255,0.06);
  padding-top: 8px;
}

.copyright-sub {
  font-size: 8px;
  color: #334155;
  font-style: italic;
}

/* ── Main Area ──────────────────────────────────────────────── */
#main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
  overflow: hidden;
}

/* ── Tab Bar ────────────────────────────────────────────────── */
#tab-bar {
  display: flex;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  flex-shrink: 0;
}

.tab-btn {
  padding: 13px 20px;
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.tab-btn:hover  { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* ── Tab Content ────────────────────────────────────────────── */
#tab-content {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.tab-panel {
  display: none;
  height: 100%;
  overflow: hidden;
}

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

.panel-scroll {
  height: 100%;
  overflow-y: auto;
  padding: 24px 28px calc(var(--footer-h) + 24px);
}

.panel-scroll::-webkit-scrollbar { width: 6px; }
.panel-scroll::-webkit-scrollbar-track { background: transparent; }
.panel-scroll::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

/* ── Panel Header ───────────────────────────────────────────── */
.panel-header { margin-bottom: 24px; }

.panel-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--navy);
  letter-spacing: -0.3px;
  margin-bottom: 4px;
}

.panel-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ── Form Elements ──────────────────────────────────────────── */
.form-section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--accent);
  margin: 22px 0 12px;
  padding-bottom: 7px;
  border-bottom: 1px solid var(--border);
}

.form-section-label:first-child { margin-top: 0; }

.form-group { display: flex; flex-direction: column; }

.form-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 5px;
}

.req { color: var(--alert); }

.form-input, .form-select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 13px;
  font-family: var(--font-ui);
  color: var(--text);
  background: var(--bg-card);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  appearance: none;
}

.form-input:focus, .form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.form-input::placeholder { color: #a0aec0; }

.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%2394a3b8'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

/* ── Drum-Wheel Time Picker ─────────────────────────────────── */
.drum-field { display: block; }

.drum-trigger {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  background: #0f172a;
  border: 1px solid #2d3748;
  border-radius: 6px;
  color: #a0aec0;
  font-family: var(--font-mono);
  font-size: 15px;
  letter-spacing: 1px;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s;
}
.drum-trigger:hover  { border-color: var(--accent); }
.drum-trigger:focus  { outline: 2px solid var(--accent); outline-offset: 1px; }
.drum-val-set        { color: #e2e8f0; }

/* Overlay */
.drum-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: flex-end;
}
.drum-overlay[hidden] { display: none; }

.drum-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

/* Card slides up from bottom */
.drum-card {
  position: relative;
  width: 100%;
  background: #0d1b2e;
  border-radius: 18px 18px 0 0;
  border-top: 1px solid #1e3a5f;
  z-index: 1;
  animation: drumSlideUp 0.25s cubic-bezier(0.32, 0.72, 0, 1);
}

@keyframes drumSlideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.drum-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px 10px;
  border-bottom: 1px solid #1e3a5f;
}

.drum-title {
  font-size: 14px;
  font-weight: 600;
  color: #94a3b8;
  letter-spacing: 0.5px;
}

.drum-btn {
  background: none;
  border: none;
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  color: #64748b;
}
.drum-btn:hover        { color: #94a3b8; }
.drum-btn-done         { color: var(--accent); }
.drum-btn-done:hover   { color: #3b82f6; }

/* Two-column scroll area */
.drum-cols {
  position: relative;
  display: flex;
  align-items: stretch;
  justify-content: center;
  height: 220px;
  overflow: hidden;
  padding: 0 40px;
}

/* Centre-item highlight bar */
.drum-selection-bar {
  position: absolute;
  left: 0; right: 0;
  top: 50%;
  transform: translateY(-50%);
  height: 44px;
  border-top: 1px solid #2563eb44;
  border-bottom: 1px solid #2563eb44;
  background: rgba(37, 99, 235, 0.12);
  pointer-events: none;
  z-index: 2;
}

/* Top/bottom fade */
.drum-cols::before,
.drum-cols::after {
  content: '';
  position: absolute;
  left: 0; right: 0;
  height: 80px;
  pointer-events: none;
  z-index: 3;
}
.drum-cols::before { top: 0;    background: linear-gradient(to bottom, #0d1b2e 0%, transparent 100%); }
.drum-cols::after  { bottom: 0; background: linear-gradient(to top,   #0d1b2e 0%, transparent 100%); }

.drum-sep {
  display: flex;
  align-items: center;
  font-size: 26px;
  font-weight: 700;
  color: #475569;
  padding: 0 6px;
  flex-shrink: 0;
  z-index: 4;
}

/* Scrollable column */
.drum-col {
  flex: 1;
  height: 100%;
  overflow-y: scroll;
  scroll-snap-type: y mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.drum-col::-webkit-scrollbar { display: none; }

/* Each value row */
.drum-item {
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 500;
  color: #475569;
  scroll-snap-align: center;
  user-select: none;
  transition: color 0.1s;
}
.drum-item.drum-pad  { pointer-events: none; }
.drum-item.selected  { color: #e2e8f0; font-weight: 600; }

/* ── Vasopressor Checkboxes ─────────────────────────────────── */
.vaso-checkboxes {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  padding: 8px 10px;
  background: #0f172a;
  border: 1px solid #2d3748;
  border-radius: 6px;
  min-height: 38px;
}
.vaso-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.8rem;
  color: #cbd5e0;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.vaso-item input[type="checkbox"] {
  accent-color: #48bb78;
  width: 13px;
  height: 13px;
  cursor: pointer;
}

/* ── Form Grid Layouts ──────────────────────────────────────── */
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr;     gap: 14px; margin-bottom: 14px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.form-row-4 { display: grid; grid-template-columns: repeat(4,1fr); gap: 12px; margin-bottom: 12px; }

.form-group { margin-bottom: 0; }

/* ── Submit Button ──────────────────────────────────────────── */
.submit-btn {
  display: block;
  width: 100%;
  padding: 13px;
  margin-top: 28px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 9px;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.2px;
  transition: background 0.15s, transform 0.1s;
}

.submit-btn:hover   { background: #1d4ed8; }
.submit-btn:active  { transform: scale(0.99); }
.submit-btn:disabled { background: #94a3b8; cursor: not-allowed; }

/* ── Sentinel Response Card ─────────────────────────────────── */
.sentinel-response {
  margin-top: 20px;
}

.sentinel-response.hidden { display: none; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.response-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--navy);
  border-bottom: 1px solid var(--navy-light);
}

.response-sentinel-label {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  color: #94a3b8;
  letter-spacing: 0.3px;
}

.response-ts {
  font-family: var(--font-mono);
  font-size: 10px;
  color: #475569;
}

.response-body {
  padding: 16px 20px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.7;
  color: var(--text);
  overflow-x: auto;
  max-height: 540px;
  overflow-y: auto;
}

.response-body::-webkit-scrollbar { width: 4px; }
.response-body::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }

/* ── Markdown rendered elements ─────────────────────────────── */
.response-body p { margin: 0 0 8px; }
.response-body strong { color: var(--text); font-weight: 700; }
.response-body em { font-style: italic; }

.response-body h1, .response-body h2, .response-body h3 {
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--accent);
  margin: 16px 0 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.response-body h4, .response-body h5, .response-body h6 {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  margin: 10px 0 4px;
}

.response-body ul, .response-body ol {
  padding-left: 18px;
  margin: 4px 0 10px;
}
.response-body li { margin: 2px 0; }

.response-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0 16px;
  font-size: 11px;
}
.response-body th {
  background: var(--navy);
  color: var(--accent);
  padding: 5px 10px;
  text-align: left;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  border: 1px solid var(--border);
}
.response-body td {
  padding: 5px 10px;
  border: 1px solid var(--border);
  vertical-align: top;
}
.response-body tr:nth-child(even) td { background: rgba(0,0,0,0.03); }

.response-body code {
  font-family: var(--font-mono);
  background: var(--bg-panel);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 11px;
}
.response-body pre {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 14px;
  overflow-x: auto;
  margin: 8px 0;
}
.response-body blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  color: #64748b;
  margin: 8px 0;
}
.response-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 14px 0;
}

/* ── Risk Inline Labels ─────────────────────────────────────── */
.risk-inline {
  display: inline-block;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 4px;
  margin: 1px 0;
}

.risk-inline.stable  { background: rgba(5,150,105,0.1);  color: var(--stable); }
.risk-inline.monitor { background: rgba(217,119,6,0.1);  color: var(--monitor); }
.risk-inline.alert   { background: rgba(220,38,38,0.1);  color: var(--alert); animation: pulse-alert 1.2s infinite; }

/* ── Loading State ──────────────────────────────────────────── */
.no-case-warning {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 18px 20px;
  background: #fffbeb;
  border: 1px solid #fcd34d;
  border-radius: 10px;
}
.no-case-warning .no-case-icon { font-size: 22px; flex-shrink: 0; line-height: 1.3; }
.no-case-warning strong { font-size: 14px; color: #92400e; display: block; margin-bottom: 4px; }
.no-case-warning p { font-size: 13px; color: #78350f; margin: 0; }

/* ── Save Confirmation ──────────────────────────────────────── */
.save-confirm {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 10px;
  padding: 12px 16px;
  background: #f0fdf4;
  border: 1px solid #86efac;
  border-radius: 10px;
}
.save-confirm-tick  { font-size: 18px; flex-shrink: 0; }
.save-confirm-text  { flex: 1; font-size: 13px; font-weight: 600; color: #14532d; }
.save-confirm-btn {
  flex-shrink: 0;
  padding: 7px 14px;
  background: #16a34a;
  color: #fff;
  border: none;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.save-confirm-btn:active { background: #15803d; }

/* ── Cases History Screen ───────────────────────────────────── */
.cases-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-end;
}
.cases-screen.hidden { display: none; }

.cases-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.45);
}

.cases-inner {
  position: relative;
  width: 100%;
  max-height: 80vh;
  background: var(--bg);
  border-radius: 18px 18px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 -4px 30px rgba(0,0,0,0.2);
}

.cases-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.cases-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}
.cases-close-btn {
  background: none;
  border: none;
  font-size: 18px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}
.cases-close-btn:hover { background: var(--border); }

.cases-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.no-cases-msg {
  text-align: center;
  padding: 32px 20px;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.6;
}

.case-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}
.case-item:hover        { background: var(--bg-card); }
.case-item.current      { background: #eff6ff; }
.case-item:last-child   { border-bottom: none; }

.case-item-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.case-item-surgeon {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.case-item-meta {
  font-size: 12px;
  color: var(--text-muted);
}
.case-item-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.case-risk-dot { font-size: 16px; }
.case-tag {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 10px;
  background: var(--border);
  color: var(--text-muted);
}
.case-tag.active { background: #dcfce7; color: #15803d; }
.case-tag.closed { background: #f1f5f9; color: #64748b; }

.cases-footer {
  padding: 14px 20px calc(env(safe-area-inset-bottom, 0px) + 14px);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.cases-new-btn {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.cases-new-btn:active { opacity: 0.85; }

/* ── PDF button inside each case row ────────────────────────── */
.case-pdf-btn {
  background: none;
  border: 1px solid #bfdbfe;
  border-radius: 6px;
  font-size: 15px;
  line-height: 1;
  padding: 5px 7px;
  cursor: pointer;
  flex-shrink: 0;
}
.case-pdf-btn:hover  { background: #dbeafe; }
.case-pdf-btn:active { background: #bfdbfe; }

/* ── Handover tab PDF button ────────────────────────────────── */
.handover-pdf-btn {
  display: block;
  width: 100%;
  padding: 14px;
  margin: 20px 0 0;
  background: #1e3a5f;
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}
.handover-pdf-btn:hover  { background: #1e40af; }
.handover-pdf-btn:active { opacity: 0.85; }

/* ── Generate Report Button ─────────────────────────────────── */
.generate-report-btn {
  width: 100%;
  padding: 10px 14px;
  margin-bottom: 10px;
  background: #1e3a5f;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}
.generate-report-btn:hover  { background: #1e40af; }
.generate-report-btn:active { opacity: 0.85; }

/* ── Cases header button ────────────────────────────────────── */
.top-btn.cases-btn {
  padding: 8px 10px;
  font-size: 16px;
  min-width: unset;
}

/* ── PDF Toast ──────────────────────────────────────────────── */
.pdf-toast {
  position: fixed;
  bottom: calc(var(--footer-h) + 10px);
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 32px);
  max-width: 480px;
  z-index: 900;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: #0f172a;
  color: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  animation: slideUp 0.2s ease;
}
.pdf-toast.hidden { display: none; }
@keyframes slideUp { from { transform: translateX(-50%) translateY(20px); opacity: 0; } }

.pdf-toast-icon { font-size: 22px; flex-shrink: 0; }
.pdf-toast-text { flex: 1; }
.pdf-toast-text strong { display: block; font-size: 13px; margin-bottom: 2px; }
.pdf-toast-text span   { font-size: 12px; color: #94a3b8; }
.pdf-toast-close {
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
  padding: 4px;
}

.response-loading {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 20px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
}

.response-loading p {
  font-size: 13px;
  color: var(--accent);
  font-family: var(--font-ui);
  font-weight: 500;
}

.loading-spinner {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border: 3px solid #bfdbfe;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Result card ─────────────────────────────────────────────── */
.result-card {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 10px;
  overflow: hidden;
  animation: fadeUp 0.2s ease;
}

.result-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: #dbeafe;
  border-bottom: 1px solid #bfdbfe;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 700;
  color: #1e40af;
}

.result-card .response-ts {
  color: #3b82f6;
}

.result-card .response-body {
  background: #eff6ff;
  color: #1e293b;
}

/* ── Glance Card (Level 1) ──────────────────────────────────── */
.glance-card {
  padding: 14px 16px 12px;
  border-bottom: 1px solid #bfdbfe;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.glance-risk {
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 6px;
  margin-bottom: 2px;
}
.glance-risk.stable  { background: #dcfce7; color: #14532d; }
.glance-risk.monitor { background: #fef9c3; color: #713f12; }
.glance-risk.alert   { background: #fee2e2; color: #7f1d1d; }

.glance-bullet {
  font-size: 13px;
  color: #1e293b;
  padding-left: 4px;
  line-height: 1.5;
}

.glance-action {
  font-size: 13px;
  font-weight: 600;
  color: #1e40af;
  padding: 6px 10px;
  background: #dbeafe;
  border-radius: 6px;
  margin-top: 2px;
}

/* ── Accordion (Levels 2 & 3) ───────────────────────────────── */
.accordion-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 16px;
  background: #e0eeff;
  border: none;
  border-top: 1px solid #bfdbfe;
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  color: #1e40af;
  text-align: left;
  transition: background 0.15s;
}
.accordion-btn:hover  { background: #bfdbfe; }
.accordion-btn.open   { background: #bfdbfe; }
.acc-chevron          { font-size: 11px; flex-shrink: 0; }

.accordion-body {
  border-top: 1px solid #bfdbfe;
}
.accordion-body[hidden] { display: none; }

/* ── Action Steps (Level 2) ─────────────────────────────────── */
.actions-list {
  padding: 10px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #f8faff;
}

.action-step {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 8px 10px;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 7px;
}

.action-num {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  background: #1e40af;
  color: #fff;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.action-text {
  flex: 1;
  font-size: 13px;
  color: #0f172a;
  font-weight: 500;
  line-height: 1.4;
}

.action-time {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  background: #fef3c7;
  color: #92400e;
}
.action-time[data-t="NOW"] { background: #fee2e2; color: #7f1d1d; }

/* ── Analysis Grid ──────────────────────────────────────────── */
.analysis-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 4px;
}

.analysis-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: box-shadow 0.15s;
}

.analysis-card:hover { box-shadow: 0 3px 12px rgba(0,0,0,0.08); }

.analysis-card-icon { font-size: 22px; line-height: 1; }

.analysis-card-body { flex: 1; }

.analysis-card-body h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 5px;
}

.analysis-card-body p {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 8px;
}

.alarm-input {
  margin-top: 4px;
  font-size: 12px !important;
  padding: 7px 10px !important;
}

.analysis-btn {
  padding: 9px 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 7px;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  align-self: flex-start;
  white-space: nowrap;
}

.analysis-btn:hover { background: #1d4ed8; }

/* ── Handover Form ──────────────────────────────────────────── */
.handover-form {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 22px;
  max-width: 680px;
}

.handover-form .form-row-2 { margin-bottom: 14px; }

/* ── Right Panel ────────────────────────────────────────────── */
#right-panel {
  width: var(--right-panel-w);
  min-width: var(--right-panel-w);
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: relative;
  transition: width 0.25s ease, min-width 0.25s ease;
  overflow: hidden;
}

#right-panel.collapsed { width: 28px; min-width: 28px; }

#toggle-panel {
  position: absolute;
  left: -13px;
  top: 50%;
  transform: translateY(-50%);
  width: 26px;
  height: 36px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 10px;
  color: #94a3b8;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: color 0.15s;
}

#toggle-panel:hover { color: var(--accent); }
#right-panel.collapsed #panel-content { display: none; }

#panel-content {
  overflow-y: auto;
  flex: 1;
  padding: 14px;
  display: flex;
  flex-direction: column;
}

#panel-content::-webkit-scrollbar { width: 4px; }
#panel-content::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }

.panel-section {
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.panel-section:last-child { border-bottom: none; }
.panel-section .section-title { color: #64748b; margin-bottom: 10px; }

/* ── Score Cards ────────────────────────────────────────────── */
.score-card { margin-bottom: 12px; }

.score-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 5px;
}

.score-bar-wrap { display: flex; align-items: center; gap: 8px; margin-bottom: 3px; }

.score-bar-track {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.score-bar-fill {
  height: 100%;
  background: var(--alert);
  border-radius: 3px;
  transition: width 0.6s ease, background 0.3s;
}

.score-bar-fill.green  { background: var(--stable); }
.score-bar-fill.yellow { background: var(--monitor); }
.score-bar-fill.red    { background: var(--alert); }

.score-pct {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  min-width: 28px;
  text-align: right;
}

.score-status { font-size: 9px; color: var(--text-muted); }

/* ── Value Grid ─────────────────────────────────────────────── */
.value-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.val-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.val-label { font-size: 9px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; }
.val-num   { font-family: var(--font-mono); font-size: 12px; font-weight: 600; color: var(--text); }

/* ── Alerts ─────────────────────────────────────────────────── */
.no-alerts { font-size: 11px; color: var(--text-muted); text-align: center; padding: 8px 0; }

.alert-item {
  font-size: 10px;
  padding: 6px 8px;
  background: rgba(220,38,38,0.06);
  border: 1px solid rgba(220,38,38,0.2);
  border-radius: 5px;
  color: #b91c1c;
  margin-bottom: 5px;
  line-height: 1.4;
}

/* ── Watermark ───────────────────────────────────────────────── */
#watermark {
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='420' height='180'%3E%3Ctext x='210' y='90' text-anchor='middle' dominant-baseline='middle' transform='rotate(-35 210 90)' fill='rgba(0%2C0%2C0%2C0.07)' font-family='Arial%2Csans-serif' font-size='15' font-weight='700' letter-spacing='3'%3E%C2%A9 Budoor Al-Aujan%2C CCP%3C/text%3E%3C/svg%3E");
  background-size: 420px 180px;
  background-repeat: repeat;
  pointer-events: none;
  user-select: none;
  z-index: 50;
}

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .analysis-grid { grid-template-columns: 1fr; }
  .form-row-4    { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 900px) {
  :root { --right-panel-w: 200px; }
  .form-row-3 { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 700px) {
  :root { --sidebar-w: 0px; }
  #sidebar       { display: none; }
  #right-panel   { display: none; }
  .form-row-2,
  .form-row-3,
  .form-row-4    { grid-template-columns: 1fr; }
  .analysis-grid { grid-template-columns: 1fr; }

  /* Results scroll naturally in the panel — no inner scroll cap */
  .response-body { max-height: none; overflow-y: visible; }

  /* Tab panel becomes a column: scroll area on top, action bar below */
  .tab-panel.active {
    display: flex;
    flex-direction: column;
  }

  /* Scroll area fills all space above the action bar */
  .panel-scroll {
    flex: 1;
    min-height: 0;
    /* Footer-safe bottom padding for panels without a .tab-action (Analysis, etc.) */
    padding: 16px 16px calc(var(--footer-h) + 16px);
  }

  /* Panels WITH a .tab-action can use minimal padding — action bar handles footer offset */
  .tab-panel:has(.tab-action) .panel-scroll {
    padding-bottom: 8px;
  }

  /* Action bar: always visible below the form, above the footer */
  .tab-action {
    flex-shrink: 0;
    padding: 8px 16px calc(var(--footer-h) + 10px);
    background: var(--bg);
  }

  /* Submit button fills the action bar */
  .submit-btn {
    min-height: 52px;
    margin: 0;
  }
}

@media (max-width: 420px) {
  .logo    { font-size: 13px; }
  .risk-badge { font-size: 12px; padding: 5px 12px; }
  .top-btn { font-size: 11px; padding: 5px 10px; }
}

/* ── Page Footer ─────────────────────────────────────────────── */
#page-footer {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--footer-h);
  background: var(--navy);
  border-top: 1px solid var(--navy-light);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 99;
  padding: 0 16px;
}

#page-footer p {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 10px;
  color: #475569;
  letter-spacing: 0.2px;
  line-height: 1.5;
  text-align: center;
}

/* ── PDF Report (html2canvas rendered, screen styles) ─────── */
#print-report { display: none; }

#print-report .rpt-page-hdr {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px solid #0d1b2e;
  padding-bottom: 6px;
  margin-bottom: 14px;
  font-size: 9px;
  font-weight: bold;
  color: #0d1b2e;
}
#print-report .rpt-cover { margin: 4px 0 16px; }
#print-report .rpt-title {
  font-size: 22px;
  font-weight: bold;
  color: #0d1b2e;
  margin: 0 0 4px;
}
#print-report .rpt-subtitle { font-size: 11px; color: #444; }

#print-report .rpt-section-title {
  font-size: 10px;
  font-weight: bold;
  color: #0d1b2e;
  border-bottom: 2px solid #0d1b2e;
  padding-bottom: 3px;
  margin: 16px 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
#print-report .rpt-page-break {
  border-top: 1px dashed #ccc;
  margin: 20px 0 4px;
}
#print-report .rpt-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 10px;
}
#print-report .rpt-table th {
  background: #0d1b2e;
  color: #fff;
  padding: 6px 8px;
  text-align: left;
  font-size: 9px;
  font-weight: bold;
}
#print-report .rpt-table td {
  padding: 5px 8px;
  border: 1px solid #ccc;
  font-size: 10px;
  vertical-align: top;
}
#print-report .rpt-table tr:nth-child(even) td { background: #f5f7fa; }
#print-report .rpt-compact th,
#print-report .rpt-compact td { font-size: 8px; padding: 4px 5px; }

#print-report .rpt-risk-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-weight: bold;
  font-size: 9px;
}
#print-report .rpt-risk-badge.alert   { background: #fee2e2; color: #7f1d1d; }
#print-report .rpt-risk-badge.stable  { background: #dcfce7; color: #14532d; }
#print-report .rpt-risk-badge.monitor { background: #fef9c3; color: #713f12; }

#print-report .rpt-analysis-entry {
  border: 1px solid #dde4ed;
  border-radius: 5px;
  padding: 7px 10px;
  margin-bottom: 7px;
}
#print-report .rpt-analysis-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}
#print-report .rpt-analysis-time { font-size: 9px; color: #666; }
#print-report .rpt-analysis-type { font-weight: bold; font-size: 10px; color: #0d1b2e; }
#print-report .rpt-bullet { font-size: 10px; padding: 2px 0 2px 12px; }
#print-report .rpt-action-line {
  font-size: 10px;
  font-weight: 600;
  color: #1e40af;
  background: #eff6ff;
  padding: 4px 8px;
  border-radius: 4px;
  margin-top: 4px;
}
#print-report .rpt-no-alerts {
  background: #dcfce7;
  color: #14532d;
  padding: 7px 10px;
  border-radius: 4px;
  font-size: 10px;
}
#print-report .rpt-empty { color: #666; font-style: italic; font-size: 10px; }
#print-report .rpt-footer {
  margin-top: 20px;
  padding-top: 6px;
  border-top: 1px solid #ccc;
  display: flex;
  justify-content: space-between;
  font-size: 8px;
  color: #888;
}
