:root {
  --bg: #f1f5ff;
  --surface: #ffffff;
  --ink: #101b45;
  --muted: #5f6f99;
  --line: #cbd6ff;
  --green: #002fa7;
  --green-dark: #00237d;
  --amber: #a86500;
  --red: #b42318;
  --blue: #002fa7;
  --aqua-soft: #e2e9ff;
  --aqua-pale: #f7f9ff;
  --shadow: 0 12px 30px rgba(0, 47, 167, 0.16);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

.login-gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, rgba(0, 47, 167, 0.92), rgba(37, 99, 235, 0.86));
}

.login-panel {
  width: min(460px, 100%);
  padding: 28px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 80px rgba(0, 18, 68, 0.32);
  text-align: center;
}

.login-panel .brand-mark {
  margin: 0 auto 14px;
}

.login-panel h1 {
  margin: 0 0 8px;
  font-size: 24px;
}

.login-panel p {
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.7;
}

.qr-box {
  min-height: 230px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #f8fbff;
}

.login-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.login-actions .btn {
  flex: 1;
}

button,
input,
select,
textarea {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
}

.sidebar {
  background: #002fa7;
  color: #f4f7ff;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  background: #ffffff;
  color: #002fa7;
  border-radius: 8px;
  font-weight: 800;
  font-size: 22px;
}

.brand h1 {
  margin: 0;
  font-size: 19px;
}

.brand p,
.side-note span {
  margin: 4px 0 0;
  color: #dbe4ff;
  font-size: 13px;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-btn {
  border: 0;
  color: #eef2ff;
  background: transparent;
  text-align: left;
  padding: 12px 14px;
  border-radius: 8px;
  cursor: pointer;
}

.nav-btn:hover,
.nav-btn.active {
  background: #1c4fd1;
}

.side-note {
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  display: grid;
  gap: 4px;
}

.main {
  padding: 24px;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.eyebrow {
  color: var(--blue);
  font-weight: 700;
  letter-spacing: 0;
  margin: 0 0 4px;
  font-size: 12px;
}

.topbar h2 {
  margin: 0;
  font-size: 28px;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.mini-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.role-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.role-switch select {
  width: auto;
  min-width: 132px;
  padding: 7px 10px;
}

.period-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 8px;
  justify-content: flex-end;
}

.period-controls label {
  display: inline-grid;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
}

.period-controls input {
  width: 132px;
  height: 34px;
  padding: 6px 8px;
}

.role-badge {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef6ff;
  color: var(--ink);
}

.role-badge[data-role="owner"] {
  background: #eaf2ff;
  color: var(--blue-deep);
  border-color: #a9c7ff;
}

.role-badge[data-role="authorized"] {
  background: #eef9ff;
  color: #075985;
  border-color: #b9e6ff;
}

.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 38px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 700;
}

.btn.primary {
  background: var(--green);
  color: white;
}

.btn.primary:hover {
  background: var(--green-dark);
}

.btn.secondary {
  background: var(--aqua-pale);
  color: var(--ink);
  border-color: var(--line);
}

.btn.danger {
  background: #fff1f0;
  border-color: #f5b8b2;
  color: var(--red);
}

.btn.small {
  min-height: 32px;
  padding: 5px 10px;
}

.file-label input {
  display: none;
}

.view {
  display: none;
}

.active-view {
  display: block;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.business-metrics {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin-bottom: 0;
}

.metric,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  padding: 18px;
  display: grid;
  gap: 7px;
}

.metric span,
.metric small,
.panel-head span {
  color: var(--muted);
}

.metric strong {
  font-size: 30px;
}

.metric strong,
.metric small {
  overflow-wrap: anywhere;
}

.metric.warning strong {
  color: var(--amber);
}

.grid.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

#dashboard {
  display: none;
  gap: 16px;
}

#dashboard.active-view {
  display: grid;
}

.sensitive-panel.restricted {
  display: none;
}

.owner-only.restricted {
  display: none;
}

.nav-btn.owner-gated.needs-owner {
  opacity: 0.78;
}

.nav-btn.owner-gated.needs-owner::after {
  content: "锁";
  float: right;
  font-size: 12px;
  opacity: 0.85;
}

.payroll-panel {
  padding: 0;
  overflow: hidden;
}

.payroll-panel .panel-head {
  padding: 18px 18px 0;
}

.payroll-frame {
  display: block;
  width: 100%;
  height: calc(100vh - 130px);
  min-height: 680px;
  border: 0;
  background: #fff;
}

.temp-payroll-panel {
  margin-top: 16px;
}

