:root {
  --primary: #1a56db;
  --primary-hover: #1e429f;
  --primary-light: #e1effe;
  --primary-bg: #eff6ff;
  --green: #057a55;
  --green-light: #def7ec;
  --red: #e02424;
  --red-light: #fde8e8;
  --orange: #ff5a1f;
  --orange-light: #feecdc;
  --purple: #7e3af2;
  --purple-light: #edebfe;
  --g50: #f9fafb; --g100: #f3f4f6; --g200: #e5e7eb; --g300: #d1d5db;
  --g400: #9ca3af; --g500: #6b7280; --g600: #4b5563; --g700: #374151;
  --g800: #1f2937; --g900: #111827;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.12);
  --transition: all 0.2s ease;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--g50);
  color: var(--g800);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ============ LOGIN ============ */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #1a56db 100%);
  position: relative;
  overflow: hidden;
}

.login-wrap::before {
  content: '';
  position: absolute;
  width: 600px; height: 600px;
  background: radial-gradient(circle, rgba(26,86,219,0.3), transparent 70%);
  top: -200px; right: -100px;
}

.login-card {
  background: white;
  padding: 48px 40px;
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 420px;
  text-align: center;
  position: relative;
  z-index: 1;
}

.login-card .icon {
  width: 64px; height: 64px;
  background: var(--primary-light);
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 20px;
  font-size: 28px;
}

.login-card h1 { font-size: 26px; color: var(--g900); margin-bottom: 4px; font-weight: 700; }
.login-card .sub { color: var(--g500); font-size: 14px; margin-bottom: 32px; }

/* ============ FORMS ============ */
.field { margin-bottom: 16px; text-align: left; }
.field label {
  display: block; font-size: 13px; font-weight: 600;
  color: var(--g700); margin-bottom: 6px;
}
.field input, .field select, .field textarea {
  width: 100%; padding: 11px 14px;
  border: 1.5px solid var(--g200);
  border-radius: var(--radius);
  font-size: 14px; background: white;
  transition: var(--transition);
  outline: none; font-family: inherit;
}
.field input:focus, .field select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,86,219,0.12);
}
.field input[readonly] { background: var(--g50); color: var(--g500); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

.check-group {
  display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px;
}
.check-group label {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 500; color: var(--g700);
  padding: 6px 12px; border-radius: 20px;
  background: var(--g50); border: 1px solid var(--g200);
  cursor: pointer; transition: var(--transition);
}
.check-group label:has(input:checked) {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}
.check-group input { display: none; }

.err-msg { color: var(--red); font-size: 13px; margin-top: 8px; display: none; }

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 20px; border: none; border-radius: var(--radius);
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: var(--transition); text-decoration: none; font-family: inherit;
  white-space: nowrap;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-green { background: var(--green); color: white; }
.btn-green:hover { background: #046c4e; }
.btn-red { background: var(--red); color: white; }
.btn-red:hover { background: #c81e1e; }
.btn-ghost { background: transparent; color: var(--g600); border: 1.5px solid var(--g200); }
.btn-ghost:hover { background: var(--g50); border-color: var(--g300); }
.btn-sm { padding: 7px 14px; font-size: 13px; }
.btn-full { width: 100%; }
.btn-icon { padding: 7px 10px; }

/* ============ LAYOUT ============ */
.app { display: none; }

.topbar {
  background: white;
  border-bottom: 1px solid var(--g200);
  padding: 0 28px; height: 64px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 100;
  backdrop-filter: blur(8px);
}
.topbar-brand {
  display: flex; align-items: center; gap: 10px;
  font-size: 18px; font-weight: 700; color: var(--primary);
}
.topbar-brand .dot { width: 8px; height: 8px; background: var(--green); border-radius: 50%; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.container { max-width: 1440px; margin: 0 auto; padding: 28px; }

/* ============ TABS ============ */
.tabs {
  display: flex; gap: 4px; margin-bottom: 28px;
  background: var(--g100); padding: 4px;
  border-radius: var(--radius); width: fit-content;
}
.tab {
  padding: 8px 20px; border-radius: 8px;
  font-size: 13px; font-weight: 600; cursor: pointer;
  color: var(--g500); transition: var(--transition);
  border: none; background: none; font-family: inherit;
}
.tab.active { background: white; color: var(--g900); box-shadow: var(--shadow); }
.tab:hover:not(.active) { color: var(--g700); }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ============ STAT CARDS ============ */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px; margin-bottom: 28px;
}

.stat {
  background: white; border-radius: var(--radius-lg);
  padding: 20px 24px; box-shadow: var(--shadow);
  border-left: 4px solid var(--g200);
  transition: var(--transition);
}
.stat:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.stat .num { font-size: 30px; font-weight: 800; color: var(--g900); line-height: 1.2; }
.stat .lbl { font-size: 12px; font-weight: 600; color: var(--g400); text-transform: uppercase; letter-spacing: 0.06em; margin-top: 2px; }
.stat.blue { border-color: var(--primary); }
.stat.blue .num { color: var(--primary); }
.stat.green { border-color: var(--green); }
.stat.green .num { color: var(--green); }
.stat.orange { border-color: var(--orange); }
.stat.orange .num { color: var(--orange); }
.stat.purple { border-color: var(--purple); }
.stat.purple .num { color: var(--purple); }

/* ============ CARDS / PANELS ============ */
.card {
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 20px;
}

.card-head {
  padding: 18px 24px;
  border-bottom: 1px solid var(--g100);
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px;
}
.card-head h2 { font-size: 15px; font-weight: 700; color: var(--g800); }
.card-body { padding: 24px; }
.card-body.flush { padding: 0; }

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 20px; margin-bottom: 20px;
}

.chart-box {
  background: white; border-radius: var(--radius-lg);
  box-shadow: var(--shadow); padding: 20px;
}
.chart-box h3 {
  font-size: 13px; font-weight: 700; color: var(--g500);
  text-transform: uppercase; letter-spacing: 0.05em;
  margin-bottom: 16px;
}
.chart-box canvas { max-height: 260px; }

/* ============ FILTERS ============ */
.filters {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
}
.search-box {
  position: relative;
}
.search-box input {
  padding: 9px 14px 9px 36px;
  border: 1.5px solid var(--g200);
  border-radius: var(--radius);
  font-size: 13px; width: 260px;
  outline: none; transition: var(--transition);
  font-family: inherit;
}
.search-box input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,86,219,0.12); }
.search-box::before {
  content: '\1F50D'; position: absolute;
  left: 12px; top: 50%; transform: translateY(-50%);
  font-size: 14px; opacity: 0.4;
}
.filters select {
  padding: 9px 12px; border: 1.5px solid var(--g200);
  border-radius: var(--radius); font-size: 13px;
  outline: none; font-family: inherit; cursor: pointer;
  background: white;
}

