:root {
  --ink: #182225;
  --ink-soft: #566064;
  --ink-mute: #858d8f;
  --paper: #ffffff;
  --pearl: #f4f2ed;
  --line: #dfddd5;
  --line-strong: #c8c3b7;
  --gold: #c8a96a;
  --gold-deep: #9f7e40;
  --gold-soft: #f2ead9;
  --green: #347056;
  --green-soft: #e8f2ed;
  --red: #a6493a;
  --red-soft: #f6e9e6;
  --blue-soft: #e7eff2;
  --orange-soft: #f8eadb;
  --shadow: 0 14px 34px rgba(22, 31, 34, .08);
}

* { box-sizing: border-box; }
html { color-scheme: light; background: var(--pearl); }
body {
  margin: 0;
  color: var(--ink);
  background-color: var(--pearl);
  background-image: radial-gradient(rgba(24, 34, 37, .045) 1px, transparent 1px);
  background-size: 28px 28px;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
button { color: inherit; }
button, select { cursor: pointer; }
.hidden { display: none !important; }
.staff .admin-only { display: none !important; }

.gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  min-height: 100svh;
  padding: 22px;
  background:
    linear-gradient(135deg, rgba(17, 27, 30, .96), rgba(37, 48, 50, .94)),
    radial-gradient(circle at 20% 10%, rgba(200, 169, 106, .3), transparent 34%);
}
.gate-panel {
  width: min(100%, 430px);
  padding: 42px;
  background: var(--paper);
  border-top: 3px solid var(--gold);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .28);
}
.gate-mark, .brand-mark {
  display: grid;
  place-items: center;
  background: var(--gold);
  color: #172226;
  font-family: "Songti SC", serif;
  font-weight: 800;
}
.gate-mark { width: 58px; height: 58px; font-size: 31px; margin-bottom: 28px; }
.gate h1 { margin: 4px 0 10px; font-size: 32px; letter-spacing: .08em; }
.gate-copy { margin: 0 0 28px; color: var(--ink-soft); line-height: 1.7; }
.gate-note { margin: 18px 0 0; color: var(--ink-mute); text-align: center; font-size: 12px; }
.form-error { min-height: 20px; margin: 10px 0 0; color: var(--red); font-size: 13px; text-align: center; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  color: white;
  background: linear-gradient(110deg, #111b1e, #273336);
  border-bottom: 2px solid var(--gold);
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark { width: 40px; height: 40px; font-size: 22px; }
.brand strong { display: block; font-size: 17px; letter-spacing: .08em; }
.brand small { display: block; margin-top: 4px; color: rgba(255, 255, 255, .55); font-size: 9px; letter-spacing: .15em; }
.top-meta { display: flex; align-items: center; gap: 12px; }
.status-dot, .role-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 26px;
  padding: 4px 9px;
  border: 1px solid rgba(255, 255, 255, .2);
  font-size: 11px;
  letter-spacing: .04em;
}
.status-dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #6fc893; }
.role-badge { color: var(--gold); }
.topbar .text-button { color: rgba(255, 255, 255, .7); }

.shell { display: grid; grid-template-columns: 228px minmax(0, 1fr); min-height: calc(100svh - 72px); }
.sidebar {
  position: sticky;
  top: 72px;
  height: calc(100svh - 72px);
  display: flex;
  flex-direction: column;
  padding: 26px 18px 18px;
  background: rgba(255, 255, 255, .88);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(12px);
}
.store-identity { padding: 0 10px 22px; border-bottom: 1px solid var(--line); }
.store-identity small, .store-identity span { display: block; color: var(--ink-mute); font-size: 11px; }
.store-identity strong { display: block; margin: 7px 0 4px; font-size: 16px; }
.sidebar nav { display: grid; gap: 4px; padding: 20px 0; }
.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 10px;
  border: 0;
  border-left: 2px solid transparent;
  background: transparent;
  color: var(--ink-soft);
  text-align: left;
  font-size: 14px;
}
.nav-item span { color: var(--ink-mute); font-family: ui-monospace, monospace; font-size: 10px; }
.nav-item:hover { background: #f4f3ef; color: var(--ink); }
.nav-item.active { background: var(--gold-soft); border-left-color: var(--gold-deep); color: var(--ink); font-weight: 700; }
.nav-count { margin-left: auto; min-width: 20px; padding: 2px 6px; color: white; background: var(--red); text-align: center; font-size: 10px; }
.sidebar-foot { margin-top: auto; padding: 16px 10px 4px; border-top: 1px solid var(--line); }
.sidebar-foot small { display: block; margin-top: 9px; color: var(--ink-mute); font-size: 10px; }
.sync-indicator { font-size: 11px; color: var(--green); }
.sync-indicator.pending { color: var(--red); }

.content { min-width: 0; padding: 42px clamp(24px, 4vw, 64px) 70px; }
.view { display: none; max-width: 1280px; margin: 0 auto; }
.view.active { display: block; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 28px; }
.page-head h1 { margin: 3px 0 0; font-size: clamp(26px, 3vw, 38px); letter-spacing: -.02em; }
.page-head > p { max-width: 460px; margin: 0; color: var(--ink-soft); font-size: 13px; text-align: right; line-height: 1.6; }
.eyebrow { margin: 0; color: var(--gold-deep); font-size: 10px; font-weight: 800; letter-spacing: .18em; }
.head-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }

