:root {
  --ink: #152720;
  --muted: #6c7d75;
  --line: #dfe9e4;
  --surface: #ffffff;
  --canvas: #f4f8f6;
  --green: #176b52;
  --green-soft: #e4f3ed;
  --blue: #3370ff;
  --red: #c94444;
  --red-soft: #fff0ee;
  --yellow: #9a6a10;
  --yellow-soft: #fff7df;
  --shadow: 0 16px 40px rgba(28, 61, 48, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", sans-serif;
}
button, input, textarea { font: inherit; }
button { cursor: pointer; }

.topbar {
  height: 72px;
  padding: 0 32px;
  display: flex;
  align-items: center;
  gap: 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.94);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(12px);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
  min-width: 210px;
}
.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: white;
  font-weight: 800;
  background: linear-gradient(145deg, #20815f, #154c3e);
  box-shadow: 0 8px 18px rgba(23,107,82,.24);
}
.brand strong, .brand small { display: block; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.role-switcher {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--canvas);
  border-radius: 12px;
}
.role-switcher button {
  padding: 8px 14px;
  color: var(--muted);
  border: 0;
  border-radius: 9px;
  background: transparent;
}
.role-switcher button.active { color: var(--green); background: white; box-shadow: 0 2px 8px rgba(0,0,0,.06); }
.ghost-button { margin-left: auto; padding: 9px 14px; color: var(--muted); border: 1px solid var(--line); background: white; border-radius: 10px; }
.portal-label { margin-left: auto; color: var(--muted); font-size: 13px; font-weight: 700; }
.portal-label:empty { display: none; }