.temp-payroll-metrics {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.temp-payroll-form {
  margin-bottom: 16px;
}

.temp-payroll-form .btn[type="submit"] {
  align-self: end;
  min-height: 42px;
}

.labor-entry-form {
  margin: 0 0 16px;
}

.labor-entry-scroll {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.entry-line-table {
  min-width: 1260px;
}

.entry-line-table th,
.entry-line-table td {
  padding: 8px;
  white-space: nowrap;
}

.entry-line-table input,
.entry-line-table select {
  min-width: 0;
  height: 34px;
  padding: 6px 8px;
}

.entry-line-table input[name="date"] { width: 132px; }
.entry-line-table input[name="name"] { width: 96px; }
.entry-line-table select[name="workType"] { width: 88px; }
.entry-line-table input[name="wage"],
.entry-line-table input[name="overtimeWage"],
.entry-line-table input[name="pieceAmount"] { width: 96px; }
.entry-line-table input[name="pieceProduct"],
.entry-line-table input[name="notes"] { width: 150px; }
.entry-line-table input[name="pieceQty"],
.entry-line-table input[name="pieceUnitPrice"] { width: 84px; }
.entry-line-table input[name="registrar"] { width: 108px; }
.entry-line-table select[name="paidStatus"] { width: 92px; }

.analytics-grid h4 {
  margin: 0 0 10px;
  color: var(--ink);
}

.panel {
  padding: 18px;
  min-width: 0;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
}

.panel-head.inline {
  margin: 12px 0;
}

.panel-head h3 {
  margin: 0;
  font-size: 18px;
}

.split {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.production-split,
.ledger-split {
  grid-template-columns: minmax(360px, 520px) minmax(0, 1fr);
}

.wide-split {
  grid-template-columns: minmax(380px, 560px) minmax(0, 1fr);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.filter-row {
  display: grid;
  grid-template-columns: minmax(180px, 240px) minmax(220px, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

label,
.wide-label {
  display: grid;
  gap: 6px;
  color: #273765;
  font-size: 14px;
  font-weight: 700;
}

input,
select,
textarea,
.search {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  background: #fbfeff;
  color: var(--ink);
}

.check-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
  margin-top: 12px;
}

.check-grid label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: var(--muted);
}

.check-grid input {
  width: auto;
}

.chain-store-editor {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.chain-store-rows {
  display: grid;
  gap: 10px;
}

.chain-store-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--line);
  background: #f8fbff;
  border-radius: 8px;
  max-width: 100%;
  overflow: hidden;
}

.chain-store-row label {
  min-width: 0;
  font-size: 12px;
}

.chain-store-row label:nth-child(4),
.chain-store-row .btn {
  grid-column: 1 / -1;
}

.chain-store-row .btn {
  justify-self: start;
  width: auto;
}

.partner-detail-panel {
  max-width: 980px;
}

.partner-detail-preview {
  overflow: auto;
  background: #eef4ff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.partner-detail-preview .print-doc {
  max-width: 794px;
  min-height: 1060px;
  margin: 0 auto;
  box-shadow: var(--shadow);
}

textarea {
  resize: vertical;
}

.form-panel .btn[type="submit"] {
  width: 100%;
  margin-top: 14px;
}

.table-wrap {
  width: 100%;
  overflow: auto;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
  vertical-align: top;
}

th {
  color: #273765;
  background: #e9eeff;
  position: sticky;
  top: 0;
  z-index: 1;
}

.tag {
  display: inline-flex;
  align-items: center;
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 700;
  background: var(--aqua-soft);
  color: var(--green);
}

.tag.warn {
  background: #fff4df;
  color: var(--amber);
}

.tag.bad {
  background: #fff1f0;
  color: var(--red);
}

.stars {
  color: var(--green);
  font-size: 15px;
  white-space: nowrap;
}

.bar-chart {
  display: grid;
  gap: 9px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(54px, 92px) minmax(120px, 1fr) minmax(86px, auto);
  gap: 10px;
  align-items: center;
  font-size: 13px;
}

.bar-row span,
.bar-row strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-row strong {
  text-align: right;
  color: var(--ink);
}

.bar-track {
  height: 10px;
  background: #e8edff;
  border-radius: 999px;
  overflow: hidden;
}

.bar-track i {
  display: block;
  height: 100%;
  background: var(--green);
  border-radius: inherit;
}

.tag:empty {
  display: none;
}

.compact-list {
  display: grid;
  gap: 10px;
}

.compact-item {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.compact-item:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.compact-item strong {
  display: block;
}

.compact-item span {
  color: var(--muted);
  font-size: 13px;
}

.usage-rows {
  display: grid;
  gap: 8px;
}

.usage-row {
  display: grid;
  grid-template-columns: 1fr 120px 36px;
  gap: 8px;
  align-items: center;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  background: white;
  border-radius: 8px;
  cursor: pointer;
  font-size: 20px;
  color: var(--red);
}

.explain-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-bottom: 18px;
}

.report-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.notice-box {
  display: grid;
  gap: 6px;
  background: var(--aqua-soft);
  border: 1px solid #bfcbff;
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 14px;
  color: #1d3272;
}

.notice-box span {
  color: #5c6d99;
  line-height: 1.6;
}

.report-card {
  min-height: 96px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 14px;
  text-align: left;
  cursor: pointer;
  display: grid;
  gap: 8px;
}

.report-card:hover {
  border-color: var(--blue);
}

.report-card div {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.subhead {
  margin-top: 18px;
}

.report-card strong {
  font-size: 16px;
}

.report-card span {
  color: var(--muted);
  line-height: 1.5;
}

.report-preview {
  margin-top: 18px;
  overflow: auto;
}

.print-doc {
  background: #fff;
  color: #111;
  padding: 24px;
}

.print-doc h1 {
  text-align: center;
  font-size: 22px;
  margin: 0 0 10px;
}

.print-meta {
  text-align: center;
  color: #555;
  margin: 0 0 16px;
}

.print-doc table {
  min-width: 0;
  font-size: 12px;
}

.print-doc th,
.print-doc td {
  border: 1px solid #222;
  padding: 6px;
}

.print-subtitle {
  font-size: 15px;
  margin: 14px 0 8px;
}

.partner-info-table th {
  width: 15%;
  background: #eef3ff;
}

.attachment-table th:first-child,
.attachment-table td:first-child {
  width: 48px;
  text-align: center;
}

.attachment-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.attachment-preview {
  margin: 0;
  break-inside: avoid;
  text-align: center;
}

.attachment-preview img {
  max-width: 100%;
  max-height: 220px;
  border: 1px solid #999;
  object-fit: contain;
}

.attachment-preview figcaption {
  margin-top: 4px;
  font-size: 12px;
  color: #333;
}

.sign-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  margin-top: 28px;
}

.detail-list {
  display: grid;
  grid-template-columns: 140px 1fr;
  border: 1px solid #222;
  border-bottom: 0;
}

.detail-list dt,
.detail-list dd {
  margin: 0;
  padding: 8px;
  border-bottom: 1px solid #222;
}

.detail-list dt {
  background: #f2f2f2;
  font-weight: 700;
  border-right: 1px solid #222;
}

.explain-grid h4 {
  margin: 0 0 8px;
}

.explain-grid p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: #002fa7;
  color: white;
  padding: 12px 16px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    padding: 16px;
  }

  .nav {
    grid-template-columns: repeat(3, 1fr);
  }

  .side-note {
    display: none;
  }

  .metrics,
  .business-metrics,
  .grid.two,
  .split,
  .production-split,
  .ledger-split,
  .wide-split,
  .report-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .main {
    padding: 16px;
  }

  .topbar,
  .panel-head,
  .compact-item {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    justify-content: stretch;
  }

  .top-actions .btn,
  .file-label {
    flex: 1 1 140px;
    text-align: center;
  }

  .nav {
    grid-template-columns: 1fr 1fr;
  }

  .metrics,
  .business-metrics,
  .form-grid,
  .filter-row,
  .explain-grid,
  .check-grid {
    grid-template-columns: 1fr;
  }

  .usage-row {
    grid-template-columns: 1fr;
  }

  .chain-store-row {
    grid-template-columns: 1fr;
  }

  .icon-btn {
    width: 100%;
  }

  .payroll-frame {
    height: calc(100vh - 170px);
    min-height: 620px;
  }
}

@media print {
  body {
    background: white;
  }

  .sidebar,
  .topbar,
  .nav,
  .toast,
  .btn,
  .side-note,
  form,
  .report-grid {
    display: none !important;
  }

  .app-shell,
  .main {
    display: block;
    padding: 0;
  }

  .view {
    display: block;
  }

  .panel {
    box-shadow: none;
    border: 0;
    padding: 0;
  }

  .table-wrap {
    overflow: visible;
  }

  table {
    min-width: 0;
  }

  th {
    position: static;
  }

  .print-body {
    margin: 0;
  }

  .print-body .print-doc {
    padding: 18mm 12mm;
  }
}
