/* ── Tokens ──────────────────────────────────────────────── */
:root {
  --bg:         #f2f5f0;
  --card:       #ffffff;
  --text:       #111a14;
  --muted:      #6b7b72;
  --line:       #e2e8df;
  --green:      #18703f;
  --green-dark: #0f5530;
  --green-mid:  #239155;
  --green-soft: #eaf4ee;
  --amber:      #d97706;
  --amber-soft: #fef9ec;
  --red:        #dc2626;
  --red-soft:   #fef2f2;
  --blue:       #2563eb;
  --shadow-sm:  0 2px 8px rgba(15,40,25,.07);
  --shadow:     0 6px 20px rgba(15,40,25,.10);
  --shadow-lg:  0 12px 36px rgba(15,40,25,.13);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

/* ── Reset ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
body  { margin: 0; background: var(--bg); color: var(--text); overflow: hidden; }
h1, h2, h3, p { margin-top: 0; }
button, input  { font: inherit; cursor: pointer; }
.hidden        { display: none !important; }

/* ── Phone shell ─────────────────────────────────────────── */
.phone {
  width: min(100%, 480px);
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  position: relative;
  background: var(--card);
  box-shadow: var(--shadow-lg);
}

/* ── Role gate (splash) ──────────────────────────────────── */
.role-gate {
  height: 100dvh;
  position: relative;
  overflow: hidden;
  display: block;
  padding: 0;
  background:
    linear-gradient(180deg, rgba(8,44,25,.12) 0%, rgba(8,44,25,.08) 34%, rgba(8,44,25,.58) 100%),
    url("/web/assets/gate-photo.png") center / cover no-repeat;
}

.gate-shade {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(255,255,255,.28) 0%, rgba(255,255,255,.04) 42%, rgba(8,44,25,.72) 100%);
}

.gate-content {
  position: relative;
  z-index: 1;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 48px 24px 30px;
}

.gate-copy {
  width: 100%;
  max-width: 360px;
  text-align: left;
}

.splash-kicker {
  display: inline-flex;
  padding: 7px 11px;
  margin-bottom: 14px;
  border-radius: 999px;
  background: rgba(255,255,255,.72);
  color: var(--green-dark);
  font-size: 12px;
  font-weight: 900;
  backdrop-filter: blur(10px);
}

.splash-title {
  font-size: 46px;
  font-weight: 900;
  letter-spacing: 0;
  color: #12351f;
  margin-bottom: 8px;
  text-shadow: 0 1px 12px rgba(255,255,255,.65);
}

.splash-sub {
  margin: 0;
  max-width: 310px;
  color: #244534;
  font-size: 15px;
  line-height: 1.6;
  font-weight: 700;
}

.gate-panel {
  width: 100%;
  padding: 18px;
  border-radius: 22px;
  background: rgba(255,255,255,.88);
  border: 1px solid rgba(255,255,255,.72);
  box-shadow: 0 18px 42px rgba(10,35,20,.25);
  backdrop-filter: blur(18px);
}

.gate-panel h2 {
  margin-bottom: 12px;
  color: var(--green-dark);
  font-size: 22px;
  line-height: 1.25;
}

