/* ============================================================
   SleepLab SCI — Apple/iOS Design Language
   SF 字体栈 · 连续圆角卡片 · iOS 系统色 · 浅/深色自适应
   ============================================================ */
:root {
  --bg: #F2F2F7;                       /* systemGroupedBackground */
  --bg-elev: #FFFFFF;
  --card: #FFFFFF;
  --card2: rgba(120, 120, 128, .08);   /* secondarySystemFill */
  --fill: rgba(118, 118, 128, .12);
  --line: rgba(60, 60, 67, .12);       /* separator */
  --txt: #1C1C1E;                      /* label */
  --txt2: rgba(60, 60, 67, .62);       /* secondaryLabel */
  --txt3: rgba(60, 60, 67, .38);
  --acc: #007AFF;                      /* systemBlue */
  --acc2: #5856D6;                     /* systemIndigo */
  --deep: #5856D6;
  --rem: #AF52DE;
  --core: #30B0C7;
  --teal: #30B0C7;
  --good: #34C759;
  --ok: #30B0C7;
  --warn: #FF9500;
  --bad: #FF3B30;
  --r-xs: 10px;
  --r-sm: 14px;
  --r-md: 18px;
  --r-lg: 24px;
  --r-xl: 30px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-elev: #1C1C1E;
    --card: #1C1C1E;
    --card2: rgba(120, 120, 128, .18);
    --fill: rgba(120, 120, 128, .24);
    --line: rgba(84, 84, 88, .45);
    --txt: #FFFFFF;
    --txt2: rgba(235, 235, 245, .62);
    --txt3: rgba(235, 235, 245, .35);
    --acc: #0A84FF;
    --acc2: #5E5CE6;
    --deep: #5E5CE6;
    --rem: #BF5AF2;
    --core: #40C8E0;
    --teal: #40C8E0;
    --good: #30D158;
    --ok: #40C8E0;
    --warn: #FF9F0A;
    --bad: #FF453A;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 28px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--txt);
  font: 15.5px/1.65 -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
        "Helvetica Neue", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  letter-spacing: .1px;
}
.wrap { max-width: 1020px; margin: 0 auto; padding: 0 18px 90px; }

/* ---------- 顶部：iOS 大标题 + 圆角方形图标 ---------- */
header.top { display: flex; align-items: center; gap: 16px; padding: 34px 0 6px; }
.logo {
  width: 58px; height: 58px; border-radius: 15.5px; /* iOS 图标圆角比例 ~27% */
  display: grid; place-items: center; font-size: 28px; flex: none;
  background: linear-gradient(145deg, #0A84FF, #5856D6 55%, #AF52DE);
  box-shadow: 0 6px 18px rgba(88, 86, 214, .35);
}
header.top h1 { font-size: 27px; font-weight: 800; letter-spacing: .2px; }
header.top .sub { color: var(--txt2); font-size: 13.5px; margin-top: 2px; }
.badges { margin-left: auto; display: flex; flex-wrap: wrap; gap: 7px; justify-content: flex-end; max-width: 340px; }
.badges span {
  font-size: 11px; font-weight: 600; color: var(--txt2);
  background: var(--fill); padding: 5px 11px; border-radius: 99px;
}

/* ---------- 区块标题（iOS 分组头样式） ---------- */
h2.sec { font-size: 21px; font-weight: 800; margin: 46px 0 4px; }
p.sec-sub { color: var(--txt2); font-size: 13.5px; margin-bottom: 16px; }
.group-head {
  font-size: 13px; font-weight: 600; color: var(--txt2); text-transform: uppercase;
  letter-spacing: .6px; margin: 22px 4px 9px;
}

/* ---------- 上传区 ---------- */
#drop {
  border-radius: var(--r-xl); background: var(--bg-elev); box-shadow: var(--shadow);
  min-height: 170px; display: grid; place-items: center; cursor: pointer;
  transition: .18s; padding: 18px; border: 2px dashed transparent;
}
#drop.drag, #drop:hover { border-color: var(--acc); background: color-mix(in srgb, var(--acc) 5%, var(--bg-elev)); }
#drop .hint { color: var(--txt2); font-size: 13.5px; text-align: center; }
#drop .hint b { color: var(--txt); display: block; font-size: 16px; font-weight: 700; margin-bottom: 4px; }
#imgPrev { max-width: 100%; max-height: 400px; border-radius: var(--r-md); }

