/* Base styles, reusable ws-* UI components, the app shell, and the login screen for Warpspeed.
   All colors are sourced from the design tokens in theme.css so every component themes itself. */

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

html { font-size: 16px; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--ws-font-sans);
  background-color: var(--ws-bg);
  color: var(--ws-text);
  -webkit-font-smoothing: antialiased;
}

.mono {
  font-family: var(--ws-font-mono);
  font-variant-numeric: tabular-nums;
}

a { color: var(--ws-primary); text-decoration: none; }
a:hover { color: var(--ws-primary-hover); text-decoration: underline; }

h1, h2, h3 { color: var(--ws-text-strong); }

/* ── Reusable components ──────────────────────────────────────────────────── */

.ws-card {
  background: var(--ws-surface);
  border: 1px solid var(--ws-border);
  border-radius: var(--ws-radius);
}

.ws-field { margin-bottom: 16px; }

.ws-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--ws-text);
}

.ws-input {
  width: 100%;
  padding: 11px 13px;
  font-size: 0.95rem;
  color: var(--ws-text);
  background: var(--ws-surface-2);
  border: 1px solid var(--ws-border);
  border-radius: var(--ws-radius-sm);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

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

.ws-input:focus {
  border-color: var(--ws-primary);
  box-shadow: 0 0 0 3px var(--ws-focus-ring);
}

.ws-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: var(--ws-radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.ws-btn-block { width: 100%; }

.ws-btn-primary { background: var(--ws-primary); color: var(--ws-primary-contrast); }
.ws-btn-primary:hover { background: var(--ws-primary-hover); color: var(--ws-primary-contrast); text-decoration: none; }

.ws-btn-outline { background: transparent; color: var(--ws-text); border-color: var(--ws-border); }
.ws-btn-outline:hover { border-color: var(--ws-primary); color: var(--ws-primary); text-decoration: none; }

/* Light/dark toggle button (sun in dark mode, moon in light mode). */
.ws-theme-toggle {
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--ws-surface);
  border: 1px solid var(--ws-border);
  color: var(--ws-text);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.ws-theme-toggle:hover { color: var(--ws-primary); border-color: var(--ws-primary); }
.ws-theme-toggle--floating { position: fixed; top: 18px; right: 18px; z-index: 50; }
.ws-theme-toggle .icon-moon { display: none; }
.ws-theme-toggle .icon-sun { display: inline-flex; }
[data-theme="light"] .ws-theme-toggle .icon-sun { display: none; }
[data-theme="light"] .ws-theme-toggle .icon-moon { display: inline-flex; }

/* ── App shell (authenticated pages) ─────────────────────────────────────── */

.app-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 22px;
  background: var(--ws-surface);
  border-bottom: 1px solid var(--ws-border);
}
.app-nav { display: flex; gap: 6px; margin-left: 14px; margin-right: auto; }
.app-nav a {
  padding: 8px 12px;
  border-radius: var(--ws-radius-sm);
  color: var(--ws-text-muted);
  font-weight: 500;
}
.app-nav a:hover { color: var(--ws-text); background: var(--ws-surface-2); text-decoration: none; }
.app-nav a.active {
  color: var(--ws-primary);
  background: color-mix(in srgb, var(--ws-primary) 14%, transparent);
}
.app-bar-right { display: flex; align-items: center; gap: 10px; }
.app-user { color: var(--ws-text-muted); font-weight: 500; font-size: 0.9rem; }
.logout-form { margin: 0; }
.app-main { padding: 24px; max-width: 1280px; margin: 0 auto; }

/* ── Brand ───────────────────────────────────────────────────────────────── */

.brand { display: inline-flex; align-items: center; gap: 10px; }
.brand-mark { color: var(--ws-primary); flex: 0 0 auto; }
.brand-name {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ws-text-strong);
}
.brand-name .accent { color: var(--ws-primary); }
.brand-beta {
  align-self: flex-start;
  margin-top: 1px;
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ws-primary);
  background: color-mix(in srgb, var(--ws-primary) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--ws-primary) 38%, transparent);
  padding: 1px 6px;
  border-radius: 999px;
}

