/* 档期记 — mobile first, iOS-flavoured */

:root {
  --bg: #f2f2f7;
  --bg-elev: #ffffff;
  --card: #ffffff;
  --text: #111114;
  --text-2: #6b6b73;
  --text-3: #9a9aa2;
  --line: #e6e6ea;
  --line-soft: #f0f0f4;
  --accent: #5b5bd6;
  --accent-soft: #ececfb;
  --green: #34c759;
  --orange: #ff9500;
  --red: #ff3b30;
  --blue: #0a84ff;
  --teal: #30b0c7;
  --pink: #ff2d55;
  --radius: 16px;
  --radius-sm: 11px;
  --tab-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 6px 20px rgba(20,20,40,.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-elev: #1c1c1e;
    --card: #1c1c1e;
    --text: #f2f2f7;
    --text-2: #a1a1a8;
    --text-3: #6e6e76;
    --line: #2c2c2e;
    --line-soft: #242426;
    --accent: #7b7bf0;
    --accent-soft: #26264a;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { border: 0; background: none; padding: 0; cursor: pointer; }
input, textarea, select { background: var(--bg-elev); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; font-size: 16px; outline: none; -webkit-appearance: none; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
select { background-image: none; }
a { color: var(--accent); text-decoration: none; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
#main {
  padding: calc(8px + var(--safe-t)) 0 calc(var(--tab-h) + var(--safe-b) + 12px);
  min-height: 100%;
}
.view { display: none; padding: 0 16px 8px; animation: fade .18s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: .4 } to { opacity: 1 } }

/* ---------- tab bar ---------- */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: calc(var(--tab-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: flex; align-items: stretch;
  background: color-mix(in srgb, var(--bg-elev) 86%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: .5px solid var(--line);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--text-3); font-size: 10.5px; letter-spacing: .2px; padding-top: 6px;
}
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tab.active { color: var(--accent); }
.tab:active { opacity: .6; }

#fab {
  position: fixed; right: 18px; z-index: 41;
  bottom: calc(var(--tab-h) + var(--safe-b) + 16px);
  width: 54px; height: 54px; border-radius: 27px;
  background: var(--accent); color: #fff; font-size: 30px; line-height: 1; font-weight: 300;
  box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 45%, transparent);
  display: flex; align-items: center; justify-content: center;
  transition: transform .15s ease;
}
#fab:active { transform: scale(.92); }

/* ---------- generic ---------- */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; margin-bottom: 12px;
}
.card.tight { padding: 0; overflow: hidden; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.tiny { font-size: 11.5px; }
.strong { font-weight: 600; }
.mono { font-variant-numeric: tabular-nums; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 18px 2px 8px; }
.section-title h2 { font-size: 17px; margin: 0; font-weight: 650; letter-spacing: .2px; }
.section-title .link { font-size: 13.5px; color: var(--accent); }
.hr { height: .5px; background: var(--line); margin: 10px 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--accent); color: #fff; border-radius: 12px; padding: 11px 16px; font-weight: 600; font-size: 15px;
}
.btn:active { opacity: .82; }
.btn.block { width: 100%; }
.btn.ghost { background: var(--accent-soft); color: var(--accent); }
.btn.plain { background: transparent; color: var(--accent); padding: 8px 6px; }
.btn.danger { background: color-mix(in srgb, var(--red) 12%, transparent); color: var(--red); }
.btn.sm { padding: 7px 12px; font-size: 13px; border-radius: 9px; }
.btn[disabled] { opacity: .5; }