/* ============ TABLE ============ */
table { width: 100%; border-collapse: collapse; }
thead th {
  background: var(--g50); padding: 11px 16px;
  text-align: left; font-size: 11px; font-weight: 700;
  color: var(--g400); text-transform: uppercase;
  letter-spacing: 0.06em; border-bottom: 1px solid var(--g200);
}
tbody td {
  padding: 13px 16px; font-size: 14px;
  border-bottom: 1px solid var(--g100);
  transition: background 0.15s;
}
tbody tr { cursor: pointer; }
tbody tr:hover td { background: var(--primary-bg); }
tbody tr:active td { background: var(--primary-light); }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge-mounjaro { background: var(--primary-light); color: var(--primary); }
.badge-wegovy { background: var(--green-light); color: var(--green); }
.badge-M { background: #dbeafe; color: #1e40af; }
.badge-F { background: #fce7f3; color: #9d174d; }

.pag {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-top: 1px solid var(--g100);
  font-size: 13px; color: var(--g500);
}
.pag-btns { display: flex; gap: 6px; }
.pag button {
  padding: 6px 14px; border: 1px solid var(--g200);
  border-radius: 6px; background: white; cursor: pointer;
  font-size: 13px; transition: var(--transition); font-family: inherit;
}
.pag button:hover:not(:disabled) { background: var(--g50); }
.pag button:disabled { opacity: 0.4; cursor: not-allowed; }

/* ============ PATIENT DETAIL ============ */
.patient-top {
  display: flex; align-items: center; gap: 16px;
  margin-bottom: 28px; flex-wrap: wrap;
}
.back-link {
  display: flex; align-items: center; gap: 6px;
  font-size: 14px; font-weight: 600; color: var(--primary);
  cursor: pointer; padding: 6px 12px; border-radius: var(--radius);
  border: none; background: var(--primary-light);
  transition: var(--transition); font-family: inherit;
}
.back-link:hover { background: var(--primary); color: white; }
.patient-top h1 { font-size: 24px; font-weight: 800; flex: 1; }
.patient-top .actions { display: flex; gap: 8px; }

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px; margin-bottom: 24px;
}

.info-panel {
  background: white; border-radius: var(--radius-lg);
  box-shadow: var(--shadow); padding: 24px;
}
.info-panel h3 {
  font-size: 12px; font-weight: 700; color: var(--g400);
  text-transform: uppercase; letter-spacing: 0.06em;
  margin-bottom: 16px; padding-bottom: 10px;
  border-bottom: 2px solid var(--g100);
}

.info-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0; border-bottom: 1px solid var(--g50);
}
.info-row:last-child { border: none; }
.info-row .k { font-size: 13px; color: var(--g500); }
.info-row .v { font-size: 14px; font-weight: 600; color: var(--g800); }

