/* cani · 实体店可行性测算 —— 视觉：冷静、精确的决策工具 */

:root {
  --bg: #eceff3;
  --bg-grad: radial-gradient(1200px 600px at 15% -10%, #f6f8fa 0%, var(--bg) 55%);
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --ink: #111820;
  --ink-2: #374151;
  --muted: #6b7684;
  --line: #e3e8ee;
  --line-2: #eef1f5;
  --accent: #0f766e;
  --accent-soft: #e6f4f2;
  --accent-ink: #0b5a54;
  --good: #16a34a;
  --good-soft: #e8f6ec;
  --warn: #d97706;
  --warn-soft: #fdf1e0;
  --bad: #dc2626;
  --bad-soft: #fdeaea;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 6px 20px -8px rgba(16, 24, 40, .12);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono-num: ui-monospace, "SF Mono", "Roboto Mono", Menlo, monospace;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  min-height: 100vh;
}

button { font-family: inherit; cursor: pointer; -webkit-appearance: none; appearance: none; }
input, select, textarea { font-family: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }

/* ------------------------------- 顶栏 ------------------------------- */

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 10px 18px;
  background: rgba(255, 255, 255, .86);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: baseline; gap: 9px; min-width: 0; }
/* 站名是中文，别用等宽字体（没有 CJK 字形会随机回落），字距也要放松一点 */
.brand .mark {
  font-size: 20px; font-weight: 800; letter-spacing: .02em;
  color: var(--accent); white-space: nowrap;
}
.brand .tag { font-size: 12.5px; color: var(--muted); white-space: nowrap; }

