/* ============================================================
   装修预算管家 — Design System
   ============================================================ */
:root {
  /* Warm neutral base */
  --bg: #F4F2EE;
  --surface: #FFFFFF;
  --surface-2: #FAF9F6;
  --surface-3: #F1EEE8;
  --border: #E7E2D9;
  --border-strong: #D8D2C6;

  /* Text */
  --ink: #2B2824;
  --text: #3A3631;
  --muted: #8C857A;
  --faint: #B4ADA1;

  /* Brand — terracotta/clay (warm, fits home/renovation) */
  --primary: #BC6643;
  --primary-dark: #A1542F;
  --primary-soft: #F6E7DD;
  --primary-tint: #FBF2EC;

  /* Semantic */
  --success: #2E8B5B;
  --success-soft: #E2F2E9;
  --danger: #CF3F31;
  --danger-soft: #FBE6E3;
  --warn: #C98A1E;
  --warn-soft: #FBF0D9;
  --info: #3C72A6;
  --info-soft: #E6EFF7;

  /* Chart palette */
  --c1: #BC6643; --c2: #3C72A6; --c3: #2E8B5B; --c4: #C98A1E;
  --c5: #8C6BB1; --c6: #4FA3A3; --c7: #D08770; --c8: #A0998A;

  --radius: 14px;
  --radius-sm: 9px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(43, 40, 36, .05), 0 1px 3px rgba(43, 40, 36, .04);
  --shadow: 0 4px 14px rgba(43, 40, 36, .07);
  --shadow-lg: 0 18px 50px rgba(43, 40, 36, .18);
  --sidebar-w: 244px;
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
          "Microsoft YaHei", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
::selection { background: var(--primary-soft); }
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

/* ============ Layout shell ============ */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: 11px;
  padding: 20px 20px 16px;
}
.brand .logo {
  width: 38px; height: 38px; border-radius: 11px;
  background: linear-gradient(135deg, var(--primary), #D98A5E);
  display: grid; place-items: center; color: #fff; font-size: 20px;
  box-shadow: 0 4px 12px rgba(188, 102, 67, .35);
  flex: 0 0 auto;
}
.brand .title { font-weight: 700; color: var(--ink); font-size: 15.5px; letter-spacing: .2px; }
.brand .subtitle { font-size: 11.5px; color: var(--faint); margin-top: 1px; }

.nav { padding: 8px 12px; display: flex; flex-direction: column; gap: 2px; }
.nav-label {
  font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: .08em;
  padding: 14px 12px 6px; font-weight: 600;
}
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--text); font-weight: 500; font-size: 13.5px;
  width: 100%; text-align: left; transition: background .12s, color .12s;
}
.nav-item .ico { width: 18px; text-align: center; font-size: 15px; opacity: .85; }
.nav-item:hover { background: var(--surface-3); }
.nav-item.active { background: var(--primary-tint); color: var(--primary-dark); font-weight: 600; }
.nav-item.active .ico { opacity: 1; }
.nav-item .count {
  margin-left: auto; font-size: 11px; color: var(--muted);
  background: var(--surface-3); padding: 1px 7px; border-radius: 20px; font-weight: 600;
}
.nav-item.active .count { background: var(--primary-soft); color: var(--primary-dark); }

.sidebar-foot { margin-top: auto; padding: 14px; border-top: 1px solid var(--border); }
.storage-note { font-size: 11px; color: var(--faint); line-height: 1.5; text-align: center; }

/* ============ Main ============ */
.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 16px 28px; border-bottom: 1px solid var(--border);
  background: rgba(244,242,238,.85); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 19px; color: var(--ink); font-weight: 700; letter-spacing: .2px; }
