:root {
  --bg: #f6f5f1;
  --card: #ffffff;
  --ink: #1d2320;
  --ink-2: #5a645f;
  --ink-3: #8b948f;
  --line: #e6e3dc;
  --brand: #0f3d34;
  --brand-2: #1f6b5a;
  --brand-soft: #e3efe9;
  /* Chinese market convention: red = up, green = down */
  --up: #c8372d;
  --down: #1a8a55;
  --warn: #b7791f;
  --warn-soft: #fbf1df;
  --bad-soft: #fbe6e3;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 30, 25, .05), 0 2px 10px rgba(20, 30, 25, .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111513; --card: #1a201d; --ink: #e9ece9; --ink-2: #a8b1ac; --ink-3: #78827d; --line: #2a322e;
    --brand: #8fd1bb; --brand-2: #6cbba1; --brand-soft: #1e2d27; --up: #f0675b; --down: #4cc387;
    --warn: #e0a84a; --warn-soft: #2e2618; --bad-soft: #321d1b; --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }
.up { color: var(--up); } .down { color: var(--down); } .muted { color: var(--ink-3); } .small { font-size: 13px; }

.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 17px; }
.brand img { width: 28px; height: 28px; border-radius: 8px; }
.icon-btn { background: none; border: 0; padding: 6px; color: var(--ink-2); border-radius: 10px; }
.icon-btn:active { background: var(--line); }

