/* ═══════════════════════════════════════
   RADIA — MEDICAL PLATFORM STYLES
   Clean clinical aesthetic: off-white + deep navy + electric blue
═══════════════════════════════════════ */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface2: #f9fafb;
  --border: #e5e7eb;
  --border2: #d1d5db;
  --navy: #0f1f3d;
  --navy2: #1a2f52;
  --blue: #1e6ff1;
  --blue-light: #e8f0fe;
  --blue-dark: #1558cc;
  --green: #16a34a;
  --green-light: #dcfce7;
  --orange: #ea580c;
  --orange-light: #fff7ed;
  --purple: #7c3aed;
  --purple-light: #f5f3ff;
  --red: #dc2626;
  --text: #111827;
  --text2: #4b5563;
  --text3: #9ca3af;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.12);
  --font: 'DM Sans', sans-serif;
  --mono: 'DM Mono', monospace;
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ── SCREENS ── */
.screen { display: none; }
.screen.active { display: flex; }

/* ── LOGIN ── */
#screen-login {
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  background: var(--navy);
}

/* ── REGISTER — mismo centrado que login ── */
#screen-register {
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  background: var(--navy);
}

.login-bg {
  position: absolute; inset: 0; pointer-events: none;
}
.login-grid {
  position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(30,111,241,.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(30,111,241,.08) 1px, transparent 1px);
  background-size: 40px 40px;
}
.login-glow {
  position: absolute;
  top: -200px; left: 50%; transform: translateX(-50%);
  width: 700px; height: 700px;
  background: radial-gradient(circle, rgba(30,111,241,.2) 0%, transparent 70%);
}

.login-card {
  position: relative; z-index: 1;
  background: var(--surface);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 420px;
  box-shadow: var(--shadow-lg);
}

.login-logo {
  display: flex; align-items: center; gap: 12px; margin-bottom: 32px;
}
.logo-mark {
  width: 44px; height: 44px; color: var(--blue);
  display: flex; align-items: center; justify-content: center;
}
.logo-mark svg { width: 100%; height: 100%; }
.logo-mark.small { width: 28px; height: 28px; }
.logo-name { font-size: 20px; font-weight: 600; color: var(--text); letter-spacing: -.3px; }
.logo-sub { font-size: 11px; color: var(--text3); margin-top: 1px; }

.login-title { font-size: 22px; font-weight: 600; letter-spacing: -.3px; margin-bottom: 6px; }
.login-desc { color: var(--text2); font-size: 13px; margin-bottom: 28px; }

.form-group { margin-bottom: 16px; }
.form-group label {
  display: block; font-size: 12px; font-weight: 500;
  color: var(--text2); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .5px;
}
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border2);
  border-radius: var(--radius);
  font-family: var(--font); font-size: 14px; color: var(--text);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
.form-group textarea { resize: vertical; line-height: 1.5; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(30,111,241,.12);
}

.login-error {
  background: #fef2f2; border: 1px solid #fecaca; color: var(--red);
  padding: 10px 14px; border-radius: var(--radius); font-size: 13px;
  margin-bottom: 16px;
}

.login-hint {
  margin-top: 24px; padding: 14px;
  background: var(--blue-light); border-radius: var(--radius);
  font-size: 12px; color: var(--text2); line-height: 1.7;
  font-family: var(--mono);
}

/* auth-toggle centrado */
.auth-toggle {
  margin-top: 16px;
  text-align: center;
  font-size: 13px;
  color: var(--text3);
}
.auth-toggle a {
  color: var(--blue);
  cursor: pointer;
  font-weight: 500;
  text-decoration: none;
}
.auth-toggle a:hover { text-decoration: underline; }

/* ── BUTTONS ── */
.btn-primary {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--blue); color: #fff;
  border: none; border-radius: var(--radius);
  padding: 10px 20px; font-family: var(--font); font-size: 14px; font-weight: 500;
  cursor: pointer; transition: background .15s, transform .1s;
}
.btn-primary:hover { background: var(--blue-dark); }
.btn-primary:active { transform: scale(.98); }
.btn-primary svg { width: 16px; height: 16px; }

.btn-secondary {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--surface); color: var(--text2);
  border: 1.5px solid var(--border2); border-radius: var(--radius);
  padding: 9px 18px; font-family: var(--font); font-size: 14px; font-weight: 500;
  cursor: pointer; transition: background .15s, border-color .15s;
}
.btn-secondary:hover { background: var(--bg); border-color: var(--blue); color: var(--blue); }

.btn-logout {
  display: flex; align-items: center; gap: 7px;
  background: transparent; color: var(--text3);
  border: none; padding: 8px 12px; border-radius: var(--radius);
  font-family: var(--font); font-size: 13px; cursor: pointer;
  width: 100%; transition: color .15s, background .15s;
}
.btn-logout:hover { color: var(--red); background: rgba(220,38,38,.06); }
.btn-logout svg { width: 16px; height: 16px; }