/* ── Login screen (MyChart-inspired split card) ──────────────────────────── */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(1100px 560px at 50% -12%, color-mix(in srgb, var(--ws-primary) 12%, transparent), transparent 60%),
    var(--ws-bg);
}

.login-card {
  width: 100%;
  max-width: 940px;
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  background: var(--ws-surface);
  border: 1px solid var(--ws-border);
  border-radius: var(--ws-radius);
  box-shadow: var(--ws-shadow);
  overflow: hidden;
}

.login-aside {
  padding: 36px 34px;
  background: var(--ws-surface-2);
  border-right: 1px solid var(--ws-border);
}
.login-tagline { margin: 22px 0 4px; font-size: 1.05rem; color: var(--ws-text-strong); font-weight: 600; }
.login-tagline-sub { margin: 0; color: var(--ws-text-muted); font-size: 0.9rem; }

.feature { display: flex; gap: 12px; margin-top: 22px; }
.feature-icon { color: var(--ws-primary); flex: 0 0 auto; margin-top: 2px; }
.feature-title { font-weight: 600; color: var(--ws-text-strong); }
.feature-desc { font-size: 0.88rem; color: var(--ws-text-muted); margin-top: 2px; }

.login-panel { padding: 40px 34px; display: flex; flex-direction: column; justify-content: center; }
.login-panel h1 { font-size: 1.45rem; margin: 0 0 4px; }
.login-sub { color: var(--ws-text-muted); margin: 0 0 26px; font-size: 0.92rem; }

.field-row-end { display: flex; justify-content: flex-end; margin: -8px 0 16px; }
.field-row-end a { font-size: 0.85rem; }

.login-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 22px 0 14px;
  color: var(--ws-text-muted);
  font-size: 0.8rem;
}
.login-divider::before, .login-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--ws-border);
}

.login-actions { display: flex; gap: 10px; }
.login-actions .ws-btn { flex: 1; }

.login-foot {
  margin-top: 26px;
  padding-top: 16px;
  border-top: 1px solid var(--ws-border);
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 0.8rem;
  color: var(--ws-text-muted);
}
.login-foot a { color: var(--ws-text-muted); }
.login-foot a:hover { color: var(--ws-primary); }

.login-error {
  margin-bottom: 16px;
  padding: 10px 12px;
  font-size: 0.85rem;
  color: var(--ws-danger);
  background: color-mix(in srgb, var(--ws-danger) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--ws-danger) 40%, transparent);
  border-radius: var(--ws-radius-sm);
}
.login-hint { margin: 14px 0 0; font-size: 0.78rem; color: var(--ws-text-muted); }
.login-hint strong { color: var(--ws-text); }

@media (max-width: 760px) {
  .login-card { grid-template-columns: 1fr; max-width: 460px; }
  .login-aside { border-right: none; border-bottom: 1px solid var(--ws-border); }
}

