:root {
  color-scheme: light;
  --ink: #422006;
  --muted: #7c6657;
  --line: #f0dfcf;
  --paper: #fffdf9;
  --canvas: #fff8ef;
  --primary: #c2410c;
  --primary-dark: #9a3412;
  --primary-soft: #ffedd5;
  --accent: #f97316;
  --danger: #c2410c;
  --danger-soft: #fff0e6;
  --shadow: 0 16px 40px rgba(124, 45, 18, 0.09);
  --radius: 20px;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--canvas); }
body { margin: 0; min-width: 320px; color: var(--ink); background: radial-gradient(circle at 82% 4%, rgba(249, 115, 22, .14), transparent 24rem), var(--canvas); }
button, input, textarea, select { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 3px solid rgba(194, 65, 12, .24); outline-offset: 2px; }
[hidden] { display: none !important; }

.auth-shell { min-height: 100vh; padding: 40px 20px; display: grid; place-items: center; align-content: center; gap: 24px; }
.auth-brand { display: flex; align-items: center; gap: 12px; }
.auth-brand strong, .auth-brand small { display: block; }
.auth-brand strong { font-size: 23px; }
.auth-brand small { color: var(--muted); margin-top: 3px; }
.auth-card { width: min(480px, 100%); padding: 36px; background: rgba(255,253,249,.96); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow); }
.auth-card h1 { margin: 8px 0 10px; font-size: clamp(34px, 6vw, 46px); letter-spacing: -.04em; }
.auth-lead { color: var(--muted); line-height: 1.7; margin: 0 0 25px; }
.auth-form { display: grid; }
.auth-submit { width: 100%; min-height: 52px; margin-top: 4px; }
.auth-links { display: flex; justify-content: space-between; margin-top: 12px; }
.auth-back { justify-self: center; margin-top: 10px; }
.auth-terms { margin: 2px 0 18px; }
.auth-error { margin: 12px 0 0; font-size: 14px; }
.auth-status { text-align: center; justify-items: center; gap: 16px; }
.auth-status p { color: var(--muted); line-height: 1.7; margin: 0; }
.auth-status-icon { width: 60px; height: 60px; display: grid; place-items: center; border-radius: 20px; color: var(--primary); background: var(--primary-soft); font-size: 28px; }
.auth-footnote { color: var(--muted); font-size: 13px; text-align: center; margin: 0; }
.header-controls { display: flex; align-items: center; gap: 14px; }
.account-email { color: var(--muted); font-size: 13px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sync-status { color: var(--muted); font-size: 12px; white-space: nowrap; }

.app-shell { min-height: 100vh; }
.app-header { height: 76px; padding: 0 28px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid rgba(240, 223, 207, .9); background: rgba(255,253,249,.88); backdrop-filter: blur(14px); position: sticky; top: 0; z-index: 20; }
.brand { border: 0; background: none; display: inline-flex; gap: 12px; align-items: center; text-align: left; padding: 6px; cursor: pointer; }
.brand strong { display: block; font-size: 20px; letter-spacing: .02em; }
.brand small { display: block; color: var(--muted); margin-top: 2px; font-size: 12px; }
.brand-mark { width: 38px; height: 38px; border-radius: 12px; background: linear-gradient(145deg, #f97316, var(--primary)); display: grid; place-items: center; box-shadow: 0 8px 18px rgba(194,65,12,.22); }
.brand-mark::before, .brand-mark::after, .brand-mark span { content: ""; display: block; border: 2px solid #fff; border-radius: 999px; position: absolute; }
.brand-mark { position: relative; }
.brand-mark::before { width: 8px; height: 8px; }
.brand-mark::after { width: 18px; height: 18px; border-color: rgba(255,255,255,.7); border-left-color: transparent; border-bottom-color: transparent; transform: rotate(45deg); }
.brand-mark span { width: 27px; height: 27px; border-color: rgba(255,255,255,.38); border-left-color: transparent; border-bottom-color: transparent; transform: rotate(45deg); }

.workspace { display: grid; grid-template-columns: 224px minmax(0, 1fr); min-height: calc(100vh - 76px); }
.side-nav { padding: 30px 20px; border-right: 1px solid var(--line); display: flex; flex-direction: column; justify-content: space-between; background: rgba(255,250,244,.72); }
.nav-label { color: #94a09d; font-size: 11px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; margin: 0 12px 10px; }
.nav-item { width: 100%; min-height: 48px; border: 0; background: transparent; border-radius: 12px; padding: 0 14px; display: flex; align-items: center; gap: 12px; color: #53625f; cursor: pointer; margin-bottom: 5px; font-size: 15px; font-weight: 650; }
.nav-item span { width: 20px; font-size: 19px; color: #7c8d89; }
.nav-item:hover { background: #fff0e2; }
.nav-item.is-active { color: var(--primary-dark); background: var(--primary-soft); }
.nav-item.is-active span { color: var(--primary); }
.privacy-note { padding: 16px; border: 1px solid #f1dfcd; border-radius: 16px; background: #fffaf4; display: flex; gap: 10px; align-items: flex-start; }
.privacy-icon { color: var(--primary); font-size: 20px; }
.privacy-note strong { font-size: 12px; }
.privacy-note p { font-size: 11px; color: var(--muted); line-height: 1.5; margin: 3px 0 0; }
.privacy-link { border: 0; background: none; color: var(--primary); font-size: 12px; font-weight: 750; padding: 8px 0 0; cursor: pointer; text-align: left; text-decoration: underline; text-underline-offset: 3px; }

.main-content { width: 100%; max-width: 1320px; margin: 0 auto; padding: 42px 44px 80px; }
.view { animation: reveal .26s ease; }
@keyframes reveal { from { opacity: 0; transform: translateY(5px); } }
.page-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; margin-bottom: 28px; }
.page-heading.compact { align-items: flex-start; }
.page-heading h1 { font-size: clamp(35px, 3.8vw, 48px); line-height: 1.12; margin: 5px 0 9px; letter-spacing: -.04em; }
.page-heading p:not(.eyebrow) { color: var(--muted); margin: 0; font-size: 16px; line-height: 1.55; }
.eyebrow { color: var(--primary); font-weight: 800; letter-spacing: .09em; font-size: 11px; text-transform: uppercase; margin: 0; }
.back-link { border: 0; background: none; color: var(--primary); padding: 0; margin-bottom: 14px; cursor: pointer; }

.button { min-height: 46px; border-radius: 12px; padding: 0 20px; border: 1px solid transparent; font-size: 15px; font-weight: 750; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.button.primary { background: linear-gradient(135deg, #ea580c, var(--primary)); color: white; box-shadow: 0 7px 18px rgba(194,65,12,.2); }
.button.primary:hover { background: var(--primary-dark); }
.button.secondary { background: var(--primary-soft); color: var(--primary-dark); }
.button.quiet { background: white; border-color: var(--line); color: #3e4e4a; }
.text-button { border: 0; background: none; color: var(--primary); font-weight: 750; padding: 8px 0; cursor: pointer; }
.text-button span { margin-left: 6px; }
.text-button.small { font-size: 12px; }
.danger-text { color: var(--danger); margin-left: auto; }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.metric-card { background: rgba(255,253,249,.92); border: 1px solid var(--line); border-radius: 18px; padding: 19px; min-height: 124px; display: flex; flex-direction: column; justify-content: space-between; box-shadow: 0 5px 18px rgba(124,45,18,.035); }
.metric-card span { color: var(--muted); font-size: 13px; font-weight: 700; }
.metric-card strong { font-size: clamp(27px, 2.4vw, 35px); letter-spacing: -.04em; }
.metric-card small { color: #9a8270; font-size: 12px; line-height: 1.4; }
.metric-card.emphasis { border-color: #fed7aa; background: linear-gradient(145deg, #fffaf4, #ffedd5); }
.metric-card.emphasis strong { color: var(--primary-dark); }
.metric-card.danger strong { color: var(--danger); }

.content-grid { display: grid; grid-template-columns: minmax(0, 1fr) 310px; gap: 18px; align-items: start; }
.right-column { display: grid; gap: 18px; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.action-panel, .ledger-panel { overflow: hidden; }
.panel-heading { min-height: 65px; display: flex; align-items: center; justify-content: space-between; padding: 0 22px; border-bottom: 1px solid var(--line); }
.panel-heading > div { display: flex; align-items: center; gap: 10px; }
.panel-heading h2 { font-size: 18px; margin: 0; }
.pulse-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 5px rgba(240,162,77,.14); }
.count-badge { color: var(--muted); background: var(--canvas); padding: 5px 9px; border-radius: 999px; font-size: 11px; }
.focus-card { padding: 24px; background: linear-gradient(145deg, #c2410c, #f97316); color: white; overflow: hidden; position: relative; }
.focus-card::after { content: ""; position: absolute; width: 150px; height: 150px; border: 28px solid rgba(255,255,255,.10); border-radius: 50%; right: -72px; top: -72px; }
.focus-card .eyebrow { color: #ffedd5; }
.focus-card h2 { font-size: 25px; line-height: 1.3; margin: 8px 0 12px; position: relative; z-index: 1; }
.focus-card > p:not(.eyebrow) { color: rgba(255,255,255,.8); line-height: 1.7; font-size: 15px; }
.focus-card .text-button { color: #fff7ed; margin-top: 7px; }
.data-card { padding: 20px; text-align: center; background: #fffaf4; }
.data-card > div { display: flex; gap: 12px; text-align: left; align-items: center; margin-bottom: 16px; }
.data-card p { margin: 3px 0 0; color: var(--muted); font-size: 11px; }
.data-icon { width: 38px; height: 38px; border-radius: 11px; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-size: 19px; }
.data-card .button { width: 100%; }
.data-privacy-link { display: block; margin: 4px auto 0; text-align: center; }

.record-list { display: grid; }
.receivable-card { border-bottom: 1px solid #edf1ef; position: relative; }
.receivable-card:last-child { border-bottom: 0; }
.receivable-card::before { content: ""; position: absolute; left: 0; top: 17px; bottom: 17px; width: 3px; border-radius: 0 3px 3px 0; background: #b7d6cb; opacity: 0; }
.receivable-card.is-overdue::before { background: var(--danger); opacity: 1; }
.card-open { width: 100%; border: 0; background: var(--paper); padding: 19px 22px; display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(120px, .8fr); text-align: left; gap: 6px 18px; cursor: pointer; }
.card-open:hover { background: #fff7ef; }
.card-topline { display: flex; gap: 9px; align-items: center; min-width: 0; }
.client-name { font-size: 19px; font-weight: 800; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.project-name { color: var(--muted); font-size: 14px; }
.card-amount { grid-column: 2; grid-row: 1; text-align: right; font-size: 23px; font-weight: 800; }
.card-meta { grid-column: 2; grid-row: 2; text-align: right; color: var(--muted); font-size: 12px; }
.status-pill { display: inline-flex; align-items: center; min-height: 24px; padding: 0 9px; border-radius: 999px; font-size: 11px; font-weight: 800; flex: none; background: #eef2f1; color: #65736f; }
.status-unbilled { background: #fff3df; color: #96601e; }
.status-awaiting { background: #eaf1f8; color: #416782; }
.status-partial { background: var(--primary-soft); color: var(--primary-dark); }
.status-paid { background: #e6f4e9; color: #347345; }
.status-paused { background: #efefef; color: #666; }
.empty-state { padding: 48px 24px; text-align: center; }
.empty-icon { width: 56px; height: 56px; margin: 0 auto 14px; border-radius: 18px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); font-size: 26px; }
.empty-state h3 { margin: 0 0 6px; }
.empty-state p { color: var(--muted); font-size: 13px; margin: 0 0 18px; }

.filter-row { display: flex; gap: 8px; padding: 16px 20px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.filter-chip { min-height: 36px; border: 1px solid var(--line); background: white; border-radius: 999px; padding: 0 14px; color: var(--muted); white-space: nowrap; cursor: pointer; }
.filter-chip.is-active { background: var(--ink); color: white; border-color: var(--ink); }

.receivable-form { overflow: hidden; max-width: 920px; }
.form-section { padding: 28px; display: grid; grid-template-columns: 46px minmax(0, 1fr); gap: 20px; border-bottom: 1px solid var(--line); }
.section-number { width: 38px; height: 38px; border-radius: 12px; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-size: 11px; font-weight: 900; }
.form-section-content h2 { font-size: 17px; margin: 7px 0 20px; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.field-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field { display: grid; gap: 8px; color: #4b5b57; font-size: 12px; font-weight: 700; margin-bottom: 16px; }
.field input, .field textarea, .field select { width: 100%; border: 1px solid #cfdbd6; border-radius: 10px; min-height: 45px; padding: 10px 12px; color: var(--ink); background: white; transition: border .15s, box-shadow .15s; }
.field textarea { resize: vertical; line-height: 1.6; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(20,108,96,.08); }
.check-field { display: flex; gap: 11px; align-items: flex-start; margin-top: 5px; cursor: pointer; }
.check-field input { width: 18px; height: 18px; accent-color: var(--primary); margin-top: 2px; }
.check-field strong, .check-field small { display: block; }
.check-field strong { font-size: 13px; }
.check-field small { color: var(--muted); margin-top: 4px; }
.pause-field { padding: 14px; border: 1px solid var(--line); border-radius: 10px; }
.form-actions, .modal-actions { padding: 20px 28px; display: flex; justify-content: flex-end; gap: 10px; }
.form-error { color: var(--danger); font-size: 12px; margin: 0 28px 14px; min-height: 18px; }

.modal { width: min(680px, calc(100vw - 30px)); max-height: calc(100vh - 40px); border: 0; border-radius: 20px; padding: 0; color: var(--ink); box-shadow: 0 24px 80px rgba(18,40,36,.25); overflow: auto; }
.small-modal { width: min(560px, calc(100vw - 30px)); }
.modal::backdrop { background: rgba(18,36,33,.48); backdrop-filter: blur(3px); }
.modal-head { padding: 24px 26px 16px; display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 5px 0 0; font-size: 23px; }
.icon-button { width: 40px; height: 40px; border: 1px solid var(--line); background: white; border-radius: 50%; font-size: 24px; cursor: pointer; }
.modal form, #reminder-dialog > .field { padding: 22px 26px 0; }
.modal .modal-actions { border-top: 1px solid var(--line); padding: 18px 26px; }
.modal-actions.wrap { flex-wrap: wrap; }
.detail-summary { padding: 23px 26px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; background: #f8faf8; }
.detail-stat { display: grid; gap: 5px; }
.detail-stat span { color: var(--muted); font-size: 11px; }
.detail-stat strong { font-size: 17px; }
.detail-meta { padding: 20px 26px; display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.detail-meta div, .timeline-item { border: 1px solid var(--line); border-radius: 11px; padding: 13px; }
.detail-meta span, .timeline-item span { display: block; color: var(--muted); font-size: 10px; margin-bottom: 5px; }
.timeline { padding: 0 26px 20px; }
.timeline h3 { font-size: 14px; margin: 0 0 10px; }
.timeline-list { display: grid; gap: 8px; }
.timeline-item p { margin: 0; font-size: 12px; line-height: 1.55; }
.calendar-actions { padding: 0 26px 16px; display: flex; gap: 20px; }
.privacy-content { padding: 8px 26px 22px; }
.privacy-section { padding: 17px 0; border-bottom: 1px solid var(--line); }
.privacy-section:last-child { border-bottom: 0; padding-bottom: 0; }
.privacy-section h3 { margin: 0 0 7px; font-size: 16px; }
.privacy-section p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.75; }

.toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); background: #183b36; color: white; border-radius: 10px; padding: 11px 16px; font-size: 13px; opacity: 0; pointer-events: none; transition: .2s ease; z-index: 100; box-shadow: var(--shadow); }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.mobile-nav { display: none; }

@media (max-width: 1020px) {
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .content-grid { grid-template-columns: 1fr; }
  .right-column { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 760px) {
  body { background: var(--canvas); padding-bottom: 70px; }
  .app-header { height: 66px; padding: 0 16px; }
  .brand small, .header-action, .side-nav, .desktop-only { display: none !important; }
  .brand-mark { width: 34px; height: 34px; }
  .workspace { display: block; min-height: auto; }
  .main-content { padding: 26px 15px 34px; }
  .page-heading { margin-bottom: 20px; }
  .page-heading h1 { font-size: 35px; }
  .page-heading p:not(.eyebrow) { font-size: 15px; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  .metric-card { min-height: 108px; padding: 15px; border-radius: 14px; }
  .metric-card strong { font-size: 26px; }
  .right-column { grid-template-columns: 1fr; }
  .focus-card { display: block; padding: 20px; }
  .panel { border-radius: 15px; }
  .card-open { grid-template-columns: minmax(0, 1fr) auto; padding: 17px; gap: 7px 10px; }
  .client-name { font-size: 18px; }
  .project-name { font-size: 13px; }
  .card-amount { font-size: 20px; }
  .card-meta { max-width: 128px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .mobile-nav { position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; height: 66px; display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--line); background: rgba(255,253,249,.96); backdrop-filter: blur(12px); padding: 5px max(8px, env(safe-area-inset-right)) max(5px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); }
  .mobile-nav button { border: 0; background: none; color: var(--muted); font-size: 10px; font-weight: 700; display: grid; place-items: center; align-content: center; gap: 1px; }
  .mobile-nav button span { font-size: 19px; }
  .mobile-nav button.is-active { color: var(--primary); }
  .mobile-nav .mobile-add span { width: 34px; height: 28px; border-radius: 10px; display: grid; place-items: center; color: white; background: var(--primary); }
  .form-section { grid-template-columns: 1fr; gap: 3px; padding: 22px 18px; }
  .section-number { width: 32px; height: 28px; border-radius: 8px; }
  .field-grid, .field-grid.three { grid-template-columns: 1fr; gap: 0; }
  .form-actions { position: sticky; bottom: 0; background: white; padding: 14px 18px; }
  .form-actions .button { flex: 1; }
  .detail-summary { padding: 18px; grid-template-columns: 1fr 1fr; }
  .detail-meta { padding: 16px 18px; grid-template-columns: 1fr; }
  .timeline { padding: 0 18px 18px; }
  .modal { max-height: calc(100vh - 16px); }
  .modal-head { padding: 20px 18px 14px; }
  .modal form, #reminder-dialog > .field { padding: 18px 18px 0; }
  .modal .modal-actions { padding: 14px 18px; }
  .modal-actions.wrap .button { flex: 1 1 42%; }
  .danger-text { flex-basis: 100%; margin-left: 0; }
  .calendar-actions { padding: 0 18px 14px; flex-wrap: wrap; gap: 6px 18px; }
  .privacy-content { padding: 6px 18px 18px; }
  .privacy-section h3 { font-size: 17px; }
  .privacy-section p { font-size: 15px; }
  .toast { bottom: 82px; max-width: calc(100vw - 30px); text-align: center; }
  .auth-shell { padding: 26px 15px; align-content: start; }
  .auth-brand { margin-top: 18px; }
  .auth-card { padding: 27px 20px; border-radius: 19px; }
  .auth-card h1 { font-size: 38px; }
  .account-email, [data-refresh-records], .sync-status { display: none; }
  .header-controls { gap: 8px; }
}

@media (max-width: 390px) {
  .metrics { grid-template-columns: 1fr; }
  .metric-card { min-height: 94px; }
}
