/* ============================================================
   团队成本计算器 · 样式
   纯静态 · 无外部依赖 · 浅色主题
   ============================================================ */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --ink: #14181f;
  --ink-2: #4d5563;
  --ink-3: #8a92a0;
  --line: #e4e7ec;
  --line-soft: #eff1f4;
  --brand: #1b2431;
  --brand-2: #2c3748;
  --accent: #b45309;
  --accent-soft: #fdf4ea;
  --ok: #0f766e;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(20, 24, 31, .04);
  --shadow-md: 0 6px 20px -8px rgba(20, 24, 31, .14);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans SC",
               "Noto Sans CJK SC", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}

h1, h2, h3, p { margin: 0; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0;
  margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ─────────── Topbar ─────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 66px;
  padding-top: 10px;
  padding-bottom: 10px;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.brand-mark {
  flex: none;
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: var(--brand);
  color: #fff;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 19px;
  line-height: 1;
  padding-bottom: 1px;
}

.brand-text { min-width: 0; }

.brand-text h1 {
  font-size: 16px;
  font-weight: 650;
  letter-spacing: .2px;
  line-height: 1.35;
}

.brand-text p {
  font-size: 11.5px;
  color: var(--ink-3);
  letter-spacing: .3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-side {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: none;
}

.privacy-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  color: var(--ok);
  background: #f0f9f7;
  border: 1px solid #d3ece7;
  padding: 4px 9px;
  border-radius: 100px;
  white-space: nowrap;
}

.save-state {
  font-size: 11.5px;
  color: var(--ink-3);
  white-space: nowrap;
  transition: color .25s;
}

.save-state.is-saving { color: var(--accent); }

/* ─────────── Overview ─────────── */
.overview { padding: 34px 0 6px; }

.overview-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.eyebrow {
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 6px;
}

.team-name {
  font-family: inherit;
  font-size: 25px;
  font-weight: 650;
  letter-spacing: -.2px;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-bottom: 1.5px dashed transparent;
  padding: 2px 0 3px;
  width: 100%;
  max-width: 420px;
  outline: none;
  transition: border-color .2s;
}
.team-name:hover { border-bottom-color: var(--line); }
.team-name:focus { border-bottom-color: var(--brand); }

.overview-actions { display: flex; gap: 8px; flex: none; padding-bottom: 4px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px 15px;
  box-shadow: var(--shadow-sm);
}

.stat-label {
  font-size: 12px;
  color: var(--ink-3);
  letter-spacing: .3px;
  margin-bottom: 7px;
}

.stat-value {
  display: flex;
  align-items: baseline;
  gap: 2px;
  font-size: 26px;
  font-weight: 660;
  letter-spacing: -.5px;
  line-height: 1.2;
  color: var(--ink);
}

.stat-value .cny {
  font-size: 15px;
  font-weight: 500;
  color: var(--ink-3);
  margin-right: 1px;
}

.stat-value .unit {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-3);
  margin-left: 3px;
}

.stat-sub {
  font-size: 11.5px;
  color: var(--ink-3);
  margin-top: 6px;
}