.templates { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; }
.chip {
  border: 1px solid var(--line); background: var(--surface);
  color: var(--ink-2); font-size: 13px; font-weight: 600;
  padding: 6px 12px; border-radius: 999px; transition: all .15s ease;
  white-space: nowrap;
}
.chip:hover { border-color: #cbd5e1; background: var(--surface-2); }
.chip[aria-pressed="true"] {
  background: var(--accent); border-color: var(--accent); color: #fff;
  box-shadow: 0 2px 8px -2px rgba(15, 118, 110, .5);
}

.actions { display: flex; gap: 8px; align-items: center; }
.btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  font-size: 13px; font-weight: 600; padding: 7px 14px; border-radius: 999px;
  transition: all .15s ease; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: #cbd5e1; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }

/* 移动端常驻结果条，桌面端不用（结果面板本来就吸在旁边） */
.mobar { display: none; }

/* ------------------------------- 布局 ------------------------------- */

.layout {
  display: grid; gap: 18px;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "results" "params";
  padding: 18px; max-width: 1280px; margin: 0 auto; align-items: start;
}
.params { grid-area: params; min-width: 0; }
.results { grid-area: results; min-width: 0; }

@media (min-width: 980px) {
  .layout {
    grid-template-columns: minmax(0, 1.5fr) minmax(360px, .9fr);
    grid-template-areas: "params results";
    padding: 22px;
  }
  .results { position: sticky; top: 74px; }
}

.panel { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

/* ------------------------------- 分组卡片 ------------------------------- */

.section {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden;
}
.section-head {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 16px; border-bottom: 1px solid var(--line-2);
  background: linear-gradient(180deg, #fff, var(--surface-2));
}
.section-head h2 { font-size: 14.5px; font-weight: 700; letter-spacing: -.01em; }
.section-head .sub { font-size: 12px; color: var(--muted); font-weight: 500; }
.section-head .spacer { margin-left: auto; }
.section-total { font-size: 13px; font-weight: 700; color: var(--ink-2); }

.add-btn {
  border: 1px dashed #c7d0da; background: transparent; color: var(--accent);
  font-size: 12.5px; font-weight: 600; padding: 5px 11px; border-radius: 999px;
  transition: all .15s ease;
}
.add-btn:hover { background: var(--accent-soft); border-color: var(--accent); border-style: solid; }

.section-body { padding: 6px 16px 14px; }
.section-hint { padding: 10px 16px 0; font-size: 12px; color: var(--muted); }

/* ------------------------------- 行项目 ------------------------------- */

.row { padding: 12px 0; border-bottom: 1px solid var(--line-2); }
.row:last-child { border-bottom: none; }
.row-top { display: flex; align-items: center; gap: 8px; }

.row-label {
  flex: 1; min-width: 0; border: 1px solid transparent; background: transparent;
  font-size: 14px; font-weight: 600; color: var(--ink); padding: 5px 8px;
  border-radius: var(--radius-sm); transition: all .13s ease;
}
.row-label:hover { background: var(--surface-2); }
.row-label:focus { background: #fff; border-color: var(--accent); outline: none; }

.icon-btn {
  border: none; background: transparent; color: #b6c0cc; font-size: 15px;
  width: 28px; height: 28px; border-radius: 8px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center; transition: all .13s ease;
  flex: 0 0 auto;
}
.icon-btn:hover { background: var(--bad-soft); color: var(--bad); }
.icon-btn.star { color: #cbd5e1; }
.icon-btn.star[aria-pressed="true"] { color: #f59e0b; }
.icon-btn.star:hover { background: var(--warn-soft); color: var(--warn); }

.row-controls { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 9px; align-items: flex-end; }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > .flabel { font-size: 11px; color: var(--muted); font-weight: 600; letter-spacing: .01em; }
.field.grow { flex: 1; }

input[type="number"], input[type="text"].mini {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  font-size: 13.5px; padding: 6px 9px; border-radius: var(--radius-sm);
  width: 100%; min-width: 0; transition: border-color .13s ease;
  font-variant-numeric: tabular-nums;
}
input[type="number"] { text-align: right; font-family: var(--mono-num); }
input[type="number"]:focus, input[type="text"].mini:focus { border-color: var(--accent); outline: none; }
input[type="number"]:hover { border-color: #cbd5e1; }

.field.w-amount { width: 132px; }
.field.w-small { width: 84px; }
.field.w-mid { width: 104px; }

/* 利用率：滑块 + 百分比 */
.rate-wrap { display: flex; align-items: center; gap: 9px; width: 190px; max-width: 100%; }
input[type="range"] {
  -webkit-appearance: none; appearance: none; flex: 1; min-width: 60px;
  height: 5px; border-radius: 999px; background: var(--line); cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 17px; height: 17px; border-radius: 50%;
  background: var(--accent); border: 2.5px solid #fff; box-shadow: 0 1px 4px rgba(16, 24, 40, .28);
  cursor: pointer; transition: transform .1s ease;
}
input[type="range"]::-webkit-slider-thumb:active { transform: scale(1.14); }
input[type="range"]::-moz-range-thumb {
  width: 15px; height: 15px; border-radius: 50%; background: var(--accent);
  border: 2.5px solid #fff; box-shadow: 0 1px 4px rgba(16, 24, 40, .28); cursor: pointer;
}
.rate-val { font-size: 12.5px; font-weight: 700; color: var(--accent); width: 40px; text-align: right; font-variant-numeric: tabular-nums; }

/* flat/driver 分段切换 */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; flex: 0 0 auto; }
.seg button {
  border: none; background: transparent; color: var(--muted); font-size: 11.5px; font-weight: 600;
  padding: 5px 10px; transition: all .13s ease;
}
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-ink); }

.money-hint { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.switch { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; color: var(--muted); cursor: pointer; user-select: none; }
.switch input { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }

/* ------------------------------- 结果面板 ------------------------------- */

.result-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}

.headline { padding: 20px 20px 18px; border-bottom: 1px solid var(--line-2); }
.headline .kicker { font-size: 12px; color: var(--muted); font-weight: 600; letter-spacing: .04em; }
.headline .big {
  font-size: 46px; font-weight: 800; letter-spacing: -.035em; line-height: 1.05;
  margin-top: 4px; font-variant-numeric: tabular-nums; color: var(--ink);
}
.headline .big.bad { color: var(--bad); }
.headline .big small { font-size: 20px; font-weight: 700; letter-spacing: -.02em; }
.verdict {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 10px;
  font-size: 12.5px; font-weight: 700; padding: 4px 11px; border-radius: 999px;
}
.verdict.good { background: var(--good-soft); color: #15803d; }
.verdict.ok { background: var(--accent-soft); color: var(--accent-ink); }
.verdict.warn { background: var(--warn-soft); color: #b45309; }
.verdict.bad { background: var(--bad-soft); color: #b91c1c; }
.verdict .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line-2); }
.metric { background: var(--surface); padding: 13px 16px; }
.metric .mlabel { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.metric .mvalue { font-size: 18px; font-weight: 750; margin-top: 3px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.metric .mvalue.good { color: var(--good); }
.metric .mvalue.bad { color: var(--bad); }
.metric .msub { font-size: 11px; color: var(--muted); margin-top: 1px; font-variant-numeric: tabular-nums; }

.chart-card { padding: 16px 14px 10px; border-top: 1px solid var(--line-2); }
.chart-title { font-size: 12px; font-weight: 700; color: var(--ink-2); padding: 0 6px 8px; display: flex; justify-content: space-between; align-items: baseline; }
.chart-title .legend { font-size: 11px; color: var(--muted); font-weight: 500; }
.chart-box { position: relative; width: 100%; }
.chart-box svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-tip {
  position: absolute; pointer-events: none; opacity: 0; transition: opacity .1s ease;
  background: rgba(17, 24, 32, .94); color: #fff; font-size: 11px; padding: 6px 9px;
  border-radius: 7px; white-space: nowrap; transform: translate(-50%, -120%);
  font-variant-numeric: tabular-nums; box-shadow: 0 4px 12px rgba(0,0,0,.2);
}
.chart-tip.on { opacity: 1; }

.table-toggle {
  width: 100%; border: none; border-top: 1px solid var(--line-2); background: var(--surface-2);
  color: var(--ink-2); font-size: 12.5px; font-weight: 600; padding: 11px; transition: background .13s ease;
}
.table-toggle:hover { background: #eef1f5; }
.table-wrap { max-height: 320px; overflow: auto; border-top: 1px solid var(--line-2); }
table.monthly { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
table.monthly th, table.monthly td { padding: 7px 12px; text-align: right; white-space: nowrap; }
table.monthly th:first-child, table.monthly td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); }
table.monthly thead th { position: sticky; top: 0; background: var(--surface-2); color: var(--muted); font-weight: 600; font-size: 11px; z-index: 1; }
table.monthly tbody tr { border-top: 1px solid var(--line-2); }
table.monthly tbody tr:hover td { background: var(--surface-2); }
table.monthly tbody tr:hover td:first-child { background: var(--surface-2); }
table.monthly td.neg { color: var(--bad); }
table.monthly td.pos { color: var(--good); }
table.monthly tr.payback td { background: var(--good-soft); font-weight: 700; }

/* ------------------------------- 其他 ------------------------------- */

.foot { max-width: 1280px; margin: 0 auto; padding: 8px 22px 34px; font-size: 11.5px; color: var(--muted); line-height: 1.6; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(10px);
  background: rgba(17, 24, 32, .95); color: #fff; font-size: 13px; font-weight: 500;
  padding: 10px 18px; border-radius: 999px; box-shadow: 0 8px 24px rgba(0,0,0,.24);
  opacity: 0; transition: all .22s cubic-bezier(.2,.8,.2,1); z-index: 50; pointer-events: none;
  max-width: 90vw; text-align: center;
}
.toast[hidden] { display: none; }
.toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }

.empty-note { font-size: 12.5px; color: var(--muted); padding: 14px 0 6px; }

/* ------------------------------- 移动端 ------------------------------- */

/*
 * 手机上原本最难用的两点：结论要滚回顶部才看得见；一个金额输入能撑起 133px 高的行。
 * 所以这里做两件事——结果条固定在最上方常驻（顶栏随之让位、不再吸顶），
 * 字段改成「标签在左、输入右对齐」的横排，两个一行；只有一个数字的行直接并到标题行。
 */
@media (max-width: 979px) {
  body { padding-top: 46px; }

  .mobar {
    position: fixed; top: 0; left: 0; right: 0; z-index: 40;
    display: flex; align-items: center; gap: 8px; height: 46px; padding: 0 14px;
    background: rgba(255, 255, 255, .95);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--line);
    box-shadow: var(--shadow-sm);
  }
  .mobar-k { font-size: 11.5px; color: var(--muted); font-weight: 600; }
  .mobar-v { font-size: 19px; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
  .mobar-v.bad { color: var(--bad); }
  .mobar .verdict { margin-top: 0; font-size: 11px; padding: 3px 9px; }
  .mobar-net {
    margin-left: auto; min-width: 0; overflow: hidden; text-overflow: ellipsis;
    font-size: 12px; font-weight: 700; color: var(--good);
    font-variant-numeric: tabular-nums; white-space: nowrap;
  }
  .mobar-net.neg { color: var(--bad); }

  .topbar {
    position: static; gap: 10px; padding: 10px 14px;
    background: var(--surface); backdrop-filter: none; -webkit-backdrop-filter: none;
  }
  .brand .tag { display: none; }
  .templates { order: 3; width: 100%; margin-left: 0; overflow-x: auto; flex-wrap: nowrap; padding-bottom: 2px; -webkit-overflow-scrolling: touch; }
  .actions .btn { padding: 7px 12px; }

  .layout { padding: 12px; gap: 12px; }
  .section-head { flex-wrap: wrap; padding: 11px 14px; gap: 6px 8px; }
  /* 说明文字换到标题下面单独一行：手机上更需要这些解释，别为了省高度砍掉 */
  .section-head .sub { order: 5; flex: 1 1 100%; font-size: 11px; line-height: 1.45; }
  .section-body { padding: 4px 14px 12px; }

  /* 结论已在常驻条里，标题区退回普通卡片头 */
  .headline { padding: 14px 16px 13px; }
  .headline .big { font-size: 34px; }
  .headline .big small { font-size: 17px; }
  .headline .verdict { display: none; }
  .metric { padding: 11px 14px; }
  .metric .mvalue { font-size: 16.5px; }

  .row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 10px 0; }
  /* 170px ≈ 名称输入被压到 0 时「★ + 固定/按量 + ✕」的宽度。给死基数而不是 auto：
     名称框是 <input>，自带 ~170px 的固有宽度，用 auto 会让标题行独占一行。 */
  .row-top { flex: 1 1 170px; min-width: 0; }
  .row-label { font-size: 13.5px; padding: 5px 6px; }

  /*
   * 控件区不再自成一块：display:contents 让字段直接参与 .row 的换行，
   * 于是「标题 + 一个金额输入」能挤在同一行（一次性投入行从 133px 降到 51px）。
   * 数字字段的 basis 用 auto，让换行按内容实际宽度决定——写死一个小 basis 会先按它排版、
   * 再被 min-content 顶回去，字段就溢出、被 .section 的 overflow:hidden 悄悄裁掉。
   * 滑块字段反过来给死 200px：它的内容可以任意压缩，得靠 basis 占住一条能拖的轨道。
   */
  .row > .row-controls { display: contents; }
  .row > .field { flex: 1 1 auto; }
  .row > .field:has(.rate-wrap) { flex: 1 1 200px; }
  .row > .switch { flex: 0 0 auto; }
  /* 方案区/爬坡区的控件不在 .row 里，滑块要占满整行才好拖 */
  .section-body > .row-controls > .field { flex: 1 1 100%; }

  /* 字段横排：标签在左、输入右对齐，省掉一整行高度。!important 盖掉写死的 style="width:230px" */
  .field { flex-direction: row; align-items: center; gap: 8px; width: auto !important; min-width: auto; }
  .field > .flabel { flex: 0 0 auto; font-size: 11.5px; white-space: nowrap; }
  .field > input[type="number"], .field > input[type="text"].mini { margin-left: auto; flex: 0 0 auto; width: 82px; }
  .field.grow > input[type="text"].mini { width: auto; flex: 1 1 auto; text-align: left; }
  .money-hint { display: none; }
  .rate-wrap { width: auto; flex: 1 1 auto; }
}

/* 窄到放不下「回本 + 数值 + 结论 + 月净」时，先丢掉能从数值本身看出来的那个词 */
@media (max-width: 360px) {
  .mobar-k { display: none; }
  .mobar-v { font-size: 17px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
