:root {
  color-scheme: light;
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  font-size: 16px;
  --bg: #f3f6f8;
  --surface: #ffffff;
  --surface-soft: #f7fafb;
  --text: #14212b;
  --muted: #64727d;
  --line: #dce4e8;
  --primary: #0f766e;
  --primary-dark: #0a5d57;
  --primary-soft: #dff5f1;
  --blue: #2563eb;
  --blue-soft: #eaf1ff;
  --orange: #c65b12;
  --orange-soft: #fff0df;
  --red: #b42318;
  --red-soft: #ffebe9;
  --green: #198754;
  --green-soft: #e6f6ed;
  --shadow: 0 12px 40px rgba(28, 45, 55, 0.09);
  --radius: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { min-width: 320px; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(1.5rem, 2.5vw, 2rem); margin-bottom: .35rem; }
h2 { font-size: 1.25rem; margin-bottom: .4rem; }
h3 { font-size: 1rem; margin-bottom: .35rem; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.order-number {
  color: var(--primary);
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  letter-spacing: .04em;
  white-space: nowrap;
}
.money { font-variant-numeric: tabular-nums; font-weight: 700; }
.eyebrow { color: var(--primary); font-size: .8rem; font-weight: 800; letter-spacing: .08em; margin-bottom: .35rem; text-transform: uppercase; }

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 15% 10%, rgba(15,118,110,.16), transparent 28%),
    radial-gradient(circle at 90% 85%, rgba(37,99,235,.12), transparent 28%),
    #edf3f5;
}
.login-card { width: min(430px, 100%); padding: 40px; background: var(--surface); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow); }
.brand-mark { width: 56px; height: 56px; display: grid; place-items: center; border-radius: 16px; background: linear-gradient(145deg, #0f766e, #14a389); color: white; font-size: 1.45rem; font-weight: 900; box-shadow: 0 10px 24px rgba(15,118,110,.22); margin-bottom: 22px; }
.brand-mark.small { width: 40px; height: 40px; border-radius: 12px; margin: 0; font-size: 1.05rem; }
.login-intro { color: var(--muted); line-height: 1.7; margin-bottom: 24px; }
.login-hint { font-size: .86rem; color: var(--muted); text-align: center; margin: 18px 0 0; }

.stack { display: grid; gap: 16px; }
label { display: grid; gap: 7px; color: #34434e; font-size: .9rem; font-weight: 700; }
input, select, textarea {
  width: 100%;
  border: 1px solid #cbd7dd;
  background: white;
  color: var(--text);
  border-radius: 10px;
  padding: 12px 13px;
  min-height: 46px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 92px; resize: vertical; line-height: 1.55; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15,118,110,.12); }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px; }
.field-row.three { grid-template-columns: repeat(3, minmax(0,1fr)); }
.checkbox { display: flex; align-items: center; gap: 9px; font-weight: 700; }
.checkbox input { width: 18px; height: 18px; min-height: 0; }

.button { border: 0; border-radius: 10px; min-height: 46px; padding: 11px 18px; font-weight: 800; transition: transform .12s, background .12s; }
.button:active { transform: translateY(1px); }
.button.primary { background: var(--primary); color: white; }
.button.primary:hover { background: var(--primary-dark); }
.button.secondary { background: white; color: var(--text); border: 1px solid var(--line); }
.button.secondary:hover { background: var(--surface-soft); }
.button.danger { background: var(--red-soft); color: var(--red); }
.button.wide { width: 100%; }
.button.compact { min-height: 40px; padding: 8px 14px; font-size: .9rem; }
.text-button { border: 0; background: transparent; color: var(--primary); font-weight: 800; padding: 6px; }
.icon-button { border: 0; background: var(--surface-soft); color: var(--text); width: 40px; height: 40px; border-radius: 50%; font-size: 1.45rem; }

.app { min-height: 100vh; display: grid; grid-template-columns: 230px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 22px 16px; background: #102b2d; color: white; display: flex; flex-direction: column; }
.side-brand { display: flex; align-items: center; gap: 11px; padding: 0 8px 22px; border-bottom: 1px solid rgba(255,255,255,.1); }
.side-brand strong, .side-brand span { display: block; }
.side-brand span { color: #9dc1be; font-size: .78rem; margin-top: 2px; }
.main-nav { display: grid; gap: 7px; margin-top: 22px; }
.main-nav button { border: 0; border-radius: 10px; padding: 12px 14px; text-align: left; color: #bfd1d0; background: transparent; font-weight: 700; }
.main-nav button:hover, .main-nav button.active { background: rgba(255,255,255,.1); color: white; }
.sidebar-user { margin-top: auto; display: grid; grid-template-columns: 38px 1fr auto; align-items: center; gap: 9px; padding: 16px 6px 0; border-top: 1px solid rgba(255,255,255,.1); }
.sidebar-user strong, .sidebar-user span { display: block; }
.sidebar-user span { font-size: .75rem; color: #9dc1be; margin-top: 2px; }
.sidebar-user .text-button { color: #bde7df; font-size: .8rem; }
.avatar { width: 38px; height: 38px; display: grid; place-items: center; background: #1c4a4b; border-radius: 50%; font-weight: 900; }

.workspace { min-width: 0; }
.topbar { min-height: 90px; padding: 18px 28px; background: rgba(255,255,255,.92); border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 18px; position: sticky; top: 0; z-index: 10; backdrop-filter: blur(12px); }
.topbar h1 { margin-bottom: 0; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.live-status { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: .82rem; font-weight: 700; margin-right: 4px; }
.live-status i { width: 8px; height: 8px; background: var(--green); border-radius: 50%; box-shadow: 0 0 0 4px var(--green-soft); }
.notification-button.enabled { color: #7a5200; border-color: #edc85d; background: #fff6cf; }
.content { padding: 24px 28px 90px; max-width: 1500px; width: 100%; margin: 0 auto; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 14px; margin-bottom: 22px; }
.stat-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; min-height: 126px; display: flex; flex-direction: column; justify-content: space-between; box-shadow: 0 4px 18px rgba(25, 46, 55, .035); }
.stat-card .label { color: var(--muted); font-size: .85rem; font-weight: 700; }
.stat-card strong { font-size: 1.85rem; line-height: 1; }
.stat-card small { color: var(--muted); font-size: .76rem; }
.stat-card.accent { background: linear-gradient(145deg, #0e766f, #0d5f5a); color: white; border-color: transparent; }
.stat-card.accent .label, .stat-card.accent small { color: #c7ebe7; }

.grid-two { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(300px, .65fr); gap: 18px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 4px 18px rgba(25,46,55,.035); overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0; }
.panel-body { padding: 20px; }
.panel-body.flush { padding: 0; }
.empty { padding: 34px 20px; color: var(--muted); text-align: center; }

.reminder-list, .simple-list, .timeline { list-style: none; padding: 0; margin: 0; }
.reminder-item, .simple-item { display: grid; grid-template-columns: 10px minmax(0,1fr) auto; gap: 12px; padding: 15px 20px; border-bottom: 1px solid var(--line); align-items: center; }
.reminder-item:last-child, .simple-item:last-child { border-bottom: 0; }
.reminder-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--orange); }
.reminder-dot.urgent { background: var(--red); box-shadow: 0 0 0 4px var(--red-soft); }
.reminder-item strong, .simple-item strong { display: block; margin-bottom: 4px; }
.reminder-item p, .simple-item p { margin: 0; color: var(--muted); font-size: .82rem; }
.row-action { border: 0; background: var(--surface-soft); color: var(--primary); font-weight: 800; padding: 8px 10px; border-radius: 8px; }

.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.toolbar .search { flex: 1; min-width: 220px; }
.toolbar select { width: auto; min-width: 170px; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { padding: 14px 15px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-size: .8rem; letter-spacing: .03em; background: #f8fafb; position: sticky; top: 0; }
td { font-size: .9rem; }
tr[data-order-id] { cursor: pointer; }
tr[data-order-id]:hover { background: #f8fbfb; }
tr.collision-row, tr.collision-row:hover { background: #fff1f0; box-shadow: inset 5px 0 0 var(--red); }
.collision-row td { color: #a62921; }
.collision-row .muted { color: #b24b44; }
.collision-number { color: var(--red); }
.collision-alert { display: inline-flex; align-items: center; min-height: 28px; padding: 4px 9px; border-radius: 999px; background: var(--red); color: white; font-size: .75rem; font-weight: 900; }
.collision-panel { margin-top: 18px; border-color: #efb5b0; }
.collision-reminder { background: #fff8f7; }
.row-action.danger { color: var(--red); border-color: #efb5b0; background: var(--red-soft); }
.collision-section { border: 2px solid #efb5b0; background: #fffafa; }
.collision-record { padding: 14px 0; border-bottom: 1px solid #f1d0cd; }
.collision-record:first-of-type { padding-top: 0; }
.collision-record:last-child { padding-bottom: 0; border-bottom: 0; }
.collision-record-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }

.status { display: inline-flex; align-items: center; min-height: 28px; padding: 4px 9px; border-radius: 999px; font-size: .75rem; font-weight: 800; background: var(--blue-soft); color: var(--blue); }
.status.warn { background: var(--orange-soft); color: var(--orange); }
.status.danger { background: var(--red-soft); color: var(--red); }
.status.success { background: var(--green-soft); color: var(--green); }
.status.neutral { background: #eef2f4; color: #53626c; }

.form-card { max-width: 820px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); }
.form-card header { padding-bottom: 18px; margin-bottom: 20px; border-bottom: 1px solid var(--line); }
.form-card header p { color: var(--muted); margin-bottom: 0; line-height: 1.65; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.help { color: var(--muted); font-size: .8rem; font-weight: 500; line-height: 1.5; }

.drawer-backdrop { position: fixed; inset: 0; background: rgba(10,25,30,.45); z-index: 40; }
.drawer { position: fixed; top: 0; right: 0; width: min(680px, 100%); height: 100vh; background: white; z-index: 50; box-shadow: -20px 0 50px rgba(10,25,30,.15); overflow: auto; }
.drawer-head { position: sticky; top: 0; z-index: 2; background: rgba(255,255,255,.96); display: grid; grid-template-columns: auto minmax(0,1fr) auto; gap: 12px; align-items: center; padding: 16px 22px; border-bottom: 1px solid var(--line); backdrop-filter: blur(10px); }
.drawer-head h2 { margin: 0; }
.drawer-heading { min-width: 0; }
.drawer-heading h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-back-button { min-height: 40px; border: 1px solid #b9d9d4; border-radius: 10px; background: var(--primary-soft); color: var(--primary-dark); padding: 8px 12px; font-weight: 900; white-space: nowrap; }
.drawer-content { padding: 20px 22px 50px; }
.order-summary { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; margin-bottom: 18px; }
.summary-box { background: var(--surface-soft); border: 1px solid var(--line); border-radius: 12px; padding: 13px; }
.summary-box span { display: block; color: var(--muted); font-size: .75rem; margin-bottom: 5px; }
.summary-box strong { display: block; line-height: 1.35; word-break: break-word; }
.process-flow { display: flex; gap: 0; overflow-x: auto; padding: 4px 2px 16px; margin-bottom: 12px; scrollbar-width: thin; }
.process-step { position: relative; min-width: 104px; flex: 1; text-align: center; color: var(--muted); font-size: .76rem; font-weight: 800; padding-top: 25px; }
.process-step::before { content: ""; position: absolute; z-index: 1; top: 4px; left: 50%; width: 13px; height: 13px; transform: translateX(-50%); border-radius: 50%; background: #cbd7dc; box-shadow: 0 0 0 4px #eef3f5; }
.process-step::after { content: ""; position: absolute; top: 10px; left: 0; right: 0; height: 2px; background: #dce4e8; }
.process-step:first-child::after { left: 50%; }
.process-step:last-child::after { right: 50%; }
.process-step.done, .process-step.current { color: var(--primary-dark); }
.process-step.done::before, .process-step.current::before { background: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft); }
.process-step.done::after { background: var(--primary); }
.process-step.current::before { width: 16px; height: 16px; top: 2px; }
.special-request { margin: 0 0 16px; padding: 13px 15px; border-radius: 12px; background: var(--orange-soft); color: #7f3908; border: 1px solid #f4c48f; font-weight: 800; line-height: 1.55; }
.special-tag { display: inline-block; max-width: 220px; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; padding: 4px 8px; border-radius: 7px; background: var(--orange-soft); color: #8a3f0c; font-size: .75rem; font-weight: 800; }
.processing-note { display: inline-block; max-width: 240px; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; padding: 4px 8px; border-radius: 7px; background: #edf4ff; color: #28548f; font-size: .75rem; font-weight: 800; }
.referral-notice { padding: 13px 15px; border: 1px solid #b9d9d4; border-radius: 12px; background: var(--primary-soft); color: var(--primary-dark); font-size: .85rem; font-weight: 800; line-height: 1.55; }
.referral-tag { display: inline-flex; margin-top: 5px; padding: 3px 7px; border-radius: 7px; background: var(--green-soft); color: var(--green); font-size: .72rem; font-weight: 900; }
.action-section { margin: 18px 0; padding: 18px; border: 1px solid var(--line); border-radius: 14px; background: white; }
.action-section h3 { margin-bottom: 12px; }
.action-section p { color: var(--muted); font-size: .85rem; line-height: 1.6; }
.action-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; }
.action-grid .full { grid-column: 1 / -1; }
.timeline { margin-top: 8px; }
.timeline li { position: relative; padding: 0 0 18px 24px; border-left: 2px solid var(--line); margin-left: 5px; }
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline li::before { content: ""; position: absolute; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); left: -6px; top: 4px; box-shadow: 0 0 0 4px var(--primary-soft); }
.timeline strong { display: block; font-size: .86rem; }
.timeline p { margin: 4px 0; color: #40505b; line-height: 1.5; font-size: .85rem; }
.timeline time { color: var(--muted); font-size: .74rem; }

.bill-card { margin: 18px 0; border: 1px solid #b9d9d4; border-radius: 14px; overflow: hidden; background: #fbfefd; }
.bill-card header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 15px 17px; background: var(--primary-soft); border-bottom: 1px solid #b9d9d4; }
.bill-card header h3 { margin: 0; }
.bill-table { width: 100%; }
.bill-table td { white-space: normal; padding: 11px 16px; }
.bill-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.bill-total td { border-top: 2px solid #b9d9d4; font-size: 1rem; font-weight: 900; color: var(--primary-dark); }
.bill-note { padding: 11px 16px; color: var(--muted); font-size: .8rem; line-height: 1.55; border-top: 1px solid var(--line); }
.expense-editor { padding: 14px; border: 1px dashed #afc8c7; border-radius: 12px; background: var(--surface-soft); }
.expense-editor-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.expense-editor-head strong { font-size: .9rem; }
.expense-row { display: grid; grid-template-columns: minmax(120px,1.4fr) minmax(110px,.8fr) minmax(100px,.8fr) auto; gap: 8px; margin-bottom: 8px; align-items: end; }
.expense-row input, .expense-row select { min-height: 42px; padding: 9px 10px; }
.expense-remove { width: 42px; height: 42px; border: 0; border-radius: 9px; background: var(--red-soft); color: var(--red); font-weight: 900; }
.bill-preview { margin-top: 12px; padding: 13px; border-radius: 10px; background: white; border: 1px solid var(--line); line-height: 1.7; font-size: .86rem; }
.bill-preview strong { color: var(--primary-dark); }
.finance-report { margin-bottom: 20px; }
.finance-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 16px; }
.finance-head h2 { margin: 2px 0 5px; }
.finance-head p:last-child { margin: 0; color: var(--muted); font-size: .84rem; }
.period-switch { display: flex; gap: 8px; }
.finance-breakdown { margin-top: 16px; }

.team-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 14px; }
.person-card { padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.person-card header { display: flex; align-items: center; gap: 11px; margin-bottom: 15px; }
.person-card h3 { margin: 0 0 3px; }
.person-card p { margin: 0; color: var(--muted); font-size: .8rem; }
.person-card footer { display: flex; justify-content: space-between; align-items: center; padding-top: 12px; border-top: 1px solid var(--line); }
.promoter-level { display: inline-flex; margin-top: 5px; width: fit-content; padding: 3px 8px; border-radius: 999px; font-size: .7rem; font-weight: 900; }
.promoter-level.silver { color: #46545e; background: #e9eef1; }
.promoter-level.gold { color: #7a5200; background: #fff0b8; }
.promoter-level.diamond { color: #155e75; background: #cffafe; }
.level-control { margin: 0 0 14px; }
.level-control select { min-height: 40px; padding: 8px 10px; }

.toast { position: fixed; top: 18px; left: 50%; transform: translate(-50%, -20px); z-index: 100; background: #18383a; color: white; border-radius: 10px; padding: 11px 16px; font-weight: 700; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--red); }
.mobile-nav { display: none; }

@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .team-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
}

@media (max-width: 760px) {
  .app { display: block; }
  .sidebar { display: none; }
  .topbar { min-height: 74px; padding: 12px 16px; }
  .topbar .eyebrow { display: none; }
  .topbar h1 { font-size: 1.25rem; }
  .top-actions .live-status { display: none; }
  .top-actions .secondary { display: inline-flex; min-height: 40px; padding: 8px 12px; }
  .top-actions .button.primary { display: none; }
  .content { padding: 16px 14px 88px; }
  .stats-grid { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; }
  .stat-card { min-height: 112px; padding: 15px; }
  .stat-card strong { font-size: 1.5rem; }
  .grid-two { grid-template-columns: 1fr; }
  .toolbar { flex-wrap: wrap; }
  .toolbar .search { min-width: 100%; }
  .toolbar select { flex: 1; min-width: 0; }
  .field-row, .field-row.three, .action-grid { grid-template-columns: 1fr; }
  .action-grid .full { grid-column: auto; }
  .form-card { padding: 18px; }
  .team-grid { grid-template-columns: 1fr; }
  .finance-head { align-items: stretch; flex-direction: column; }
  .period-switch .button { flex: 1; }
  .mobile-nav { position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; min-height: 66px; display: grid; grid-template-columns: repeat(5,1fr); align-items: center; background: rgba(255,255,255,.96); border-top: 1px solid var(--line); padding: 6px max(8px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); backdrop-filter: blur(12px); }
  .mobile-nav button { border: 0; background: transparent; color: var(--muted); font-size: .75rem; font-weight: 800; padding: 10px 4px; }
  .mobile-nav button.active { color: var(--primary); }
  .mobile-nav .mobile-add { width: 48px; height: 48px; justify-self: center; border-radius: 50%; background: var(--primary); color: white; font-size: 1.5rem; padding: 0; }
  .drawer { width: 100%; }
  .drawer-head, .drawer-content { padding-left: 16px; padding-right: 16px; }
  .drawer-head { gap: 9px; }
  .drawer-head .eyebrow { display: none; }
  .drawer-heading h2 { font-size: 1rem; }
  .drawer-back-button { padding: 8px 10px; }
  .order-summary { grid-template-columns: 1fr 1fr; gap: 9px; }
  .expense-row { grid-template-columns: 1fr 1fr; }
  .expense-row .expense-name { grid-column: 1 / -1; }
  .expense-remove { width: 100%; }
  .summary-box { padding: 11px; }
  .login-card { padding: 28px 22px; }
}

@media (max-width: 390px) {
  .stats-grid { grid-template-columns: 1fr; }
  .order-summary { grid-template-columns: 1fr; }
}
