:root {
  color-scheme: light;
  --blue: #1769e0;
  --blue-deep: #0d47a1;
  --blue-soft: #eaf3ff;
  --ink: #162033;
  --muted: #667085;
  --line: #dfe6ef;
  --surface: #ffffff;
  --canvas: #f4f7fb;
  --success: #0b8f55;
  --warning: #b75f00;
  --danger: #c93636;
  --shadow: 0 14px 40px rgba(27, 62, 111, .09);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--canvas); color: var(--ink); }
body { min-height: 100vh; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: var(--blue); }

.loading-screen,
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 12% 10%, rgba(50, 139, 255, .18), transparent 34%),
    radial-gradient(circle at 88% 88%, rgba(84, 193, 255, .14), transparent 32%),
    linear-gradient(145deg, #f8fbff 0%, #eef5ff 100%);
}

.loading-card,
.login-card {
  width: min(100%, 460px);
  background: rgba(255, 255, 255, .94);
  border: 1px solid rgba(213, 225, 241, .9);
  border-radius: 28px;
  padding: 34px;
  box-shadow: 0 28px 80px rgba(25, 74, 137, .14);
  backdrop-filter: blur(14px);
}

.brand { display: flex; align-items: center; gap: 13px; }
.brand img { width: 46px; height: 46px; border-radius: 14px; box-shadow: 0 8px 18px rgba(23, 105, 224, .24); }
.brand-name { font-size: 19px; font-weight: 760; letter-spacing: .02em; }
.brand-subtitle { color: var(--muted); font-size: 12px; margin-top: 2px; }
.login-card h1 { margin: 34px 0 8px; font-size: clamp(26px, 6vw, 34px); letter-spacing: -.04em; }
.login-card > p { color: var(--muted); line-height: 1.65; margin: 0 0 28px; }

