/* 轩辕财务系统：桌面与移动端体验统一层。只负责呈现，不参与业务计算。 */
:root {
  --ui-canvas: #f3f5f7;
  --ui-surface: #fcfcfb;
  --ui-ink: #20252b;
  --ui-muted: #626c77;
  --ui-line: #dde2e7;
  --ui-gold: #d5ae43;
  --ui-gold-text: #856210;
  --ui-dark: #111418;
  --ui-dark-panel: #191e24;
  --ui-dark-raised: #222830;
  --ui-dark-text: #edf0f3;
  --ui-dark-muted: #a2acb8;
  --ui-radius: 12px;
}

body {
  font-family: "Microsoft YaHei UI", "PingFang SC", "Noto Sans SC", system-ui, sans-serif;
  text-rendering: optimizeLegibility;
}

button, input, select, textarea { font: inherit; }
button, .btn, .drawer-item, .page-btn { touch-action: manipulation; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible,
textarea:focus-visible, .drawer-item:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid rgba(197, 155, 44, 0.42);
  outline-offset: 2px;
}
::selection { background: rgba(213, 174, 67, 0.28); color: var(--ui-ink); }

/* 前台：保持明亮工作区与黑金导航。 */
.app-layout {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--ui-canvas);
  color: var(--ui-ink);
  --text-primary: var(--ui-ink);
  --text-secondary: #53606c;
  --text-muted: #68737e;
  --bg-white: var(--ui-surface);
  --bg-light: #f3f5f6;
  --bg-hover: #edf0f2;
  --border: var(--ui-line);
  --border-light: #e9edf0;
  --green: #26733f;
  --red: #b52b27;
}
.main-content {
  width: 100%;
  min-width: 0;
  max-width: 1080px;
  padding: 32px 40px 56px;
}
.main-content > div:first-child { margin-bottom: 24px !important; }
.main-content > div:first-child h1 {
  color: var(--ui-ink);
  font-size: 24px !important;
  letter-spacing: -0.02em;
}
.card, .order-item, .chicken-card, .preview-card {
  border-color: var(--ui-line);
  border-radius: var(--ui-radius);
  box-shadow: 0 1px 2px rgba(26, 35, 44, 0.04);
}
.card { padding: 24px; }
.card:hover, .chicken-card:hover { box-shadow: 0 5px 18px rgba(26, 35, 44, 0.06); }
.form-label { color: #53606c; font-size: 13px; margin-bottom: 7px; }
.input, .select, .textarea {
  min-height: 44px;
  padding: 10px 12px;
  border-color: #d5dce2;
  border-radius: 8px;
  background: var(--ui-surface);
  color: var(--ui-ink);
  font-size: 15px;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: #b28a28;
  box-shadow: 0 0 0 3px rgba(197, 155, 44, 0.13);
}
.input::placeholder { color: #7a858f; }
input[type="number"], .amount, .number-gold, .stat-value { font-variant-numeric: tabular-nums; }
.number-gold, .step-item.active { color: var(--ui-gold-text); }

.btn {
  min-height: 40px;
  padding: 9px 16px;
  border-radius: 8px;
  font-weight: 600;
  transition: background-color 0.16s ease, border-color 0.16s ease, color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn-sm { min-height: 36px; padding: 7px 12px; }
.btn-primary {
  color: #1c2024;
  background: var(--ui-gold);
  border-color: var(--ui-gold);
}
.btn-primary:hover:not(:disabled) {
  color: #15181b;
  background: #c39a30;
  border-color: #c39a30;
}
.btn-secondary { background: var(--ui-surface); color: #46525e; border-color: #cfd6dc; }
.btn-secondary:hover { background: #f0f2f4; border-color: #aeb8c1; color: var(--ui-ink); }
.btn-text { min-width: 36px; min-height: 36px; }
.btn:disabled { opacity: 0.48; }

/* 前台桌面导航不再依赖悬停展开，避免文字露出和内容跳动。 */
.drawer {
  background: var(--ui-dark);
  border-right: 1px solid rgba(255, 255, 255, 0.07);
}
.drawer > div:first-child {
  min-height: 72px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 16px 20px !important;
}
.drawer-item {
  min-height: 44px;
  margin: 3px 10px;
  padding: 10px 12px;
  border: 0;
  border-radius: 8px;
  color: #b7c0ca;
}
.drawer-item:hover { color: #f2d174; background: rgba(213, 174, 67, 0.09); }
.drawer-item.active {
  color: #f2d174;
  background: rgba(213, 174, 67, 0.12);
  border: 0;
}
.drawer-item.active::after {
  content: "";
  width: 6px;
  height: 6px;
  margin-left: auto;
  border-radius: 50%;
  background: #e0bb57;
  flex: 0 0 auto;
}
.drawer-mobile {
  width: min(84vw, 320px);
  max-width: 320px;
  height: 100vh;
  height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 16px 0 40px rgba(0, 0, 0, 0.2);
}
.drawer-close {
  position: absolute;
  top: 13px;
  right: 12px;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #c4ccd4;
  font-size: 25px;
  cursor: pointer;
}
.drawer-close:hover { color: #f2d174; background: rgba(255, 255, 255, 0.06); }

/* 做账步骤与录入区。 */
.step-bar {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 5px;
  padding: 5px;
  margin-bottom: 24px;
  border-radius: 11px;
  background: #e7ebee;
}
.step-item {
  min-width: 0;
  padding: 10px 7px;
  border: 0;
  border-radius: 7px;
  color: #66727e;
  font-size: 13px;
  white-space: nowrap;
}
.step-item.active { background: var(--ui-surface); box-shadow: 0 1px 4px rgba(27, 35, 42, 0.08); font-weight: 600; }
.step-item.done { color: #26733f; border: 0; }
.chicken-row, .boss-row {
  border-color: #dce2e7;
  border-radius: 10px;
  background: var(--ui-surface);
}
.chicken-row { grid-template-columns: minmax(170px, 1.3fr) minmax(175px, 1fr) 90px 140px 40px; }
.boss-row { grid-template-columns: minmax(140px, 1fr) 90px minmax(120px, 0.8fr) minmax(110px, 0.8fr) 40px; }
.chicken-row .input, .boss-row .input { min-height: 42px; }
.boss-row.self-row { border-left: 1px solid var(--ui-line); background: rgba(213, 174, 67, 0.07); }
.preview-card { background: var(--ui-surface); }
.copy-btn { min-height: 48px; border-radius: 8px; background: var(--ui-gold); }
.copy-btn:hover { background: #c39a30; }

/* 筛选、记录与表格。 */
.filter-bar, .action-bar { gap: 12px; padding: 16px !important; border-radius: var(--ui-radius); }
.filter-bar > div, .action-bar > div { min-width: 0; }
.order-header { padding: 15px 17px; gap: 12px; }
.order-header > div:first-child { min-width: 0; }
.order-detail { padding: 18px; }
.table-wrap, .admin-table-wrap {
  max-width: 100%;
  margin: 0;
  border-radius: 10px;
  overscroll-behavior-inline: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.table th { padding: 13px 14px; color: #53606c; }
.table td { padding: 13px 14px; }
.pagination { flex-wrap: wrap; gap: 6px; }
.page-btn { min-width: 38px; height: 38px; border-radius: 8px; }
.page-btn.active { color: var(--ui-gold-text); }
.empty-state { min-height: 220px; display: grid; place-content: center; }

/* 弹窗与反馈。 */
.modal-card {
  border-radius: 14px;
  background: var(--ui-surface);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.22);
}
.modal-card::before { height: 2px; background: var(--ui-gold); }
.modal-header { min-height: 60px; padding: 14px 20px; background: inherit; }
.modal-body { padding: 20px; }
.modal-footer { padding: 14px 20px; background: inherit; flex-wrap: wrap; }
.modal-close { min-width: 40px; min-height: 40px; border-radius: 8px; }
.toast-container { width: max-content; max-width: calc(100vw - 32px); }
.toast {
  max-width: 100%;
  padding: 12px 17px;
  border-radius: 9px;
  line-height: 1.5;
  background: var(--ui-surface);
  box-shadow: 0 10px 35px rgba(0, 0, 0, 0.16);
}
.toast-success { background: #f0f8f2; }
.toast-error { background: #fdf2f1; }
.toast-info { background: #fbf7eb; color: #76570c; }

/* 后台：黑金质感、清晰密度与可靠的深色控件。 */
.admin-layout {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--ui-dark);
  color: var(--ui-dark-text);
  color-scheme: dark;
  --text-white: var(--ui-dark-text);
  --text-muted: var(--ui-dark-muted);
}
.admin-main { width: 100%; min-width: 0; max-width: 1600px; padding: 28px 32px 48px; }
.admin-layout .drawer { background: #0e1115; border-right: 1px solid rgba(255, 255, 255, 0.07); }
.admin-layout .drawer-desktop { width: 220px; }
.admin-layout .drawer-mobile { z-index: 1000; }
.admin-layout .drawer-item { margin: 3px 10px; }
.admin-layout .drawer-item.active { background: rgba(213, 174, 67, 0.12); }
.admin-main table th, .admin-main table td { white-space: nowrap; }
.dark-card, .admin-card, .admin-layout .stat-card {
  background: var(--ui-dark-panel);
  border-color: rgba(255, 255, 255, 0.09);
  border-radius: var(--ui-radius);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}
.admin-layout .stat-card { padding: 20px; }
.admin-layout .stat-label { color: var(--ui-dark-muted); font-size: 13px; }
.admin-layout .stat-value { margin-top: 10px; font-size: 28px; color: #e3bd55; }
.stat-unit { margin-left: 5px; color: var(--ui-dark-muted); font-size: 12px; font-weight: 500; }
#summary-cards { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
#summary-cards .stat-card { min-height: 112px; text-align: left; }
.admin-card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.admin-card-title { color: var(--ui-dark-text); font-size: 16px; font-weight: 600; }
#trend-chart { height: 320px !important; }
.dashboard-lower-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 20px; }
.admin-layout .input, .admin-layout .select, .admin-layout .textarea, .dark-input, .dark-select {
  background: var(--ui-dark-raised) !important;
  border-color: rgba(255, 255, 255, 0.15) !important;
  color: var(--ui-dark-text) !important;
}
.admin-layout .input::placeholder { color: #8994a0; }
.admin-layout .input:focus, .admin-layout .select:focus { border-color: #d5ae43 !important; }
.admin-layout .btn-primary { background: var(--ui-gold); border-color: var(--ui-gold); color: #171a1e; }
.admin-layout .btn-primary:hover:not(:disabled) { background: #e1bd58; border-color: #e1bd58; color: #171a1e; }
.admin-layout .btn-secondary { background: var(--ui-dark-raised); border-color: rgba(255, 255, 255, 0.15); color: #d4dae0; }
.admin-layout .btn-secondary:hover { background: #2a323b; color: #fff; }
.admin-table th { padding: 13px 14px; color: #aab4bf; background: #20262d; }
.admin-table td { padding: 13px 14px; color: #dce1e6; }
.admin-table tbody tr:hover { background: rgba(213, 174, 67, 0.04); }
.admin-layout .modal-card { background: var(--ui-dark-panel); border-color: rgba(255, 255, 255, 0.11); }
.admin-layout .modal-header, .admin-layout .modal-footer { background: var(--ui-dark-panel); }
.admin-layout .modal-body { color: #dce1e6; }
.admin-layout .toast { background: var(--ui-dark-raised); color: var(--ui-dark-text); }
.admin-mobile-header { display: none; }
.admin-menu-button { min-width: 44px; padding: 8px 11px !important; color: #e3bd55 !important; border-color: rgba(255, 255, 255, 0.14) !important; }
.admin-mobile-title { display: flex; flex-direction: column; min-width: 0; }
.admin-mobile-title span { color: var(--ui-dark-muted); font-size: 11px; }
.admin-mobile-title strong { color: var(--ui-dark-text); font-size: 17px; }
.admin-front-link { min-height: 44px; display: inline-flex; align-items: center; padding: 0 8px; color: #e3bd55; font-size: 14px; }

@media (min-width: 768px) {
  .app-layout { padding-left: 208px; }
  .app-layout .drawer-desktop, .app-layout .drawer-desktop:hover { width: 208px; }
  .app-layout .drawer-desktop .drawer-text { opacity: 1; }
  #step-1 .card { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
  #step-1 .card > .form-group { margin: 0; }
  #step-1 .card > div:last-child { grid-column: 1 / -1; margin-top: 0 !important; }
}

@media (min-width: 768px) and (max-width: 1000px) {
  .chicken-row, .boss-row {
    position: relative;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 13px 12px;
    padding: 16px;
  }
  .chicken-row > div:first-child, .boss-row > div:first-child { grid-column: 1 / -1; padding-right: 34px; }
  .chicken-row > div:nth-child(4) { grid-column: 1 / -1; }
  .chicken-row > div:last-child, .boss-row > div:last-child { position: absolute; top: 7px; right: 7px; }
  .boss-row .group-select { grid-column: 1 / -1; }
}

@media (max-width: 1023px) {
  .main-content { padding: 26px 24px 44px; }
  .admin-main { padding: 24px 22px 40px; }
  #summary-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-lower-grid { grid-template-columns: 1fr; }
}

@media (max-width: 767px) {
  .app-layout { padding-left: 0; }
  .main-content { max-width: 100%; padding: 16px 16px calc(32px + env(safe-area-inset-bottom)); }
  .main-content > div:first-child {
    display: grid !important;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 12px;
    min-height: 44px;
    margin-bottom: 18px !important;
  }
  .main-content > div:first-child h1 { font-size: 20px !important; text-align: left; }
  .main-content > div:first-child > div:last-child:not(.mobile-only) { font-size: 11px !important; }
  .card { padding: 17px; }
  .input, .select, .textarea { min-height: 46px; font-size: 16px; }
  .btn, .btn-sm, .btn-text { min-height: 44px; }
  .btn-text { min-width: 44px; }
  [data-drawer-toggle] { min-width: 44px; padding: 8px 11px; }
  .step-bar { gap: 3px; padding: 4px; margin-bottom: 17px; }
  .step-item { padding: 10px 2px; font-size: 12px; }

  .chicken-row, .boss-row {
    position: relative;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 13px 12px;
    padding: 16px;
    margin-bottom: 12px;
  }
  .chicken-row > div:first-child, .boss-row > div:first-child { grid-column: 1 / -1; padding-right: 34px; }
  .chicken-row > div:nth-child(4) { grid-column: 1 / -1; }
  .chicken-row > div:last-child, .boss-row > div:last-child { position: absolute; top: 7px; right: 7px; }
  .chicken-row .form-label, .boss-row .form-label { font-size: 12px; }
  .chicken-row .input, .boss-row .input { min-width: 0; padding: 9px 10px; font-size: 16px; }
  .boss-row .group-select { display: block; grid-column: 1 / -1; }
  .boss-row.self-row { border-left: 1px solid var(--ui-line); }
  #step-1 .card > div:last-child .btn { width: 100%; }
  #step-2 .card > div:last-child, #step-3 .card > div:last-child, #step-4 .card > div:last-child {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px !important;
  }
  #step-2 .card > div:last-child > div { grid-column: 1 / -1; grid-row: 1; text-align: center; }
  #step-2 .card > div:last-child > button:first-child { grid-column: 1; grid-row: 2; }
  #step-2 .card > div:last-child > button:last-child { grid-column: 2; grid-row: 2; }
  #step-2 .card > div:last-child .btn, #step-3 .card > div:last-child .btn, #step-4 .card > div:last-child .btn {
    width: 100%;
    padding-left: 9px;
    padding-right: 9px;
    white-space: normal;
  }

  .filter-bar { display: grid !important; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: end; }
  .filter-bar > div, .filter-bar .form-group { min-width: 0; width: 100%; }
  .filter-bar .input, .filter-bar .select { width: 100% !important; min-width: 0; }
  .filter-bar > div:last-child { grid-column: 1 / -1; display: flex; }
  .filter-bar > div:last-child .btn { flex: 1; }
  #view-list-content .filter-bar > div:nth-child(3), .main-content > .filter-bar > div:nth-child(3):has(#filter-supplier) { grid-column: 1 / -1; }
  .action-bar .input { min-width: 0; }
  .action-bar .btn { flex-shrink: 0; }
  .order-header { align-items: flex-start; padding: 14px; }
  .order-header > div:first-child > strong, .order-header > div:first-child > span { display: block; margin-left: 0 !important; }
  .order-header > div:first-child > span { margin-top: 4px; }
  .order-header > div:last-child { flex-shrink: 0; }
  .order-detail { padding: 14px; }
  .detail-grid { grid-template-columns: 1fr; }
  .table { min-width: 620px; }
  .table-wrap { border-left: 1px solid var(--ui-line); border-right: 1px solid var(--ui-line); }
  .page-btn { min-width: 44px; height: 44px; }
  .modal-overlay { padding: 16px 0 0; align-items: flex-end; }
  .modal-card {
    max-width: 100%;
    max-height: 90vh;
    max-height: 90dvh;
    border-radius: 16px 16px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .modal-header { position: sticky; top: 0; z-index: 1; }
  .modal-footer { position: sticky; bottom: 0; z-index: 1; }
  .modal-footer .btn { flex: 1; }
  .toast-container { top: calc(12px + env(safe-area-inset-top)); }

  .admin-main { max-width: 100%; padding: 0 16px calc(32px + env(safe-area-inset-bottom)); }
  .admin-mobile-header {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 68px;
    margin: 0 -16px 20px;
    padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    background: #14181d;
  }
  .admin-layout .drawer-mobile { width: min(84vw, 320px); max-width: 320px; }
  .dark-card, .admin-card { padding: 16px; }
  #summary-cards { gap: 12px; margin-bottom: 18px; }
  #summary-cards .stat-card { min-height: 100px; padding: 16px; }
  .admin-layout .stat-value { font-size: clamp(20px, 6vw, 27px); overflow-wrap: anywhere; }
  #trend-chart { height: 260px !important; }
  .admin-card-header { flex-wrap: wrap; }
  .admin-card-header .input { width: auto; }
  .admin-layout .admin-table-wrap, .admin-layout div[style*="overflow-x:auto"] { max-width: 100%; }
  .admin-layout .modal-footer .btn { min-width: 0; }
}

@media (max-width: 374px) {
  .main-content { padding-left: 12px; padding-right: 12px; }
  .step-item { font-size: 11px; }
  .chicken-row, .boss-row { grid-template-columns: 1fr; }
  .chicken-row > div, .boss-row > div, .boss-row .group-select { grid-column: 1; }
  .filter-bar { grid-template-columns: 1fr; }
  .filter-bar > div { grid-column: 1 !important; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
  .page-enter { animation: none; }
}