.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 4px 9px; border-radius: 20px;
  background: var(--bg); color: var(--text-2); font-size: 12px; white-space: nowrap;
}
.chip.sel { background: var(--accent); color: #fff; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }

.empty { text-align: center; color: var(--text-3); font-size: 13.5px; padding: 26px 10px; }
.empty .big { font-size: 30px; display: block; margin-bottom: 6px; opacity: .5; }

/* ---------- calendar ---------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 2px 10px; }
.cal-title { font-size: 22px; font-weight: 700; letter-spacing: .3px; }
.cal-title small { font-size: 13px; font-weight: 500; color: var(--text-2); margin-left: 6px; }
.cal-nav { display: flex; gap: 6px; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 17px; background: var(--card); box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: center; color: var(--text-2); font-size: 15px;
}
.icon-btn:active { opacity: .6; }

.month { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 10px 8px 6px; }
.weekdays, .grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.weekdays div { text-align: center; font-size: 11px; color: var(--text-3); padding: 2px 0 6px; }
.grid { row-gap: 2px; }
.cell {
  position: relative; height: 46px; border-radius: 10px; display: flex; flex-direction: column;
  align-items: center; justify-content: flex-start; padding-top: 6px; font-size: 14px; color: var(--text);
}
.cell .num { width: 26px; height: 26px; line-height: 26px; text-align: center; border-radius: 13px; font-variant-numeric: tabular-nums; }
.cell.dim { color: var(--text-3); }
.cell.today .num { background: var(--accent); color: #fff; font-weight: 600; }
.cell.sel:not(.today) .num { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.cell .marks { display: flex; gap: 2.5px; margin-top: 2px; height: 5px; align-items: center; }
.cell .marks i { width: 4px; height: 4px; border-radius: 50%; display: block; }
.cell .more { font-size: 9px; color: var(--text-3); }

/* agenda */
.agenda-head { display: flex; align-items: baseline; justify-content: space-between; margin: 16px 2px 8px; }
.agenda-head h2 { margin: 0; font-size: 17px; font-weight: 650; }
.agenda-head .sub { font-size: 12.5px; color: var(--text-2); }
.agenda { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.agenda .item { display: flex; gap: 12px; padding: 12px 14px; align-items: flex-start; border-bottom: .5px solid var(--line-soft); }
.agenda .item:last-child { border-bottom: 0; }
.agenda .time { width: 46px; flex: none; font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; padding-top: 1px; }
.agenda .body { flex: 1; min-width: 0; }
.agenda .title { font-size: 15px; font-weight: 550; display: flex; align-items: center; gap: 6px; }
.agenda .title.done { text-decoration: line-through; color: var(--text-3); }
.agenda .meta { font-size: 12px; color: var(--text-2); margin-top: 2px; display: flex; gap: 8px; flex-wrap: wrap; }
.agenda .bar { width: 3px; border-radius: 2px; align-self: stretch; flex: none; }
.agenda .lead { display: flex; gap: 10px; flex: 1; min-width: 0; }
.check {
  width: 24px; height: 24px; border-radius: 12px; border: 1.5px solid var(--line); flex: none;
  display: flex; align-items: center; justify-content: center; color: transparent;
}
.agenda .check {
  width: 24px; height: 24px; border-radius: 12px; border: 1.5px solid var(--line); flex: none;
  display: flex; align-items: center; justify-content: center; color: transparent; margin-top: 1px;
}
.agenda .check.on { background: var(--green); border-color: var(--green); color: #fff; }
.item-link { display: flex; align-items: center; justify-content: space-between; padding: 13px 14px; border-bottom: .5px solid var(--line-soft); }
.item-link:last-child { border-bottom: 0; }
.item-link:active { background: var(--line-soft); }

/* ---------- forms / sheets ---------- */
#sheet-root .backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 60; animation: fade .2s ease;
  backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 61;
  background: var(--bg-elev); border-radius: 22px 22px 0 0;
  max-height: 92vh; display: flex; flex-direction: column;
  animation: slideUp .26s cubic-bezier(.2,.9,.3,1);
  padding-bottom: calc(var(--safe-b) + 10px);
}
@keyframes slideUp { from { transform: translateY(100%) } to { transform: none } }
.sheet .grabber { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 8px auto 0; }
.sheet h3 { margin: 10px 18px 4px; font-size: 17px; font-weight: 650; }
.sheet .sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 6px 18px 4px; }
.sheet .sheet-footer { padding: 10px 18px 4px; display: flex; gap: 10px; }
.sheet .sheet-footer .btn { flex: 1; }

.field { margin: 12px 0; }
.field > label { display: block; font-size: 12.5px; color: var(--text-2); margin: 0 2px 6px; }
.field-row { display: flex; gap: 10px; }
.field-row > .field { flex: 1; margin: 12px 0; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chips .chip { padding: 7px 12px; font-size: 13px; background: var(--bg); }
.chips .chip.sel { background: var(--accent); color: #fff; }
.seg {
  display: flex; background: var(--bg); border-radius: 10px; padding: 3px; gap: 3px;
}
.seg button { flex: 1; padding: 7px 4px; border-radius: 8px; font-size: 13.5px; color: var(--text-2); font-weight: 500; }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.1); font-weight: 600; }

/* ---------- toast ---------- */
#toast-root { position: fixed; left: 0; right: 0; bottom: calc(var(--tab-h) + var(--safe-b) + 74px); z-index: 80; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  background: rgba(28,28,30,.94); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 13.5px;
  animation: toastIn .2s ease; max-width: 86vw; text-align: center;
}
@keyframes toastIn { from { opacity: 0; transform: translateY(6px) } to { opacity: 1; transform: none } }

