:root {
  --background: #f4f4f4;
  --surface: #ffffff;
  --surface-muted: #ededed;
  --ink: #1b1b1b;
  --muted: #5f5f5f;
  --line: #dedede;
  --accent: #242424;
  --accent-hover: #101010;
  --orange: #ff6900;
  --orange-hover: #ef6000;
  --orange-surface: #fff0e6;
  --orange-ink: #241409;
  --focus: #a53d00;
  --sidebar: #202020;
  --sidebar-line: #414141;
  --sidebar-text: #f3f3f3;
  --sidebar-muted: #b5b5b5;
  --danger: #8f2c2c;
  --warning: #795019;
  --sidebar-width: 15.25rem;
  font-family: "Microsoft YaHei UI", "PingFang SC", "Noto Sans CJK SC", system-ui, sans-serif;
  color: var(--ink);
  background: var(--background);
  font-synthesis: none;
  line-height: 1.55;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 0; }
a { color: var(--accent); text-underline-offset: .18em; }
a:hover { color: var(--accent-hover); }
button, input, select, textarea { font: inherit; }
button, summary { cursor: pointer; }
img { max-width: 100%; height: auto; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
h1, h2, h3, p, dl, ul { margin: 0; }
h1, h2, h3 { overflow-wrap: anywhere; line-height: 1.25; }
h1 { font-size: clamp(1.8rem, 1.18rem + 2vw, 2.75rem); letter-spacing: -.035em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p + p { margin-top: .65rem; }
.muted, .helptext, small { color: var(--muted); }
.skip-link { position: absolute; top: .5rem; left: .5rem; z-index: 10; padding: .65rem; background: var(--surface); transform: translateY(-160%); }
.skip-link:focus { transform: translateY(0); }

.workspace { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; display: flex; flex-direction: column; height: 100vh; height: 100dvh; padding: 1.65rem 1rem 1rem; overflow: auto; color: var(--sidebar-text); background: var(--sidebar); border-right: 1px solid var(--sidebar-line); }
.brand { display: flex; align-items: center; gap: .72rem; width: fit-content; text-decoration: none; color: var(--ink); }
.sidebar .brand { padding: 0 .38rem 1.45rem; }
.sidebar .brand, .sidebar .brand:hover { color: var(--sidebar-text); }
.sidebar small { color: var(--sidebar-muted); }
.sidebar :focus-visible { outline-color: var(--orange); }
.brand-mark { display: grid; place-items: center; width: 2.4rem; height: 2.4rem; flex: none; border-radius: .6rem; background: var(--accent); color: white; font-size: 1.02rem; font-weight: 700; }
.sidebar .brand-mark { background: var(--sidebar-text); color: var(--ink); }
.brand strong, .brand small, .sidebar-account strong, .sidebar-account small { display: block; }
.brand small { font-size: .73rem; }
.main-nav { display: grid; gap: .32rem; }
.main-nav a { display: flex; align-items: center; min-height: 2.62rem; padding: .38rem .85rem; border-radius: .42rem; color: var(--sidebar-text); font-size: .88rem; text-decoration: none; }
.main-nav a:hover { background: #303030; }
.main-nav a[aria-current=page] { background: #383838; box-shadow: inset 3px 0 0 var(--orange); font-weight: 700; }
.sidebar-account { margin-top: auto; padding: .95rem .6rem .2rem; border-top: 1px solid var(--sidebar-line); font-size: .82rem; }
.sidebar-account strong, .account-menu summary { overflow-wrap: anywhere; }
.work-area { min-width: 0; }
.topbar { min-height: 4rem; display: flex; justify-content: flex-end; align-items: center; gap: 1rem; padding: .45rem clamp(1rem, 3.2vw, 3rem); border-bottom: 1px solid var(--line); background: var(--surface); }
.topbar .today { color: var(--muted); font-size: .82rem; }
.account-menu { position: relative; max-width: 13rem; }
.account-menu summary { padding: .55rem .65rem; font-size: .88rem; }
.menu-panel { position: absolute; z-index: 6; top: calc(100% + .3rem); right: 0; display: grid; gap: .22rem; min-width: 11rem; max-width: min(17rem, calc(100vw - 2rem)); padding: .65rem; background: var(--surface); border: 1px solid var(--line); border-radius: .55rem; box-shadow: 0 10px 26px #00000019; }
.menu-panel a, .menu-panel button, .menu-panel > span { display: block; width: 100%; text-align: left; padding: .35rem .5rem; }
.menu-panel a { text-decoration: none; }
.menu-panel a:hover, .menu-panel button:hover { background: var(--surface-muted); }
.menu-panel .mobile-only, .mobile-brand, .bottom-nav { display: none; }
.main-content { width: min(100%, 81rem); min-width: 0; margin: 0 auto; padding: clamp(1.15rem, 3vw, 2.75rem); }
.page-header { display: flex; align-items: end; justify-content: space-between; gap: 1rem; margin-bottom: clamp(1rem, 2.5vw, 1.7rem); }
.page-header p { margin-top: .32rem; color: var(--muted); font-size: .9rem; }
.guest-shell .main-content { display: grid; justify-items: center; }
.guest-header { max-width: 81rem; padding: 1.75rem clamp(1rem, 3vw, 3rem); margin: auto; }
.sign-in { width: min(100%, 27rem); margin: clamp(1rem, 7vh, 5rem) auto 0; }
.sign-in > p { margin-top: .52rem; }
.sign-in > form { margin-top: 1.25rem; }
.sign-in .btn { width: 100%; }
.text-button { padding: 0; color: var(--accent); background: transparent; border: 0; }

.panel { min-width: 0; background: var(--surface); padding: clamp(1rem, 2.4vw, 1.45rem); border: 1px solid var(--line); border-radius: .62rem; }
.panel + .panel, .panel + .metric-grid, .metric-grid + .panel, .dashboard-grid + .panel { margin-top: 1rem; }
.section-head, .actions { display: flex; align-items: center; flex-wrap: wrap; gap: .55rem; }
.section-head { justify-content: space-between; min-height: 2rem; margin-bottom: .68rem; }
.section-head > a { font-size: .84rem; }
.queue-panel { margin-bottom: 1rem; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.13fr) minmax(0, 1fr); gap: 1rem; }
.dashboard-grid > .panel + .panel, .stack > .panel + .panel { margin-top: 0; }
.stack { display: grid; gap: .9rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr)); gap: .85rem; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat { min-width: 0; padding: 1.02rem clamp(.75rem, 2vw, 1.3rem); background: var(--surface); border: 1px solid var(--line); border-radius: .55rem; }
.stat dt { color: var(--muted); font-size: .78rem; }
.stat dd { margin: .2rem 0 0; font-weight: 700; font-size: clamp(1.05rem, .85rem + 1.45vw, 1.95rem); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat dd small { font-size: .7em; font-weight: 500; }
.record-list { padding: 0; list-style: none; }
.record-list li + li { border-top: 1px solid var(--line); }
.record-list a { display: flex; justify-content: space-between; align-items: center; gap: .4rem; padding: .7rem .3rem; text-decoration: none; color: var(--ink); }
.record-list a:hover { background: var(--surface-muted); }
.record-list small, .record-list strong { display: block; overflow-wrap: anywhere; }
.record-list small { font-size: .78rem; }
.empty { padding: 1.2rem .2rem; color: var(--muted); }
.badge { display: inline-flex; flex: none; max-width: 100%; align-items: center; padding: .15rem .51rem; background: var(--surface-muted); color: #333333; font-size: .76rem; font-weight: 650; border-radius: .3rem; line-height: 1.6; }
.badge[data-status=duplicate], .badge[data-status=new], .badge[data-status=pending], .badge[data-status=draft] { background: var(--orange-surface); color: var(--warning); }
.badge[data-status=rejected], .badge[data-status=lost], .badge[data-status=cancelled] { background: #f7e8e6; color: var(--danger); }

.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 2.64rem; padding: .4rem .82rem; border-radius: .38rem; border: 1px solid var(--line); background: var(--surface); color: var(--ink); text-decoration: none; font-size: .88rem; font-weight: 600; line-height: 1.25; }
.btn:hover { background: var(--surface-muted); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: white; }
.page-header .btn-primary { background: var(--orange); border-color: var(--orange); color: var(--orange-ink); }
.page-header .btn-primary:hover { background: var(--orange-hover); border-color: var(--orange-hover); }
.btn-danger { border-color: #cb9c9c; color: var(--danger); }
.btn[disabled], button[disabled] { opacity: .55; cursor: default; }
.flashes { display: grid; gap: .45rem; padding: 0; list-style: none; margin: 0 0 1rem; }
.flash { border: 1px solid var(--line); padding: .65rem .8rem; background: var(--surface); border-radius: .4rem; }
.flash.error { border-color: #d5a3a3; color: var(--danger); background: #fbefef; }
.flash.warning { border-color: #e7bea2; color: var(--warning); background: var(--orange-surface); }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr)); gap: .9rem; align-items: end; }
dl.form-grid { align-items: start; }
dl.form-grid dt { color: var(--muted); font-size: .8rem; }
dl.form-grid dd { margin: .12rem 0 0; }
.quote-row { display: flex; align-items: start; justify-content: space-between; flex-wrap: wrap; gap: .6rem; }
.quote-row details { flex: 1 1 16rem; }
form { min-width: 0; }
form label { display: block; margin-bottom: .25rem; font-weight: 600; font-size: .88rem; }
form :where(input, select, textarea):not([type=checkbox], [type=radio], [type=hidden], [type=submit], [type=button]) { width: 100%; min-width: 0; min-height: 2.6rem; padding: .44rem .55rem; color: var(--ink); background: var(--surface); border: 1px solid #bcbcbc; border-radius: .36rem; }
form textarea { min-height: 5.4rem; resize: vertical; }
form [aria-invalid=true] { border-color: var(--danger) !important; }
form input[type=checkbox], form input[type=radio] { width: 1.15rem; height: 1.15rem; vertical-align: middle; accent-color: var(--accent); }
form .helptext { display: block; margin-top: .3rem; font-size: .78rem; }
.errorlist { padding: .32rem 0 .32rem 1.1rem; color: var(--danger); font-size: .84rem; }
fieldset { min-width: 0; border: 1px solid var(--line); border-radius: .5rem; }
.table-wrap, .table-scroll, .table-container { max-width: 100%; overflow: auto; }
.data-table, .panel table { width: 100%; border-collapse: collapse; text-align: left; font-variant-numeric: tabular-nums; }
.data-table :is(td, th), .panel table :is(td, th) { padding: .6rem .55rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.data-table thead, .panel table thead { background: var(--surface-muted); font-size: .82rem; color: var(--muted); }
.data-table tbody th, .panel tbody th { font-weight: 600; }
.data-table :is(td, th), .panel table :is(td, th), .panel dd { overflow-wrap: anywhere; }

@media (max-width: 64rem) {
  .workspace { grid-template-columns: 12rem minmax(0, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 48rem) {
  html { scroll-padding-bottom: calc(4.7rem + env(safe-area-inset-bottom, 0px)); }
  .workspace { display: block; }
  .sidebar, .topbar .today { display: none; }
  .topbar { min-height: 3.5rem; padding-inline: 1rem; justify-content: space-between; }
  .mobile-brand { display: inline; color: var(--ink); font-weight: 750; text-decoration: none; }
  .menu-panel .mobile-only { display: block; }
  .bottom-nav { position: fixed; z-index: 5; bottom: 0; inset-inline: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .2rem; padding: .25rem .45rem calc(.28rem + env(safe-area-inset-bottom, 0px)); background: var(--surface); border-top: 1px solid var(--line); }
  .bottom-nav a { display: grid; align-items: center; text-align: center; min-height: 3rem; font-size: .82rem; color: var(--ink); text-decoration: none; border-radius: .38rem; }
  .bottom-nav a[aria-current=page] { font-weight: 700; background: var(--orange-surface); box-shadow: inset 0 2px 0 var(--orange); }
  .workspace .main-content { padding-bottom: calc(4rem + env(safe-area-inset-bottom, 0px)); }
  .page-header { align-items: start; }
  dl.form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem; }
  :is(input, textarea, select) { font-size: 1rem; }
}

@media (max-width: 26rem) {
  .main-content { padding-inline: .82rem; }
  .metric-grid, .dashboard-grid { gap: .55rem; }
  .page-header { flex-wrap: wrap; }
  .record-list a { flex-wrap: wrap; }
}