/* ---------- 表单：iOS 分组圆角卡片 + 圆角输入块 ---------- */
form .grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
  gap: 11px; margin-bottom: 6px;
}
.fld {
  background: var(--bg-elev); border-radius: var(--r-sm); padding: 11px 14px 12px;
  box-shadow: var(--shadow); min-width: 0;
}
.fld label { display: block; font-size: 12px; font-weight: 600; color: var(--txt2); margin-bottom: 4px; }
.fld input, .fld select {
  width: 100%; background: transparent; border: none; color: var(--txt);
  font-size: 16.5px; font-weight: 600; font-family: inherit; outline: none; padding: 2px 0 0;
}
.fld input::placeholder { color: var(--txt3); font-weight: 500; }
.fld select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--txt2) 50%), linear-gradient(135deg, var(--txt2) 50%, transparent 50%); background-position: calc(100% - 14px) 55%, calc(100% - 9px) 55%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 22px; }
.fld small { display: block; color: var(--txt3); font-size: 10.5px; margin-top: 3px; }
.form-sec { margin-top: 10px; }

.btn {
  margin-top: 28px; width: 100%; padding: 16px; font-size: 16.5px; font-weight: 700; color: #fff;
  border: none; border-radius: var(--r-md); cursor: pointer; font-family: inherit;
  background: linear-gradient(135deg, var(--acc), var(--acc2));
  box-shadow: 0 8px 22px rgba(10, 100, 255, .28); transition: .15s;
}
.btn:hover { transform: translateY(-1px); filter: brightness(1.05); }
.btn:active { transform: scale(.985); }
.btn.ghost {
  background: var(--fill); color: var(--acc); box-shadow: none;
  width: auto; padding: 10px 20px; margin: 0; font-size: 13.5px;
}

/* ---------- 报告 ---------- */
#report { display: none; margin-top: 36px; }
#report.show { display: block; }

.score-hero {
  display: flex; gap: 26px; align-items: center; flex-wrap: wrap;
  background: var(--bg-elev); border-radius: var(--r-xl); box-shadow: var(--shadow);
  padding: 28px 30px;
}
.ring {
  --p: 0; width: 136px; height: 136px; border-radius: 50%; flex: none;
  background: conic-gradient(var(--acc) calc(var(--p)*1%), var(--fill) 0);
  display: grid; place-items: center;
}
.ring-c {
  width: 106px; height: 106px; border-radius: 50%; background: var(--bg-elev);
  display: grid; place-items: center; text-align: center;
}
.ring-c b { font-size: 36px; font-weight: 800; line-height: 1.05; }
.ring-c span { font-size: 10.5px; color: var(--txt2); }
.hero-txt { flex: 1; min-width: 260px; }
.state { display: inline-block; font-size: 18px; font-weight: 800; padding: 5px 16px; border-radius: 99px; margin-bottom: 9px; }
.t-good { color: var(--good); background: rgba(52,199,89,.14); }
.t-ok { color: var(--ok); background: rgba(48,176,199,.14); }
.t-warn { color: var(--warn); background: rgba(255,149,0,.14); }
.t-bad { color: var(--bad); background: rgba(255,59,48,.13); }
.hero-txt > p { color: var(--txt2); font-size: 14px; }
.dims { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 7px; }
.dim { font-size: 12px; font-weight: 600; background: var(--card2); padding: 5px 12px; border-radius: 99px; color: var(--txt2); }

.report-tools { display: flex; flex-direction: column; gap: 9px; flex: none; }
.report-tools .btn.ghost { white-space: nowrap; }

/* 图表卡片 */
.charts { display: grid; grid-template-columns: 300px 1fr; gap: 12px; margin-top: 12px; }
@media (max-width: 860px) { .charts { grid-template-columns: 1fr; } }
.chart-box { background: var(--bg-elev); border-radius: var(--r-lg); box-shadow: var(--shadow); padding: 18px; }
.chart-box h4 { font-size: 13.5px; font-weight: 700; margin-bottom: 10px; }
.chart-box h4 em { font-style: normal; color: var(--txt3); font-weight: 500; font-size: 11px; }
.chart-box canvas { width: 100%; height: 210px; }
.chart-box.wide canvas { height: 240px; }
.legend { display: flex; gap: 14px; justify-content: center; font-size: 12.5px; color: var(--txt2); margin-top: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 4px; margin-right: 5px; }