.hidden { display: none !important; }

/* ── APP LAYOUT ── */
#screen-app {
  height: 100vh; overflow: hidden;
}

.sidebar {
  width: 220px; min-width: 220px;
  background: var(--navy);
  display: flex; flex-direction: column;
  padding: 20px 12px;
  gap: 4px;
}

.sidebar-logo {
  display: flex; align-items: center; gap: 10px;
  color: #fff; font-size: 16px; font-weight: 600;
  padding: 4px 12px 20px;
  letter-spacing: -.2px;
}
.sidebar-logo .logo-mark { color: var(--blue); }

.sidebar-nav { flex: 1; display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius);
  color: rgba(255,255,255,.55); font-size: 14px; font-weight: 400;
  cursor: pointer; text-decoration: none;
  transition: all .15s;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover { color: #fff; background: rgba(255,255,255,.07); }
.nav-item.active { color: #fff; background: rgba(30,111,241,.25); font-weight: 500; }

.sidebar-bottom { padding-top: 12px; border-top: 1px solid rgba(255,255,255,.1); }

.user-pill {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px 14px;
}
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--blue); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; flex-shrink: 0;
}
.user-info { overflow: hidden; }
.user-info > div:first-child { color: #fff; font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { color: rgba(255,255,255,.4); font-size: 11px; margin-top: 1px; }

/* ── MAIN CONTENT ── */
.main-content {
  flex: 1; display: flex; flex-direction: column;
  overflow: hidden; background: var(--bg);
}

.top-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.top-bar-left { font-size: 15px; color: var(--text2); }
.top-bar-left strong { color: var(--text); font-weight: 600; }
.top-bar-right { display: flex; align-items: center; gap: 12px; }

.legal-badge {
  display: flex; align-items: center; gap: 5px;
  background: #f0fdf4; color: var(--green);
  border: 1px solid #bbf7d0;
  padding: 5px 10px; border-radius: 20px; font-size: 11px; font-weight: 500;
}
.legal-badge svg { width: 12px; height: 12px; }
.date-badge {
  color: var(--text3); font-size: 12px; font-family: var(--mono);
}

/* ── TAB CONTENT ── */
.tab-content { display: none; flex: 1; overflow-y: auto; padding: 28px 32px; flex-direction: column; }
.tab-content.active { display: flex; }

.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px;
}
.page-header h1 { font-size: 22px; font-weight: 600; letter-spacing: -.3px; }

/* ── STATS ── */
.stats-row {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 20px;
  display: flex; align-items: center; gap: 16px;
  box-shadow: var(--shadow);
}
.stat-icon {
  width: 44px; height: 44px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.stat-icon svg { width: 22px; height: 22px; }
.stat-icon.blue { background: var(--blue-light); color: var(--blue); }
.stat-icon.green { background: var(--green-light); color: var(--green); }
.stat-icon.orange { background: var(--orange-light); color: var(--orange); }
.stat-icon.purple { background: var(--purple-light); color: var(--purple); }
.stat-value { font-size: 26px; font-weight: 600; line-height: 1; margin-bottom: 4px; letter-spacing: -.5px; }
.stat-label { font-size: 12px; color: var(--text2); }

/* ── RECENT SECTION ── */
.section-title { font-size: 15px; font-weight: 600; margin-bottom: 16px; }
.recent-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px;
}
.empty-state {
  grid-column: 1/-1;
  text-align: center; padding: 60px 20px; color: var(--text3);
}
.empty-state svg { width: 60px; height: 60px; margin-bottom: 16px; opacity: .4; }
.empty-state p { font-size: 14px; line-height: 1.6; margin-bottom: 16px; }