/* ── Diagnosis color system (migrated from the normalizer; theme-independent) ── */
.dx-NSR, .dx-SB, .dx-ST { --dx: #198754; }                              /* Sinus rhythms = green */
.dx-Afib, .dx-AFLU, .dx-AFibRVR { --dx: #6f42c1; }                      /* AF = purple */
.dx-PVC, .dx-VBig, .dx-VTrig, .dx-VCoup, .dx-VTrip, .dx-VT, .dx-VRun { --dx: #dc3545; } /* Ventricular = red */
.dx-PAC, .dx-SVT, .dx-SVTA, .dx-ATACH { --dx: #fd7e14; }                /* Supraventricular = orange */
.dx-Paced { --dx: #0dcaf0; }                                            /* Paced = cyan */
.dx-ARTIFACT, .dx-UnClass { --dx: #6c757d; }                            /* Artifact = gray */
.dx-Mobitz1, .dx-Mobitz2, .dx-CHB, .dx-AVB1 { --dx: #e83e8c; }          /* AV blocks = pink */
.dx-default { --dx: #adb5bd; }

/* ── Clinician dashboard ─────────────────────────────────────────────────── */

.clinician-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.search { position: relative; flex: 0 1 360px; }
.search-input { padding-left: 38px; }
.search-icon {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ws-text-muted);
  pointer-events: none;
}

.board {
  display: grid;
  grid-template-columns: 260px repeat(3, 1fr);
  gap: 18px;
  align-items: start;
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 440px;
  background: var(--ws-surface);
  border: 1px solid var(--ws-border);
  border-radius: var(--ws-radius);
}
.panel-head {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--ws-border);
}
.panel-title {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ws-text-strong);
}
.panel-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--dot, var(--ws-primary));
  flex: 0 0 auto;
}
.panel-dot--bins { --dot: var(--ws-primary); }
.panel-dot--active { --dot: var(--ws-status-active); }
.panel-dot--pending { --dot: var(--ws-status-pending); }
.panel-dot--done { --dot: var(--ws-status-done); }
.panel-count {
  margin-left: auto;
  min-width: 28px;
  padding: 1px 9px;
  text-align: center;
  font-family: var(--ws-font-mono);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--ws-text-muted);
  background: var(--ws-surface-2);
  border: 1px solid var(--ws-border);
  border-radius: 999px;
}
.panel-body { padding: 6px; overflow-y: auto; }
.panel-empty {
  padding: 26px 16px;
  text-align: center;
  font-size: 0.88rem;
  color: var(--ws-text-muted);
}

.panel-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
}
.panel-body .panel-row:hover { background: var(--ws-surface-2); }
.panel-body .panel-row + .panel-row { border-top: 1px solid var(--ws-border); border-radius: 0; }

/* STAT studies: unmissable left accent + tint, sorted to the top of their column by the handler. */
.scan-row.is-stat {
  border-left: 3px solid var(--ws-danger);
  padding-left: 9px;
  background: color-mix(in srgb, var(--ws-danger) 7%, transparent);
}
.scan-row.is-stat:hover { background: color-mix(in srgb, var(--ws-danger) 12%, transparent); }

.bin-list { list-style: none; margin: 0; padding: 8px; }
.bin-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--ws-radius-sm);
  cursor: pointer;
}
.bin-item:hover { background: var(--ws-surface-2); }
.bin-link { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex: 1 1 auto; min-width: 0; }
.bin-item:not(.is-empty) { cursor: pointer; }
.bin-name { color: var(--ws-text); }
.bin-count {
  min-width: 26px;
  text-align: center;
  font-size: 0.74rem;
  font-weight: 700;
  padding: 1px 8px;
  border-radius: 999px;
  color: #fff;
  background: var(--dx, var(--ws-text-muted));
}
.bin-item.is-empty { opacity: 0.55; }
.bin-item.is-empty .bin-count { color: var(--ws-text-muted); background: var(--ws-border); }

.row-main { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.row-name { font-weight: 600; color: var(--ws-text-strong); }
.row-name, .row-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: 0.82rem; color: var(--ws-text-muted); }
.row-end {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
  margin-left: auto;
  padding-left: 10px;
  text-align: right;
  flex: 0 0 auto;
}
.row-metric { font-size: 0.82rem; color: var(--ws-text-muted); }
.row-date { font-size: 0.8rem; color: var(--ws-text-muted); white-space: nowrap; }
.report-row { cursor: pointer; }
.report-link { display: flex; align-items: center; gap: 10px; flex: 1 1 auto; min-width: 0; }

.stat-badge {
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #fff;
  background: var(--ws-danger);
  padding: 2px 7px;
  border-radius: 999px;
}

@media (max-width: 1024px) {
  .board { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  .board { grid-template-columns: 1fr; }
  .panel { min-height: 0; }
}

/* ── Accessibility & motion ──────────────────────────────────────────────── */

.ws-input:focus-visible,
.ws-btn:focus-visible,
.ws-theme-toggle:focus-visible,
.app-nav a:focus-visible,
.bin-item:focus-visible {
  outline: 2px solid var(--ws-primary);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: no-preference) {
  @keyframes ws-rise {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
  }
  .board > .panel { animation: ws-rise 0.45s ease both; }
  .board > .panel:nth-child(1) { animation-delay: 0.02s; }
  .board > .panel:nth-child(2) { animation-delay: 0.08s; }
  .board > .panel:nth-child(3) { animation-delay: 0.14s; }
  .board > .panel:nth-child(4) { animation-delay: 0.20s; }
}