.topbar .sub { color: var(--muted); font-size: 12.5px; margin-top: 1px; }
.topbar .spacer { flex: 1; }
.content { padding: 24px 28px 60px; max-width: 1280px; width: 100%; }
.view { display: none; animation: fade .25s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ============ Buttons ============ */
.btn {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  padding: 8px 15px; border-radius: var(--radius-sm); font-weight: 600; font-size: 13px;
  background: var(--surface); border: 1px solid var(--border-strong); color: var(--text);
  transition: all .14s; white-space: nowrap;
}
.btn:hover { background: var(--surface-3); border-color: var(--faint); }
.btn .ico { font-size: 14px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 2px 8px rgba(188,102,67,.28); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-danger { color: var(--danger); border-color: var(--danger-soft); background: var(--danger-soft); }
.btn-danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }
.btn-sm { padding: 5px 11px; font-size: 12px; border-radius: 7px; }
.btn-icon { padding: 7px; width: 32px; height: 32px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ============ Cards / KPI ============ */
.grid { display: grid; gap: 16px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow-sm); position: relative; overflow: hidden;
}
.kpi .label { font-size: 12.5px; color: var(--muted); font-weight: 500; display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 25px; font-weight: 700; color: var(--ink); margin-top: 7px; letter-spacing: -.3px; }
.kpi .value.sm { font-size: 21px; }
.kpi .delta { font-size: 12px; margin-top: 5px; font-weight: 600; display: inline-flex; align-items: center; gap: 4px; }
.kpi .accent-bar { position: absolute; left: 0; top: 0; bottom: 0; width: 4px; }
.kpi .sub { font-size: 11.5px; color: var(--faint); margin-top: 4px; }
.up { color: var(--danger); } .down { color: var(--success); }

.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); margin-bottom: 18px;
}
.panel-head {
  display: flex; align-items: center; gap: 12px; padding: 15px 18px; border-bottom: 1px solid var(--border);
}
.panel-head h3 { font-size: 14.5px; color: var(--ink); font-weight: 700; }
.panel-head .desc { font-size: 12px; color: var(--muted); font-weight: 400; }
.panel-head .spacer { flex: 1; }
.panel-body { padding: 18px; }
.panel-body.flush { padding: 0; }

.cols-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; }
.cols-2.even { grid-template-columns: 1fr 1fr; }
@media (max-width: 1000px) { .cols-2, .cols-2.even { grid-template-columns: 1fr; } }

.chart-wrap { position: relative; height: 280px; }
.chart-wrap.tall { height: 320px; }