.recent-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); overflow: hidden;
  cursor: pointer; transition: box-shadow .15s, transform .15s;
}
.recent-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.recent-card-img { height: 120px; background: #1a2540; overflow: hidden; position: relative; }
.recent-card-img img { width: 100%; height: 100%; object-fit: cover; opacity: .9; }
.recent-card-body { padding: 12px; }
.recent-card-name { font-size: 12px; font-weight: 500; color: var(--text); margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-card-date { font-size: 11px; color: var(--text3); font-family: var(--mono); }

/* ── STEPS ── */
.steps-bar {
  display: flex; align-items: center; gap: 0;
  margin-bottom: 28px;
}
.step {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 500; color: var(--text3);
  padding: 8px 16px;
}
.step span {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--border2); color: var(--text3);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
}
.step.active { color: var(--blue); }
.step.active span { background: var(--blue); color: #fff; }
.step.done { color: var(--green); }
.step.done span { background: var(--green); color: #fff; }
.step-sep { flex: 1; height: 1px; background: var(--border2); min-width: 20px; }

.step-panel { animation: fadeIn .2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ── UPLOAD ── */
.upload-area {
  border: 2px dashed var(--border2); border-radius: var(--radius-lg);
  padding: 48px 24px; text-align: center; cursor: pointer;
  transition: border-color .15s, background .15s;
  background: var(--surface); margin-bottom: 0;
}
.upload-area:hover { border-color: var(--blue); background: var(--blue-light); }
.upload-inner { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.upload-inner svg { width: 52px; height: 52px; color: var(--text3); }
.upload-label { font-size: 15px; font-weight: 500; color: var(--text); }
.upload-sub { font-size: 13px; color: var(--text3); }

/* ── TWO COL ── */
.two-col { display: grid; grid-template-columns: 1fr 1.4fr; gap: 24px; }
.col-preview { }
.preview-frame {
  border-radius: var(--radius-lg); overflow: hidden;
  background: #0f1f3d; aspect-ratio: 1; position: relative;
}
.preview-frame img { width: 100%; height: 100%; object-fit: cover; }
.preview-label {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,.6); backdrop-filter: blur(4px);
  color: #fff; font-size: 11px; padding: 8px 12px; font-family: var(--mono);
}

.col-form { }
.form-section-title { font-size: 16px; font-weight: 600; margin-bottom: 6px; }
.form-note { font-size: 13px; color: var(--text2); margin-bottom: 20px; line-height: 1.5; }
.form-actions { display: flex; gap: 10px; margin-top: 8px; }

/* ── LOADING ── */
.loading-panel { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px; padding: 80px; }

.pulse-ring {
  width: 64px; height: 64px; border-radius: 50%;
  border: 3px solid var(--blue-light);
  border-top-color: var(--blue);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 16px; font-weight: 500; color: var(--text); }
.loading-sub { font-size: 13px; color: var(--text3); font-family: var(--mono); }

/* ── RESULTS ── */
.results-grid { display: grid; grid-template-columns: 1fr 1.5fr; gap: 24px; }

.results-img-wrapper {
  border-radius: var(--radius-lg); overflow: hidden;
  background: #0a1628; aspect-ratio: 1; position: relative;
}
.results-img-wrapper img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.results-img-wrapper canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 2;
}

.heatmap-controls {
  margin-top: 12px; display: flex; flex-direction: column; gap: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px;
}
.toggle-label { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 13px; }
.toggle-label input { display: none; }
.toggle-track { width: 36px; height: 20px; background: var(--border2); border-radius: 10px; position: relative; transition: background .2s; }
.toggle-track .toggle-thumb { position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; background: #fff; border-radius: 50%; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.toggle-label input:checked + .toggle-track { background: var(--blue); }
.toggle-label input:checked + .toggle-track .toggle-thumb { transform: translateX(16px); }

.slider-group { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text2); }
.slider-group input[type=range] { flex: 1; accent-color: var(--blue); }

.history-card-meta { margin-top: 12px; font-size: 12px; color: var(--text3); line-height: 1.8; font-family: var(--mono); }

/* ── ANALYSIS PANEL ── */
.results-analysis-col {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 22px;
  display: flex; flex-direction: column; gap: 14px;
  overflow-y: auto; max-height: calc(100vh - 200px);
}

.analysis-header { display: flex; align-items: center; justify-content: space-between; }
.analysis-badge {
  display: flex; align-items: center; gap: 5px;
  background: var(--blue-light); color: var(--blue);
  padding: 5px 10px; border-radius: 20px; font-size: 12px; font-weight: 500;
}
.analysis-badge svg { width: 13px; height: 13px; }
.analysis-id { font-size: 11px; color: var(--text3); font-family: var(--mono); }

.analysis-block { border-radius: var(--radius); padding: 14px; }
.analysis-block.obs { background: var(--bg); border: 1px solid var(--border); }
.analysis-block.zones { background: #eff6ff; border: 1px solid #bfdbfe; }
.analysis-block.interp { background: #fffbeb; border: 1px solid #fed7aa; }
.analysis-block.reco { background: #f0fdf4; border: 1px solid #bbf7d0; }

.block-title {
  font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px;
  margin-bottom: 8px; display: flex; align-items: center; gap: 6px;
}
.block-title.obs { color: var(--text2); }
.block-title.zones { color: #1d4ed8; }
.block-title.interp { color: #92400e; }
.block-title.reco { color: var(--green); }

.block-text { font-size: 13px; line-height: 1.65; color: var(--text); }

.legal-notice {
  display: flex; align-items: flex-start; gap: 8px;
  background: var(--navy); color: rgba(255,255,255,.65);
  border-radius: var(--radius); padding: 12px 14px;
  font-size: 12px; line-height: 1.55;
}
.legal-notice svg { width: 14px; height: 14px; flex-shrink: 0; margin-top: 1px; color: rgba(255,255,255,.5); }

.result-actions { display: flex; gap: 10px; }

/* tags */
.tag-review {
  display: inline-flex; align-items: center; gap: 3px;
  background: #fff7ed; color: var(--orange);
  border: 1px solid #fed7aa;
  padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 500;
}
.tag-ok {
  display: inline-flex; align-items: center; gap: 3px;
  background: var(--green-light); color: var(--green);
  border: 1px solid #bbf7d0;
  padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 500;
}

/* ── HISTORY ── */
.history-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}

.history-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); overflow: hidden;
  cursor: pointer; transition: box-shadow .15s, transform .15s;
}
.history-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.history-card-img { height: 120px; background: #1a2540; overflow: hidden; position: relative; }
.history-card-img img { width: 100%; height: 100%; object-fit: cover; opacity: .9; }
.history-card-body { padding: 12px; }
.history-card-title { font-size: 12px; font-weight: 500; color: var(--text); margin-bottom: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-card-meta { font-size: 11px; color: var(--text3); font-family: var(--mono); display: flex; flex-wrap: wrap; gap: 3px; align-items: center; }

/* ── CHAT WIDGET ── */
.chat-widget { position: fixed; bottom: 24px; right: 24px; z-index: 1000; }

.chat-fab {
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--navy); color: #fff;
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-lg); position: relative;
  transition: transform .15s, background .15s;
}
.chat-fab:hover { transform: scale(1.08); background: var(--navy2); }
.chat-fab svg { width: 22px; height: 22px; }

.chat-badge {
  position: absolute; top: -2px; right: -2px;
  background: var(--blue); color: #fff;
  font-size: 9px; font-weight: 700; letter-spacing: .5px;
  padding: 2px 5px; border-radius: 10px;
  border: 2px solid var(--bg);
}

.chat-panel {
  position: absolute; bottom: 64px; right: 0;
  width: 340px; background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; overflow: hidden;
  animation: slideUp .2s ease;
}
@keyframes slideUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  background: var(--navy); color: #fff;
}
.chat-title { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 500; }
.chat-dot { width: 8px; height: 8px; border-radius: 50%; background: #4ade80; animation: blink 2s infinite; }
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: .4; } }
.chat-close { background: transparent; border: none; color: rgba(255,255,255,.6); cursor: pointer; font-size: 16px; padding: 0 4px; }
.chat-close:hover { color: #fff; }

.chat-messages {
  flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px;
  min-height: 240px; max-height: 320px;
}
.chat-msg { display: flex; }
.chat-msg.bot { justify-content: flex-start; }
.chat-msg.user { justify-content: flex-end; }
.msg-bubble {
  max-width: 80%; padding: 10px 13px; border-radius: 12px;
  font-size: 13px; line-height: 1.55;
}
.chat-msg.bot .msg-bubble { background: var(--bg); color: var(--text); border-bottom-left-radius: 3px; }
.chat-msg.user .msg-bubble { background: var(--blue); color: #fff; border-bottom-right-radius: 3px; }

.chat-input-area {
  display: flex; gap: 8px; padding: 12px;
  border-top: 1px solid var(--border);
}
.chat-input-area input {
  flex: 1; border: 1.5px solid var(--border2); border-radius: 8px;
  padding: 8px 12px; font-family: var(--font); font-size: 13px;
  outline: none;
}
.chat-input-area input:focus { border-color: var(--blue); }
.chat-send {
  width: 36px; height: 36px; border-radius: 8px;
  background: var(--blue); color: #fff; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.chat-send:hover { background: var(--blue-dark); }
.chat-send svg { width: 16px; height: 16px; }

/* ── MODAL ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  backdrop-filter: blur(4px); z-index: 2000;
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.modal-card {
  background: var(--surface); border-radius: var(--radius-lg);
  width: 100%; max-width: 820px; max-height: 85vh; overflow-y: auto;
  padding: 28px; position: relative; box-shadow: var(--shadow-lg);
  animation: fadeIn .2s ease;
}
.modal-close {
  position: absolute; top: 16px; right: 16px;
  background: var(--bg); border: 1px solid var(--border);
  width: 30px; height: 30px; border-radius: 50%;
  cursor: pointer; font-size: 14px; color: var(--text2);
  display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: var(--border); }

.modal-results-grid { display: grid; grid-template-columns: 1fr 1.4fr; gap: 20px; margin-bottom: 20px; }
.modal-img { border-radius: var(--radius); overflow: hidden; background: #0f1f3d; aspect-ratio: 1; }
.modal-img img { width: 100%; height: 100%; object-fit: cover; }
