:root {
  --bg: #FAFBFC;
  --surface: #FFFFFF;
  --surface-hover: #F8F9FB;
  --ink: #14181F;
  --muted: #6B7280;
  --muted-light: #9CA3AF;
  --line: #EAECEF;
  --line-soft: #F1F2F4;
  --navy: #16233F;
  --navy-light: #24365C;
  --navy-soft: #EEF1F6;
  --ws-accent: #C08A1E;

  --status-notice: #C08A1E;
  --status-demand: #CC5F26;
  --status-suspended: #9B3A3A;
  --status-monitoring: #7C8592;
  --status-overdue: #E0342E;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(16,24,40,0.04), 0 1px 3px rgba(16,24,40,0.05);
  --shadow-md: 0 4px 14px rgba(16,24,40,0.07);
  --shadow-lg: 0 16px 40px rgba(16,24,40,0.16);

  --font-display: 'Barlow Semi Condensed', sans-serif;
  --font-body: 'Inter', sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.01em;
}

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(120deg, #101A30, #1C2C4D, #223A66, #16233F);
  background-size: 300% 300%;
  animation: gradientShift 12s ease infinite;
  padding: 24px;
}

@keyframes gradientShift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

.login-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 44px 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 32px;
}

.brand-mark {
  flex-shrink: 0;
}

.brand-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 19px;
  color: var(--ink);
  line-height: 1.25;
}

.brand-subtitle {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 3px;
}

#login-form label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  margin: 16px 0 7px;
  color: var(--muted);
  letter-spacing: 0.01em;
}

#login-form input {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: var(--font-body);
  background: var(--surface);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

#login-form input:focus {
  outline: none;
  border-color: var(--navy-light);
  box-shadow: 0 0 0 3px rgba(36,54,92,0.12);
}

#login-btn {
  width: 100%;
  margin-top: 24px;
  padding: 12px;
  background: var(--navy);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

#login-btn:hover { background: var(--navy-light); }
#login-btn:active { transform: scale(0.99); }
#login-btn:disabled { opacity: 0.55; cursor: default; }

.error-text {
  color: var(--status-overdue);
  background: #FDEEEC;
  font-size: 13px;
  margin-top: 14px;
  margin-bottom: 0;
  padding: 9px 13px;
  border-radius: 8px;
}

.info-text {
  color: #2F6B4F;
  background: #E9F5EE;
  padding: 9px 13px;
  border-radius: 8px;
  font-size: 13px;
  margin-top: 14px;
  margin-bottom: 0;
}

.login-links {
  display: flex;
  justify-content: space-between;
  margin-top: 16px;
}

.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 12.5px;
  font-family: var(--font-body);
  cursor: pointer;
  padding: 0;
  transition: color 0.15s ease;
}
.link-btn:hover { color: var(--navy); }