/* 卡片（iOS 分组内嵌样式） */
.card { background: var(--bg-elev); border-radius: var(--r-lg); box-shadow: var(--shadow); padding: 22px 24px; margin-top: 13px; }
.card header { display: flex; align-items: center; gap: 11px; margin-bottom: 15px; }
.card .no {
  width: 28px; height: 28px; border-radius: 9px; color: #fff;
  background: linear-gradient(135deg, var(--acc), var(--acc2));
  display: grid; place-items: center; font-size: 13px; font-weight: 800; flex: none;
}
.card h3 { font-size: 16.5px; font-weight: 750; }
.ref {
  font-size: 10.5px; font-weight: 600; color: var(--txt2); background: var(--card2);
  border-radius: 99px; padding: 3px 10px; margin-left: auto; cursor: help; white-space: nowrap;
}

ul.flags, ul.plain, ol.plan-acts { list-style: none; }
ul.flags li { padding: 10px 0; border-bottom: .5px solid var(--line); display: flex; flex-direction: column; gap: 2px; }
ul.flags li:last-child { border: none; }
ul.flags b { font-size: 14.5px; }
ul.flags span { color: var(--txt2); font-size: 13px; }
ul.plain li { padding: 6px 0 6px 18px; position: relative; color: var(--txt); font-size: 13.5px; }
ul.plain li::before { content: ""; position: absolute; left: 2px; top: 13px; width: 7px; height: 7px; border-radius: 50%; background: var(--acc); opacity: .8; }

.cause, .act, .nutri, .ex {
  background: var(--card2); border-radius: var(--r-sm); padding: 13px 16px; margin-bottom: 10px;
}
.cause-h, .act-h { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; flex-wrap: wrap; }
.cause p, .act p, .nutri p { font-size: 13px; color: var(--txt2); }
.fix { color: var(--teal) !important; font-weight: 600; }
.act-grid { display: grid; grid-template-columns: 64px 1fr; gap: 3px 12px; font-size: 13px; margin-top: 8px; }
.act-grid span { color: var(--txt3); }
.act-grid b { font-weight: 600; font-size: 13px; }

ul.preds { list-style: none; }
ul.preds li { display: flex; align-items: baseline; gap: 10px; padding: 9px 0; border-bottom: .5px solid var(--line); flex-wrap: wrap; }
ul.preds li:last-child { border: none; }
ul.preds b { min-width: 96px; }
ul.preds span { flex: 1; color: var(--txt2); font-size: 13px; }
ul.preds i { font-style: normal; font-size: 11px; font-weight: 600; color: var(--txt2); background: var(--card2); padding: 3px 10px; border-radius: 99px; }
.overall-risk {
  margin-top: 12px; padding: 12px 16px; border-radius: var(--r-sm);
  background: rgba(255,149,0,.1); color: var(--txt); font-size: 13.5px;
}
.overall-risk b { color: var(--warn); }
.note { font-size: 12px; color: var(--txt3); margin-top: 10px; }

.tbl { overflow-x: auto; border-radius: var(--r-sm); background: var(--card2); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; background: transparent; }
th { text-align: left; color: var(--txt2); font-weight: 600; font-size: 12px; padding: 10px 14px; border-bottom: .5px solid var(--line); white-space: nowrap; }
td { padding: 11px 14px; border-bottom: .5px solid var(--line); vertical-align: top; }
tr:last-child td { border: none; }
td .sub { color: var(--txt3); font-size: 11.5px; margin-top: 3px; max-width: 430px; }
.vd { font-size: 11.5px; font-weight: 700; padding: 3px 11px; border-radius: 99px; white-space: nowrap; }
.v-good { color: var(--good); background: rgba(52,199,89,.13); }
.v-warn { color: var(--warn); background: rgba(255,149,0,.13); }
.v-bad { color: var(--bad); background: rgba(255,59,48,.12); }
td a { color: var(--acc); text-decoration: none; font-weight: 600; }

.plan-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin-bottom: 14px; }
.plan-grid > div { background: var(--card2); border-radius: var(--r-sm); padding: 13px 15px; }
.plan-grid span { display: block; font-size: 11.5px; color: var(--txt2); }
.plan-grid b { font-size: 17.5px; font-weight: 750; }
ol.plan-acts { counter-reset: p; }
ol.plan-acts li { counter-increment: p; padding: 8px 0 8px 36px; position: relative; font-size: 13.5px; border-bottom: .5px solid var(--line); }
ol.plan-acts li:last-child { border: none; }
ol.plan-acts li::before {
  content: counter(p); position: absolute; left: 0; top: 8px; width: 24px; height: 24px;
  border-radius: 8px; background: var(--fill); display: grid; place-items: center;
  font-size: 12px; font-weight: 700; color: var(--acc);
}
.avoid {
  margin-top: 12px; font-size: 12.5px; color: var(--bad);
  background: rgba(255,59,48,.08); padding: 11px 15px; border-radius: var(--r-sm);
}