.field { display: grid; gap: 8px; margin: 16px 0; }
.field label, .field-label { color: #344054; font-size: 13px; font-weight: 680; }
.field small { color: var(--muted); line-height: 1.45; }
.input, .select, .textarea {
  width: 100%;
  border: 1px solid #cdd7e4;
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  padding: 11px 13px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.textarea { min-height: 106px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 4px rgba(23, 105, 224, .12); }
.inline-field { display: grid; grid-template-columns: 1fr auto; gap: 10px; }

.button {
  border: 0;
  border-radius: 12px;
  padding: 10px 16px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform .12s, filter .12s, background .12s;
}
.button:hover { filter: brightness(.98); }
.button:active { transform: translateY(1px); }
.button:disabled { cursor: not-allowed; opacity: .55; }
.button-primary { color: #fff; background: linear-gradient(135deg, #2477e7, #1557c4); box-shadow: 0 8px 20px rgba(23, 105, 224, .22); }
.button-secondary { color: #174f9f; background: var(--blue-soft); }
.button-outline { color: #344054; background: #fff; border: 1px solid var(--line); }
.button-danger { color: #a42626; background: #fff0f0; }
.button-wide { width: 100%; padding: 12px 18px; }
.button-small { padding: 7px 11px; border-radius: 9px; font-size: 12px; }

.login-meta { display: flex; align-items: flex-start; gap: 9px; margin-top: 20px; padding: 13px; border-radius: 12px; color: #47627f; background: #f5f9ff; font-size: 12px; line-height: 1.55; }
.login-meta .dot { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; background: var(--success); margin-top: 5px; }

.shell { min-height: 100vh; display: grid; grid-template-columns: 252px minmax(0, 1fr); }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 16px;
  background: #fff;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  z-index: 10;
}
.sidebar .brand { padding: 3px 8px 22px; }
.sidebar .brand img { width: 40px; height: 40px; border-radius: 12px; }
.nav { display: grid; gap: 7px; margin-top: 12px; }
.nav-button {
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: #465269;
  padding: 11px 13px;
  display: flex;
  align-items: center;
  gap: 11px;
  text-align: left;
  font-weight: 650;
}
.nav-button:hover { background: #f5f8fc; }
.nav-button.active { color: #1358c2; background: var(--blue-soft); }
.nav-icon { width: 22px; text-align: center; font-size: 17px; }
.sidebar-footer { margin-top: auto; padding: 14px 8px 0; border-top: 1px solid var(--line); }
.signed-in { font-size: 12px; color: var(--muted); line-height: 1.45; margin-bottom: 10px; overflow-wrap: anywhere; }

.main { min-width: 0; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 8;
  min-height: 72px;
  padding: 15px clamp(20px, 4vw, 46px);
  background: rgba(244, 247, 251, .88);
  backdrop-filter: blur(16px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid rgba(223, 230, 239, .72);
}
.page-title { margin: 0; font-size: 22px; letter-spacing: -.025em; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.user-chip { display: flex; align-items: center; gap: 9px; padding: 6px 10px 6px 7px; background: #fff; border: 1px solid var(--line); border-radius: 999px; color: #344054; font-size: 13px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; color: #fff; background: linear-gradient(135deg, #2276e7, #54b7ef); font-weight: 800; }
.content { width: min(100%, 1440px); margin: 0 auto; padding: 26px clamp(20px, 4vw, 46px) 56px; }

.hero {
  color: #fff;
  border-radius: 24px;
  padding: clamp(24px, 4vw, 40px);
  background:
    radial-gradient(circle at 84% 18%, rgba(255,255,255,.19), transparent 23%),
    linear-gradient(135deg, #0d4dab, #2381e9 65%, #39a8ea);
  box-shadow: 0 20px 46px rgba(23, 87, 172, .22);
  overflow: hidden;
  position: relative;
}
.hero::after { content: ""; position: absolute; width: 230px; height: 230px; right: -70px; bottom: -120px; border-radius: 50%; border: 42px solid rgba(255,255,255,.08); }
.hero h2 { margin: 0 0 9px; font-size: clamp(24px, 3vw, 34px); letter-spacing: -.04em; }
.hero p { max-width: 720px; margin: 0; opacity: .9; line-height: 1.65; }
.hero-actions { margin-top: 22px; display: flex; flex-wrap: wrap; gap: 10px; }
.hero .button-secondary { background: #fff; color: #155bbb; }
.hero .button-outline { border-color: rgba(255,255,255,.35); background: rgba(255,255,255,.1); color: #fff; }

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.section { margin-top: 26px; }
.section-head { display: flex; justify-content: space-between; align-items: end; gap: 16px; margin-bottom: 13px; }
.section-head h2, .section-head h3 { margin: 0; letter-spacing: -.025em; }
.section-head p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 8px 24px rgba(31, 56, 91, .045); }
.card-body { padding: 20px; }
.stat-card { padding: 19px; display: flex; align-items: center; gap: 14px; }
.stat-icon { width: 44px; height: 44px; flex: 0 0 auto; border-radius: 13px; display: grid; place-items: center; background: var(--blue-soft); color: var(--blue); font-size: 21px; }
.stat-value { font-weight: 800; font-size: 25px; letter-spacing: -.04em; }
.stat-label { color: var(--muted); font-size: 12px; margin-top: 2px; }

.status-badge { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 5px 9px; font-size: 11px; font-weight: 760; white-space: nowrap; }
.status-active, .status-verified, .status-completed { color: #067244; background: #eaf9f1; }
.status-pending, .status-open { color: #9a4c00; background: #fff4e8; }
.status-in_progress { color: #1757a6; background: #eaf3ff; }
.status-revoked, .status-rejected, .status-suspended, .status-cancelled, .status-expired { color: #a32c2c; background: #fff0f0; }

.notice { border-radius: 14px; padding: 14px 16px; line-height: 1.6; font-size: 13px; }
.notice-info { color: #28557f; background: #edf6ff; border: 1px solid #cfe5fb; }
.notice-warning { color: #7a4500; background: #fff7e8; border: 1px solid #f2ddba; }
.notice-danger { color: #8c2929; background: #fff1f1; border: 1px solid #f1cccc; }

.patient-list { display: grid; gap: 12px; }
.patient-row { padding: 17px; display: grid; grid-template-columns: minmax(180px, 1.3fr) minmax(160px, 1fr) minmax(130px, .8fr) auto; align-items: center; gap: 16px; }
.patient-name { font-weight: 760; }
.patient-meta, .subtle { color: var(--muted); font-size: 12px; line-height: 1.55; }
.metric-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 7px; }
.tag { color: #315a86; background: #eff5fb; border-radius: 999px; padding: 4px 7px; font-size: 10px; }

.empty { padding: 44px 24px; text-align: center; color: var(--muted); }
.empty-icon { font-size: 38px; margin-bottom: 12px; }
.empty h3 { color: var(--ink); margin: 0 0 7px; }
.empty p { margin: 0 auto 18px; max-width: 520px; line-height: 1.6; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 18px; }
.form-grid .span-2 { grid-column: span 2; }
.check-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; margin-top: 9px; }
.check-item { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 11px; padding: 9px 10px; background: #fff; font-size: 12px; }
.check-item:has(input:checked) { color: #1558af; border-color: #8dbcf3; background: #f0f7ff; }
.check-item input { accent-color: var(--blue); }

.copy-box { display: grid; grid-template-columns: 1fr auto; gap: 9px; margin-top: 14px; }
.code-value { padding: 12px; border-radius: 12px; background: #f2f6fb; border: 1px dashed #b7c7db; overflow-wrap: anywhere; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

.detail-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.back-button { border: 0; color: #315a86; background: transparent; padding: 0; margin-bottom: 12px; font-weight: 700; }
.detail-name { margin: 0; font-size: 27px; letter-spacing: -.035em; }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 4px; background: #eaf0f7; border-radius: 13px; margin: 22px 0 16px; }
.tab-button { flex: 0 0 auto; border: 0; border-radius: 10px; color: #59677c; background: transparent; padding: 9px 13px; font-weight: 680; }
.tab-button.active { color: #1558af; background: #fff; box-shadow: 0 4px 14px rgba(34, 68, 110, .09); }

.metric-card { padding: 16px; }
.metric-card .metric-title { color: var(--muted); font-size: 12px; }
.metric-card .metric-value { font-size: 23px; font-weight: 800; letter-spacing: -.035em; margin-top: 7px; }
.metric-card .metric-unit { font-size: 11px; color: var(--muted); margin-left: 4px; font-weight: 500; }
.metric-card .metric-samples { font-size: 10px; color: #8792a3; margin-top: 5px; }

.chart { min-height: 190px; display: flex; align-items: end; gap: 8px; padding: 24px 6px 6px; overflow-x: auto; }
.chart-column { min-width: 38px; flex: 1; display: grid; justify-items: center; gap: 6px; }
.chart-bar-wrap { height: 128px; width: 22px; display: flex; align-items: end; border-radius: 8px; background: #edf2f8; overflow: hidden; }
.chart-bar { width: 100%; min-height: 3px; border-radius: 8px; background: linear-gradient(180deg, #54b5f0, #1769e0); }
.chart-value { font-size: 10px; color: #38526f; }
.chart-label { font-size: 10px; color: var(--muted); }

.timeline { display: grid; gap: 10px; }
.timeline-item { display: grid; grid-template-columns: 40px 1fr auto; gap: 12px; align-items: center; padding: 13px 0; border-bottom: 1px solid #edf1f5; }
.timeline-item:last-child { border-bottom: 0; }
.timeline-icon { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; color: #1769e0; background: #edf5ff; }
.timeline-value { font-weight: 780; }

.task-row, .note-row { padding: 15px 0; border-bottom: 1px solid #edf1f5; }
.task-row:last-child, .note-row:last-child { border-bottom: 0; }
.task-head, .note-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.task-title { font-weight: 740; }
.task-actions { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 8px; }
.note-body { margin-top: 8px; color: #344054; line-height: 1.7; white-space: pre-wrap; }

.toast-region { position: fixed; right: 22px; bottom: 22px; z-index: 100; display: grid; gap: 10px; width: min(380px, calc(100vw - 44px)); }
.toast { border-radius: 13px; padding: 13px 15px; color: #fff; background: #23344e; box-shadow: var(--shadow); animation: toast-in .18s ease-out; line-height: 1.45; font-size: 13px; }
.toast.error { background: #a93535; }
.toast.success { background: #087a4a; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

.spinner { width: 22px; height: 22px; border: 3px solid #dce9f8; border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { min-height: 84px; border-radius: 14px; background: linear-gradient(90deg, #edf1f6 25%, #f8fafc 45%, #edf1f6 65%); background-size: 300% 100%; animation: shimmer 1.4s infinite; }
@keyframes shimmer { to { background-position: -150% 0; } }

.mobile-nav { display: none; }

@media (max-width: 1050px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .patient-row { grid-template-columns: 1fr 1fr auto; }
  .patient-row > :nth-child(3) { display: none; }
  .check-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .shell { display: block; padding-bottom: 72px; }
  .sidebar { display: none; }
  .topbar { min-height: 62px; padding: 12px 17px; }
  .topbar .user-chip span:last-child { display: none; }
  .content { padding: 18px 15px 38px; }
  .grid-2, .grid-3, .grid-4, .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .check-grid { grid-template-columns: 1fr 1fr; }
  .patient-row { grid-template-columns: 1fr auto; }
  .patient-row > :nth-child(2), .patient-row > :nth-child(3) { display: none; }
  .detail-header { display: block; }
  .hero { border-radius: 19px; }
  .mobile-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    padding: 7px max(8px, env(safe-area-inset-right)) max(7px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    background: rgba(255,255,255,.96);
    border-top: 1px solid var(--line);
    backdrop-filter: blur(18px);
  }
  .mobile-nav .nav-button { display: grid; justify-items: center; gap: 2px; padding: 5px 2px; font-size: 10px; }
  .mobile-nav .nav-icon { font-size: 18px; }
  .toast-region { right: 12px; bottom: 84px; width: calc(100vw - 24px); }
}

@media (max-width: 430px) {
  .login-card { padding: 25px 20px; border-radius: 22px; }
  .inline-field { grid-template-columns: 1fr; }
  .check-grid { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .metric-card .metric-value { font-size: 19px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