.tag-list { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 4px; }
.tag {
  padding: 5px 14px; border-radius: 20px;
  font-size: 12px; font-weight: 700;
}
.tag-si { background: var(--red-light); color: var(--red); }
.tag-no { background: var(--green-light); color: var(--green); }

/* Ctrl table */
.ctrl-table th:first-child, .ctrl-table td:first-child { width: 40px; text-align: center; }

.delta-neg { color: var(--green); font-weight: 600; }
.delta-pos { color: var(--red); font-weight: 600; }

/* ============ MODAL ============ */
.overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(15,23,42,0.6); z-index: 200;
  align-items: center; justify-content: center;
  backdrop-filter: blur(4px);
}
.overlay.open { display: flex; }

.modal {
  background: white; border-radius: 16px;
  padding: 32px; width: 95%; max-width: 640px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.25s ease;
}
@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.modal h2 { font-size: 18px; font-weight: 700; margin-bottom: 24px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; margin-top: 24px; }
.modal .sep {
  border: none; border-top: 1px solid var(--g100);
  margin: 20px 0;
}
.modal .section-title {
  font-size: 12px; font-weight: 700; color: var(--g400);
  text-transform: uppercase; letter-spacing: 0.06em;
  margin-bottom: 12px;
}

/* ============ TOAST ============ */
.toast {
  position: fixed; bottom: 28px; right: 28px;
  padding: 14px 24px; border-radius: var(--radius);
  font-size: 14px; font-weight: 600; z-index: 999;
  transform: translateY(100px); opacity: 0;
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-lg);
  color: white;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.ok { background: var(--green); }
.toast.err { background: var(--red); }

/* ============ SPINNER ============ */
.spin { display: inline-block; width: 18px; height: 18px; border: 2.5px solid var(--g200); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; align-items: center; justify-content: center; padding: 60px; gap: 10px; color: var(--g400); font-size: 14px; }

/* Empty state */
.empty { text-align: center; padding: 48px 20px; color: var(--g400); }
.empty .empty-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.3; }
.empty p { font-size: 14px; }

/* ============ COMPARISON ============ */
.comp-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  border: 1.5px solid var(--g200);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.comp-col {
  padding: 0;
}
.comp-col-head {
  padding: 14px 20px;
  font-size: 14px; font-weight: 800;
  text-transform: uppercase; letter-spacing: 0.05em;
  text-align: center;
}
.comp-col:first-child .comp-col-head {
  background: var(--primary-light); color: var(--primary);
  border-right: 1px solid var(--g200);
}
.comp-col:last-child .comp-col-head {
  background: var(--green-light); color: var(--green);
}
.comp-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 20px;
  border-top: 1px solid var(--g100);
}
.comp-col:first-child .comp-row { border-right: 1px solid var(--g200); }
.comp-row .ck { font-size: 12px; color: var(--g500); }
.comp-row .cv { font-size: 15px; font-weight: 700; }
.comp-col:first-child .comp-row .cv { color: var(--primary); }
.comp-col:last-child .comp-row .cv { color: var(--green); }

.comp-highlight {
  background: var(--g50);
}
.winner { position: relative; }
.winner::after {
  content: '\2605'; position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  font-size: 12px; color: var(--orange);
}

/* ============ RESPONSIVE ============ */
@media (max-width: 768px) {
  .container { padding: 16px; }
  .topbar { padding: 0 16px; }
  .stats-row { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat { padding: 14px 16px; }
  .stat .num { font-size: 22px; }
  .field-row, .field-row-3 { grid-template-columns: 1fr; }
  .chart-grid { grid-template-columns: 1fr; }
  .info-grid { grid-template-columns: 1fr; }
  .search-box input { width: 100%; }
  .filters { width: 100%; }
  .modal { padding: 24px 20px; }
  .patient-top h1 { font-size: 18px; }
  .tabs { width: 100%; }
  .tab { flex: 1; text-align: center; font-size: 12px; padding: 8px 12px; }
  .hide-m { display: none !important; }
}