.app-shell { max-width: 1380px; margin: 0 auto; padding: 32px; }
.portal-home { max-width: 1040px; margin: 60px auto; }
.portal-home > div:first-child { max-width: 680px; margin-bottom: 28px; }
.portal-home h1 { margin: 8px 0; font-size: 40px; }
.portal-home p { color: var(--muted); line-height: 1.65; }
.portal-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.portal-card { padding: 24px; color: inherit; text-decoration: none; border: 1px solid var(--line); border-radius: 18px; background: white; box-shadow: var(--shadow); transition: .2s ease; }
.portal-card:hover { transform: translateY(-2px); border-color: #b9dfcf; }
.portal-card h2 { margin: 18px 0 8px; }
.portal-card p { margin: 0; font-size: 13px; }
.portal-card.subdued { background: transparent; box-shadow: none; }
.page-header { margin-bottom: 26px; display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; }
.page-header h1 { margin: 0 0 7px; font-size: 28px; letter-spacing: -.7px; }
.page-header p { margin: 0; color: var(--muted); }
.eyebrow { color: var(--green); text-transform: uppercase; font-size: 12px; font-weight: 800; letter-spacing: 1.2px; }
.grid { display: grid; gap: 20px; }
.grid.stats { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 20px; }
.grid.two { grid-template-columns: 1.25fr .75fr; }
.grid.two.advisor-layout { grid-template-columns: .75fr 1.25fr; }
.card {
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 16px; font-size: 17px; }
.card h3 { margin: 0 0 6px; font-size: 15px; }
.card p { color: var(--muted); line-height: 1.65; }
.stat { min-height: 118px; }
.stat strong { display: block; margin: 10px 0 4px; font-size: 28px; }
.stat span { color: var(--muted); font-size: 13px; }
.stat.accent { color: white; background: linear-gradient(145deg, #1c7859, #164c3f); border: 0; }
.stat.accent span { color: rgba(255,255,255,.76); }
.stat.mini { min-height: 88px; padding: 14px; box-shadow: none; }
.stat.mini strong { font-size: 18px; }
.finance-stats { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; margin: 12px 0 0 !important; gap: 10px !important; }

.banner {
  margin-bottom: 20px;
  padding: 18px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  border: 1px solid #b9dfcf;
  border-radius: 16px;
  background: var(--green-soft);
}
.banner.warning { border-color: #edd7a0; background: var(--yellow-soft); }
.banner strong { display: block; margin-bottom: 4px; }
.banner p { margin: 0; color: var(--muted); font-size: 13px; }
.primary, .secondary, .danger {
  border: 0;
  border-radius: 10px;
  padding: 10px 15px;
  font-weight: 700;
}
.primary { color: white; background: var(--green); }
.secondary { color: var(--green); background: var(--green-soft); }
.danger { color: var(--red); background: var(--red-soft); }
.small { padding: 7px 10px; font-size: 12px; }

.list { display: grid; gap: 12px; }
.list-item {
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fff;
}
.list-item.row { display: flex; justify-content: space-between; align-items: center; gap: 14px; }
.meta { color: var(--muted); font-size: 12px; line-height: 1.6; }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 4px 8px; font-size: 11px; font-weight: 700; border-radius: 99px; }
.badge.green { color: var(--green); background: var(--green-soft); }
.badge.red { color: var(--red); background: var(--red-soft); }
.badge.yellow { color: var(--yellow); background: var(--yellow-soft); }
.badge.gray { color: var(--muted); background: var(--canvas); }
.disease-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.metric-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.integration-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.metric { padding: 14px; border-radius: 12px; background: var(--canvas); }
.metric strong { display: block; font-size: 22px; margin: 7px 0 3px; }
.metric small { color: var(--muted); }
.consent-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px; }
.consent-row + .consent-row { padding-top: 13px; border-top: 1px solid var(--line); }
.consent-actions { display: flex; gap: 7px; }
.form { display: grid; gap: 10px; }
.form input, .form textarea, .form select {
  width: 100%;
  padding: 11px 12px;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  background: white;
}
.form textarea { min-height: 100px; resize: vertical; }
.form input:focus, .form textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.compact-form { padding-top: 12px; border-top: 1px solid var(--line); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.empty { padding: 32px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: 13px; }
.loading { padding: 80px; text-align: center; color: var(--muted); }
.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  padding: 13px 17px;
  max-width: 360px;
  color: white;
  background: var(--ink);
  border-radius: 11px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: .2s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--red); }
.progress { height: 7px; overflow: hidden; border-radius: 99px; background: var(--line); }
.progress > span { height: 100%; display: block; border-radius: inherit; background: var(--green); }
.notice { padding: 12px; color: var(--yellow); font-size: 12px; line-height: 1.6; border-radius: 10px; background: var(--yellow-soft); }
.boundary-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.boundary-columns > div { padding: 14px; border-radius: 12px; background: var(--canvas); }
.boundary-columns ul { margin: 10px 0 0; padding-left: 18px; color: var(--muted); font-size: 12px; line-height: 1.7; }
.boundary-title { font-size: 13px; }
.boundary-title.allowed { color: var(--green); }
.boundary-title.prohibited { color: var(--red); }
.patient-link { color: inherit; text-decoration: none; }
.patient-link:hover h3 { color: var(--green); }
.ai-card-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.ai-card-heading h2 { margin-top: 6px; }
.quick-prompts { display: flex; flex-wrap: wrap; gap: 7px; margin: 12px 0; }
.ai-answer { margin-top: 16px; padding: 16px; border: 1px solid #b9dfcf; border-radius: 13px; background: var(--green-soft); }
.ai-answer p { color: var(--ink); white-space: pre-wrap; }
.ai-history { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.record-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.record-content { margin: 10px 0 0; color: var(--ink) !important; white-space: pre-wrap; }
.record-table-wrap { max-width: 100%; max-height: 420px; overflow: auto; scrollbar-gutter: stable; scrollbar-color: #a9c8bb var(--canvas); scrollbar-width: thin; border: 1px solid var(--line); border-radius: 12px; }
.record-table-wrap::-webkit-scrollbar { width: 10px; height: 10px; }
.record-table-wrap::-webkit-scrollbar-track { background: var(--canvas); border-radius: 99px; }
.record-table-wrap::-webkit-scrollbar-thumb { background: #a9c8bb; border: 2px solid var(--canvas); border-radius: 99px; }
.record-table { width: max-content; min-width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.record-table th, .record-table td { min-width: 132px; padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); white-space: nowrap; background: white; }
.record-table th { position: sticky; top: 0; z-index: 2; color: var(--muted); font-size: 11px; background: var(--canvas); }
.record-table th small { display: block; margin-top: 3px; color: var(--muted); font-weight: 400; }
.record-table .sticky-date { position: sticky; left: 0; z-index: 1; min-width: 138px; border-right: 1px solid #cddbd4; background: white; box-shadow: 5px 0 10px rgba(28, 61, 48, .04); }
.record-table thead .sticky-date { z-index: 3; background: var(--canvas); }
.record-table tr:last-child td { border-bottom: 0; }
.record-table th:last-child, .record-table td:last-child { border-right: 0; }
.metric-missing { color: var(--muted); }
.timeline { display: grid; gap: 0; }
.timeline-item { position: relative; display: grid; grid-template-columns: 18px 1fr; gap: 10px; padding-bottom: 18px; }
.timeline-item:not(:last-child)::before { content: ""; position: absolute; left: 6px; top: 12px; bottom: 0; width: 2px; background: var(--line); }
.timeline-dot { position: relative; z-index: 1; width: 14px; height: 14px; margin-top: 2px; border: 3px solid white; border-radius: 50%; box-shadow: 0 0 0 1px var(--line); background: var(--green); }
.timeline-dot.yellow { background: #d9a52e; }
.timeline-dot.red { background: var(--red); }
.timeline-item p { margin: 5px 0 0; color: var(--ink); font-size: 13px; }
.archive-browser h3 { margin: 18px 0 10px; }
.archive-section { margin-top: 20px; padding-top: 4px; border-top: 1px solid var(--line); }

@media (max-width: 900px) {
  .topbar { height: auto; padding: 12px 16px; flex-wrap: wrap; }
  .brand { min-width: 0; }
  .ghost-button { display: none; }
  .role-switcher { order: 3; width: 100%; }
  .role-switcher button { flex: 1; }
  .app-shell { padding: 20px 14px; }
  .grid.stats, .grid.two, .grid.two.advisor-layout { grid-template-columns: 1fr; }
  .grid.stats { grid-template-columns: repeat(2, 1fr); }
  .page-header { align-items: flex-start; flex-direction: column; }
  .metric-grid { grid-template-columns: 1fr; }
  .integration-grid { grid-template-columns: 1fr; }
  .boundary-columns { grid-template-columns: 1fr; }
  .portal-grid { grid-template-columns: 1fr; }
  .portal-label { margin-left: 0; }
}