/* ---------- App shell / sidebar ---------- */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 248px;
  flex-shrink: 0;
  background: var(--navy);
  color: white;
  display: flex;
  flex-direction: column;
  padding: 24px 18px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
  padding: 0 4px;
}
.sidebar-brand .brand-title { color: white; }
.sidebar-brand .brand-subtitle { color: #9BA8C4; font-size: 11.5px; word-break: break-word; }

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

.nav-btn {
  text-align: left;
  background: transparent;
  border: none;
  color: #B7C1D6;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 11px;
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}
.nav-btn svg { flex-shrink: 0; opacity: 0.75; transition: opacity 0.15s ease; }
.nav-btn:hover { background: rgba(255,255,255,0.06); color: white; transform: translateX(2px); }
.nav-btn:hover svg { opacity: 1; }
.nav-btn.active { background: rgba(255,255,255,0.12); color: white; font-weight: 600; }
.nav-btn.active svg { opacity: 1; }

.sidebar-signout { margin-top: 20px; }

.ghost-btn {
  background: transparent;
  border: 1.5px solid rgba(255,255,255,0.25);
  color: white;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 13.5px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.ghost-btn:hover { background: rgba(255,255,255,0.08); border-color: rgba(255,255,255,0.4); }

.ghost-btn-dark {
  background: transparent;
  border: 1.5px solid var(--line);
  color: var(--navy);
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 6px;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.ghost-btn-dark:hover { background: var(--navy-soft); border-color: var(--navy-light); }

.main-content {
  flex: 1;
  padding: 32px 36px 64px;
  max-width: 1020px;
}

.corner-brand {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.7;
  pointer-events: none;
  min-width: 160px;
}

@media (max-width: 1500px) {
  .corner-brand { display: none; }
}

.view { display: none; }
.view.active { display: block; animation: fadeIn 0.2s ease; }

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

.view-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 25px;
  margin: 0 0 22px;
  letter-spacing: -0.01em;
}

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 1.5px solid var(--line);
}

.tab-btn {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  padding: 11px 20px;
  background: transparent;
  border: none;
  border-bottom: 2.5px solid transparent;
  margin-bottom: -1.5px;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 9px;
  transition: color 0.15s ease;
}

.tab-btn:hover { color: var(--ink); }

.tab-btn.active {
  color: var(--navy);
  border-bottom-color: var(--navy);
}

.count-pill {
  background: var(--line-soft);
  color: var(--muted);
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  transition: background 0.15s ease, color 0.15s ease;
}

.tab-btn.active .count-pill {
  background: var(--navy);
  color: white;
}

.panel { display: none; }
.panel.active { display: block; }

.panel-empty {
  text-align: center;
  color: var(--muted-light);
  padding: 70px 20px;
  font-size: 14.5px;
}

/* ---------- Patient cards ---------- */
.card-list { display: flex; flex-direction: column; gap: 10px; }

.patient-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.18s ease, border-color 0.18s ease, transform 0.12s ease;
  animation: cardIn 0.35s ease backwards;
}
.patient-card:hover {
  box-shadow: var(--shadow-md);
  border-color: #DCE0E6;
  transform: translateY(-2px);
}
.patient-card:nth-child(1) { animation-delay: 0.02s; }
.patient-card:nth-child(2) { animation-delay: 0.06s; }
.patient-card:nth-child(3) { animation-delay: 0.10s; }
.patient-card:nth-child(4) { animation-delay: 0.14s; }
.patient-card:nth-child(5) { animation-delay: 0.18s; }
.patient-card:nth-child(6) { animation-delay: 0.22s; }
.patient-card:nth-child(7) { animation-delay: 0.26s; }
.patient-card:nth-child(8) { animation-delay: 0.30s; }

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

.patient-card.overdue { border-left: 3px solid var(--status-overdue); }

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.patient-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 17.5px;
  letter-spacing: -0.01em;
}

.patient-meta {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 3px;
}

.status-badge {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 5px 11px;
  border-radius: 999px;
  white-space: nowrap;
  color: white;
}

.status-suspended { background: var(--status-suspended); }
.status-first_notice_sent,
.status-second_notice_requested,
.status-second_notice_pending_delivery,
.status-second_notice_delivered { background: var(--status-notice); }
.status-final_demand_sent,
.status-final_demand_delivered { background: var(--status-demand); }
.status-forwarded_to_county,
.status-monitoring { background: var(--status-monitoring); }

.overdue-flag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--status-overdue);
  margin-top: 10px;
}
.overdue-flag::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--status-overdue);
  animation: pulse 1.6s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(224,52,46,0.5); }
  50% { box-shadow: 0 0 0 5px rgba(224,52,46,0); }
}

.stage-tracker {
  display: flex;
  gap: 4px;
  margin: 12px 0;
}
.stage-dot {
  height: 4px;
  flex: 1;
  border-radius: 3px;
  background: var(--line-soft);
  transition: background 0.2s ease;
}
.stage-dot.filled { background: var(--navy); }
.stage-dot.filled.overdue { background: var(--status-overdue); }

/* ---------- Forms ---------- */
.form-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 26px 28px;
  margin-bottom: 22px;
  max-width: 580px;
  box-shadow: var(--shadow-sm);
}