.stat-main {
  background: linear-gradient(180deg, #fffdfa 0%, #fff 60%);
  border-color: #ecd9c2;
}
.stat-main .stat-value { color: var(--accent); }
.stat-main .stat-label { color: var(--accent); opacity: .82; }

/* ─────────── Panel ─────────── */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin-top: 16px;
  box-shadow: var(--shadow-sm);
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.panel-head h2 {
  font-size: 17px;
  font-weight: 650;
  letter-spacing: .1px;
}

.panel-desc {
  font-size: 12.5px;
  color: var(--ink-3);
  margin-top: 3px;
}

/* ─────────── Buttons ─────────── */
.btn {
  font-family: inherit;
  font-size: 13px;
  font-weight: 550;
  line-height: 1;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  padding: 9px 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background .16s, border-color .16s, color .16s, transform .06s;
  white-space: nowrap;
  user-select: none;
}
.btn:active { transform: translateY(.5px); }
.btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

.btn-primary {
  background: var(--brand);
  color: #fff;
  box-shadow: 0 1px 2px rgba(20, 24, 31, .18);
}
.btn-primary:hover { background: var(--brand-2); }

.btn-ghost {
  background: var(--surface);
  color: var(--ink-2);
  border-color: var(--line);
}
.btn-ghost:hover { background: #fafbfc; border-color: #d3d8e0; color: var(--ink); }

.btn-text {
  background: none;
  color: var(--ink-3);
  padding: 6px 0;
  font-size: 12.5px;
}
.btn-text:hover { color: var(--brand); }

/* ─────────── Roles table ─────────── */
.roles-head,
.role-row {
  display: grid;
  grid-template-columns: minmax(110px, 1.6fr) 66px 106px 98px 98px 106px 104px 124px 72px;
  gap: 8px;
  align-items: start;
}

.roles-head {
  padding: 0 10px 9px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 4px;
}

.roles-head span {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-3);
  letter-spacing: .2px;
  line-height: 1.3;
  display: flex;
  flex-direction: column;
  gap: 1px;
  align-items: flex-end;
  text-align: right;
}

.roles-head span:first-child {
  align-items: flex-start;
  text-align: left;
}

.roles-head em {
  font-style: normal;
  font-size: 9.5px;
  font-weight: 400;
  color: #a8aeba;
  letter-spacing: 0;
}

.roles-list { display: flex; flex-direction: column; gap: 2px; }

.role-row {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: background .15s, border-color .15s;
}
.role-row:hover { background: #fafbfc; border-color: var(--line-soft); }
.role-row:focus-within { background: #fff; border-color: #d8dde5; box-shadow: var(--shadow-md); }

.f { position: relative; min-width: 0; }

.f > .f-label { display: none; }

.inp {
  width: 100%;
  font-family: inherit;
  font-size: 13.5px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 9px;
  line-height: 1.4;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  font-variant-numeric: tabular-nums;
}

.inp:hover { border-color: #d3d8e0; }

.inp:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(27, 36, 49, .08);
}

.inp-text { font-weight: 550; }
.inp-num { text-align: right; }

.inp::-webkit-outer-spin-button,
.inp::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.inp[type="number"] { -moz-appearance: textfield; appearance: textfield; }

.inp::placeholder { color: #b8bec9; font-weight: 400; }

.f-title .f-hint,
.f > .f-hint {
  position: absolute;
  right: 8px;
  bottom: -13px;
  font-size: 9.5px;
  color: var(--accent);
  opacity: .8;
  pointer-events: none;
  white-space: nowrap;
}

.row-sum {
  display: block;
  text-align: right;
  font-size: 13.5px;
  font-weight: 620;
  color: var(--ink);
  padding: 8px 2px 0;
  letter-spacing: -.2px;
}
.row-sum.is-zero { color: #c2c8d2; font-weight: 500; }

.f-act {
  display: flex;
  gap: 2px;
  justify-content: flex-end;
  padding-top: 2px;
}

.btn-icon {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 6px;
  color: var(--ink-3);
  cursor: pointer;
  transition: background .15s, color .15s;
  padding: 0;
}
.btn-icon:hover { background: var(--line-soft); color: var(--ink); }
.btn-icon[data-act="del"]:hover { background: #fdeeee; color: #b91c1c; }
.btn-icon:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }

.panel-foot { padding-top: 12px; border-top: 1px dashed var(--line); margin-top: 6px; }

/* ─────────── Empty state ─────────── */
.empty-state {
  text-align: center;
  padding: 44px 20px 40px;
  color: var(--ink-3);
}
.empty-art { color: #c8ced9; margin-bottom: 12px; }
.empty-title { font-size: 15px; font-weight: 600; color: var(--ink-2); }
.empty-desc { font-size: 12.5px; margin-top: 4px; max-width: 380px; margin-inline: auto; }
.empty-actions { display: flex; gap: 8px; justify-content: center; margin-top: 18px; }

/* ─────────── Detail table ─────────── */
.table-scroll { overflow-x: auto; margin: 0 -6px; padding: 0 6px; }

.detail-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.8px;
  min-width: 620px;
}

.detail-table th {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .3px;
  color: var(--ink-3);
  text-align: left;
  padding: 0 8px 8px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.detail-table td {
  padding: 9px 8px;
  border-bottom: 1px solid var(--line-soft);
  white-space: nowrap;
  color: var(--ink-2);
}

.detail-table td:first-child {
  color: var(--ink);
  font-weight: 550;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.detail-table tbody tr:hover td { background: #fafbfc; }

.detail-table td.is-money { color: var(--ink-2); }
.detail-table td.is-strong { color: var(--ink); font-weight: 600; }

.detail-table tfoot td {
  border-bottom: 0;
  border-top: 1.5px solid var(--ink);
  padding-top: 11px;
  padding-bottom: 2px;
  font-weight: 660;
  color: var(--ink);
  font-size: 13px;
}

.ta-r { text-align: right !important; }

.th-unit {
  display: block;
  font-style: normal;
  font-size: 9px;
  font-weight: 400;
  color: #aeb4c0;
  letter-spacing: 0;
  margin-top: 1px;
}

.share-bar {
  display: inline-block;
  height: 4px;
  border-radius: 2px;
  background: var(--brand);
  opacity: .22;
  vertical-align: middle;
  margin-left: 6px;
  min-width: 2px;
}

.table-note {
  font-size: 11px;
  color: var(--ink-3);
  margin-top: 12px;
  line-height: 1.55;
}

/* ─────────── Structure stack ─────────── */
.struct-stack {
  display: flex;
  height: 38px;
  border-radius: 9px;
  overflow: hidden;
  background: var(--line-soft);
}

.struct-seg {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10.5px;
  font-weight: 650;
  color: #fff;
  letter-spacing: .2px;
  overflow: hidden;
  white-space: nowrap;
  transition: width .38s cubic-bezier(.4, 0, .2, 1);
  border-right: 1px solid rgba(255, 255, 255, .55);
}
.struct-seg:last-child { border-right: 0; }

.struct-legend {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px 18px;
  margin-top: 16px;
}

.legend-item { display: flex; flex-direction: column; gap: 1px; min-width: 0; }

.legend-top {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--ink-3);
  white-space: nowrap;
}

.struct-dot {
  width: 7px; height: 7px;
  border-radius: 2px;
  flex: none;
}

.legend-val {
  font-size: 15px;
  font-weight: 620;
  color: var(--ink);
  letter-spacing: -.2px;
}

.legend-pct { font-size: 11px; color: var(--ink-3); }

.struct-total {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
  font-size: 11.5px;
  color: var(--ink-3);
  flex: none;
}

.struct-total strong {
  font-size: 21px;
  font-weight: 660;
  color: var(--accent);
  letter-spacing: -.4px;
}

/* ─────────── Rule grid ─────────── */
.rule-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  gap: 14px;
  align-items: end;
}

.rule-field { display: flex; flex-direction: column; gap: 6px; }

.rule-label { font-size: 12px; color: var(--ink-3); }

.rule-input {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 7px 11px;
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
.rule-input:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(27, 36, 49, .08);
}

.rule-input input {
  width: 52px;
  border: 0;
  outline: none;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  background: transparent;
  font-variant-numeric: tabular-nums;
}
.rule-input input::-webkit-outer-spin-button,
.rule-input input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.rule-input input[type="number"] { -moz-appearance: textfield; }

.rule-input em {
  font-style: normal;
  font-size: 11.5px;
  color: var(--ink-3);
  white-space: nowrap;
}

.rule-actions { display: flex; gap: 8px; }

.rule-note { font-size: 11.5px; color: var(--ink-3); margin-top: 12px; }

/* ─────────── Export ─────────── */
.export-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.export-card {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  text-align: left;
  font-family: inherit;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  cursor: pointer;
  transition: border-color .16s, box-shadow .16s, background .16s;
}
.export-card:hover {
  border-color: #ccd3dd;
  box-shadow: var(--shadow-md);
  background: #fcfdfe;
}
.export-card:active { transform: translateY(.5px); }
.export-card:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

.export-icon {
  flex: none;
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 8px;
  background: #f4f6f8;
  color: var(--ink-2);
}

.export-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.export-body strong { font-size: 13px; font-weight: 600; color: var(--ink); }
.export-body em {
  font-style: normal;
  font-size: 11px;
  color: var(--ink-3);
  line-height: 1.45;
}

/* ─────────── Note panel ─────────── */
.note-panel { background: #fbfbfc; }

.calc-formula {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.calc-formula code {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-2);
  letter-spacing: -.1px;
  line-height: 1.5;
  word-break: break-word;
}

.calc-list {
  margin: 14px 0 0;
  padding-left: 18px;
  font-size: 12.5px;
  color: var(--ink-2);
  line-height: 1.75;
}
.calc-list li::marker { color: var(--ink-3); }

/* ─────────── Footer ─────────── */
.site-foot {
  padding: 32px 0 44px;
  text-align: center;
  font-size: 12px;
  color: var(--ink-3);
  line-height: 1.7;
}
.foot-sub { font-size: 11px; color: #a8aeba; margin-top: 2px; }

/* ─────────── Toast ─────────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 14px);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--brand);
  color: #fff;
  font-size: 12.5px;
  padding: 9px 12px 9px 15px;
  border-radius: 100px;
  box-shadow: 0 10px 30px -8px rgba(20, 24, 31, .45);
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s, transform .22s;
  z-index: 90;
  max-width: calc(100vw - 32px);
}

.toast.is-on {
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto;
}

.toast-action {
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: #ffd9a8;
  background: rgba(255, 255, 255, .12);
  border: 0;
  border-radius: 100px;
  padding: 4px 10px;
  cursor: pointer;
}
.toast-action:hover { background: rgba(255, 255, 255, .2); }

/* ─────────── Print ─────────── */
.print-head { display: none; }

@media print {
  :root { --bg: #fff; }
  body { background: #fff; font-size: 11pt; }
  .topbar, .roles-panel, .note-panel, .export-panel, .site-foot,
  .overview-actions, .table-note, .toast { display: none !important; }
  .wrap { max-width: none; padding: 0; }
  .panel {
    border: 0;
    box-shadow: none;
    padding: 0;
    margin-top: 14px;
    break-inside: avoid;
  }
  .print-head {
    display: block;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--ink);
    margin-bottom: 4px;
  }
  .print-head h1 { font-size: 17pt; font-weight: 700; }
  .print-head p { font-size: 9pt; color: #555; margin-top: 3px; }
  .stat-grid { gap: 0; border: 1px solid #ccc; border-radius: 0; }
  .stat { border: 0; border-right: 1px solid #ddd; border-radius: 0; box-shadow: none; }
  .stat:last-child { border-right: 0; }
  .stat-main { background: #fff; }
  .stat-value, .stat-main .stat-value { color: #000; }
  .team-name { border: 0; font-size: 15pt; }
  .detail-table { min-width: 0; font-size: 9.5pt; }
  .detail-table th, .detail-table td { padding: 5px 6px; }
  .struct-stack, .struct-seg {
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }
  .panel-head { flex-direction: row; }
  @page { margin: 14mm; }
}

/* ─────────── Responsive ─────────── */
@media (max-width: 1040px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .export-grid { grid-template-columns: repeat(2, 1fr); }
  .struct-legend { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .rule-actions { grid-column: 1 / -1; }
}

@media (max-width: 900px) {
  .roles-head { display: none; }

  .roles-list { gap: 10px; }

  .role-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px 12px;
    padding: 14px;
    border: 1px solid var(--line);
    background: #fcfcfd;
    border-radius: 12px;
  }

  .f-title { grid-column: 1 / -1; }

  .f > .f-label {
    display: block;
    font-size: 10.5px;
    color: var(--ink-3);
    margin-bottom: 4px;
    letter-spacing: .2px;
  }

  .row-sum { text-align: left; padding-top: 0; }

  .f-act {
    grid-column: 1 / -1;
    border-top: 1px dashed var(--line);
    padding-top: 9px;
    justify-content: flex-end;
  }

  .f-sum {
    display: flex;
    align-items: center;
    justify-content: space-between;
    grid-column: 1 / -1;
    background: #f5f7f9;
    border-radius: 8px;
    padding: 7px 11px;
  }
  .f-sum::before {
    content: "年度小计";
    font-size: 11.5px;
    color: var(--ink-3);
  }

  .panel { padding: 18px 16px; }
  .overview-head { flex-direction: column; align-items: stretch; gap: 12px; }
  .team-name { max-width: none; font-size: 22px; }
  .overview-actions { padding-bottom: 0; }
  .topbar-side .save-state { display: none; }
}

@media (max-width: 560px) {
  .wrap { padding: 0 14px; }
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 9px; }
  .stat { padding: 13px 14px; }
  .stat-value { font-size: 21px; }
  .stat-value .cny { font-size: 13px; }
  .stat-sub { display: none; }
  .export-grid { grid-template-columns: 1fr; }
  .rule-grid { grid-template-columns: 1fr; }
  .panel-head { flex-direction: column; gap: 12px; }
  .brand-text p { display: none; }
  .privacy-chip { font-size: 10.5px; padding: 3px 7px; }
  .role-row { grid-template-columns: 1fr 1fr; }
  .struct-legend { grid-template-columns: 1fr 1fr; gap: 12px 14px; }
  .struct-total { align-items: flex-start; }
  .struct-stack { height: 32px; }
  .struct-seg { font-size: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