/* ============ Tables ============ */
.table-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.table-scroll { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  text-align: left; padding: 11px 14px; font-size: 11.5px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--border);
  background: var(--surface-2); white-space: nowrap; position: sticky; top: 0;
}
table.data th.r, table.data td.r { text-align: right; }
table.data td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tbody tr { transition: background .1s; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr:last-child td { border-bottom: none; }
.row-group-head td {
  background: var(--surface-3); font-weight: 700; color: var(--ink); font-size: 12.5px;
  text-transform: none; letter-spacing: 0;
}
.row-group-head .gsum { font-weight: 600; color: var(--muted); font-size: 12px; }
table.data tfoot td { padding: 12px 14px; font-weight: 700; color: var(--ink); border-top: 2px solid var(--border-strong); background: var(--surface-2); }
.cell-name { font-weight: 600; color: var(--ink); }
.cell-sub { font-size: 11.5px; color: var(--faint); margin-top: 1px; }
.row-actions { display: flex; gap: 2px; justify-content: flex-end; opacity: 0; transition: opacity .12s; }
tr:hover .row-actions { opacity: 1; }
.over { color: var(--danger); font-weight: 700; }
.under { color: var(--success); font-weight: 600; }

/* ============ Badges / pills ============ */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 20px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap; line-height: 1.6;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.b-gray { background: var(--surface-3); color: var(--muted); }
.b-blue { background: var(--info-soft); color: var(--info); }
.b-green { background: var(--success-soft); color: var(--success); }
.b-amber { background: var(--warn-soft); color: var(--warn); }
.b-red { background: var(--danger-soft); color: var(--danger); }
.b-primary { background: var(--primary-soft); color: var(--primary-dark); }
.tag {
  display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 6px;
  background: var(--surface-3); color: var(--muted); font-size: 11px; font-weight: 500;
}

/* ============ Filters ============ */
.filter {
  appearance: none; padding: 7px 30px 7px 12px; border: 1px solid var(--border-strong);
  border-radius: 8px; background: var(--surface) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238C857A' stroke-width='2.5'><path d='M6 9l6 6 6-6'/></svg>") no-repeat right 10px center;
  font-size: 12.5px; font-weight: 500; color: var(--text); cursor: pointer;
}
.search {
  padding: 7px 12px 7px 32px; border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--surface) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%238C857A' stroke-width='2'><circle cx='11' cy='11' r='7'/><path d='M21 21l-4.3-4.3'/></svg>") no-repeat left 10px center;
  font-size: 13px; min-width: 200px;
}
.search:focus, .filter:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-tint); }
.seg { display: inline-flex; background: var(--surface-3); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button { padding: 5px 12px; border-radius: 7px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

/* ============ Forms / modal ============ */
.modal-back {
  position: fixed; inset: 0; background: rgba(43,40,36,.42); backdrop-filter: blur(3px);
  display: none; align-items: flex-start; justify-content: center; z-index: 100; padding: 40px 16px; overflow-y: auto;
}
.modal-back.show { display: flex; animation: fade .18s; }
.modal {
  background: var(--surface); border-radius: var(--radius-lg); width: 100%; max-width: 620px;
  box-shadow: var(--shadow-lg); animation: pop .22s cubic-bezier(.16,1,.3,1); margin: auto 0;
}
.modal.wide { max-width: 860px; }
@keyframes pop { from { opacity: 0; transform: scale(.96) translateY(10px); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; align-items: center; padding: 20px 24px 14px; }
.modal-head h2 { font-size: 17px; color: var(--ink); font-weight: 700; }
.modal-head .x { margin-left: auto; font-size: 20px; color: var(--faint); width: 32px; height: 32px; border-radius: 8px; }
.modal-head .x:hover { background: var(--surface-3); color: var(--text); }
.modal-body { padding: 4px 24px 8px; max-height: 64vh; overflow-y: auto; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 16px 24px 22px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--text); }
.field label .opt { color: var(--faint); font-weight: 400; }
.field input, .field select, .field textarea {
  padding: 9px 12px; border: 1px solid var(--border-strong); border-radius: 9px;
  background: var(--surface-2); font-size: 13.5px; transition: border .12s, box-shadow .12s; width: 100%;
}
.field textarea { resize: vertical; min-height: 60px; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary); background: var(--surface); box-shadow: 0 0 0 3px var(--primary-tint);
}
.field .hint { font-size: 11px; color: var(--faint); }
.field select { appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238C857A' stroke-width='2.5'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px;
}
.input-prefix { position: relative; }
.input-prefix > span { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 13px; pointer-events: none; }
.input-prefix input { padding-left: 24px; }

/* ============ Cases (collection) ============ */
.case-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(248px, 1fr)); gap: 16px; }
.case-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow-sm); transition: transform .15s, box-shadow .15s; display: flex; flex-direction: column;
}
.case-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.case-cover {
  height: 152px; background: var(--surface-3); background-size: cover; background-position: center;
  position: relative; display: grid; place-items: center; color: var(--faint); font-size: 34px;
}
.case-cover .src-badge { position: absolute; top: 10px; left: 10px; }
.case-body { padding: 13px 15px 15px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.case-title { font-weight: 700; color: var(--ink); font-size: 14px; line-height: 1.4; }
.case-tags { display: flex; flex-wrap: wrap; gap: 5px; }
.case-note { font-size: 12px; color: var(--muted); line-height: 1.5; }
.case-foot { display: flex; align-items: center; gap: 8px; margin-top: auto; padding-top: 6px; }
.case-foot .room-tag { font-size: 11.5px; color: var(--faint); }
.case-foot .actions { margin-left: auto; display: flex; gap: 2px; }

.src-xhs { background: #FDE7EC; color: #E0245E; }
.src-wx { background: #E2F4E4; color: #2Ba84a; }
.src-pdf { background: #FBE6E3; color: #CF3F31; }
.src-web { background: #E6EFF7; color: #3C72A6; }
.src-img { background: #F0EAF7; color: #8C6BB1; }
.src-other { background: var(--surface-3); color: var(--muted); }

/* ============ Quote comparison ============ */
.quote-group { margin-bottom: 18px; }
.qg-head { display: flex; align-items: center; gap: 12px; padding: 15px 18px; border-bottom: 1px solid var(--border); }
.qg-head .qg-title { font-size: 15px; font-weight: 700; color: var(--ink); }
.qg-head .qg-meta { font-size: 12px; color: var(--muted); }
.qg-stats { display: flex; gap: 18px; margin-left: 8px; }
.qg-stat { font-size: 12px; color: var(--muted); }
.qg-stat b { color: var(--ink); font-size: 13px; }
.qg-stat.best b { color: var(--success); }
.quote-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; padding: 18px; }
.quote-card {
  border: 1.5px solid var(--border); border-radius: var(--radius); padding: 15px; position: relative;
  transition: border .15s, box-shadow .15s; background: var(--surface-2);
}
.quote-card.selected { border-color: var(--primary); background: var(--primary-tint); box-shadow: 0 0 0 3px var(--primary-tint); }
.quote-card.cheapest::after {
  content: "最低价"; position: absolute; top: -9px; right: 12px; background: var(--success); color: #fff;
  font-size: 10.5px; font-weight: 700; padding: 2px 8px; border-radius: 20px;
}
.qc-top { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 10px; }
.qc-vendor { font-weight: 700; color: var(--ink); font-size: 14px; }
.qc-brand { font-size: 12px; color: var(--muted); }
.qc-price { font-size: 22px; font-weight: 800; color: var(--primary-dark); letter-spacing: -.5px; }
.qc-price small { font-size: 12px; font-weight: 600; color: var(--muted); }
.qc-unit { font-size: 11.5px; color: var(--faint); margin-top: 1px; }
.qc-rows { margin: 11px 0; display: flex; flex-direction: column; gap: 5px; }
.qc-row { display: flex; font-size: 12px; gap: 8px; }
.qc-row .k { color: var(--faint); flex: 0 0 46px; }
.qc-row .v { color: var(--text); flex: 1; }
.qc-prc { display: flex; gap: 10px; margin: 9px 0; }
.qc-pro, .qc-con { font-size: 11.5px; line-height: 1.5; flex: 1; }
.qc-pro { color: var(--success); } .qc-con { color: var(--danger); }
.qc-foot { display: flex; align-items: center; gap: 6px; margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border); }
.stars { color: var(--warn); font-size: 12.5px; letter-spacing: 1px; }
.qc-foot .actions { margin-left: auto; display: flex; gap: 2px; }
.type-chip { font-size: 10.5px; padding: 1px 7px; border-radius: 5px; font-weight: 700; }
.type-custom { background: var(--primary-soft); color: var(--primary-dark); }
.type-finished { background: var(--info-soft); color: var(--info); }
.type-semi { background: var(--warn-soft); color: var(--warn); }

/* ============ Empty / misc ============ */
.empty { text-align: center; padding: 56px 20px; color: var(--muted); }
.empty .ico { font-size: 46px; opacity: .4; margin-bottom: 12px; }
.empty h4 { font-size: 15px; color: var(--text); font-weight: 700; margin-bottom: 6px; }
.empty p { font-size: 13px; max-width: 360px; margin: 0 auto 16px; line-height: 1.6; }

.progress { height: 7px; background: var(--surface-3); border-radius: 20px; overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: 20px; background: var(--primary); transition: width .4s; }
.mini-bar { display: flex; align-items: center; gap: 8px; }
.mini-bar .progress { flex: 1; min-width: 60px; }
.mini-bar .pct { font-size: 11.5px; color: var(--muted); font-weight: 600; flex: 0 0 auto; }

/* ============ Toast ============ */
.toasts { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.toast {
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 11px; font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 9px; animation: slideUp .3s cubic-bezier(.16,1,.3,1);
}
.toast.ok .i { color: #6FD99A; } .toast.err .i { color: #FF8A7A; }
@keyframes slideUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }

/* ============ Settings ============ */
.set-row { display: flex; align-items: center; gap: 16px; padding: 16px 0; border-bottom: 1px solid var(--border); }
.set-row:last-child { border: none; }
.set-row .info { flex: 1; }
.set-row .info h4 { font-size: 13.5px; color: var(--ink); font-weight: 600; }
.set-row .info p { font-size: 12px; color: var(--muted); margin-top: 2px; }
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip-edit { display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: 8px; background: var(--surface-3); font-size: 12.5px; font-weight: 500; }
.chip-edit button { color: var(--faint); font-size: 14px; line-height: 1; }
.chip-edit button:hover { color: var(--danger); }

@media (max-width: 760px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; z-index: 90; box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .menu-toggle { display: inline-flex !important; }
  .content { padding: 16px; }
  .topbar { padding: 14px 16px; }
  .form-grid { grid-template-columns: 1fr; }
}
.menu-toggle { display: none; }
.backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 80; }
.backdrop.show { display: block; }