.form-card-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16.5px;
  margin: 0 0 16px;
  letter-spacing: -0.01em;
}

.form-card label,
.stage-info label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  margin: 16px 0 7px;
  color: var(--muted);
  letter-spacing: 0.01em;
}
.form-card label:first-child { margin-top: 0; }

.form-card input[type="text"],
.form-card input[type="date"],
.form-card input[type="number"],
.form-card select,
.form-card textarea,
.stage-info input,
.stage-info select {
  width: 100%;
  padding: 10px 13px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 14.5px;
  font-family: var(--font-body);
  background: white;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-card input:focus,
.form-card select:focus,
.form-card textarea:focus,
.stage-info input:focus,
.stage-info select:focus {
  outline: none;
  border-color: var(--navy-light);
  box-shadow: 0 0 0 3px rgba(36,54,92,0.1);
}

.form-card textarea { resize: vertical; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.checkbox-label {
  display: flex !important;
  align-items: center;
  gap: 9px;
  font-weight: 500 !important;
  color: var(--ink) !important;
}
.checkbox-label input[type="checkbox"] { width: auto; accent-color: var(--navy); }

.primary-btn {
  margin-top: 20px;
  padding: 11px 22px;
  background: linear-gradient(135deg, var(--navy-light), var(--navy));
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14.5px;
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  transition: box-shadow 0.2s ease, transform 0.1s ease;
  box-shadow: 0 2px 8px rgba(22,35,63,0.25);
}
.primary-btn:hover { box-shadow: 0 4px 16px rgba(22,35,63,0.4); }
.primary-btn:active { transform: scale(0.99); }

.form-message {
  margin-top: 14px;
  font-size: 13px;
  padding: 9px 13px;
  border-radius: 8px;
}
.form-message.success { background: #E9F5EE; color: #2F6B4F; }
.form-message.error { background: #FDEEEC; color: var(--status-overdue); }

.form-divider {
  border: none;
  border-top: 1px solid var(--line);
  margin: 22px 0;
}

.hint-text {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 6px;
  line-height: 1.5;
}

.stage-info {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(16,24,40,0.55);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  z-index: 50;
  animation: fadeIn 0.15s ease;
}

.modal {
  background: white;
  border-radius: 18px;
  max-width: 480px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 30px;
  position: relative;
  box-shadow: var(--shadow-lg);
}

.modal-close {
  position: absolute;
  top: 16px; right: 18px;
  background: var(--line-soft);
  border: none;
  width: 30px; height: 30px;
  border-radius: 50%;
  font-size: 19px;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
  transition: background 0.15s ease;
}
.modal-close:hover { background: var(--line); }

.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line-soft);
  font-size: 14px;
}
.detail-row:last-child { border-bottom: none; }
.detail-label { color: var(--muted); font-weight: 500; flex-shrink: 0; }
.detail-value { text-align: right; }

.clinical-box {
  margin-top: 18px;
  padding: 13px 15px;
  background: #FBF3EC;
  border: 1px solid #EFDFCB;
  border-radius: 10px;
  font-size: 13.5px;
  line-height: 1.5;
}
.clinical-box-label {
  font-weight: 700;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--status-demand);
  margin-bottom: 5px;
}

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex-direction: row;
    align-items: center;
    padding: 14px;
    overflow-x: auto;
  }
  .sidebar-brand { margin-bottom: 0; margin-right: 12px; }
  .sidebar-brand .brand-subtitle { display: none; }
  .side-nav { flex-direction: row; flex: none; }
  .nav-btn { white-space: nowrap; }
  .sidebar-signout { margin-top: 0; margin-left: 8px; }
  .main-content { padding: 20px 18px; }
  .form-grid { grid-template-columns: 1fr; }
}


