:root {
  color-scheme: light;
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-soft: #eef1ed;
  --ink: #18201d;
  --muted: #65716c;
  --line: #d8ded9;
  --sidebar: #17201d;
  --sidebar-muted: #a7b2ad;
  --accent: #0f7a5b;
  --accent-strong: #095d45;
  --accent-soft: #dff1e9;
  --amber: #a76714;
  --amber-soft: #fff0d8;
  --danger: #a13d3d;
  --danger-soft: #f8e4e4;
  --radius: 8px;
  --shadow: 0 12px 30px rgba(26, 39, 33, 0.08);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body { margin: 0; min-height: 100vh; color: var(--ink); background: var(--bg); font-family: Inter, "Microsoft YaHei", system-ui, sans-serif; letter-spacing: 0; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 3px solid rgba(15, 122, 91, 0.25); outline-offset: 2px; }
[hidden] { display: none !important; }

.eyebrow { margin: 0 0 6px; color: var(--accent); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.site-contact { color: rgba(255,255,255,.45); font-size: 11px; }
.back-link { color: var(--muted); font-size: 13px; text-decoration: none; }

.login-view { min-height: 100vh; display: grid; place-items: center; padding: 32px 18px 64px; background: var(--sidebar); position: relative; }
.login-panel { width: min(420px, 100%); padding: 34px; border: 1px solid rgba(255,255,255,.12); border-radius: var(--radius); background: #f8faf7; box-shadow: 0 28px 80px rgba(0,0,0,.28); }
.login-panel .back-link { display: inline-block; margin-bottom: 44px; }
.login-panel h1 { margin: 0; font-size: 32px; line-height: 1.2; }
.login-copy { margin: 12px 0 26px; color: var(--muted); line-height: 1.7; }
.login-form { display: grid; gap: 16px; }
.login-form label { display: grid; gap: 7px; font-size: 13px; font-weight: 700; }
.login-form input { height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 6px; background: white; }
.login-view > .site-contact { position: absolute; bottom: 18px; margin: 0; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 230px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 22px 14px; color: white; background: var(--sidebar); }
.brand-block { display: flex; align-items: center; gap: 11px; padding: 4px 8px 25px; border-bottom: 1px solid rgba(255,255,255,.1); }
.brand-mark { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 6px; color: #fff; background: var(--accent); font-weight: 900; }
.brand-block div { min-width: 0; display: grid; gap: 3px; }
.brand-block strong { font-size: 14px; }
.brand-block span:last-child { color: var(--sidebar-muted); font-size: 11px; }
.main-nav { display: grid; gap: 5px; padding-top: 22px; }
.nav-item { min-height: 42px; padding: 0 12px; border: 0; border-radius: 6px; color: var(--sidebar-muted); background: transparent; text-align: left; font-weight: 700; }
.nav-item:hover { color: white; background: rgba(255,255,255,.06); }
.nav-item.is-active { color: white; background: var(--accent); }
.sidebar-footer { margin-top: auto; display: grid; gap: 9px; padding: 18px 8px 4px; color: rgba(255,255,255,.44); font-size: 10px; line-height: 1.5; }
.sidebar-footer a { color: var(--sidebar-muted); text-decoration: none; font-size: 12px; }

.workspace { min-width: 0; padding: 0 34px 48px; }
.topbar { min-height: 96px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--line); }
.topbar h1 { margin: 0; font-size: 24px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.sync-status { padding: 5px 8px; border-radius: 5px; color: var(--accent-strong); background: var(--accent-soft); font-size: 11px; font-weight: 800; }
.sync-status[data-state="saving"] { color: var(--amber); background: var(--amber-soft); }
.sync-status[data-state="local"] { color: var(--amber); background: var(--amber-soft); }
.sync-status[data-state="error"] { color: var(--danger); background: var(--danger-soft); }

.local-data-banner { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-top: 18px; padding: 14px 16px; border: 1px solid #e5c68d; border-radius: var(--radius); background: var(--amber-soft); }
.local-data-banner div { min-width: 0; display: grid; gap: 4px; }
.local-data-banner strong { color: #71430b; font-size: 13px; }
.local-data-banner span { color: #7c633f; font-size: 11px; line-height: 1.6; }
.local-data-banner .button { flex: 0 0 auto; border-color: #d8b879; background: rgba(255,255,255,.62); }

.view { display: none; padding-top: 26px; }
.view.is-active { display: block; }
.button { min-height: 38px; display: inline-flex; align-items: center; justify-content: center; padding: 0 14px; border: 1px solid transparent; border-radius: 6px; font-size: 13px; font-weight: 800; text-decoration: none; }
.button--primary { color: white; background: var(--accent); }
.button--primary:hover { background: var(--accent-strong); }
.button--secondary { color: var(--ink); border-color: var(--line); background: var(--surface); }
.button--secondary:hover { border-color: #aeb9b3; background: var(--surface-soft); }
.button--quiet { color: var(--muted); background: transparent; }
.button--full { width: 100%; }
.icon-button { width: 38px; height: 38px; padding: 0; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); background: var(--surface); font-size: 20px; line-height: 1; }
.form-message { min-height: 18px; margin: 0; color: var(--danger); font-size: 12px; }

.filter-bar, .view-toolbar { display: flex; align-items: end; gap: 12px; margin-bottom: 20px; }
.filter-bar label { display: grid; gap: 5px; color: var(--muted); font-size: 11px; font-weight: 700; }
.filter-bar input, .order-filters input, .order-filters select { height: 38px; padding: 0 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.view-toolbar { justify-content: space-between; align-items: center; }
.view-toolbar > p { margin: 0; color: var(--muted); font-size: 13px; }
.order-filters { display: flex; flex-wrap: wrap; gap: 8px; }
.order-filters input { width: 230px; }

.summary-grid { display: grid; grid-template-columns: repeat(5, minmax(140px, 1fr)); gap: 12px; margin-bottom: 20px; }
.summary-card { min-height: 118px; padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.summary-card p { margin: 0 0 18px; color: var(--muted); font-size: 12px; }
.summary-card strong { display: block; font-size: clamp(21px, 2vw, 28px); line-height: 1; }
.summary-card span { display: block; margin-top: 9px; color: var(--muted); font-size: 10px; }
.summary-card--profit { color: white; border-color: var(--accent); background: var(--accent); }
.summary-card--profit p, .summary-card--profit span { color: rgba(255,255,255,.74); }

.content-grid { display: grid; gap: 16px; }
.content-grid--wide { grid-template-columns: minmax(0, 1.7fr) minmax(260px, .8fr); }
.panel { min-width: 0; padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.panel--flush { padding: 0; overflow: hidden; }
.panel-heading { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 18px; }
.panel-heading h2 { margin: 0; font-size: 17px; }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { padding: 11px 12px; color: var(--muted); background: var(--surface-soft); text-align: left; white-space: nowrap; }
td { padding: 13px 12px; border-top: 1px solid var(--line); vertical-align: middle; }
td strong { display: block; }
.cell-note { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; }
.table-actions { display: flex; justify-content: flex-end; gap: 5px; }
.text-button { padding: 4px 6px; border: 0; color: var(--accent); background: transparent; font-size: 11px; font-weight: 800; }
.text-button--danger { color: var(--danger); }
.recent-list { display: grid; }
.recent-item { display: grid; grid-template-columns: 1fr auto; gap: 5px 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.recent-item:first-child { border-top: 0; padding-top: 0; }
.recent-item strong { font-size: 12px; }
.recent-item span { color: var(--muted); font-size: 10px; }
.recent-item b { grid-row: 1 / 3; grid-column: 2; align-self: center; font-size: 13px; }
.empty-inline { padding: 28px 8px; color: var(--muted); text-align: center; font-size: 12px; }

.product-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.product-card { padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.product-card__head { display: flex; justify-content: space-between; gap: 14px; }
.product-card h2 { margin: 0; font-size: 18px; }
.product-card__sku { margin: 5px 0 0; color: var(--muted); font-size: 11px; }
.product-card__price { color: var(--accent); font-size: 20px; }
.product-metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 20px; }
.product-metrics div { padding: 11px; border-radius: 6px; background: var(--surface-soft); }
.product-metrics span { display: block; color: var(--muted); font-size: 10px; }
.product-metrics strong { display: block; margin-top: 6px; font-size: 13px; }
.product-card__footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.product-card__footer p { margin: 0; color: var(--muted); font-size: 10px; }
.empty-state { padding: 80px 20px; border: 1px dashed #b9c3bd; border-radius: var(--radius); text-align: center; }
.empty-state h2 { margin: 0 0 8px; font-size: 18px; }
.empty-state p { margin: 0; color: var(--muted); }

.status-pill { display: inline-flex; min-width: 48px; justify-content: center; padding: 5px 7px; border-radius: 5px; color: var(--accent-strong); background: var(--accent-soft); font-size: 10px; font-weight: 800; }
.status-pill--placed { color: var(--amber); background: var(--amber-soft); }
.status-pill--refunded { color: var(--danger); background: var(--danger-soft); }

.capacity-layout { display: grid; grid-template-columns: minmax(360px, 1fr) minmax(300px, .8fr); gap: 18px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.field { min-width: 0; display: grid; gap: 6px; color: var(--muted); font-size: 11px; font-weight: 700; }
.field--wide { grid-column: 1 / -1; }
.field input, .field select, .field textarea { width: 100%; min-height: 40px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); background: var(--surface); }
.field textarea { resize: vertical; }
.input-unit { display: flex; align-items: center; min-height: 40px; padding: 0 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.input-unit input { min-width: 0; padding: 0; border: 0; background: transparent; }
.input-unit span { color: var(--muted); white-space: nowrap; }
.checkbox-field { grid-template-columns: auto 1fr; align-content: end; align-items: center; min-height: 62px; }
.checkbox-field input { width: 18px; min-height: 18px; }
.capacity-results { display: grid; align-content: start; gap: 12px; }
.capacity-hero { min-height: 178px; padding: 28px; border-radius: var(--radius); color: white; background: var(--sidebar); }
.capacity-hero p { margin: 0 0 26px; color: var(--sidebar-muted); font-size: 12px; }
.capacity-hero strong { font-size: 56px; line-height: 1; }
.capacity-hero span { margin-left: 8px; color: var(--sidebar-muted); }
.metric-stack { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.metric-item { padding: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.metric-item span { display: block; color: var(--muted); font-size: 10px; }
.metric-item strong { display: block; margin-top: 7px; font-size: 18px; }
.capacity-note { margin: 0; padding: 13px; color: var(--muted); border-left: 3px solid var(--amber); background: var(--amber-soft); font-size: 11px; line-height: 1.6; }

.dialog { width: min(560px, calc(100% - 28px)); max-height: calc(100vh - 32px); padding: 24px; border: 0; border-radius: var(--radius); color: var(--ink); background: var(--surface); box-shadow: 0 24px 90px rgba(0,0,0,.28); overflow-y: auto; }
.dialog--large { width: min(920px, calc(100% - 28px)); }
.dialog::backdrop { background: rgba(11, 17, 14, .62); backdrop-filter: blur(2px); }
.dialog-heading { display: flex; align-items: start; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.dialog-heading h2 { margin: 0; font-size: 21px; }
.dialog-copy { color: var(--muted); line-height: 1.7; }
.form-section { margin-top: 22px; padding-top: 20px; border-top: 1px solid var(--line); }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.section-heading h3 { margin: 0; font-size: 15px; }
.section-heading p { margin: 5px 0 0; color: var(--muted); font-size: 11px; }
.cost-items, .order-items { display: grid; gap: 8px; }
.cost-row { display: grid; align-items: center; gap: 7px; padding: 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-soft); }
.cost-row--rd { grid-template-columns: 1.4fr .65fr .65fr .75fr 1fr auto 28px; }
.cost-row--material { grid-template-columns: 1.2fr 1.2fr .7fr .8fr .6fr .75fr auto 28px; }
.cost-row input, .cost-row select { min-width: 0; height: 36px; padding: 0 8px; border: 1px solid var(--line); border-radius: 5px; background: white; font-size: 11px; }
.cost-row strong { white-space: nowrap; font-size: 11px; }
.row-remove { width: 28px; height: 28px; padding: 0; border: 0; border-radius: 5px; color: var(--danger); background: var(--danger-soft); font-size: 17px; }
.order-row { display: grid; grid-template-columns: minmax(190px, 1fr) 100px 120px auto 28px; align-items: end; gap: 8px; padding: 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-soft); }
.order-row > select, .order-row input { width: 100%; height: 38px; padding: 0 8px; border: 1px solid var(--line); border-radius: 5px; background: white; }
.order-row label { display: grid; gap: 4px; color: var(--muted); font-size: 9px; }
.order-row strong { align-self: center; white-space: nowrap; font-size: 12px; }
.dialog-summary { display: flex; flex-wrap: wrap; gap: 10px 24px; margin-top: 22px; padding: 15px; border-radius: 6px; background: var(--surface-soft); font-size: 11px; }
.dialog-summary strong { display: block; margin-top: 4px; font-size: 15px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.backup-actions { display: flex; gap: 10px; margin-top: 20px; }
.file-button input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 20; max-width: 360px; padding: 12px 16px; border-radius: 6px; color: white; background: var(--sidebar); box-shadow: var(--shadow); font-size: 12px; opacity: 0; transform: translateY(10px); pointer-events: none; transition: .2s ease; }
.toast.is-visible { opacity: 1; transform: translateY(0); }

@media (max-width: 1120px) {
  .summary-grid { grid-template-columns: repeat(3, 1fr); }
  .content-grid--wide { grid-template-columns: 1fr; }
  .product-metrics { grid-template-columns: repeat(2, 1fr); }
  .cost-row--material { grid-template-columns: repeat(4, 1fr); }
  .cost-row--material strong { grid-column: 1 / -2; }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: static; width: 100%; height: auto; padding: 12px; }
  .brand-block { padding: 2px 4px 12px; }
  .main-nav { grid-template-columns: repeat(4, minmax(86px, 1fr)); gap: 5px; padding-top: 12px; overflow-x: auto; }
  .main-nav { scrollbar-width: none; }
  .main-nav::-webkit-scrollbar { display: none; }
  .nav-item { text-align: center; white-space: nowrap; font-size: 12px; }
  .sidebar-footer { display: none; }
  .workspace { padding: 0 14px 34px; }
  .topbar { min-height: 82px; }
  .topbar h1 { font-size: 19px; }
  .topbar-actions .button { display: none; }
  .local-data-banner { align-items: stretch; flex-direction: column; }
  .local-data-banner .button { align-self: flex-start; }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .summary-card { min-height: 105px; padding: 14px; }
  .product-list, .capacity-layout { grid-template-columns: 1fr; }
  .view-toolbar { align-items: stretch; flex-direction: column; }
  .order-filters { display: grid; grid-template-columns: 1fr 1fr; }
  .order-filters input { width: auto; grid-column: 1 / -1; }
  .filter-bar { align-items: stretch; flex-wrap: wrap; }
  .filter-bar label { flex: 1 1 135px; }
  .form-grid { grid-template-columns: 1fr; }
  .field--wide { grid-column: auto; }
  .cost-row--rd, .cost-row--material { grid-template-columns: repeat(2, 1fr); }
  .cost-row strong { grid-column: 1; }
  .cost-row .row-remove { grid-column: 2; justify-self: end; }
  .order-row { grid-template-columns: 1fr 1fr; }
  .order-row > select { grid-column: 1 / -1; }
  .order-row strong { grid-column: 1; }
  .order-row .row-remove { grid-column: 2; justify-self: end; }
  .dialog { padding: 18px; }
  .login-panel { padding: 26px 22px; }
}

@media (max-width: 430px) {
  .summary-grid { grid-template-columns: 1fr; }
  .main-nav { grid-template-columns: repeat(4, 100px); }
  .product-metrics, .metric-stack { grid-template-columns: 1fr 1fr; }
  .sync-status { display: none; }
}