.hero-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.hero-grid.five { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.kpi {
  min-height: 124px;
  padding: 22px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-top: 2px solid var(--gold);
  box-shadow: 0 5px 20px rgba(24, 34, 37, .04);
}
.kpi.featured { color: white; background: linear-gradient(135deg, #172226, #334043); border-color: #172226; }
.kpi small { display: block; color: var(--ink-mute); font-size: 11px; }
.kpi.featured small { color: rgba(255, 255, 255, .55); }
.kpi strong { display: block; margin-top: 14px; font-size: clamp(26px, 3vw, 38px); line-height: 1; letter-spacing: -.04em; }
.kpi.featured strong { color: var(--gold); }
.kpi em { display: block; margin-top: 10px; color: var(--ink-mute); font-size: 10px; font-style: normal; }

.quick-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 18px 0; }
.quick-card {
  min-height: 150px;
  padding: 26px;
  border: 1px solid var(--line);
  background: var(--paper);
  text-align: left;
  box-shadow: 0 6px 20px rgba(24, 34, 37, .04);
}
.quick-card.dark { color: white; background: #1b272a; border-color: #1b272a; }
.quick-card span { display: block; margin-bottom: 8px; font-size: 19px; font-weight: 750; }
.quick-card small { display: block; color: var(--ink-soft); line-height: 1.6; }
.quick-card.dark small { color: rgba(255, 255, 255, .58); }
.quick-card b { display: block; margin-top: 24px; color: var(--gold-deep); font-size: 12px; }
.quick-card.dark b { color: var(--gold); }

.split-layout { display: grid; grid-template-columns: 1.2fr 1fr; gap: 18px; }
.panel, .form-card, .filter-panel {
  background: rgba(255, 255, 255, .95);
  border: 1px solid var(--line);
  box-shadow: 0 8px 28px rgba(24, 34, 37, .045);
}
.panel { min-width: 0; padding: 24px; margin-bottom: 18px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin-bottom: 18px; }
.panel-head h2 { margin: 4px 0 0; font-size: 19px; }
.stack-list { min-width: 0; display: grid; gap: 9px; }
.stack-row { width: 100%; min-width: 0; display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.stack-row:first-child { border-top: 0; }
.stack-row-main { min-width: 0; flex: 1; }
.stack-row-main strong, .stack-row-main span { display: block; }
.stack-row-main strong { font-size: 13px; }
.stack-row-main span { overflow: hidden; margin-top: 4px; color: var(--ink-soft); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 26px 12px; color: var(--ink-mute); text-align: center; font-size: 13px; }

.button {
  min-height: 40px;
  padding: 9px 16px;
  border: 1px solid var(--line-strong);
  background: white;
  font-weight: 700;
  font-size: 12px;
}
.button:disabled { cursor: wait; opacity: .55; }
.button:hover { border-color: var(--gold-deep); }
.button.primary { color: #152024; background: var(--gold); border-color: var(--gold); }
.button.primary:hover { background: #d4b876; }
.button.subtle { background: var(--gold-soft); border-color: #e3d2ad; }
.button.danger { color: var(--red); border-color: #e1b9b1; }
.button.block { width: 100%; }
.button.small { min-height: 32px; padding: 6px 10px; font-size: 11px; }
.text-button { padding: 0; border: 0; background: transparent; color: var(--gold-deep); font-size: 12px; }

.form-card { margin-bottom: 22px; }
.form-card.compact { max-width: 880px; padding: 28px; }
.form-section { display: grid; grid-template-columns: 72px minmax(0, 1fr); border-bottom: 1px solid var(--line); }
.section-number { padding: 30px 20px; color: var(--gold-deep); background: #faf9f6; font-family: ui-monospace, monospace; font-size: 12px; font-weight: 800; }
.section-body { min-width: 0; padding: 28px 32px 32px; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 22px; }
.section-title h2 { margin: 0; font-size: 19px; }
.section-title span { color: var(--ink-mute); font-size: 10px; letter-spacing: .12em; }
.form-grid { display: grid; gap: 14px; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field { display: grid; gap: 7px; margin-bottom: 14px; color: var(--ink-soft); font-size: 12px; font-weight: 650; }
.field input, .field select, .field textarea, .filter-panel input, .filter-panel select {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 10px 12px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 0;
  outline: none;
}
.field textarea { resize: vertical; line-height: 1.7; }
.field input:focus, .field select:focus, .field textarea:focus, .filter-panel input:focus, .filter-panel select:focus { border-color: var(--gold-deep); box-shadow: 0 0 0 3px rgba(200, 169, 106, .16); }
.choice-field { margin: 4px 0 18px; padding: 0; border: 0; }
.choice-field legend { margin-bottom: 9px; color: var(--ink-soft); font-size: 12px; font-weight: 650; }
.choices { display: flex; gap: 8px; }
.choices.wrap { flex-wrap: wrap; }
.choices label { position: relative; }
.choices input { position: absolute; opacity: 0; pointer-events: none; }
.choices span { display: block; min-width: 72px; padding: 9px 13px; border: 1px solid var(--line-strong); background: white; text-align: center; font-size: 12px; }
.choices.large label { flex: 1; }
.choices.large span { padding: 14px; font-weight: 750; }
.choices input:checked + span { border-color: var(--gold-deep); background: var(--gold-soft); box-shadow: inset 0 -2px var(--gold-deep); }
.conditional { padding: 18px; background: #faf9f6; border-left: 2px solid var(--gold); }
.note-box, .warning-box { padding: 14px 16px; color: var(--ink-soft); background: var(--gold-soft); border-left: 3px solid var(--gold); font-size: 12px; line-height: 1.7; }
.home-assistant-hint { margin-bottom: 16px; }
.warning-box { margin-top: 14px; color: #735025; background: #fff4df; border-color: #d79a3b; }
.submit-bar { display: flex; align-items: center; justify-content: flex-end; gap: 18px; padding: 20px 32px; background: #faf9f6; }
.submit-bar p { flex: 1; margin: 0; color: var(--ink-soft); font-size: 12px; }
.inline-state { display: flex; justify-content: space-between; color: var(--ink-mute); font-size: 12px; }

.filter-panel { display: grid; grid-template-columns: 2fr repeat(3, minmax(140px, .8fr)); gap: 10px; margin-bottom: 16px; padding: 14px; }
.filter-panel.scripts-filter { grid-template-columns: 2fr repeat(4, minmax(125px, .7fr)); }
.result-meta { margin: 12px 0; color: var(--ink-mute); font-size: 12px; }
.customer-grid, .script-grid, .store-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.customer-card, .script-card, .store-card {
  min-width: 0;
  padding: 20px;
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: 0 6px 18px rgba(24, 34, 37, .035);
}
.customer-card:hover, .script-card:hover { border-color: var(--line-strong); box-shadow: var(--shadow); }
.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.card-top h3 { margin: 0; font-size: 17px; }
.card-top small { display: block; margin-top: 5px; color: var(--ink-mute); font-size: 10px; }
.card-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 18px 0; color: var(--ink-soft); font-size: 11px; }
.card-meta span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-note { min-height: 42px; margin: 14px 0; color: var(--ink-soft); font-size: 12px; line-height: 1.7; }
.card-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.chip-row { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 12px; }
.chip { padding: 4px 7px; background: #f0efeb; color: var(--ink-soft); font-size: 10px; line-height: 1.3; }
.chip.stage { background: var(--blue-soft); }
.chip.scene { background: var(--orange-soft); }
.chip.channel { background: var(--green-soft); }
.chip.gold { background: var(--gold-soft); color: #6d5423; }
.chip.high { color: #7b2f24; background: var(--red-soft); }
.chip.ok { color: var(--green); background: var(--green-soft); }
.chip.muted { color: var(--ink-mute); }
.script-card .script-text { margin: 14px 0 0; color: #303a3d; font-size: 13px; line-height: 1.85; white-space: pre-wrap; }
.script-card .script-reason { margin-top: 12px; color: var(--ink-mute); font-size: 10px; }

.store-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.store-card.top-store { color: white; background: #1c282b; border-color: #1c282b; }
.store-card h3 { margin: 0 0 6px; font-size: 15px; }
.store-card > span { color: var(--ink-mute); font-size: 10px; }
.top-store > span { color: rgba(255, 255, 255, .55); }
.store-values { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 18px; }
.store-values small, .store-values strong { display: block; }
.store-values small { color: var(--ink-mute); font-size: 9px; }
.store-values strong { margin-top: 5px; font-size: 17px; }
.top-store .store-values strong { color: var(--gold); }
.bar-list { display: grid; gap: 16px; }
.bar-row { display: grid; grid-template-columns: 90px minmax(0, 1fr) 160px; align-items: center; gap: 14px; font-size: 12px; }
.bar-track { height: 8px; background: #eceae4; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--gold-deep), var(--gold)); }
.bar-value { color: var(--ink-soft); text-align: right; }

.modal { position: fixed; inset: 0; z-index: 80; display: grid; grid-template-columns: minmax(0, 1fr) min(680px, 92vw); }
.modal-backdrop { background: rgba(11, 18, 20, .58); backdrop-filter: blur(3px); }
.modal-panel { position: relative; overflow-y: auto; height: 100svh; padding: 42px 36px 60px; background: var(--pearl); box-shadow: -20px 0 60px rgba(0, 0, 0, .18); }
.modal-close { position: absolute; top: 14px; right: 18px; width: 34px; height: 34px; border: 0; background: transparent; font-size: 26px; }
.detail-head { margin-bottom: 18px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.detail-head h2 { margin: 4px 0; font-size: 27px; }
.detail-head p { margin: 0; color: var(--ink-soft); font-size: 12px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.detail-cell { padding: 12px; background: white; border: 1px solid var(--line); }
.detail-cell small, .detail-cell strong { display: block; }
.detail-cell small { color: var(--ink-mute); font-size: 9px; }
.detail-cell strong { margin-top: 5px; font-size: 13px; }
.detail-section { margin-top: 18px; padding: 20px; background: white; border: 1px solid var(--line); }
.detail-section h3 { margin: 0 0 14px; font-size: 16px; }
.follow-log { max-height: 240px; overflow-y: auto; padding: 12px; background: #f8f7f3; color: var(--ink-soft); font-size: 11px; line-height: 1.8; white-space: pre-wrap; }
.recommend-context { margin: 0 0 12px; color: var(--ink-soft); font-size: 11px; }

.toast { position: fixed; left: 50%; bottom: 28px; z-index: 120; transform: translate(-50%, 20px); padding: 11px 18px; color: white; background: #192427; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: .2s ease; font-size: 12px; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }

@media (max-width: 1100px) {
  .hero-grid.five { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .customer-grid, .script-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-panel, .filter-panel.scripts-filter { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-panel > input:first-child { grid-column: 1 / -1; }
}

@media (max-width: 760px) {
  .topbar { height: 62px; padding: 0 14px; }
  .brand-mark { width: 34px; height: 34px; }
  .brand strong { font-size: 14px; }
  .brand small, .status-dot { display: none; }
  .top-meta { gap: 7px; }
  .role-badge { padding: 3px 6px; font-size: 9px; }
  .shell { display: block; }
  .sidebar { position: sticky; top: 62px; z-index: 35; width: 100%; height: auto; padding: 0; border-right: 0; border-bottom: 1px solid var(--line); }
  .store-identity, .sidebar-foot { display: none; }
  .sidebar nav { display: flex; gap: 0; overflow-x: auto; padding: 0; scrollbar-width: none; }
  .nav-item { flex: 0 0 auto; width: auto; padding: 13px 14px; border-left: 0; border-bottom: 2px solid transparent; font-size: 12px; white-space: nowrap; }
  .nav-item span { display: none; }
  .nav-item.active { border-bottom-color: var(--gold-deep); }
  .content { padding: 26px 14px 60px; }
  .page-head { align-items: flex-start; margin-bottom: 20px; }
  .page-head > p { display: none; }
  .page-head h1 { font-size: 27px; }
  .head-actions { justify-content: flex-start; }
  .hero-grid, .hero-grid.five { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi { min-height: 104px; padding: 16px; }
  .quick-grid, .split-layout { grid-template-columns: minmax(0, 1fr); }
  .quick-card { min-height: 132px; padding: 20px; }
  .form-section { grid-template-columns: 1fr; }
  .section-number { padding: 16px 18px 0; background: white; }
  .section-body { padding: 12px 18px 24px; }
  .section-title { margin-bottom: 18px; }
  .form-grid.three { grid-template-columns: 1fr; gap: 0; }
  .choices.wrap label { flex: 1 0 calc(33% - 8px); }
  .choices.wrap span { min-width: 0; }
  .submit-bar { position: sticky; bottom: 0; z-index: 10; padding: 13px 16px; box-shadow: 0 -10px 30px rgba(24, 34, 37, .08); }
  .submit-bar .button { flex: 1; }
  .form-card.compact { padding: 20px 16px; }
  .filter-panel, .filter-panel.scripts-filter { grid-template-columns: 1fr; }
  .filter-panel > input:first-child { grid-column: auto; }
  .customer-grid, .script-grid, .store-grid { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 70px minmax(0, 1fr); }
  .bar-value { grid-column: 2; text-align: left; }
  .modal { display: block; }
  .modal-backdrop { display: none; }
  .modal-panel { width: 100%; padding: 42px 14px 50px; }
  .detail-grid { grid-template-columns: 1fr 1fr; }
  .gate-panel { padding: 30px 24px; }
}

@media (max-width: 390px) {
  .hero-grid, .hero-grid.five { grid-template-columns: 1fr 1fr; }
  .kpi strong { font-size: 25px; }
  .detail-grid { grid-template-columns: 1fr; }
}