/* ---------- Workspace switcher ---------- */
body[data-ws="cm"] { --ws-accent: #2FA39A; }
body[data-ws="570"] { --ws-accent: #C08A1E; }

.ws-switch { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.ws-btn {
  display: flex; align-items: center; gap: 12px; text-align: left;
  background: rgba(255,255,255,0.05); color: #B7C1D6;
  border: 1px solid rgba(255,255,255,0.10); border-radius: var(--radius-sm);
  padding: 11px 12px; cursor: pointer; font-family: var(--font-body);
  transition: background .15s ease, border-color .15s ease;
}
.ws-btn strong { display: block; font-size: 14px; font-weight: 600; }
.ws-btn small { display: block; font-size: 11px; opacity: .75; margin-top: 1px; }
.ws-btn .ws-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; background: #6B7794; }
#ws-btn-570 .ws-dot { background: #C08A1E; }
#ws-btn-cm .ws-dot { background: #2FA39A; }
.ws-btn:hover { background: rgba(255,255,255,0.09); }
.ws-btn.active { color: #fff; background: rgba(255,255,255,0.14); border-color: var(--ws-accent); box-shadow: inset 3px 0 0 var(--ws-accent); }

.side-nav[hidden] { display: none !important; }
.side-nav { flex: 0 0 auto; }
.side-nav-admin { margin-top: auto; padding-top: 14px; border-top: 1px solid rgba(255,255,255,0.10); }
.sidebar-signout { margin-top: 12px; }
.nav-btn.active { box-shadow: inset 3px 0 0 var(--ws-accent); }

/* Workspace identity on the main content area */
.main-content { border-top: 4px solid var(--ws-accent); }

@media (max-width: 860px) {
  .ws-switch { flex-direction: row; margin-bottom: 0; margin-right: 8px; }
  .ws-btn small { display: none; }
  .side-nav-admin { margin-top: 0; padding-top: 0; border-top: none; }
}

/* ---------- County report picker ---------- */
.dash-actions { display: flex; justify-content: flex-end; margin-bottom: 14px; }
.dash-actions .primary-btn { width: auto; margin: 0; padding: 10px 18px; }
.cr-picker-head { display: flex; justify-content: space-between; align-items: center; margin: 18px 0 8px; font-size: 14px; }
.cr-patient-list { border: 1px solid var(--line); border-radius: var(--radius-sm); max-height: 340px; overflow-y: auto; margin-bottom: 16px; }
.cr-pick-row { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-bottom: 1px solid var(--line-soft); cursor: pointer; font-size: 14px; }
.cr-pick-row:last-child { border-bottom: none; }
.cr-pick-row:hover { background: var(--surface-hover); }
.cr-pick-row input { width: auto; margin: 0; accent-color: var(--navy); }
.cr-pick-name { flex: 1; font-weight: 500; }
.cr-pick-stage { color: var(--muted); font-size: 12.5px; }
#cr-generate:disabled { opacity: .5; cursor: not-allowed; }

.modal-actions { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }
.modal-actions .primary-btn { width: 100%; }

/* ---------- Activity log ---------- */
.wl-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.wl-stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 14px 16px; box-shadow: var(--shadow-sm); border-top: 3px solid var(--ws-accent); }
.wl-stat-num { font-family: var(--font-display); font-size: 28px; font-weight: 700; color: var(--navy); line-height: 1.1; }
.wl-stat-label { font-size: 12px; color: var(--muted); margin-top: 2px; }
.wl-bar-row { display: grid; grid-template-columns: 170px 1fr 56px; align-items: center; gap: 10px; margin: 7px 0; font-size: 13px; }
.wl-bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wl-bar-track { background: var(--navy-soft); border-radius: 999px; height: 10px; overflow: hidden; }
.wl-bar-fill { display: block; height: 100%; background: var(--ws-accent); border-radius: 999px; }
.wl-bar-val { text-align: right; color: var(--muted); }
.wl-item { cursor: default; }
.wl-item-actions { margin-top: 8px; display: flex; gap: 14px; }
.wl-filter-actions { display: flex; gap: 10px; margin-top: 14px; }
@media (max-width: 760px) { .wl-stats { grid-template-columns: repeat(2, 1fr); } .wl-bar-row { grid-template-columns: 110px 1fr 48px; } }