ul.life { list-style: none; }
ul.life li { display: flex; gap: 14px; padding: 9px 0; border-bottom: .5px solid var(--line); }
ul.life li:last-child { border: none; }
ul.life b { min-width: 58px; color: var(--acc); font-weight: 700; }
ul.life span { color: var(--txt2); font-size: 13.5px; }

ol.prio { list-style: none; counter-reset: q; }
ol.prio li { counter-increment: q; display: grid; grid-template-columns: 36px 1fr; gap: 3px 10px; padding: 11px 0; border-bottom: .5px solid var(--line); }
ol.prio li:last-child { border: none; }
ol.prio li::before { content: "#" counter(q); font-weight: 800; color: var(--warn); font-size: 17px; grid-row: span 3; }
ol.prio b { font-size: 15px; }
ol.prio span { color: var(--txt2); font-size: 13px; }
ol.prio em { font-style: normal; font-size: 13px; color: var(--txt); grid-column: 2; }
ol.prio em::before { content: "改善后帮助："; color: var(--teal); font-weight: 700; }
ol.prio i { font-style: normal; font-size: 12px; color: var(--teal); font-weight: 600; grid-column: 2; }

/* 原则卡 */
.principles { background: linear-gradient(135deg, rgba(88,86,214,.08), rgba(10,132,255,.06)); border-radius: var(--r-lg); box-shadow: var(--shadow); padding: 22px 24px; margin-top: 13px; }
.principles h3 { font-size: 16.5px; font-weight: 750; display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.principles ul { list-style: none; }
.principles li { padding: 6px 0 6px 26px; position: relative; font-size: 13.5px; color: var(--txt2); }
.principles li::before { content: "✓"; position: absolute; left: 0; top: 6px; width: 18px; height: 18px; border-radius: 6px; background: rgba(52,199,89,.15); color: var(--good); font-size: 11px; font-weight: 800; display: grid; place-items: center; }

/* ---------- 主理人看板 ---------- */
.dash { margin-top: 13px; display: grid; gap: 12px; }
.dash-grid { display: grid; grid-template-columns: minmax(240px, 340px) 1fr; gap: 12px; }
@media (max-width: 860px) { .dash-grid { grid-template-columns: 1fr; } }
.dash-card {
  background: var(--bg-elev); border-radius: var(--r-lg); box-shadow: var(--shadow);
  padding: 18px 20px;
}
.dash-card h4 { font-size: 13px; font-weight: 700; color: var(--txt2); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.dash-card h4 .tag { font-size: 10px; font-weight: 700; color: var(--acc); background: rgba(10,132,255,.12); padding: 2px 8px; border-radius: 99px; }
.thumb-wrap { display: grid; place-items: center; background: var(--card2); border-radius: var(--r-sm); min-height: 150px; overflow: hidden; cursor: zoom-in; }
.thumb-wrap img { max-width: 100%; max-height: 240px; border-radius: var(--r-xs); }
.thumb-empty { color: var(--txt3); font-size: 12.5px; padding: 40px 10px; text-align: center; }
.dash-meta { margin-top: 9px; font-size: 11.5px; color: var(--txt3); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.dash-meta button { border: none; background: var(--fill); color: var(--bad); font-size: 11.5px; font-weight: 600; padding: 5px 12px; border-radius: 99px; cursor: pointer; font-family: inherit; }

.metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); gap: 9px; }
.metric { background: var(--card2); border-radius: var(--r-sm); padding: 11px 13px; border-left: 4px solid transparent; }
.metric b { display: block; font-size: 16.5px; font-weight: 750; line-height: 1.25; }
.metric span { font-size: 11.5px; color: var(--txt2); }
.metric em { font-style: normal; display: block; font-size: 10.5px; color: var(--txt3); margin-top: 2px; }
.m-good { border-left-color: var(--good); }
.m-warn { border-left-color: var(--warn); }
.m-bad { border-left-color: var(--bad); }

.dash-imp { list-style: none; }
.dash-imp li { display: grid; grid-template-columns: 34px 1fr; gap: 2px 10px; padding: 8px 0; border-bottom: .5px solid var(--line); }
.dash-imp li:last-child { border: none; }
.dash-imp .rk { font-weight: 800; color: var(--warn); font-size: 15px; grid-row: 1 / span 3; }
.dash-imp b, .dash-imp p { grid-column: 2; }
.dash-imp b { font-size: 14px; }
.dash-imp p { font-size: 12.5px; color: var(--txt2); }
.dash-imp p strong { color: var(--teal); font-weight: 600; }
.dash-empty { color: var(--txt3); font-size: 13px; padding: 14px 0; }

/* 灯箱 */
#lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.86); z-index: 200; display: none; place-items: center; cursor: zoom-out; backdrop-filter: blur(8px); }
#lightbox.show { display: grid; }
#lightbox img { max-width: 94vw; max-height: 90vh; border-radius: var(--r-md); box-shadow: 0 20px 60px rgba(0,0,0,.5); }

/* 看板密码门 */
.gate { max-width: 480px; margin: 0 auto; text-align: center; padding: 32px 26px; }
.gate h4 { justify-content: center; font-size: 15.5px; color: var(--txt); text-transform: none; letter-spacing: 0; }
.gate-tip { color: var(--txt2); font-size: 13px; margin-bottom: 16px; line-height: 1.7; }
.gate-row { display: flex; gap: 10px; justify-content: center; align-items: center; }
.pin-in {
  width: 140px; text-align: center; font-size: 22px; letter-spacing: 8px; font-weight: 700;
  background: var(--card2); border: none; border-radius: var(--r-sm); padding: 11px 6px 11px 14px;
  color: var(--txt); outline: none; font-family: inherit;
}
.pin-in:focus { box-shadow: 0 0 0 3px rgba(10,132,255,.28); }
.gate-err { color: var(--bad); font-size: 12.5px; min-height: 19px; margin-top: 9px; font-weight: 600; }
.gate a { color: var(--acc); }
.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-6px); } 50% { transform: translateX(6px); } 75% { transform: translateX(-4px); } }