.gate-features {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.gate-features p {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 10px;
  align-items: start;
  margin: 0;
  padding: 10px 0;
  border-bottom: 1px solid rgba(18,86,48,.12);
}

.gate-features p:last-child { border-bottom: 0; }
.gate-features strong {
  color: var(--green);
  font-size: 14px;
  font-weight: 900;
}
.gate-features span {
  color: #40534a;
  font-size: 13px;
  line-height: 1.45;
  font-weight: 700;
}

.gate-btns {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  width: 100%;
}

.role-gate .primary,
.role-gate .ghost {
  width: 100%;
  border-radius: 14px;
  min-height: 48px;
}

/* ── Topbar ──────────────────────────────────────────────── */
.app-view {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px 8px;
  background: rgba(255,255,255,.96);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.topbar-logo {
  font-size: 17px;
  font-weight: 900;
  color: var(--green-dark);
  letter-spacing: -.01em;
}

.switch-role {
  border: 0;
  background: var(--green-soft);
  color: var(--green);
  font-weight: 800;
  font-size: 13px;
  padding: 6px 14px;
  border-radius: 999px;
}

/* ── Buttons ─────────────────────────────────────────────── */
.primary {
  display: block;
  min-height: 52px;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(175deg, var(--green-mid), var(--green-dark));
  color: #fff;
  font-weight: 900;
  font-size: 16px;
  box-shadow: 0 6px 20px rgba(18,100,55,.28);
  transition: opacity .15s, transform .1s;
}

.primary:active { opacity: .88; transform: scale(.98); }

.ghost {
  display: block;
  min-height: 52px;
  border: 1.5px solid var(--line);
  border-radius: 16px;
  background: rgba(255,255,255,.85);
  color: var(--green);
  font-weight: 800;
  font-size: 16px;
  backdrop-filter: blur(4px);
  transition: border-color .15s;
}

.ghost:hover { border-color: var(--green); }
.wide        { width: 100%; }
.plain       { border: 0; background: transparent; color: var(--green); font-weight: 800; padding: 0; font-size: 13px; }

/* ── Screens ─────────────────────────────────────────────── */
.role-view   { display: none; flex: 1; overflow: hidden; }
.role-view:not(.hidden) { display: flex; flex-direction: column; flex: 1; overflow: hidden; }
.screen      { display: none; }
.screen.active {
  display: block;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 12px 14px 16px;
}
.screen.active::-webkit-scrollbar { display: none; }

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
}

.card label { display: block; color: var(--muted); font-weight: 800; font-size: 13px; margin-bottom: 8px; }
.card input[type="text"] {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  margin-bottom: 12px;
  background: var(--bg);
  color: var(--text);
}

/* ── Hero card ───────────────────────────────────────────── */
.hero-card {
  min-height: 148px;
  padding: 14px 16px;
  margin-bottom: 10px;
  border-radius: 22px;
  border: 1.5px solid var(--line);
  box-shadow: var(--shadow);
  overflow: hidden;
  background-size: cover;
  background-position: center right;
  transition: background .4s ease;
}

/* Risk-aware hero colors */
.hero-card.risk-low {
  background:
    linear-gradient(100deg, rgba(240,248,243,.98) 0%, rgba(230,244,238,.90) 55%, rgba(220,242,232,.55) 100%),
    url("/web/assets/wheat-field.svg") center right / cover no-repeat;
  border-color: #a8d9b8;
}
.hero-card.risk-mid {
  background:
    linear-gradient(100deg, rgba(255,252,240,.98) 0%, rgba(255,247,215,.90) 55%, rgba(255,240,180,.55) 100%),
    url("/web/assets/wheat-field.svg") center right / cover no-repeat;
  border-color: #f6c94a;
}
.hero-card.risk-high {
  background:
    linear-gradient(100deg, rgba(255,248,248,.98) 0%, rgba(254,235,235,.90) 55%, rgba(252,215,215,.55) 100%),
    url("/web/assets/wheat-field.svg") center right / cover no-repeat;
  border-color: #f09595;
}
.admin-hero {
  background:
    linear-gradient(100deg, rgba(240,246,255,.98) 0%, rgba(220,235,255,.80) 100%),
    url("/web/assets/wheat-field.svg") center right / cover no-repeat;
  border-color: #a8c8f0;
}

.hero-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.hero-row input {
  max-width: 140px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}

.hero-label { font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 2px; text-transform: uppercase; letter-spacing: .06em; }
h1          { font-size: 24px; line-height: 1.18; margin-bottom: 6px; }
h2          { font-size: 16px; margin-bottom: 8px; font-weight: 800; }

.risk-title {
  display: block;
  font-size: 28px;
  font-weight: 900;
  margin: 2px 0 8px;
  letter-spacing: -.02em;
}

.risk-low  .risk-title { color: var(--green); }
.risk-mid  .risk-title { color: var(--amber); }
.risk-high .risk-title { color: var(--red); }

.tag, .chip {
  display: inline-block;
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green);
  font-weight: 800;
  font-size: 12px;
  margin: 0 5px 5px 0;
}

/* ── Weather grid ────────────────────────────────────────── */
.three-cols {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.weather-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 6px;
  border-radius: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  text-align: center;
}

.wc-icon  { font-size: 18px; line-height: 1; }
.wc-label { font-size: 11px; color: var(--muted); font-weight: 700; }
.weather-cell strong { font-size: 17px; font-weight: 900; display: block; }

