:root {
    --bg: #f4f6f9;
    --card: #ffffff;
    --ink: #131a24;
    --muted: #6b7684;
    --line: #e8ecf2;
    --brand: #2f7cf6;
    --brand-soft: #eaf2fe;
    --ok: #12a150;
    --ok-soft: #e6f7ee;
    --danger: #d63b3b;
    --danger-soft: #fdeaea;
    --skip: #8a94a6;
    --radius: 18px;
    --shadow: 0 1px 2px rgba(16, 26, 44, .04), 0 6px 20px rgba(16, 26, 44, .04);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
    margin: 0;
    padding: 0;
}

body {
    background: var(--bg);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
                 "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.app {
    max-width: 620px;
    margin: 0 auto;
    padding: 20px 16px 104px;
}

/* ---------------------------------------------------------------- 页头 */
.topbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 2px 16px;
}

.topbar h1 {
    margin: 0;
    font-size: 24px;
    letter-spacing: -.4px;
    font-weight: 700;
}

.topbar .sub {
    margin-top: 3px;
    font-size: 13px;
    color: var(--muted);
}

.topbar .links { display: flex; gap: 8px; flex-shrink: 0; }

/* ---------------------------------------------------------------- 卡片 */
.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
}

.card + .card { margin-top: 12px; }

.hero {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 18px;
}

.hero .hero-text { flex: 1; min-width: 0; }

.hero .big {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -.3px;
}

.hero .big small { font-size: 14px; font-weight: 500; color: var(--muted); }

.hero .hint {
    margin-top: 4px;
    font-size: 13px;
    color: var(--muted);
}