/* 历史趋势与记录 */
.trend-box { background: var(--card2); border-radius: var(--r-sm); padding: 10px; margin-bottom: 12px; }
.trend-box canvas { width: 100%; height: 175px; }
.hthumb { width: 54px; height: 40px; object-fit: cover; border-radius: 8px; cursor: zoom-in; display: block; }
.dash-tools { display: flex; gap: 10px; flex-wrap: wrap; }
.dash-tools .btn.ghost { flex: none; }

/* ---------- 提示词 ---------- */
#promptBox { display: none; margin-top: 34px; }
#promptBox.show { display: block; }
.prompt-card { background: var(--bg-elev); border-radius: var(--r-lg); box-shadow: var(--shadow); padding: 20px; }
.prompt-card .bar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.prompt-card h3 { font-size: 15.5px; font-weight: 750; flex: 1; }
#promptOut {
  width: 100%; min-height: 190px; background: var(--card2); color: var(--txt2);
  border: none; border-radius: var(--r-sm); padding: 15px;
  font: 12.5px/1.75 ui-monospace, "SF Mono", Consolas, monospace; resize: vertical; outline: none;
}

/* ---------- 参考/脚注 ---------- */
footer { margin-top: 64px; color: var(--txt2); font-size: 12.5px; }
.disc {
  background: rgba(255,149,0,.09); border-radius: var(--r-md); padding: 15px 18px;
  margin-bottom: 22px; color: var(--txt); font-size: 13px;
}

.toast {
  position: fixed; left: 50%; bottom: 36px; transform: translateX(-50%);
  background: rgba(250, 250, 250, .92); color: #1C1C1E; backdrop-filter: blur(16px);
  padding: 11px 24px; border-radius: 99px; font-size: 13.5px; font-weight: 600;
  box-shadow: 0 10px 34px rgba(0,0,0,.22); z-index: 99; animation: pop .22s;
}
@media (prefers-color-scheme: dark) {
  .toast { background: rgba(50, 50, 54, .95); color: #fff; }
}
@keyframes pop { from { opacity: 0; transform: translateX(-50%) translateY(10px); } }

@media print {
  body { background: #fff; }
  .btn, .badges, #drop, form, #promptBox { display: none !important; }
  .card, .chart-box, .score-hero, .principles { box-shadow: none; border: .5px solid #ddd; }
}