/* ---------- fullscreen (OCR) ---------- */
.screen {
  position: fixed; inset: 0; z-index: 70; background: var(--bg);
  display: flex; flex-direction: column;
  padding: calc(var(--safe-t) + 6px) 0 var(--safe-b);
  animation: slideUp .24s ease;
}
.screen .screen-head {
  display: flex; align-items: center; gap: 10px; padding: 8px 16px 12px; border-bottom: .5px solid var(--line);
}
.screen .screen-head h2 { flex: 1; margin: 0; font-size: 17px; font-weight: 650; text-align: center; }
.screen .screen-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 14px 16px 90px; }
.screen .screen-foot {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 10px 16px calc(var(--safe-b) + 10px);
  background: color-mix(in srgb, var(--bg-elev) 92%, transparent); backdrop-filter: blur(12px);
  border-top: .5px solid var(--line); display: flex; gap: 10px;
}

/* dropzone */
.drop {
  border: 1.5px dashed color-mix(in srgb, var(--accent) 45%, transparent); border-radius: 14px;
  background: var(--accent-soft); padding: 26px 16px; text-align: center; color: var(--accent);
  font-size: 14px;
}
.drop .ico { font-size: 28px; display: block; margin-bottom: 6px; }
.preview { width: 100%; border-radius: 12px; display: block; margin-top: 10px; }
.ocr-progress { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; margin-top: 10px; }
.ocr-progress > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
textarea.ocr-text { min-height: 150px; font-size: 14px; line-height: 1.5; }

.cand { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; background: var(--card); }
.cand .cand-title { font-weight: 600; font-size: 14.5px; border: 0; background: transparent; padding: 4px 0; }
.cand .cand-row { display: flex; gap: 8px; margin-top: 6px; align-items: center; }
.cand input[type=date], .cand input[type=time] { padding: 6px 8px; font-size: 13px; border-radius: 8px; }
.cand .cand-meta { font-size: 11.5px; color: var(--text-3); }

