:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #697386;
  --line: #e3e6eb;
  --surface: #ffffff;
  --canvas: #f5f6f8;
  --brand: #b4232d;
  --brand-dark: #861b24;
  --green: #19734c;
  --amber: #9b5a05;
  --red-soft: #fff1f2;
  --shadow: 0 8px 24px rgba(23, 32, 51, 0.08);
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; margin: 0; background: var(--canvas); color: var(--ink); }

body { min-width: 320px; letter-spacing: 0; }

button, input { font: inherit; letter-spacing: 0; }

button { cursor: pointer; }

[hidden] { display: none !important; }

.boot-screen {
  min-height: 100vh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  background: var(--surface);
}

.boot-screen img { border-radius: 8px; }
.boot-screen strong { font-size: 24px; }
.boot-screen span { color: var(--muted); }

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 20px;
  background:
    linear-gradient(110deg, rgba(180, 35, 45, 0.08), transparent 45%),
    var(--canvas);
}

.login-panel {
  width: min(440px, 100%);
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-brand { display: flex; align-items: center; gap: 16px; padding-bottom: 24px; border-bottom: 1px solid var(--line); }
.login-brand img { border-radius: 8px; object-fit: cover; }
.login-brand p, .login-brand h1 { margin: 0; }
.login-brand p { color: var(--muted); font-size: 14px; }
.login-brand h1 { margin-top: 4px; font-size: 26px; }
.login-copy { padding: 28px 0 22px; }
.login-copy h2 { margin: 0 0 8px; font-size: 22px; }
.login-copy p, .form-hint { margin: 0; color: var(--muted); line-height: 1.7; }

.primary-button, .secondary-button {
  width: 100%;
  min-height: 48px;
  border-radius: 6px;
  border: 1px solid var(--brand);
  padding: 0 18px;
  font-weight: 700;
}

.primary-button { background: var(--brand); color: white; }
.primary-button:hover { background: var(--brand-dark); }
.primary-button:disabled { opacity: 0.65; cursor: wait; }
.secondary-button { background: white; color: var(--brand); }
.secondary-button.compact { width: auto; min-height: 40px; }
.form-hint { margin-top: 14px; text-align: center; font-size: 13px; }
.login-panel footer { display: flex; justify-content: space-between; gap: 16px; margin-top: 26px; color: var(--muted); font-size: 12px; }

.app-root { min-height: 100vh; }
.app-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 30;
  width: 260px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.sidebar-brand { display: flex; align-items: center; gap: 12px; min-height: 92px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.sidebar-brand img { border-radius: 6px; object-fit: cover; }
.sidebar-brand div { min-width: 0; }
.sidebar-brand strong, .sidebar-brand span { display: block; }
.sidebar-brand strong { font-size: 18px; }
.sidebar-brand span { margin-top: 3px; color: var(--muted); font-size: 12px; }
.drawer-close { display: none; margin-left: auto; }

.primary-navigation { flex: 1; display: grid; align-content: start; gap: 6px; padding: 20px 12px; }
.navigation-item {
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  text-align: left;
}
.navigation-item:hover { background: #f4f5f7; }
.navigation-item.is-active { background: var(--red-soft); color: var(--brand); font-weight: 700; }
.navigation-item > span:first-child { width: 22px; text-align: center; font-size: 20px; }

.sidebar-user { display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 10px; padding: 16px; border-top: 1px solid var(--line); }
.sidebar-user img, .identity-chip img { border-radius: 50%; object-fit: cover; }
.sidebar-user div { min-width: 0; }
.sidebar-user strong, .sidebar-user span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user span { color: var(--muted); font-size: 12px; margin-top: 3px; }
.text-button { border: 0; background: transparent; color: var(--brand); font-size: 13px; }

.app-content { min-height: 100vh; margin-left: 260px; padding: 0 32px 24px; }
.desktop-header { min-height: 92px; display: flex; align-items: center; justify-content: space-between; gap: 24px; border-bottom: 1px solid var(--line); }
.desktop-header p, .desktop-header h1 { margin: 0; }
.desktop-header p { color: var(--brand); font-size: 13px; font-weight: 700; }
.desktop-header h1 { margin-top: 4px; font-size: 24px; }
.header-actions { display: flex; align-items: center; gap: 14px; }
.identity-chip { display: flex; align-items: center; gap: 10px; }
.identity-chip strong, .identity-chip small { display: block; }
.identity-chip small { color: var(--muted); margin-top: 2px; }

.page-panel { width: min(1180px, 100%); margin: 0 auto; padding: 28px 0 12px; }
.owner-dashboard { padding-top: 24px; }
.owner-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; padding: 12px 0 22px; }
.owner-heading p, .owner-heading h2 { margin: 0; }
.owner-heading p { color: var(--brand); font-size: 13px; font-weight: 700; }
.owner-heading h2 { margin-top: 7px; font-size: 32px; line-height: 1.3; }
.data-time { display: block; margin-top: 9px; color: var(--muted); font-size: 13px; }
.read-only-badge { flex: 0 0 auto; padding: 7px 11px; border: 1px solid #c8d7ce; border-radius: 999px; background: #edf7f1; color: var(--green); font-size: 12px; font-weight: 700; }
.current-state-message { margin-bottom: 26px; padding: 14px 16px; border: 1px solid #eed28d; border-radius: 6px; background: #fff8e7; color: #714800; font-weight: 700; }
.current-state-message[data-state="ready"] { border-color: #b9d9c7; background: #edf7f1; color: var(--green); }
.dashboard-section { padding: 26px 0; border-top: 1px solid var(--line); }
.dashboard-section.priority-section { padding-top: 4px; border-top: 0; }
.dashboard-section-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 16px; }
.dashboard-section-heading p, .dashboard-section-heading h3 { margin: 0; }
.dashboard-section-heading p { color: var(--brand); font-size: 12px; font-weight: 700; }
.dashboard-section-heading h3 { margin-top: 4px; font-size: 22px; }
.dashboard-section-heading > span { color: var(--muted); font-size: 13px; }
.metric-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.decision-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.metric-card { min-height: 142px; padding: 18px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: 0 2px 10px rgba(23, 32, 51, 0.03); }
.metric-label, .metric-value, .metric-source { display: block; }
.metric-label { color: var(--muted); font-size: 13px; }
.metric-value { margin-top: 17px; font-size: 23px; line-height: 1.25; }
.metric-source { margin-top: 11px; color: var(--muted); line-height: 1.5; }
.metric-card[data-state="not-initialized"] .metric-value { color: var(--amber); font-size: 18px; }
.decision-grid .metric-card[data-state="current"] .metric-value { color: var(--brand); }

.sales-workspace { padding-top: 24px; }
.sales-section-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 22px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.sales-tab { min-height: 42px; padding: 0 17px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); font: inherit; cursor: pointer; }
.sales-tab.is-active { border-color: var(--brand); background: var(--red-soft); color: var(--brand); font-weight: 700; }
.sales-section { display: grid; gap: 18px; }
.sales-summary-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.record-list { display: grid; gap: 10px; }
.record-card { padding: 16px 18px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.record-card p { margin: 8px 0; color: var(--muted); line-height: 1.6; }
.record-card small { color: var(--muted); }
.record-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.record-actions { display: flex; gap: 8px; margin-top: 12px; }
.compact-empty { padding: 24px; }
.business-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; padding: 20px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.business-form label { display: grid; gap: 7px; color: var(--muted); font-size: 14px; font-weight: 600; }
.business-form input, .business-form select, .business-form textarea { width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid #cfd4dc; border-radius: 6px; background: white; color: var(--ink); font: inherit; }
.business-form textarea { resize: vertical; }
.business-form input:focus, .business-form select:focus, .business-form textarea:focus { border-color: var(--brand); outline: 2px solid rgba(210, 43, 44, 0.12); }
.form-span { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; }
.welcome-block { padding: 26px 0 8px; }
.welcome-block p, .welcome-block h2, .welcome-block span { margin: 0; }
.welcome-block p { color: var(--brand); font-size: 13px; font-weight: 700; }
.welcome-block h2 { margin-top: 8px; font-size: clamp(24px, 3vw, 34px); }
.welcome-block > span { display: block; margin-top: 10px; color: var(--muted); }

.status-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin: 24px 0; }
.status-card, .content-section, .detail-list, .help-list article {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 2px 10px rgba(23, 32, 51, 0.03);
}
.status-card { min-height: 132px; padding: 20px; }
.status-card span, .status-card strong, .status-card small { display: block; }
.status-card span { color: var(--muted); font-size: 13px; }
.status-card strong { margin-top: 16px; font-size: 20px; }
.status-card small { margin-top: 8px; color: var(--muted); line-height: 1.5; }
.status-card strong[data-state="ready"] { color: var(--green); }
.status-card strong[data-state="error"] { color: var(--brand); }

.content-section { padding: 24px; }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.section-heading p, .section-heading h3 { margin: 0; }
.section-heading p { color: var(--muted); font-size: 13px; }
.section-heading h3 { margin-top: 5px; font-size: 22px; }
.status-badge { flex: 0 0 auto; padding: 6px 10px; border-radius: 999px; background: #e8f5ee; color: var(--green); font-size: 12px; font-weight: 700; }
.section-description { color: var(--muted); line-height: 1.7; }
.empty-state { margin-top: 20px; padding: 28px; border: 1px dashed #c8cdd5; border-radius: 6px; background: #fafbfc; text-align: center; }
.empty-state strong { font-size: 18px; }
.empty-state p { margin: 8px 0 0; color: var(--muted); line-height: 1.6; }

.page-title-block { margin: 6px 0 22px; }
.page-title-block p, .page-title-block h2 { margin: 0; }
.page-title-block p { color: var(--brand); font-size: 13px; font-weight: 700; }
.page-title-block h2 { margin-top: 6px; font-size: 28px; }
.detail-list { margin: 0; padding: 4px 24px; }
.detail-list div { display: grid; grid-template-columns: 160px 1fr; gap: 20px; padding: 18px 0; border-bottom: 1px solid var(--line); }
.detail-list div:last-child { border-bottom: 0; }
.detail-list dt { color: var(--muted); }
.detail-list dd { margin: 0; font-weight: 700; }
.message-box { margin-top: 18px; padding: 14px 16px; border-radius: 6px; line-height: 1.6; }
.info-message { border: 1px solid #b8d4ee; background: #eef6fd; color: #24577d; }
.error-message { border: 1px solid #efafb4; background: var(--red-soft); color: var(--brand-dark); }
.help-list { display: grid; gap: 12px; }
.help-list article { padding: 20px; }
.help-list strong { font-size: 17px; }
.help-list p { margin: 8px 0 0; color: var(--muted); line-height: 1.7; }
.inline-button { width: auto; margin-top: 20px; }
.app-footer { display: flex; justify-content: space-between; gap: 16px; width: min(1180px, 100%); margin: 28px auto 0; padding-top: 18px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }

.mobile-header { display: none; }
.drawer-backdrop { display: none; }
.icon-button { width: 44px; height: 44px; border: 0; background: transparent; color: var(--ink); font-size: 24px; }
.update-banner { display: flex; align-items: center; justify-content: center; gap: 16px; margin: 0 -32px; padding: 10px 18px; background: #fff4d8; color: #744204; }
.update-banner button { border: 0; background: transparent; color: var(--brand); font-weight: 700; }
.global-message { position: fixed; z-index: 100; left: 50%; bottom: 28px; transform: translateX(-50%); padding: 12px 18px; border-radius: 6px; background: #202633; color: white; box-shadow: var(--shadow); }

@media (max-width: 900px) {
  .mobile-header {
    position: sticky;
    inset: 0 0 auto;
    z-index: 20;
    min-height: calc(58px + env(safe-area-inset-top));
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) 44px;
    align-items: end;
    gap: 8px;
    padding: env(safe-area-inset-top) 8px 7px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.98);
  }
  .mobile-header > div { align-self: center; min-width: 0; text-align: center; }
  .mobile-header strong, .mobile-header span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-header strong { font-size: 16px; }
  .mobile-header span { margin-top: 2px; color: var(--muted); font-size: 11px; }
  .app-sidebar { width: min(84vw, 320px); transform: translateX(-102%); transition: transform 180ms ease; box-shadow: var(--shadow); }
  .app-sidebar.is-open { transform: translateX(0); }
  .drawer-close { display: inline-grid; place-items: center; }
  .drawer-backdrop { position: fixed; inset: 0; z-index: 25; display: block; border: 0; background: rgba(23, 32, 51, 0.42); }
  body.drawer-open { overflow: hidden; }
  .app-content { margin-left: 0; padding: 0 16px 20px; }
  .desktop-header { display: none; }
  .page-panel { padding-top: 18px; }
  .owner-dashboard { padding-top: 12px; }
  .owner-heading { display: block; padding: 4px 0 16px; }
  .owner-heading h2 { font-size: 25px; }
  .read-only-badge { display: inline-block; margin-top: 12px; }
  .current-state-message { margin: 4px 0 20px; }
  .dashboard-section { padding: 22px 0; }
  .dashboard-section-heading { display: block; margin-bottom: 13px; }
  .dashboard-section-heading > span { display: block; margin-top: 7px; line-height: 1.5; }
  .metric-grid, .decision-grid { grid-template-columns: 1fr; gap: 10px; }
  .sales-summary-grid { grid-template-columns: 1fr 1fr; }
  .sales-section-tabs { display: grid; grid-template-columns: 1fr 1fr; }
  .sales-tab { width: 100%; }
  .business-form { grid-template-columns: 1fr; padding: 16px; }
  .form-span { grid-column: auto; }
  .form-actions { position: sticky; bottom: 0; z-index: 2; margin: 0 -16px -16px; padding: 12px 16px; background: rgba(255,255,255,.96); border-top: 1px solid var(--line); }
  .form-actions > button { flex: 1; min-height: 48px; }
  .metric-card { min-height: 112px; padding: 17px; }
  .metric-value { margin-top: 10px; }
  .metric-source { margin-top: 7px; }
  .welcome-block { padding-top: 4px; }
  .welcome-block h2 { font-size: 25px; line-height: 1.35; }
  .status-grid { grid-template-columns: 1fr; gap: 10px; margin: 18px 0; }
  .status-card { min-height: 104px; padding: 17px; }
  .status-card strong { margin-top: 10px; }
  .content-section { padding: 18px; }
  .section-heading { display: block; }
  .status-badge { display: inline-block; margin-top: 12px; }
  .empty-state { padding: 22px 16px; }
  .detail-list { padding: 2px 18px; }
  .detail-list div { grid-template-columns: 1fr; gap: 7px; padding: 15px 0; }
  .primary-button, .secondary-button { min-height: 50px; }
  .inline-button { width: 100%; }
  .app-footer { padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
  .update-banner { margin: 0 -16px; }
}

@media (max-width: 520px) {
  .sales-summary-grid, .sales-section-tabs { grid-template-columns: 1fr; }
  .login-screen { padding: 0; align-items: stretch; background: var(--surface); }
  .login-panel { min-height: 100vh; padding: calc(28px + env(safe-area-inset-top)) 20px calc(20px + env(safe-area-inset-bottom)); border: 0; border-radius: 0; box-shadow: none; }
  .login-panel footer { margin-top: auto; padding-top: 32px; }
  .status-grid { grid-template-columns: 1fr; }
  .app-footer { flex-direction: column; gap: 5px; }
  .global-message { width: calc(100% - 32px); text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
