:root {
  color-scheme: light;
  --ink: #17211d;
  --ink-soft: #4d5a54;
  --line: #d7ddd9;
  --line-strong: #aeb8b2;
  --surface: #ffffff;
  --surface-muted: #f2f4f1;
  --surface-strong: #e7ebe8;
  --green: #16714e;
  --green-dark: #0d5438;
  --orange: #c65d21;
  --red: #ad332a;
  --gold: #9a6b10;
  --blue: #356a8a;
  --purple: #725282;
  --shadow: 0 12px 34px rgb(19 32 26 / 10%);
  --radius: 6px;
  --nav-width: 228px;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--surface-muted); }

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgb(23 33 29 / 2%) 1px, transparent 1px) 0 0 / 32px 32px,
    var(--surface-muted);
  font-family: "Microsoft YaHei UI", "Noto Sans CJK SC", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button, input, select, textarea { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }

:focus-visible { outline: 3px solid rgb(22 113 78 / 35%); outline-offset: 2px; }

.boot-screen, .auth-screen {
  min-height: 100dvh;
  display: grid;
  place-content: center;
  padding: 24px;
}

.boot-screen { text-align: center; color: var(--ink-soft); }

.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border: 2px solid currentColor;
  color: var(--surface);
  background: var(--ink);
  font: 800 16px/1 Bahnschrift, sans-serif;
  letter-spacing: 1px;
}

.boot-screen .brand-mark { margin: 0 auto; }

.auth-panel {
  width: min(420px, calc(100vw - 32px));
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 5px solid var(--green);
  padding: 28px;
  box-shadow: var(--shadow);
  border-radius: var(--radius);
}

.auth-brand { display: flex; gap: 14px; align-items: center; margin-bottom: 28px; }
.auth-brand strong { display: block; font-size: 19px; }
.auth-brand span { color: var(--ink-soft); font-size: 12px; }
.auth-panel h1 { margin: 0 0 8px; font-size: 25px; }
.auth-panel > p { margin: 0 0 24px; color: var(--ink-soft); line-height: 1.7; }

.app-shell { min-height: 100dvh; display: grid; grid-template-columns: var(--nav-width) minmax(0, 1fr); }

.side-rail {
  position: sticky;
  top: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  color: #f3f7f4;
  background: var(--ink);
  border-right: 1px solid #0c120f;
}

