:root {
  --ink: #1f211f;
  --ink-soft: #343632;
  --gold: #b98942;
  --gold-light: #e4c792;
  --cream: #f5f2eb;
  --paper: #fffdf8;
  --line: #e5ded1;
  --muted: #77776f;
  --success: #2e775e;
  --warning: #b8782e;
  --danger: #b44e45;
  --shadow: 0 18px 45px rgba(31, 33, 31, .08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--cream);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--cream); }
body { overflow-x: hidden; }
body, h1, h2, h3, p, td, th { text-wrap: pretty; }
button, input, select, textarea { font: inherit; }
button, a, input, select, textarea { min-height: 44px; }
button { cursor: pointer; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--gold-light); outline-offset: 2px; }
a { color: inherit; }

.boot-state, .login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.boot-state { color: var(--muted); gap: 12px; align-content: center; }
.boot-state p { margin: 0; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--gold); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.login-card { width: min(100%, 430px); background: var(--paper); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow); overflow: hidden; }
.login-visual { min-height: 180px; padding: 28px; display: flex; flex-direction: column; justify-content: flex-end; color: #fff; background: linear-gradient(180deg, rgba(31,33,31,.08), rgba(31,33,31,.86)), url('/jinxiuhaichao-gate.jpg') center/cover; }
.login-visual h1 { margin: 0 0 8px; font-size: 27px; letter-spacing: .08em; }
.login-visual p { margin: 0; color: #e9e4da; font-size: 13px; }
.login-form { padding: 28px; }
.login-form h2 { margin: 0 0 22px; font-size: 20px; }

.field { display: grid; gap: 7px; margin: 0 0 16px; }
.field label, .field legend { font-size: 13px; font-weight: 700; color: var(--ink-soft); }
.field input, .field select, .field textarea { width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 11px 13px; background: #fff; color: var(--ink); }
.field textarea { min-height: 92px; resize: vertical; }
.field input:disabled, .field select:disabled, .field textarea:disabled { color: #999; background: #f0ede6; cursor: not-allowed; }
.field small { color: var(--muted); font-weight: 400; }
.grid-2 { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
.grid-3 { display: grid; gap: 12px; grid-template-columns: repeat(3, 1fr); }

.btn { border: 1px solid transparent; border-radius: 12px; padding: 10px 16px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; font-weight: 700; transition: transform .15s ease, background .15s ease, border-color .15s ease; }
.btn:active { transform: translateY(1px); }
.btn-primary { color: #fff; background: var(--ink); }
.btn-primary:hover { background: #2c302c; }
.btn-gold { color: #fff; background: var(--gold); }
.btn-secondary { color: var(--ink); background: transparent; border-color: var(--line); }
.btn-danger { color: #fff; background: var(--danger); }
.btn-block { width: 100%; }
.btn-sm { min-height: 38px; padding: 7px 11px; font-size: 13px; }
.btn:disabled { opacity: .48; cursor: not-allowed; transform: none; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.form-actions .btn { flex: 1 1 150px; }

.app-shell { min-height: 100vh; padding-bottom: 82px; }
.topbar { position: sticky; top: 0; z-index: 10; color: #fff; background: rgba(31,33,31,.96); border-bottom: 1px solid rgba(255,255,255,.1); backdrop-filter: blur(16px); }
.topbar-inner { width: min(100%, 1240px); margin: 0 auto; padding: max(14px, env(safe-area-inset-top)) 18px 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand-lockup { display: flex; gap: 10px; align-items: center; min-width: 0; }
.brand-mark { width: 38px; height: 38px; border-radius: 12px; object-fit: cover; border: 1px solid rgba(255,255,255,.28); }
.brand-lockup strong { display: block; font-size: 15px; letter-spacing: .1em; white-space: nowrap; }
.brand-lockup span { display: block; color: #c7c6bc; font-size: 11px; margin-top: 3px; }
.user-actions { display: flex; gap: 8px; align-items: center; }
.role-chip { padding: 6px 9px; border-radius: 999px; font-size: 11px; color: var(--gold-light); border: 1px solid rgba(228,199,146,.45); white-space: nowrap; }
.icon-btn { border: 1px solid rgba(255,255,255,.18); border-radius: 10px; color: #fff; background: transparent; padding: 6px 10px; min-height: 40px; }

.main { width: min(100%, 1240px); margin: 0 auto; padding: 18px; }
.hero { min-height: 180px; padding: 22px; margin-bottom: 16px; border-radius: 20px; color: #fff; background: linear-gradient(105deg, rgba(31,33,31,.95) 20%, rgba(31,33,31,.54)), url('/jinxiuhaichao-gate.jpg') center 56%/cover; display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; }
.hero h1 { margin: 0 0 6px; font-size: clamp(22px, 5vw, 34px); letter-spacing: .04em; }
.hero p { margin: 0; color: #dedbd1; font-size: 13px; }
.demo-notice { padding: 10px 12px; color: #73551e; background: #fff4d6; border: 1px solid #e8d4a2; border-radius: 12px; font-size: 12px; line-height: 1.5; }
.hero .demo-notice { max-width: 260px; background: rgba(255,244,214,.92); }
.view-title { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin: 4px 0 16px; }
.view-title h2 { margin: 0; font-size: 22px; }
.view-title p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }

.kpi-grid { display: grid; gap: 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 16px; }
.kpi-card { min-height: 108px; padding: 15px; border: 1px solid var(--line); border-radius: 16px; background: var(--paper); box-shadow: 0 6px 18px rgba(31,33,31,.03); }
.kpi-card .kpi-label { color: var(--muted); font-size: 12px; }
.kpi-card strong { display: block; margin-top: 9px; font-size: 27px; font-weight: 760; letter-spacing: -.03em; }
.kpi-card em { color: var(--success); font-style: normal; font-size: 11px; }
.section-card { margin-bottom: 16px; padding: 17px; background: var(--paper); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 6px 18px rgba(31,33,31,.03); }
.section-card h3 { margin: 0 0 14px; font-size: 16px; }
.section-card h3 small { color: var(--muted); font-size: 11px; font-weight: 400; }
.two-col { display: grid; gap: 16px; }
.bar-list { display: grid; gap: 11px; }
.bar-row { display: grid; grid-template-columns: 70px 1fr 42px; align-items: center; gap: 8px; font-size: 12px; }
.bar-row .track { height: 8px; overflow: hidden; border-radius: 99px; background: #ebe5d9; }
.bar-row .track i { display: block; height: 100%; border-radius: inherit; background: var(--gold); }
.bar-row b { text-align: right; font-weight: 700; }
.metric-line { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.metric-line:last-child { border-bottom: 0; }
.metric-line strong { color: var(--ink); }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 620px; }
th, td { padding: 11px 9px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: 11px; white-space: nowrap; }
td strong { display: block; }
td small { color: var(--muted); }

.filter-bar { display: grid; gap: 10px; padding: 13px; margin-bottom: 14px; background: var(--paper); border: 1px solid var(--line); border-radius: 16px; }
.filter-bar .field { margin: 0; }
.customer-list { display: grid; gap: 10px; }
.customer-card { padding: 15px; border: 1px solid var(--line); border-radius: 16px; background: var(--paper); display: grid; gap: 11px; }
.customer-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.customer-card-head strong { font-size: 16px; }
.customer-card-head small { display: block; color: var(--muted); margin-top: 4px; }
.customer-meta { display: flex; flex-wrap: wrap; gap: 7px; color: var(--muted); font-size: 12px; }
.pill { display: inline-flex; align-items: center; min-height: 27px; padding: 4px 8px; border-radius: 99px; color: var(--ink-soft); background: #ece9e1; font-size: 11px; }
.pill-gold { color: #74551e; background: #f4e5c1; }
.pill-success { color: #205d49; background: #dceee6; }
.pill-danger { color: #8c3b36; background: #f5dfdc; }
.empty-state, .error-state, .permission-state { padding: 34px 18px; text-align: center; border: 1px dashed var(--line); border-radius: 16px; color: var(--muted); background: rgba(255,253,248,.64); }
.empty-state strong, .error-state strong, .permission-state strong { display: block; color: var(--ink); margin-bottom: 6px; }
.error-state { color: var(--danger); border-color: #e6bdb9; }
.error-state strong { color: var(--danger); }
.pagination { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 16px 0; color: var(--muted); font-size: 12px; }

.stepper { display: flex; gap: 8px; margin-bottom: 16px; }
.step { flex: 1; height: 6px; border-radius: 99px; background: var(--line); }
.step.active { background: var(--gold); }
.quick-panel { max-width: 760px; }
.quick-help { padding: 12px; margin: 0 0 16px; border-radius: 12px; color: var(--ink-soft); background: #eeebe4; font-size: 13px; line-height: 1.6; }
.checkbox-row { display: flex; flex-wrap: wrap; gap: 8px; }
.checkbox-row label { min-height: 44px; display: inline-flex; align-items: center; gap: 6px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff; font-size: 12px; }
.checkbox-row input { min-height: auto; accent-color: var(--gold); }
.multi-field { min-width: 0; margin-top: 14px; border: 0; padding: 0; }
.multi-field legend { padding: 0; }
.choice-grid { display: grid; gap: 8px; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 8px; }
.choice-grid label { min-height: 44px; display: flex; align-items: center; gap: 7px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff; font-size: 12px; cursor: pointer; }
.choice-grid label:has(input:checked) { border-color: var(--gold); background: #fffaf0; }
.choice-grid input { flex: 0 0 auto; min-height: auto; accent-color: var(--gold); }
.field .choice-grid input[type="checkbox"] { width: 18px; height: 18px; min-height: 0; margin: 0; padding: 0; flex: 0 0 18px; }
.other-field { display: grid; gap: 6px; margin-top: 8px; color: var(--muted); font-size: 11px; }
.choice-hint { margin: 6px 0 0; color: var(--muted); font-size: 11px; }

.detail-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.detail-top h2 { margin: 0; font-size: 25px; }
.detail-top p { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.timeline { display: grid; gap: 0; }
.timeline-item { position: relative; padding: 0 0 18px 25px; border-left: 2px solid var(--line); }
.timeline-item:last-child { border-left-color: transparent; }
.timeline-item::before { content: ''; position: absolute; width: 9px; height: 9px; left: -6px; top: 3px; border: 2px solid var(--paper); border-radius: 50%; background: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
.timeline-item header { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 11px; }
.timeline-item strong { display: block; margin: 7px 0 5px; font-size: 14px; }
.timeline-item p { margin: 0; color: var(--ink-soft); font-size: 13px; line-height: 1.55; }
.dialog-panel { padding: 14px; margin-top: 14px; border: 1px solid var(--line); border-radius: 14px; background: #fbf8f1; }
.dialog-overlay { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 18px; background: rgba(31,33,31,.45); }
.dialog-overlay .dialog-panel { width: min(100%, 420px); margin-top: 0; box-shadow: 0 18px 50px rgba(31,33,31,.28); }
.ai-analysis-head { display: grid; gap: 10px; }
.ai-analysis-title-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-width: 0; }
.ai-analysis-title-row h3 { margin: 0; min-width: 0; }
.ai-analysis-badge { flex: 0 0 auto; padding: 4px 8px; border: 1px solid #e8d4a2; border-radius: 999px; color: #73551e; background: #fff4d6; font-size: 11px; line-height: 1.2; white-space: nowrap; }
.ai-analysis-description { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.ai-analysis-actions { width: 100%; }
.ai-analysis-primary { width: 100%; min-height: 46px; white-space: nowrap; }
.ai-analysis-meta { margin: -2px 0 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
.ai-analysis-status { margin: 12px 0 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.ai-analysis-metrics { display: grid; gap: 0; margin-top: 12px; }
.ai-analysis-summary { margin-top: 14px; padding: 12px; border-radius: 12px; background: #eeebe4; }
.ai-analysis-summary h4, .ai-analysis-item h4 { margin: 0 0 7px; font-size: 13px; }
.ai-analysis-summary p, .ai-analysis-item p { margin: 0; color: var(--ink-soft); font-size: 13px; line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; }
.ai-analysis-grid { display: grid; gap: 10px; margin-top: 12px; }
.ai-analysis-item { min-width: 0; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.ai-list { margin: 0; padding-left: 18px; color: var(--ink-soft); font-size: 13px; line-height: 1.65; }
.ai-muted { color: var(--muted); font-size: 13px; }
.ai-analysis-notice { margin: 14px 0 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
.ai-analysis-telemetry { display: block; margin-top: 10px; color: var(--muted); font-size: 11px; }

.site-footer { padding: 4px 18px calc(78px + env(safe-area-inset-bottom)); color: var(--muted); font-size: 11px; line-height: 1.5; text-align: center; }
.site-footer a { display: inline-flex; align-items: center; min-height: 44px; text-decoration: none; }
.site-footer a:hover { color: var(--ink-soft); text-decoration: underline; }

.bottom-nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 15; padding: 8px max(10px, env(safe-area-inset-left)) max(8px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: rgba(255,253,248,.96); box-shadow: 0 -10px 30px rgba(31,33,31,.08); backdrop-filter: blur(14px); }
.bottom-nav-inner { width: min(100%, 760px); margin: 0 auto; display: grid; gap: 4px; grid-template-columns: repeat(4, 1fr); }
.nav-btn { min-height: 54px; padding: 6px 3px; border: 0; border-radius: 12px; color: var(--muted); background: transparent; display: grid; place-items: center; gap: 2px; font-size: 11px; }
.nav-btn .nav-icon { font-size: 18px; line-height: 1; }
.nav-btn.active { color: var(--gold); background: #f7f0e1; font-weight: 700; }

.toast { position: fixed; left: 50%; bottom: 92px; z-index: 30; width: min(calc(100% - 32px), 420px); padding: 12px 14px; transform: translateX(-50%); border-radius: 12px; color: #fff; background: var(--ink); box-shadow: var(--shadow); font-size: 13px; text-align: center; }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }
.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; }

@media (min-width: 640px) {
  .kpi-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .filter-bar { grid-template-columns: 2fr 1fr 1fr auto; align-items: end; }
  .two-col { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ai-analysis-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .main { padding: 24px; }
}
@media (min-width: 980px) {
  .app-shell { padding-bottom: 28px; }
  .site-footer { padding-bottom: 18px; }
  .bottom-nav { position: static; padding: 0 18px 24px; border-top: 0; box-shadow: none; background: transparent; }
  .bottom-nav-inner { width: min(100%, 1240px); padding: 0 18px; display: flex; justify-content: flex-start; gap: 8px; }
  .nav-btn { min-width: 108px; min-height: 44px; display: flex; justify-content: center; flex-direction: row; gap: 8px; }
}
@media (max-width: 420px) {
  .choice-grid { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
