:root {
  color-scheme: light;
  --paper: #f4f6f4;
  --card: #ffffff;
  --ink: #1f2b24;
  --muted: #667169;
  --line: #dde3df;
  --forest: #234b38;
  --forest-soft: #edf4ef;
  --sand: #eef1ee;
  --amber: #8b5a18;
  --danger: #9c3f38;
  --shadow: 0 3px 14px rgb(31 43 36 / 5%);
  --radius: 12px;
  --font-song: "SimSun", "Songti SC", "STSong", "Noto Serif CJK SC", serif;
  font-family: var(--font-song);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--paper); }
body { min-height: 100vh; margin: 0; background: var(--paper); color: var(--ink); }
body, button, input, select, textarea, option { font-family: var(--font-song) !important; }
button, input, select, textarea { font-size: inherit; }
button, label { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }

.topbar { position: sticky; top: 0; z-index: 20; border-bottom: 1px solid var(--line); background: rgb(255 255 255 / 96%); backdrop-filter: blur(12px); }
.topbar-inner { display: flex; max-width: 1240px; height: 70px; margin: auto; padding: 0 24px; align-items: center; justify-content: space-between; gap: 24px; }
.brand { display: flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; }
.brand-mark { display: grid; width: 42px; height: 42px; place-items: center; border-radius: 9px; background: var(--forest); color: white; font-family: var(--font-song); font-size: 19px; font-weight: 700; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 17px; letter-spacing: -.02em; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.nav { display: flex; gap: 3px; padding: 3px; border-radius: 9px; background: #eef2ef; }
.nav-button { border: 0; border-radius: 7px; background: transparent; padding: 8px 16px; color: var(--muted); cursor: pointer; font-size: 14px; font-weight: 600; white-space: nowrap; }
.nav-button:hover { color: var(--ink); }
.nav-button.active { background: white; color: var(--forest); box-shadow: 0 1px 5px rgb(31 43 36 / 10%); }
.header-actions { display: flex; align-items: center; gap: 2px; }
.mobile-nav { display: none; max-width: 1240px; margin: auto; padding: 0 16px 11px; gap: 3px; overflow-x: auto; }

.page-shell { width: min(1240px, calc(100% - 32px)); margin: auto; padding: 32px 0 64px; }
.view { display: none; }
.view.active { display: block; animation: enter .22s ease-out; }
@keyframes enter { from { opacity: 0; transform: translateY(4px); } }
.split { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.page-heading { margin-bottom: 24px; align-items: flex-end; }
.page-heading h1 { margin: 3px 0 7px; font-family: var(--font-song); font-size: clamp(29px, 4vw, 38px); letter-spacing: 0; line-height: 1.2; }
.page-heading p, .card-heading p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.7; }
.page-heading .eyebrow { color: var(--forest); font-weight: 700; }
.button-row { display: flex; align-items: center; gap: 8px; }
.button { display: inline-flex; min-height: 40px; align-items: center; justify-content: center; border: 1px solid transparent; border-radius: 8px; padding: 0 15px; cursor: pointer; font-size: 14px; font-weight: 700; text-decoration: none; transition: background-color .15s ease, border-color .15s ease; }
.button:hover { transform: none; }
.button:active { opacity: .82; }
.button.primary { background: var(--forest); color: white; box-shadow: none; }
.button.primary:hover { background: #294b3c; }
.button.secondary { border-color: var(--line); background: var(--card); }
.button.outline { border-color: var(--line); background: transparent; }
.button.ghost { background: transparent; color: var(--muted); }
.button.ghost:hover { background: #f1eadc; color: var(--ink); }
.button.small { min-height: 34px; padding: 0 11px; }
.button.compact { min-height: 34px; padding: 0 9px; font-size: 12px; }
.button:disabled { cursor: not-allowed; opacity: .5; transform: none; }
.icon-button { display: grid; width: 34px; height: 34px; place-items: center; border: 0; border-radius: 9px; background: transparent; color: var(--muted); cursor: pointer; font-size: 24px; }
.icon-button:hover { background: #f2ecdf; color: var(--ink); }

.metric-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.metric-card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); padding: 18px; box-shadow: var(--shadow); }
.metric-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 13px; font-weight: 600; }
.metric-icon { display: grid; width: 35px; height: 35px; place-items: center; border-radius: 8px; background: var(--forest-soft); color: var(--forest); font-weight: 800; }
.metric-value { display: block; margin-top: 15px; font-family: var(--font-song); font-size: 25px; letter-spacing: 0; font-variant-numeric: tabular-nums; }
.metric-note { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(300px, .9fr); gap: 18px; margin-bottom: 18px; }
.card { overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow); }
.card-heading { padding: 19px 20px 17px; }
.card-heading h2 { margin: 0 0 4px; font-family: var(--font-song); font-size: 18px; }

.month-card { display: flex; min-height: 330px; flex-direction: column; border-radius: var(--radius); background: var(--forest); padding: 22px; color: white; box-shadow: var(--shadow); }
.month-card-top { display: flex; align-items: center; justify-content: space-between; }
.month-icon { display: grid; width: 44px; height: 44px; place-items: center; border-radius: 9px; background: rgb(255 255 255 / 10%); font-family: var(--font-song); font-size: 20px; }
.month-card input { width: 142px; height: 36px; border: 1px solid rgb(255 255 255 / 18%); border-radius: 9px; background: rgb(255 255 255 / 8%); padding: 0 10px; color: white; color-scheme: dark; }
.month-kicker { margin: 38px 0 5px; color: rgb(255 255 255 / 62%); font-size: 13px; }
.month-profit { font-family: var(--font-song); font-size: 32px; letter-spacing: 0; }
.month-help { margin: 8px 0 0; color: rgb(255 255 255 / 62%); font-size: 12px; line-height: 1.6; }
.month-breakdown { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: auto; border-top: 1px solid rgb(255 255 255 / 10%); padding-top: 18px; }
.month-breakdown span, .month-breakdown strong { display: block; }
.month-breakdown span { color: rgb(255 255 255 / 56%); font-size: 12px; }
.month-breakdown strong { margin-top: 5px; font-size: 16px; font-variant-numeric: tabular-nums; }

.table-wrap { overflow-x: auto; border-top: 1px solid var(--line); }
table { width: 100%; min-width: 650px; border-collapse: collapse; text-align: left; font-size: 13px; }
th { background: #faf6ee; padding: 11px 16px; color: var(--muted); font-size: 11px; font-weight: 600; white-space: nowrap; }
td { border-top: 1px solid #eee7db; padding: 13px 16px; font-variant-numeric: tabular-nums; }
tbody tr:first-child td { border-top: 0; }
td.name { font-weight: 700; }
.text-right { text-align: right; }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 4px 9px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.badge.good, .badge.sale { background: #eaf4e7; color: #3e6e35; }
.badge.low { background: #fff0dd; color: var(--amber); }
.badge.purchase { background: #e7f0ff; color: #315c9b; }
.delete-button { border: 0; border-radius: 8px; background: transparent; padding: 6px 8px; color: var(--muted); cursor: pointer; font-size: 12px; }
.delete-button:hover { background: #fff0ee; color: var(--danger); }
.empty { display: grid; min-height: 215px; place-items: center; border-top: 1px solid var(--line); padding: 36px 20px; text-align: center; }
.empty-mark { display: grid; width: 48px; height: 48px; margin: auto; place-items: center; border-radius: 16px; background: var(--forest-soft); color: var(--forest); font-size: 20px; }
.empty h3 { margin: 13px 0 4px; font-family: var(--font-song); font-size: 16px; }
.empty p { max-width: 360px; margin: 0 auto; color: var(--muted); font-size: 12px; line-height: 1.7; }
.empty .button { margin-top: 13px; }
.month-input { height: 40px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); padding: 0 11px; color: var(--ink); }

.dialog { width: min(520px, calc(100% - 28px)); max-height: calc(100vh - 32px); overflow: auto; border: 0; border-radius: 18px; background: var(--card); padding: 0; color: var(--ink); box-shadow: 0 24px 80px rgb(25 35 28 / 22%); }
.dialog::backdrop { background: rgb(20 24 21 / 28%); backdrop-filter: blur(3px); }
.dialog form { padding: 20px; }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.dialog-heading h2 { margin: 1px 0 5px; font-family: var(--font-song); font-size: 21px; }
.dialog-heading p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.65; }
.form-fields { display: grid; gap: 15px; margin-top: 22px; }
.field { display: grid; gap: 7px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.field label { font-size: 12px; font-weight: 700; }
.field input, .field select, .field textarea { width: 100%; min-height: 40px; border: 1px solid var(--line); border-radius: 10px; background: white; padding: 8px 11px; color: var(--ink); outline: 0; transition: .15s; }
.field textarea { min-height: 82px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: #6c8b79; box-shadow: 0 0 0 3px rgb(58 98 75 / 10%); }
.form-error { min-height: 18px; margin: 10px 0 0; color: var(--danger); font-size: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin: 5px -20px -20px; border-top: 1px solid var(--line); background: #faf6ee; padding: 14px 20px; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 40; max-width: min(360px, calc(100% - 40px)); border-radius: 12px; background: var(--forest); padding: 12px 16px; color: white; box-shadow: 0 12px 35px rgb(32 60 47 / 25%); font-size: 13px; font-weight: 700; opacity: 0; pointer-events: none; transform: translateY(10px); transition: .22s ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }
.auth-pending .topbar, .auth-pending .page-shell, .auth-pending .connection-banner { display: none; }
.auth-screen { display: grid; min-height: 100vh; place-items: center; padding: 24px; background: radial-gradient(circle at 10% 12%, rgb(32 60 47 / 10%), transparent 34%), radial-gradient(circle at 90% 88%, rgb(160 84 0 / 8%), transparent 32%), var(--paper); }
.auth-card { width: min(430px, 100%); border: 1px solid var(--line); border-radius: 24px; background: rgb(255 253 248 / 96%); padding: 32px; box-shadow: 0 24px 70px rgb(61 49 31 / 12%); }
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 36px; }
.auth-brand strong, .auth-brand small { display: block; }
.auth-brand strong { font-size: 17px; }
.auth-brand small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.auth-card h1 { margin: 5px 0 8px; font-family: var(--font-song); font-size: 32px; letter-spacing: 0; }
.auth-card .eyebrow { margin: 0; color: var(--forest); font-size: 13px; font-weight: 700; }
.auth-description { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.7; }
.login-form { display: grid; gap: 15px; margin-top: 25px; }
.auth-submit { width: 100%; min-height: 44px; margin-top: 2px; }
.auth-help { margin: 18px 0 0; color: var(--muted); font-size: 11px; text-align: center; }
.sync-status { display: inline-flex; align-items: center; gap: 6px; padding: 0 8px; color: #477157; font-size: 11px; font-weight: 700; white-space: nowrap; }
.sync-status i { width: 7px; height: 7px; border-radius: 999px; background: #4d8d5d; box-shadow: 0 0 0 3px rgb(77 141 93 / 12%); }
.sync-status.syncing { color: var(--amber); }
.sync-status.syncing i { background: #c47a19; animation: pulse 1s infinite; }
.sync-status.error { color: var(--danger); }
.sync-status.error i { background: var(--danger); }
.user-email { max-width: 150px; overflow: hidden; padding: 0 6px; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.connection-banner { border-bottom: 1px solid #f1c5bf; background: #fff0ee; padding: 10px 18px; color: #9b352a; font-size: 12px; font-weight: 700; text-align: center; }
@keyframes pulse { 50% { opacity: .4; } }

@media (max-width: 1080px) {
  .user-email { display: none; }
  .sync-status span { display: none; }
}

@media (max-width: 900px) {
  .nav { display: none; }
  .mobile-nav { display: flex; }
  .topbar-inner { height: 64px; padding: 0 16px; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .month-card { min-height: 290px; }
}

@media (max-width: 620px) {
  .page-shell { width: min(100% - 24px, 1240px); padding-top: 22px; }
  .brand small { display: none; }
  #exportButton, #userEmail { display: none; }
  .auth-card { padding: 26px 22px; }
  .auth-brand { margin-bottom: 28px; }
  .page-heading.split { align-items: stretch; flex-direction: column; }
  .button-row { width: 100%; flex-wrap: wrap; }
  .button-row .button { flex: 1; }
  .button-row .month-input { width: 100%; }
  .metric-grid { grid-template-columns: 1fr; gap: 10px; }
  .metric-card { padding: 16px; }
  .card-heading.split { align-items: flex-start; }
  .field-row { grid-template-columns: 1fr; }
  .dialog-actions .button { flex: 1; }
}

/* 商品图片与移动端操作面板 */
button, .button, .nav-button, label[for] { touch-action: manipulation; }
.product-cell { display: flex; align-items: center; gap: 11px; min-width: 150px; }
.product-cell .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.product-thumb { display: grid; flex: 0 0 auto; place-items: center; overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: var(--forest-soft); color: var(--forest); font-family: var(--font-song); font-weight: 800; }
.product-thumb img { width: 100%; height: 100%; object-fit: cover; }
.product-thumb.tiny { width: 34px; height: 34px; border-radius: 9px; font-size: 12px; }
.product-thumb.small { width: 46px; height: 46px; font-size: 15px; }
.product-thumb.large { width: 78px; height: 78px; border-radius: 15px; font-size: 22px; }
.product-thumb.placeholder { background: linear-gradient(145deg, #eef4eb, #e1eadf); }
.row-actions { white-space: nowrap; }
.edit-button { border: 0; border-radius: 8px; background: transparent; padding: 6px 8px; color: var(--forest); cursor: pointer; font-size: 12px; font-weight: 700; }
.edit-button:hover { background: var(--forest-soft); }
.mobile-records { display: none; }
.mobile-action-bar { display: none; }
.image-field { display: grid; gap: 9px; }
.image-field > label { font-size: 12px; font-weight: 700; }
.image-field-row { display: flex; align-items: center; gap: 14px; }
.image-picker { display: grid; width: 104px; height: 104px; flex: 0 0 auto; place-items: center; overflow: hidden; border: 1px dashed #acb8ac; border-radius: 16px; background: #f3f6f1; color: var(--forest); cursor: pointer; }
.image-picker > span, .image-picker img { width: 100%; height: 100%; }
.image-picker > span { display: grid; place-items: center; font-size: 25px; font-weight: 400; text-align: center; }
.image-picker span small { display: block; margin-top: -24px; font-size: 10px; font-weight: 700; }
.image-picker img { object-fit: cover; }
.image-field-row > div { min-width: 0; }
.image-field-row p { margin: 8px 0 0; color: var(--muted); font-size: 10px; line-height: 1.5; }
.image-remove { display: block; margin-top: 8px; border: 0; background: transparent; padding: 0; color: var(--danger); cursor: pointer; font-size: 11px; }
.dialog-empty { min-height: 150px; border: 0; }

@media (max-width: 700px) {
  :root { --radius: 12px; }
  html { background: var(--paper); }
  body { padding-bottom: calc(82px + env(safe-area-inset-bottom)); background: var(--paper); }
  .topbar { box-shadow: none; }
  .topbar-inner { height: 58px; padding: 0 14px; gap: 10px; }
  .brand { gap: 8px; }
  .brand-mark { width: 36px; height: 36px; border-radius: 11px; font-size: 16px; }
  .brand strong { font-size: 16px; }
  .header-actions { margin-left: auto; }
  .header-actions #exportButton, .header-actions label[for="importFile"] { display: none; }
  .sync-status { padding: 0 2px; }
  .mobile-nav { display: grid; grid-template-columns: repeat(3, 1fr); padding: 0 12px 9px; gap: 5px; }
  .mobile-nav .nav-button { width: 100%; padding: 8px 5px; }
  .page-shell { width: min(100% - 24px, 1240px); padding: 20px 0 28px; }
  .page-heading { margin-bottom: 18px; }
  .page-heading h1 { margin-top: 2px; font-size: 27px; }
  .page-heading p { line-height: 1.55; }
  .page-heading > div > p:last-child:not(.eyebrow) { display: none; }
  .page-heading .button-row .button { display: none; }
  .page-heading .button-row { width: 100%; }
  .button-row .month-input { width: 100%; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
  .metric-card { min-width: 0; padding: 14px; border-radius: 12px; box-shadow: none; }
  .metric-top { gap: 5px; font-size: 11px; }
  .metric-icon { width: 29px; height: 29px; border-radius: 7px; font-size: 11px; }
  .metric-value { overflow: hidden; margin-top: 10px; font-size: clamp(19px, 5.6vw, 24px); text-overflow: ellipsis; white-space: nowrap; }
  .metric-note { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .dashboard-grid { gap: 12px; margin-bottom: 12px; }
  .card { border-color: var(--line); box-shadow: none; }
  .card-heading { padding: 16px 15px 13px; }
  .card-heading h2 { font-size: 17px; }
  .card-heading .button { min-height: 34px; padding: 0 10px; }
  .month-card { min-height: 250px; padding: 19px; }
  .month-kicker { margin-top: 28px; }
  .month-profit { font-size: 30px; }
  .desktop-table { display: none; }
  .mobile-records { display: block; border-top: 1px solid var(--line); }
  .mobile-record { display: flex; align-items: flex-start; gap: 12px; padding: 14px; border-bottom: 1px solid var(--line); background: var(--card); }
  .mobile-record:last-child { border-bottom: 0; }
  .mobile-record-main { min-width: 0; flex: 1; }
  .mobile-record-title { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
  .mobile-record-title strong { overflow: hidden; padding-top: 2px; font-size: 15px; line-height: 1.35; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-record p { margin: 6px 0 0; color: var(--muted); font-size: 11px; }
  .mobile-record p b { color: var(--ink); font-size: 13px; }
  .price-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 9px; }
  .price-pair span { min-width: 0; border-radius: 6px; background: #f3f6f4; padding: 6px 7px; color: var(--muted); font-size: 10px; }
  .price-pair b { display: block; overflow: hidden; margin-top: 2px; color: var(--ink); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-record-actions { display: flex; gap: 12px; margin-top: 10px; }
  .mobile-record-actions button { border: 0; background: transparent; padding: 3px 0; color: var(--forest); font-size: 11px; font-weight: 700; }
  .mobile-record-actions button.danger { color: var(--danger); }
  .transaction-record .mobile-record-title strong { max-width: 72%; }
  .transaction-equation { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-top: 9px; }
  .transaction-equation span { color: var(--muted); font-size: 11px; }
  .transaction-equation b { color: var(--ink); font-size: 16px; white-space: nowrap; }
  .mobile-action-bar { position: fixed; right: 0; bottom: 0; left: 0; z-index: 25; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; border-top: 1px solid var(--line); background: rgb(255 255 255 / 96%); padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); box-shadow: 0 -3px 12px rgb(31 43 36 / 5%); backdrop-filter: blur(12px); }
  .mobile-action-bar .button { min-height: 48px; border-radius: 9px; font-size: 15px; }
  .mobile-action-bar .button span { margin-right: 7px; font-size: 18px; }
  .toast { right: 12px; bottom: calc(78px + env(safe-area-inset-bottom)); left: 12px; max-width: none; text-align: center; }
  .dialog { position: fixed; inset: auto 0 0; width: 100%; max-width: none; max-height: min(90dvh, 760px); margin: 0; border-radius: 18px 18px 0 0; }
  .dialog form { padding: 20px 18px 0; }
  .dialog-heading { position: sticky; top: -20px; z-index: 2; margin: -20px -18px 0; background: var(--card); padding: 20px 18px 12px; }
  .dialog-heading h2 { font-size: 22px; }
  .form-fields { gap: 14px; margin-top: 15px; }
  .field input, .field select, .field textarea { min-height: 48px; border-radius: 8px; padding: 10px 12px; font-size: 16px; }
  .field textarea { min-height: 76px; }
  .field-row { grid-template-columns: 1fr 1fr; gap: 10px; }
  .dialog-actions { position: sticky; bottom: 0; margin: 8px -18px 0; padding: 12px 18px calc(12px + env(safe-area-inset-bottom)); }
  .dialog-actions .button { min-height: 48px; border-radius: 8px; font-size: 15px; }
  .image-picker { width: 92px; height: 92px; }
  .empty { min-height: 180px; }
}

@media (max-width: 390px) {
  .page-shell { width: min(100% - 18px, 1240px); }
  .metric-card { padding: 12px; }
  .field-row { grid-template-columns: 1fr; }
  .product-thumb.large { width: 70px; height: 70px; }
  .mobile-record { gap: 10px; padding: 12px; }
}