/* ---------- training ---------- */
.hero {
  border-radius: 20px; padding: 16px; color: #fff; margin-bottom: 12px;
  background: linear-gradient(135deg, #3a3aa8, #6e6ee8 55%, #8f7bff);
  box-shadow: 0 10px 26px rgba(90,90,220,.28);
}
.hero .k { font-size: 12px; opacity: .8; letter-spacing: 1px; }
.hero .t { font-size: 21px; font-weight: 700; margin: 4px 0 2px; }
.hero .m { font-size: 12.5px; opacity: .85; }
.hero .actions { display: flex; gap: 8px; margin-top: 12px; }
.hero .actions .btn { background: rgba(255,255,255,.18); color: #fff; backdrop-filter: blur(4px); font-size: 13.5px; padding: 8px 14px; }

.setlist { display: flex; flex-direction: column; gap: 6px; }
.setrow { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; background: var(--bg); }
.setrow.done { background: color-mix(in srgb, var(--green) 12%, var(--bg)); }
.setrow .idx { width: 22px; font-size: 12px; color: var(--text-2); }
.setrow input { width: 62px; padding: 6px 8px; font-size: 14px; text-align: center; }
.setrow .unit { font-size: 11.5px; color: var(--text-3); }
.ex-block { margin-bottom: 12px; }
.ex-block .ex-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.ex-block .ex-name { font-weight: 600; font-size: 14.5px; }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--card); border-radius: 14px; padding: 10px; box-shadow: var(--shadow); }
.stat .v { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .k { font-size: 11px; color: var(--text-2); margin-top: 2px; }

/* ---------- diet ---------- */
.ring-wrap { display: flex; align-items: center; gap: 16px; }
.ring { width: 108px; height: 108px; flex: none; position: relative; }
.ring svg { transform: rotate(-90deg); }
.ring .center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring .center b { font-size: 21px; font-variant-numeric: tabular-nums; }
.ring .center span { font-size: 10.5px; color: var(--text-2); }
.macro-bars { flex: 1; display: flex; flex-direction: column; gap: 9px; }
.mbar .mbar-top { display: flex; justify-content: space-between; font-size: 11.5px; margin-bottom: 3px; }
.mbar .track { height: 6px; border-radius: 3px; background: var(--line-soft); overflow: hidden; }
.mbar .fill { height: 100%; border-radius: 3px; transition: width .3s; }
.meal-head { display: flex; align-items: center; justify-content: space-between; padding: 11px 14px; border-bottom: .5px solid var(--line-soft); }
.meal-head .m-name { font-weight: 600; font-size: 14.5px; }
.food-row { display: flex; align-items: center; gap: 10px; padding: 9px 14px; border-bottom: .5px solid var(--line-soft); font-size: 14px; }
.food-row:last-child { border-bottom: 0; }
.food-row .f-name { flex: 1; min-width: 0; }
.food-row .f-kcal { color: var(--text-2); font-size: 13px; font-variant-numeric: tabular-nums; }

canvas { width: 100%; display: block; }
.chartbox { background: var(--card); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); margin-bottom: 12px; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 11.5px; color: var(--text-2); margin-top: 6px; }
.legend i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; margin-right: 4px; }

.notice { display: flex; gap: 8px; font-size: 13px; background: var(--accent-soft); color: var(--accent); padding: 10px 12px; border-radius: 12px; margin-bottom: 12px; }
.warn { background: color-mix(in srgb, var(--orange) 12%, transparent); color: var(--orange); }

/* ---------- settings list ---------- */
.list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 12px; }
.list .li { display: flex; align-items: center; gap: 12px; padding: 13px 14px; border-bottom: .5px solid var(--line-soft); }
.list .li:last-child { border-bottom: 0; }
.list .li .lab { flex: 1; font-size: 14.5px; }
.list .li .val { color: var(--text-2); font-size: 13.5px; }
.list .li:active { background: var(--line-soft); }
.list .li .ico { width: 28px; height: 28px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 15px; flex: none; }

.kv { display: flex; justify-content: space-between; padding: 6px 0; font-size: 13.5px; }
.kv .k { color: var(--text-2); }
.kv .v { font-variant-numeric: tabular-nums; font-weight: 500; }

.progress-line { height: 8px; border-radius: 4px; background: var(--line-soft); overflow: hidden; }
.progress-line > i { display: block; height: 100%; background: var(--accent); }