/* ── Section labels & utility ────────────────────────────── */
.section-line   { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.inline-title   { font-size: 14px; font-weight: 800; color: var(--muted); margin: 10px 0 6px; text-transform: uppercase; letter-spacing: .05em; }
.today-compact  { margin-bottom: 4px; }
.muted          { color: var(--muted); line-height: 1.6; }
.chips          { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 4px; min-width: 0; }
.compact-chip   { padding: 4px 9px; font-size: 12px; white-space: normal; overflow-wrap: anywhere; max-width: 100%; }
.field-label    { font-size: 11px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 4px; }

/* ── Steps ───────────────────────────────────────────────── */
.steps { display: grid; gap: 7px; }
.step  { display: grid; grid-template-columns: 28px 1fr; gap: 10px; align-items: start; }
.step b {
  display: grid; place-items: center;
  width: 26px; height: 26px; border-radius: 50%;
  background: linear-gradient(175deg, var(--green-mid), var(--green-dark));
  color: #fff; font-size: 12px; font-weight: 900;
  box-shadow: 0 2px 6px rgba(18,100,55,.25);
}
.step p { margin-bottom: 0; line-height: 1.45; font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ── Clinic ──────────────────────────────────────────────── */
.page-title     { margin: 0 2px 8px; }
.clinic-title   { display: block; margin-bottom: 6px; }
.clinic-title h1 { margin-bottom: 0; }
.clinic-title p  { font-size: 13px; color: var(--muted); margin-bottom: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-card    { padding: 14px; }

.square-upload {
  position: relative;
  display: grid;
  place-items: center;
  width: 118px;
  height: 118px;
  border: 2px dashed var(--line);
  border-radius: 20px;
  overflow: hidden;
  background: var(--bg);
  transition: border-color .18s, background .18s;
  flex-shrink: 0;
}
.square-upload:hover  { border-color: var(--green-mid); background: var(--green-soft); }
.square-upload input  { display: none; }

.upload-placeholder   { text-align: center; font-size: 13px; font-weight: 800; color: var(--muted); line-height: 1.6; }
.preview { position: absolute; inset: 0; display: block; width: 100%; height: 100%; object-fit: cover; border-radius: 18px; }
.image-actions {
  position: absolute; left: 7px; right: 7px; bottom: 7px;
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
}
.image-actions button {
  min-height: 26px; border: 0; border-radius: 8px;
  background: rgba(255,255,255,.9); color: var(--green);
  font-size: 11px; font-weight: 900;
  box-shadow: 0 2px 8px rgba(0,0,0,.10);
}

.diagnosis-layout { display: grid; grid-template-columns: 118px minmax(0, 1fr); gap: 12px; align-items: start; margin-bottom: 12px; }
.clinic-right     { display: flex; flex-direction: column; gap: 8px; min-width: 0; }

.status {
  padding: 10px 12px; border-radius: 12px;
  background: var(--green-soft); color: var(--green);
  font-weight: 800; line-height: 1.5; white-space: normal; font-size: 13px;
  overflow-wrap: anywhere;
}

.prescription .field-label { margin: 8px 0 2px; }
.prescription { min-width: 0; }
.diag-name { color: var(--green-dark); margin-bottom: 5px; font-size: 20px; font-weight: 900; overflow-wrap: anywhere; }

.sample-row { display: flex; gap: 8px; overflow-x: auto; margin-top: 10px; padding-bottom: 2px; scrollbar-width: none; }
.sample-row::-webkit-scrollbar { display: none; }
.sample { flex: 0 0 76px; border: 1px solid var(--line); border-radius: 14px; background: #fff; padding: 6px; color: var(--green); font-weight: 800; font-size: 12px; }
.sample img { width: 100%; height: 52px; object-fit: cover; border-radius: 10px; display: block; margin-bottom: 4px; }

/* ── Prescription ────────────────────────────────────────── */
.rx-box          { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.rx-box > .field-label { margin-bottom: 8px; }
.rx-lines        { display: grid; gap: 6px; margin-bottom: 8px; }
.rx-line         {
  display: grid; grid-template-columns: 72px 1fr; gap: 8px; align-items: start;
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg);
}
.rx-line span    { color: var(--muted); font-size: 12px; font-weight: 800; }
.rx-line strong  { font-size: 13px; line-height: 1.4; color: var(--text); font-weight: 700; }
.phi-line        { border-color: #bde0c8; background: #f0f9f3; }
.phi-line span   { color: var(--green); }
.phi-line strong { color: var(--green-dark); }
/* ── Profile ─────────────────────────────────────────────── */
.profile {
  display: flex; gap: 16px; align-items: center;
  padding: 18px; min-height: 110px; margin-bottom: 10px;
  border-radius: 22px; border: 1px solid var(--line); box-shadow: var(--shadow-sm);
  background:
    linear-gradient(100deg, rgba(255,255,255,.98) 0%, rgba(255,255,255,.80) 55%, rgba(240,248,244,.50) 100%),
    url("/web/assets/wheat-field.svg") center right / cover no-repeat;
}
.avatar {
  display: grid; place-items: center;
  width: 64px; height: 64px; border-radius: 50%;
  background: linear-gradient(135deg, var(--green-soft), #c8e8d4);
  color: var(--green-dark); font-size: 26px; font-weight: 900;
  border: 2px solid #c8e8d4;
  flex-shrink: 0;
}
.mine-list { display: grid; gap: 6px; }
.mine-list div { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.mine-list div:last-child { border-bottom: 0; }
.mine-list span { color: var(--muted); font-weight: 800; font-size: 13px; }
.mine-list strong { text-align: right; font-size: 13px; }
.mine-record { padding: 12px; border-radius: 12px; background: var(--green-soft); }
.mine-record strong { color: var(--green); font-size: 15px; }
.mine-record p { margin: 6px 0 0; color: var(--muted); line-height: 1.55; font-size: 13px; }
/* ── Admin stats ─────────────────────────────────────────── */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.stat-cell {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 6px;
  text-align: center;
  box-shadow: var(--shadow-sm);
  border-top: 3px solid var(--line);
}

.stat-cell span   { display: block; color: var(--muted); font-size: 11px; font-weight: 700; margin-bottom: 4px; text-transform: uppercase; letter-spacing: .04em; }
.stat-cell strong { display: block; font-size: 26px; font-weight: 900; letter-spacing: -.03em; line-height: 1; }

.stat-cell.new     { border-top-color: var(--blue); }
.stat-cell.new strong { color: var(--blue); }
.stat-cell.high    { border-top-color: var(--red); }
.stat-cell.high strong { color: var(--red); }
.stat-cell.mid     { border-top-color: var(--amber); }
.stat-cell.mid strong { color: var(--amber); }
.stat-cell.covered { border-top-color: var(--green); }
.stat-cell.covered strong { color: var(--green); }

/* ── SVG risk map ────────────────────────────────────────── */
.region-map {
  position: relative;
  height: 158px;
  margin-bottom: 8px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background:
    linear-gradient(90deg, transparent 49%, rgba(255,255,255,.75) 49%, rgba(255,255,255,.75) 51%, transparent 51%),
    linear-gradient(0deg, transparent 49%, rgba(255,255,255,.75) 49%, rgba(255,255,255,.75) 51%, transparent 51%),
    #f7faf8;
  overflow: hidden;
}

.region-piece {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-align: center;
  border: 1.5px solid rgba(255,255,255,.9);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.03);
}

.region-piece strong { font-size: 13px; font-weight: 900; color: var(--text); }
.region-piece span { font-size: 12px; font-weight: 900; }
.region-piece em { font-style: normal; font-size: 11px; font-weight: 700; color: var(--muted); }

.region-piece.northwest { left: 10px; top: 12px; width: 46%; height: 64px; clip-path: polygon(0 14%, 96% 0, 84% 100%, 8% 88%); border-radius: 16px 10px 14px 12px; }
.region-piece.northeast { right: 10px; top: 10px; width: 47%; height: 68px; clip-path: polygon(10% 0, 100% 14%, 92% 88%, 0 100%); border-radius: 12px 16px 10px 14px; }
.region-piece.southwest { left: 12px; bottom: 10px; width: 43%; height: 66px; clip-path: polygon(0 10%, 88% 0, 100% 86%, 8% 100%); border-radius: 12px 14px 10px 16px; }
.region-piece.southeast { right: 10px; bottom: 10px; width: 50%; height: 68px; clip-path: polygon(10% 0, 98% 8%, 100% 92%, 0 100%); border-radius: 12px 10px 16px 14px; }

.region-piece.low { background: #ddf0e4; }
.region-piece.low span { color: var(--green); }
.region-piece.medium { background: #fef3c7; }
.region-piece.medium span { color: var(--amber); }
.region-piece.high { background: #fee2e2; }
.region-piece.high span { color: var(--red); }
.legend { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin: 0 4px 0 10px; }
.dot.high { background: var(--red); }
.dot.mid  { background: var(--amber); }
.dot.low  { background: var(--green); }

.notice-text { line-height: 1.7; white-space: pre-line; }

/* ── Bottom nav ──────────────────────────────────────────── */
.bottom-nav {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--line);
  background: rgba(255,255,255,.96);
  backdrop-filter: blur(16px);
  flex-shrink: 0;
}

.nav {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 8px 0;
  border: 0;
  background: transparent;
  color: #8a9490;
  font-size: 14px;
  font-weight: 900;
  transition: color .15s;
}

.nav.active { color: var(--green); }

/* ── Small breakpoint ────────────────────────────────────── */
@media (max-width: 380px) {
  .splash-title  { font-size: 32px; }
  h1             { font-size: 21px; }
  .square-upload { width: 104px; height: 104px; border-radius: 18px; }
  .diagnosis-layout { grid-template-columns: 104px minmax(0, 1fr); gap: 10px; }
  .status { padding: 9px 10px; font-size: 12px; }
  .diag-name { font-size: 18px; }
  .stats         { gap: 5px; }
  .stat-cell strong { font-size: 22px; }
}