.view { padding: 4px 16px calc(env(safe-area-inset-bottom, 0px) + 84px); max-width: 720px; margin: 0 auto; }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; justify-content: space-around;
  padding: 6px 4px calc(env(safe-area-inset-bottom, 0px) + 6px); background: var(--card); border-top: 1px solid var(--line);
}
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0; font-size: 11px; color: var(--ink-3); text-decoration: none; }
.tabbar a svg { width: 23px; height: 23px; }
.tabbar a.active { color: var(--brand); font-weight: 600; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin: 12px 0; border: 1px solid var(--line); }
.card h2 { font-size: 15px; margin: 0 0 10px; color: var(--ink-2); font-weight: 600; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.card h2 .act { font-size: 13px; font-weight: 500; color: var(--brand-2); background: none; border: 0; padding: 0; }
.hero { background: var(--brand); color: #fff; border: 0; }
@media (prefers-color-scheme: dark) { .hero { background: #163a31; color: var(--ink); } }
.hero .label { opacity: .78; font-size: 13px; }
.hero .big { font-size: 34px; font-weight: 700; letter-spacing: -.5px; margin: 2px 0 4px; }
.hero .summary { font-size: 16px; line-height: 1.6; margin-top: 10px; padding-top: 12px; border-top: 1px solid rgba(255,255,255,.18); }
.hero .chg-up { color: #ffb4ac; } .hero .chg-down { color: #9ff0c4; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.kpi .k { font-size: 12px; color: var(--ink-3); }
.kpi .v { font-size: 20px; font-weight: 650; margin-top: 2px; }
.kpi .s { font-size: 12px; margin-top: 2px; }

.list { margin: 0; padding: 0; list-style: none; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list .main { min-width: 0; flex: 1; }
.list .title { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .sub { font-size: 12px; color: var(--ink-3); }
.list .right { text-align: right; flex-shrink: 0; }

.todo { display: flex; gap: 10px; padding: 10px 12px; border-radius: 10px; margin: 6px 0; font-size: 14px; }
.todo.risk { background: var(--bad-soft); } .todo.data { background: var(--warn-soft); }
.todo .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 7px; flex-shrink: 0; }
.todo.risk .dot { background: var(--up); } .todo.data .dot { background: var(--warn); }
.ok-box { padding: 12px; border-radius: 10px; background: var(--brand-soft); color: var(--brand-2); font-size: 14px; }

.light { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.light:last-child { border-bottom: 0; }
.light .lamp { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.lamp.ok { background: var(--down); } .lamp.near { background: var(--warn); } .lamp.breach { background: var(--up); }
.light .lbl { flex: 1; font-size: 14px; }
.light .val { font-size: 14px; }

.bar { height: 10px; border-radius: 5px; background: var(--line); overflow: hidden; display: flex; }
.bar span { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: 12px; color: var(--ink-2); }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; }

.note { font-size: 14px; line-height: 1.7; color: var(--ink); white-space: pre-wrap; }
.foot { font-size: 12px; color: var(--ink-3); margin: 14px 2px; line-height: 1.6; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-radius: 11px; padding: 10px 16px; font-weight: 600; background: var(--brand); color: #fff; }
@media (prefers-color-scheme: dark) { .btn { color: #0d1512; } }
.btn.secondary { background: var(--brand-soft); color: var(--brand-2); }
.btn.ghost { background: transparent; color: var(--ink-2); border: 1px solid var(--line); }
.btn.danger { background: var(--bad-soft); color: var(--up); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

input[type=text], input[type=number], input[type=password], input[type=date], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand-2); }
textarea { resize: vertical; min-height: 84px; }
label.field { display: block; margin: 10px 0; font-size: 13px; color: var(--ink-2); }
label.field > span { display: block; margin-bottom: 4px; }
.seg { display: flex; background: var(--line); padding: 3px; border-radius: 11px; margin: 8px 0 4px; }
.seg button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 9px; font-weight: 550; color: var(--ink-2); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; margin: 10px 0; }

.table-wrap { overflow-x: auto; margin: 0 -4px; }
table.edit { border-collapse: collapse; width: 100%; min-width: 640px; font-size: 13px; }
table.edit th { text-align: left; font-weight: 550; color: var(--ink-3); padding: 4px; white-space: nowrap; }
table.edit td { padding: 3px; }
table.edit input, table.edit select { padding: 6px 7px; font-size: 13px; border-radius: 7px; }
table.edit .w-s { width: 70px; } table.edit .w-m { width: 96px; }

.thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.thumbs img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.upload { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 14px; border: 1.5px dashed var(--line); border-radius: 12px; color: var(--ink-2); font-size: 14px; cursor: pointer; }

/* chat */
.chat { display: flex; flex-direction: column; gap: 10px; padding-bottom: 130px; }
.msg { max-width: 88%; padding: 10px 13px; border-radius: 16px; line-height: 1.65; font-size: 15px; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--brand); color: #fff; border-bottom-right-radius: 5px; white-space: pre-wrap; }
@media (prefers-color-scheme: dark) { .msg.user { color: #0d1512; } }
.msg.assistant { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.msg.assistant p { margin: 0 0 8px; } .msg.assistant p:last-child { margin-bottom: 0; }
.msg.assistant h3, .msg.assistant h4 { font-size: 15px; margin: 12px 0 6px; }
.msg.assistant ul, .msg.assistant ol { margin: 4px 0 8px; padding-left: 20px; }
.msg.assistant table { border-collapse: collapse; font-size: 13px; margin: 6px 0; display: block; overflow-x: auto; }
.msg.assistant td, .msg.assistant th { border: 1px solid var(--line); padding: 4px 7px; white-space: nowrap; }
.msg.assistant hr { border: 0; border-top: 1px solid var(--line); margin: 10px 0; }
.msg .meta { font-size: 11px; color: var(--ink-3); margin-top: 6px; }
.typing { color: var(--ink-3); font-size: 14px; }
.composer {
  position: fixed; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom, 0px) + 62px); z-index: 9;
  padding: 8px 12px; background: color-mix(in srgb, var(--bg) 94%, transparent); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.composer-inner { max-width: 720px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 44px; max-height: 140px; border-radius: 22px; padding: 11px 16px; }
.composer .send { width: 44px; height: 44px; border-radius: 50%; padding: 0; flex-shrink: 0; }
.composer-opts { max-width: 720px; margin: 0 auto 6px; display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--ink-3); }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 4px 10px; font-size: 12px; color: var(--ink-2); }
.chip.on { background: var(--brand-soft); color: var(--brand-2); border-color: transparent; font-weight: 600; }
.suggest { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.draft { border: 1px solid var(--brand-2); border-radius: 12px; padding: 10px 12px; margin-top: 8px; background: var(--brand-soft); font-size: 14px; }
.draft .st { font-size: 12px; color: var(--ink-3); }

.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.35); }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 88vh; overflow-y: auto; background: var(--bg);
  border-radius: 18px 18px 0 0; padding: 18px 16px calc(env(safe-area-inset-bottom, 0px) + 18px); max-width: 720px; margin: 0 auto;
}
.sheet-panel h3 { margin: 0 0 8px; font-size: 18px; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom, 0px) + 90px); z-index: 60;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 86vw;
}
.login { max-width: 360px; margin: 12vh auto 0; text-align: center; }
.login img { width: 72px; height: 72px; border-radius: 18px; }
.login h1 { font-size: 22px; margin: 12px 0 4px; }
.login form { text-align: left; margin-top: 18px; }
.spark { width: 100%; height: 56px; display: block; }
.empty { text-align: center; color: var(--ink-3); padding: 30px 10px; font-size: 14px; }
.range-row { display: flex; align-items: center; gap: 10px; font-size: 14px; margin: 8px 0; }
.range-row input { flex: 1; accent-color: var(--brand-2); }
.range-row b { width: 46px; text-align: right; }
.pill { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--line); color: var(--ink-2); margin-left: 6px; vertical-align: 1px; font-weight: 500; }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.acct-head { display: flex; justify-content: space-between; align-items: baseline; margin-top: 4px; }
a { color: var(--brand-2); text-decoration: none; }
.act { font-size: 13px; font-weight: 500; color: var(--brand-2); background: none; border: 0; padding: 2px 0 0; cursor: pointer; }
.list .right .act { display: block; margin-left: auto; }
.composer textarea { resize: none; }