.rail-brand { display: flex; align-items: center; gap: 11px; padding: 20px 18px 18px; border-bottom: 1px solid rgb(255 255 255 / 11%); }
.rail-brand .brand-mark { color: var(--ink); background: #f2b44b; border-color: #f2b44b; }
.rail-brand strong { display: block; font-size: 15px; }
.rail-brand small { display: block; margin-top: 3px; color: #aebbb5; }

.rail-nav { display: grid; gap: 4px; padding: 14px 10px; }
.nav-button {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  color: #bfc9c4;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  text-align: left;
}
.nav-button:hover { background: rgb(255 255 255 / 6%); color: #fff; }
.nav-button.active { color: #fff; background: rgb(255 255 255 / 10%); border-color: rgb(255 255 255 / 10%); }
.nav-count { min-width: 25px; padding: 2px 6px; color: #17211d; background: #f2b44b; border-radius: 999px; font: 700 11px/1.4 Bahnschrift, sans-serif; text-align: center; }

.rail-user { margin-top: auto; padding: 16px 18px; border-top: 1px solid rgb(255 255 255 / 11%); }
.rail-user strong, .rail-user span { display: block; }
.rail-user span { margin-top: 3px; color: #aebbb5; font-size: 12px; }
.rail-actions { display: flex; gap: 8px; margin-top: 12px; }
.rail-actions button { color: #d4ddd8; background: transparent; border: 0; padding: 6px 0; text-decoration: underline; text-underline-offset: 3px; }

.main-shell { min-width: 0; }
.topbar {
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
  background: rgb(255 255 255 / 92%);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(8px);
}
.topbar h1 { margin: 0; font-size: 20px; }
.topbar p { margin: 4px 0 0; color: var(--ink-soft); font-size: 12px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.connection-state { display: inline-flex; align-items: center; gap: 7px; color: var(--ink-soft); white-space: nowrap; }
.connection-state::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.connection-state.offline::before { background: var(--red); }
.pending-badge { padding: 5px 8px; color: #7d3d13; background: #fff0df; border: 1px solid #f0c397; border-radius: 4px; }

.page-content { width: min(1480px, 100%); margin: 0 auto; padding: 24px; }
.page-intro { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.page-intro h2 { margin: 0; font-size: 22px; }
.page-intro p { margin: 5px 0 0; color: var(--ink-soft); }
.eyebrow { margin: 0 0 5px; color: var(--green); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.muted { color: var(--ink-soft); }

.button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 15px;
  border-radius: 4px;
  border: 1px solid var(--line-strong);
  color: var(--ink);
  background: var(--surface);
  font-weight: 700;
}
.button:hover { border-color: var(--ink); }
.button-primary { color: #fff; background: var(--green); border-color: var(--green); }
.button-primary:hover { background: var(--green-dark); border-color: var(--green-dark); }
.button-danger { color: var(--red); border-color: #e0b5b0; background: #fff7f6; }
.button-quiet { background: var(--surface-muted); }
.button-small { min-height: 34px; padding: 0 10px; font-size: 12px; }
.icon-button { width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); font-size: 24px; line-height: 1; }
.button, .icon-button { transition: transform .15s ease, background-color .15s ease, border-color .15s ease, color .15s ease; }
.button:active, .icon-button:active { transform: scale(.96); }
.field input:disabled, .field textarea:disabled, .field select:disabled { color: var(--ink-soft); background: var(--surface-strong); cursor: not-allowed; }

.metric-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 18px;
}
.metric { min-width: 0; padding: 18px; border-right: 1px solid var(--line); }
.metric:last-child { border-right: 0; }
.metric span { display: block; color: var(--ink-soft); font-size: 12px; }
.metric strong { display: block; margin-top: 7px; font: 700 28px/1 Bahnschrift, "Microsoft YaHei UI", sans-serif; }
.metric strong, .nav-count { font-variant-numeric: tabular-nums; }
.metric small { display: block; margin-top: 7px; color: var(--ink-soft); }
.metric.risk strong { color: var(--red); }
.metric.attention strong { color: var(--orange); }

.content-band { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 18px; overflow: hidden; }
.band-head { min-height: 57px; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 11px 16px; border-bottom: 1px solid var(--line); }
.band-head h3 { margin: 0; font-size: 15px; }
.band-head p { margin: 3px 0 0; color: var(--ink-soft); font-size: 12px; }
.band-tools { display: flex; align-items: center; gap: 8px; }

.search-input, .field input, .field select, .field textarea {
  width: 100%;
  min-height: 42px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 9px 11px;
}
.search-input { width: min(280px, 42vw); }
.field textarea { resize: vertical; line-height: 1.6; }
.field { display: grid; gap: 7px; }
.field > span { font-weight: 700; font-size: 13px; }
.field small { color: var(--ink-soft); font-weight: 400; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.field-grid .span-2 { grid-column: 1 / -1; }

.order-table-wrap { overflow-x: auto; }
.order-table { width: 100%; min-width: 920px; border-collapse: collapse; }
.order-table th { padding: 10px 12px; color: var(--ink-soft); background: #f7f8f6; border-bottom: 1px solid var(--line); font-size: 11px; text-align: left; white-space: nowrap; }
.order-table td { padding: 12px; border-bottom: 1px solid #e6eae7; vertical-align: middle; }
.order-table tbody tr:last-child td { border-bottom: 0; }
.order-table tbody tr:hover { background: #fbfcfb; }
.order-id { font: 700 13px/1.2 Bahnschrift, "Microsoft YaHei UI", sans-serif; }
.order-meta { display: block; margin-top: 4px; color: var(--ink-soft); font-size: 11px; }

.route-track { display: flex; align-items: center; min-width: 280px; }
.route-node { width: 12px; height: 12px; flex: 0 0 auto; border: 2px solid var(--line-strong); border-radius: 50%; background: #fff; }
.route-node.completed { background: var(--green); border-color: var(--green); }
.route-node.in_progress { background: #fff4db; border-color: var(--gold); }
.route-node.exception { background: #fff; border-color: var(--red); box-shadow: inset 0 0 0 2px var(--red); }
.route-line { height: 2px; min-width: 10px; flex: 1; background: var(--line); }
.route-line.completed { background: var(--green); }

.status-pill { display: inline-flex; align-items: center; min-height: 25px; padding: 3px 8px; border: 1px solid var(--line); border-radius: 999px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.status-pill.not_started { color: #52605a; background: #f3f5f3; }
.status-pill.in_progress { color: #79510e; background: #fff6de; border-color: #e5c884; }
.status-pill.completed { color: #0d593a; background: #e7f5ee; border-color: #9bcdb7; }
.status-pill.exception { color: #8b271f; background: #fff0ee; border-color: #e4aaa5; }
.risk-label { display: inline-flex; margin-left: 5px; padding: 2px 5px; color: #fff; background: var(--red); border-radius: 3px; font-size: 10px; font-weight: 800; }
.warning-label { color: var(--orange); font-size: 11px; font-weight: 700; }

.task-list, .event-list, .user-list { display: grid; }
.task-row, .event-row, .user-row { display: grid; align-items: center; gap: 14px; padding: 14px 16px; border-bottom: 1px solid #e5e9e6; }
.task-row:last-child, .event-row:last-child, .user-row:last-child { border-bottom: 0; }
.task-row { grid-template-columns: minmax(180px, 1.1fr) minmax(130px, .8fr) minmax(140px, .8fr) auto; }
.task-main strong, .task-stage strong { display: block; }
.task-main span, .task-stage span { display: block; margin-top: 4px; color: var(--ink-soft); font-size: 12px; }
.task-actions { display: flex; gap: 7px; }
.task-locked { color: var(--ink-soft); font-size: 12px; }
.event-row { grid-template-columns: 150px minmax(170px, 1fr) minmax(150px, .8fr) 145px; }
.event-row time { color: var(--ink-soft); font: 12px Bahnschrift, sans-serif; }
.event-action { font-weight: 700; }
.user-row { grid-template-columns: minmax(140px, .6fr) 120px minmax(220px, 1fr); }

.empty-state { padding: 44px 20px; text-align: center; color: var(--ink-soft); }
.empty-state strong { display: block; margin-bottom: 7px; color: var(--ink); font-size: 16px; }
.edit-lock-note { display: grid; gap: 4px; margin-top: 22px; padding: 12px 14px; color: #79510e; background: #fff6de; border: 1px solid #e5c884; border-radius: 4px; }
.edit-lock-note span { font-size: 12px; }
.offline-list { display: grid; }
.offline-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 14px; padding: 14px 16px; border-bottom: 1px solid #e5e9e6; }
.offline-row:last-child { border-bottom: 0; }
.offline-row strong, .offline-row span { display: block; }
.offline-row span { margin-top: 4px; color: var(--ink-soft); font-size: 12px; }
.offline-row.failed { background: #fff8f6; }
.offline-row.failed span { color: var(--red); }
.offline-row time { color: var(--ink-soft); font: 12px Bahnschrift, sans-serif; white-space: nowrap; }
.offline-actions { display: flex; gap: 7px; }

.form-surface { padding: 18px; }
.section-title { margin: 24px 0 10px; padding-top: 18px; border-top: 1px solid var(--line); }
.section-title h3 { margin: 0; font-size: 15px; }
.section-title p { margin: 4px 0 0; color: var(--ink-soft); font-size: 12px; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.segmented label, .stage-checkbox {
  position: relative;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  border-radius: 4px;
  font-weight: 700;
  text-align: center;
}
.segmented input, .stage-checkbox input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label:has(input:checked), .stage-checkbox:has(input:checked) { color: #fff; background: var(--ink); border-color: var(--ink); }
.stage-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 7px; }
.unit-list { display: grid; gap: 8px; }
.unit-row { display: grid; grid-template-columns: minmax(0, 1fr) 150px 42px; gap: 8px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }

dialog { color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
dialog::backdrop { background: rgb(12 20 16 / 55%); backdrop-filter: blur(2px); }
.report-dialog { width: min(520px, calc(100vw - 24px)); padding: 0; }
.report-dialog form { padding: 20px; }
.dialog-head { display: flex; align-items: start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.dialog-head h2 { margin: 0; font-size: 20px; }
.dialog-head p:last-child { margin: 5px 0 0; }
.status-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; padding: 0; margin: 0 0 16px; border: 0; }
.status-picker legend { margin-bottom: 7px; font-weight: 700; font-size: 13px; }
.status-picker label { position: relative; }
.status-picker input { position: absolute; opacity: 0; }
.status-picker span { min-height: 44px; display: grid; place-items: center; border: 1px solid var(--line-strong); border-radius: 4px; font-weight: 700; }
.status-picker input:checked + span { color: #fff; background: var(--ink); border-color: var(--ink); }
.report-dialog .field { margin-top: 14px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.detail-dialog { width: min(920px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 0; }
.detail-body { padding: 20px; }
.detail-unit { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 14px; }
.detail-unit h3 { margin: 0 0 10px; font-size: 15px; }
.detail-stage-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 7px; }
.detail-stage { min-width: 0; padding: 10px; border: 1px solid var(--line); border-radius: 4px; background: #fafbfa; }
.detail-stage strong, .detail-stage span { display: block; }
.detail-stage span { margin-top: 6px; font-size: 11px; color: var(--ink-soft); }

.toast-region { position: fixed; right: 18px; bottom: 18px; z-index: 100; display: grid; gap: 8px; width: min(360px, calc(100vw - 36px)); }
.toast { padding: 12px 14px; color: #fff; background: var(--ink); border-left: 4px solid #f2b44b; box-shadow: var(--shadow); border-radius: 4px; }
.toast.error { border-color: #ef6a5d; }
.hidden { display: none !important; }

.mobile-header, .mobile-nav { display: none; }

@media (max-width: 900px) {
  .app-shell { display: block; padding-bottom: calc(68px + env(safe-area-inset-bottom)); }
  .side-rail { display: none; }
  .topbar { min-height: 62px; padding: 9px 14px; }
  .topbar h1 { font-size: 17px; }
  .topbar p { display: none; }
  .topbar .button { min-width: 42px; width: 42px; padding: 0; overflow: hidden; color: transparent; }
  .topbar .button::after { content: "↻"; color: var(--ink); font-size: 20px; }
  .page-content { padding: 14px; }
  .page-intro { align-items: start; }
  .metric-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .task-row { grid-template-columns: 1fr auto; }
  .task-stage { grid-column: 1; }
  .task-actions { grid-column: 2; grid-row: 1 / span 2; flex-direction: column; }
  .event-row { grid-template-columns: 1fr 115px; }
  .event-row > :nth-child(3) { grid-column: 1; }
  .event-row > :nth-child(4) { grid-column: 2; grid-row: 1; text-align: right; }
  .stage-grid, .detail-stage-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .mobile-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    min-height: calc(62px + env(safe-area-inset-bottom));
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    padding: 6px 6px env(safe-area-inset-bottom);
    background: var(--ink);
    border-top: 1px solid #000;
  }
  .mobile-nav .nav-button { min-width: 0; min-height: 50px; display: grid; place-items: center; padding: 3px; font-size: 11px; text-align: center; }
  .mobile-nav .nav-count { display: inline-flex; min-width: 20px; margin-top: 2px; padding: 1px 4px; }
}

@media (max-width: 560px) {
  .page-intro { display: block; }
  .page-intro .button { width: 100%; margin-top: 12px; }
  .band-head { align-items: stretch; flex-direction: column; }
  .band-tools { width: 100%; }
  .search-input { width: 100%; }
  .field-grid { grid-template-columns: 1fr; }
  .field-grid .span-2 { grid-column: auto; }
  .segmented { grid-template-columns: 1fr; }
  .stage-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .unit-row { grid-template-columns: 1fr 110px 42px; }
  .status-picker { grid-template-columns: 1fr; }
  .detail-stage-grid { grid-template-columns: 1fr 1fr; }
  .auth-panel { padding: 22px 18px; }
  .metric { padding: 14px; }
  .metric strong { font-size: 24px; }
  .task-row { padding: 13px; }
  .offline-row { grid-template-columns: 1fr auto; gap: 8px 12px; }
  .offline-row time { grid-column: 2; grid-row: 1; }
  .offline-actions { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: no-preference) {
  .content-band, .metric-strip { animation: enter .24s ease both; }
  .content-band:nth-of-type(2) { animation-delay: 40ms; }
  @keyframes enter { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
}