.ring {
    --p: 0;
    width: 68px;
    height: 68px;
    border-radius: 50%;
    flex-shrink: 0;
    background: conic-gradient(var(--ok) calc(var(--p) * 1%), #e9edf3 0);
    display: grid;
    place-items: center;
}

.ring > i {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background: #fff;
    display: grid;
    place-items: center;
    font-style: normal;
    font-size: 13px;
    font-weight: 700;
    color: var(--ok);
    font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- 列表 */
.section {
    margin: 22px 4px 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    letter-spacing: .2px;
}

.section .count { font-weight: 500; }

.dose {
    position: relative;
    display: flex;
    gap: 12px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 14px 14px 12px 18px;
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: background .2s ease, border-color .2s ease;
}

.dose + .dose { margin-top: 10px; }

.dose::before {
    content: "";
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 4px;
    background: var(--c, var(--brand));
}

.dose .body { flex: 1; min-width: 0; }

.dose .head {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.dose .time {
    font-size: 19px;
    font-weight: 700;
    letter-spacing: -.3px;
    font-variant-numeric: tabular-nums;
}

.dose .name {
    font-size: 15.5px;
    font-weight: 650;
    flex: 0 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dose .meta {
    margin-top: 3px;
    font-size: 12.5px;
    color: var(--muted);
    display: flex;
    flex-wrap: wrap;
    gap: 4px 10px;
}

.dose .actions {
    display: flex;
    gap: 8px;
    margin-top: 11px;
    flex-wrap: wrap;
}

.tag {
    font-size: 11.5px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 999px;
    white-space: nowrap;
    align-self: center;
    flex: 0 0 auto;
}

.tag.pending { color: #2364c9; background: var(--brand-soft); }
.tag.taken   { color: #0b7a3c; background: var(--ok-soft); }
.tag.skipped { color: #5b6472; background: #eef1f5; }
.tag.missed  { color: #bb2d2d; background: var(--danger-soft); }

.dose[data-status="taken"] { background: #fbfefc; border-color: #dcefe4; }
.dose[data-status="skipped"] { background: #fafbfc; }
.dose[data-status="missed"] { border-color: #f3dada; }

.dose.is-due { animation: glow 1.8s ease-in-out infinite; }

@keyframes glow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(47, 124, 246, 0); }
    50% { box-shadow: 0 0 0 4px rgba(47, 124, 246, .12); }
}

/* ---------------------------------------------------------------- 按钮 */
.btn {
    appearance: none;
    border: 0;
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 600;
    padding: 8px 15px;
    border-radius: 10px;
    cursor: pointer;
    transition: transform .08s ease, background .15s ease, opacity .15s;
    background: #f1f4f8;
    color: #43505f;
}

.btn:active { transform: scale(.97); }
.btn[disabled] { opacity: .5; pointer-events: none; }

.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: #2568d4; }
.btn-ok { background: var(--ok); color: #fff; }
.btn-line { background: #fff; border: 1px solid var(--line); color: #43505f; }
.btn-danger { background: var(--danger-soft); color: #bb2d2d; }
.btn-sm { font-size: 12.5px; padding: 6px 11px; }
.btn-block { width: 100%; padding: 12px; font-size: 15px; border-radius: 12px; }

/* ---------------------------------------------------------------- 空状态 */
.empty {
    text-align: center;
    padding: 44px 20px;
    color: var(--muted);
}

.empty .ico {
    width: 56px; height: 56px;
    margin: 0 auto 14px;
    border-radius: 50%;
    background: #eaeff7;
    display: grid;
    place-items: center;
}

.empty h3 { margin: 0 0 6px; font-size: 16px; color: var(--ink); }
.empty p { margin: 0 0 16px; font-size: 13.5px; }

/* ---------------------------------------------------------------- 表单 */
.field { margin-bottom: 14px; }

.field > label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #44505f;
    margin-bottom: 6px;
}

.input,
select,
textarea {
    width: 100%;
    font-family: inherit;
    font-size: 15px;
    color: var(--ink);
    background: #f7f9fc;
    border: 1px solid var(--line);
    border-radius: 11px;
    padding: 10px 12px;
    outline: none;
    transition: border-color .15s, background .15s;
}

.input:focus, select:focus, textarea:focus {
    border-color: var(--brand);
    background: #fff;
}

textarea { resize: vertical; min-height: 74px; line-height: 1.6; }

.hintline {
    font-size: 12px;
    color: var(--muted);
    margin-top: 6px;
}

code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 11.5px;
    background: #eef2f8;
    color: #3a4756;
    padding: 1px 5px;
    border-radius: 5px;
}

.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }

.chip {
    position: relative;
    display: inline-flex;
}

.chip input { position: absolute; opacity: 0; pointer-events: none; }

.chip span {
    display: inline-block;
    font-size: 13px;
    padding: 6px 11px;
    border-radius: 999px;
    background: #f1f4f8;
    color: #55606f;
    cursor: pointer;
    user-select: none;
    border: 1px solid transparent;
}

.chip input:checked + span {
    background: var(--brand-soft);
    color: #2364c9;
    border-color: #bcd6fb;
    font-weight: 600;
}

.colors { display: flex; gap: 10px; flex-wrap: wrap; }

.color-dot {
    width: 28px; height: 28px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px var(--line);
}

.color-dot input { display: none; }

.color-dot:has(input:checked) {
    box-shadow: 0 0 0 2px var(--brand);
}

/* 时间点输入行 */
.timerow { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.timerow input[type="time"] { flex: 0 0 118px; }
.timerow input[type="text"] { flex: 1; }
.timerow .del {
    flex: 0 0 auto;
    border: 0;
    background: #f4f6f9;
    color: #8a94a6;
    width: 34px; height: 34px;
    border-radius: 9px;
    cursor: pointer;
    font-size: 17px;
    line-height: 1;
}

/* ---------------------------------------------------------------- 统计 */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.stat {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 15px;
    padding: 14px;
    box-shadow: var(--shadow);
}

.stat .k { font-size: 12.5px; color: var(--muted); }
.stat .v {
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -.6px;
    margin-top: 2px;
    font-variant-numeric: tabular-nums;
}
.stat .v small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 2px; }

.chart {
    display: flex;
    align-items: flex-end;
    gap: 7px;
    height: 132px;
    margin-top: 6px;
}

.chart .col {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    height: 100%;
    justify-content: flex-end;
}

.chart .bar {
    width: 100%;
    max-width: 34px;
    border-radius: 7px 7px 4px 4px;
    background: #eef2f8;
    position: relative;
    flex: 1;
    display: flex;
    align-items: flex-end;
}

.chart .bar > i {
    display: block;
    width: 100%;
    border-radius: 7px 7px 4px 4px;
    background: linear-gradient(180deg, #6aa5ff, #2f7cf6);
    min-height: 3px;
    transition: height .4s ease;
}

.chart .bar.is-zero > i { background: #e2e8f2; }

.chart .lbl { font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.chart .col.is-today .lbl { color: var(--brand); font-weight: 700; }

.medbar { margin-top: 14px; }
.medbar .line {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    margin-bottom: 6px;
}
.medbar .track {
    height: 8px;
    background: #eef2f8;
    border-radius: 999px;
    overflow: hidden;
}
.medbar .fill {
    height: 100%;
    border-radius: 999px;
    background: var(--brand);
}

/* ---------------------------------------------------------------- 记录页 */
.datebar {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: space-between;
    padding: 4px 2px 14px;
}

.datebar .now { text-align: center; flex: 1; }
.datebar .now b { font-size: 17px; }
.datebar .now span { display: block; font-size: 12px; color: var(--muted); }

.icon-btn {
    width: 38px; height: 38px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: #fff;
    display: grid;
    place-items: center;
    color: #55606f;
    text-decoration: none;
    font-size: 17px;
    cursor: pointer;
}

.summary-line {
    display: flex;
    gap: 14px;
    font-size: 12.5px;
    color: var(--muted);
    margin-top: 6px;
    flex-wrap: wrap;
}

/* ---------------------------------------------------------------- 提示条 */
.flash {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13.5px;
    padding: 11px 14px;
    border-radius: 12px;
    margin-bottom: 14px;
    background: var(--ok-soft);
    color: #0b7a3c;
}

.flash.err { background: var(--danger-soft); color: #bb2d2d; }

/* ---------------------------------------------------------------- 底部导航 */
.tabbar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    max-width: 620px;
    margin: 0 auto;
    display: flex;
    background: rgba(255, 255, 255, .94);
    backdrop-filter: saturate(180%) blur(12px);
    border-top: 1px solid var(--line);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    z-index: 50;
}

.tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 5px 0 3px;
    text-decoration: none;
    color: #8a94a6;
    font-size: 11px;
    border-radius: 12px;
}

.tab svg { width: 21px; height: 21px; }
.tab.is-active { color: var(--brand); font-weight: 600; }

@media (min-width: 640px) {
    .tabbar { border-radius: 18px 18px 0 0; }
}
