* { box-sizing: border-box; }
body { margin: 0; background: #f4f6f8; color: #1f2937; font: 14px/1.5 "Segoe UI", "Microsoft YaHei", sans-serif; }
button, input, select { font: inherit; }
button { cursor: pointer; }
.app { min-height: 100vh; display: grid; grid-template-columns: 232px 1fr; }
.sidebar { background: #173243; color: #e8f1f5; padding: 20px 14px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; gap: 10px; align-items: center; padding: 0 8px 20px; border-bottom: 1px solid rgba(255,255,255,.12); }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 7px; background: #d97706; color: white; font-weight: 700; }
.brand strong { display: block; font-size: 15px; }
.brand small { color: #a8c2cf; }
#nav { display: grid; gap: 5px; margin-top: 18px; }
#nav button { width: 100%; border: 0; background: transparent; color: #cddbe3; text-align: left; padding: 10px 12px; border-radius: 6px; display: flex; align-items: center; gap: 9px; }
#nav button[hidden] { display: none; }
#nav button:hover, #nav button.active { background: #27536c; color: white; }
#nav svg { width: 17px; height: 17px; }
main { padding: 24px 30px 50px; max-width: 1500px; }
header { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin-bottom: 20px; }
h1 { margin: 0; font-size: 25px; }
#viewSubtitle { margin: 4px 0 0; color: #667085; }
#today { color: #667085; white-space: nowrap; }
.header-actions { display: flex; align-items: center; gap: 12px; }
.header-actions #operator { color: #344054; font-weight: 600; }
.header-actions button { min-height: 32px; padding: 5px 10px; }
.auth-required .app { display: none; }
.view { display: none; }
.view.active { display: grid; gap: 16px; }
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.stat { background: white; border: 1px solid #e4e8ec; border-radius: 8px; padding: 15px 17px; }
.stat span { display: block; color: #667085; }
.stat strong { display: block; font-size: 23px; margin-top: 5px; }
.stat em { font-style: normal; color: #0f766e; font-size: 12px; }
.panel-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.panel { background: white; border: 1px solid #e4e8ec; border-radius: 8px; padding: 17px; }
.panel h2 { font-size: 16px; margin: 0 0 14px; }
.panel h3 { font-size: 14px; margin: 18px 0 8px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 12px; align-items: end; }
label { display: grid; gap: 5px; color: #475467; font-size: 13px; }
input, select { width: 100%; min-height: 36px; border: 1px solid #cbd5e1; border-radius: 6px; padding: 7px 9px; background: white; color: #1f2937; }
input:focus, select:focus { outline: 2px solid #84b8c9; border-color: #38758b; }
.primary, .ghost, .danger { min-height: 36px; border-radius: 6px; padding: 7px 13px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid transparent; }
.primary { background: #166534; color: white; }
.primary:hover { background: #14532d; }
.ghost { background: white; color: #344054; border-color: #cbd5e1; }
.danger { background: #b42318; color: white; }
.primary svg, .ghost svg, .danger svg { width: 15px; height: 15px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 15px; }
.inline-rows { display: grid; gap: 8px; }
.inline-row { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(110px, .8fr) 40px; gap: 8px; align-items: center; }
.inline-row > * { min-width: 0; }
.inline-row > button { width: 40px; height: 40px; padding: 6px; }
.inline-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.inline-controls input, .inline-controls select { width: 145px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 9px; text-align: left; border-bottom: 1px solid #edf0f3; white-space: nowrap; }
th { color: #667085; font-size: 12px; background: #f8fafc; position: sticky; top: 0; }
tbody tr:hover { background: #fafbfc; }
.list-footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding-top: 12px; border-top: 1px solid #edf0f3; }
.list-footer > span { color: #667085; }
.list-footer > div { display: flex; align-items: center; gap: 7px; }
.list-footer span { color: #475467; }
.list-footer button { min-height: 28px; padding: 4px 8px; border-radius: 5px; border: 1px solid #cbd5e1; background: white; color: #344054; }
.list-footer button:disabled { opacity: .5; cursor: not-allowed; }
.empty { color: #98a2b3; text-align: center; padding: 24px 0 !important; }
.tag { display: inline-block; padding: 2px 7px; border-radius: 4px; font-size: 12px; background: #eef2f6; color: #475467; }
.tag.raw { background: #ecfdf5; color: #047857; }
.tag.semi { background: #eff6ff; color: #1d4ed8; }
.tag.finished { background: #fff7ed; color: #c2410c; }
.warning { color: #b42318; font-weight: 700; }
.ok { color: #067647; font-weight: 600; }
.row-actions { display: flex; gap: 6px; }
.row-actions button { min-height: 30px; padding: 5px 9px; font-size: 13px; border-radius: 5px; border: 1px solid #cbd5e1; background: white; }
.row-actions button.return { border-color: #166534; color: #166534; }
.row-actions button.loss { border-color: #b42318; color: #b42318; }
.row-action { min-height: 30px; padding: 5px 9px; font-size: 13px; border-radius: 5px; border: 1px solid #cbd5e1; background: white; color: #344054; }
.row-action.danger-action { border-color: #b42318; color: #b42318; }
.row-action:disabled, button.loading { opacity: .55; cursor: not-allowed; }
.reversed td { color: #667085; }
.return-detail { align-items: center; display: flex; gap: 6px; justify-content: space-between; }
.return-detail + .return-detail { border-top: 1px solid #edf0f3; margin-top: 6px; padding-top: 6px; }
.return-detail.reversed span { color: #667085; text-decoration: line-through; }
.mini-action { border: 1px solid #f2c5c0; border-radius: 4px; background: white; color: #b42318; font-size: 12px; min-height: 24px; padding: 3px 6px; white-space: nowrap; }
.report-period { margin: 18px 0 10px; font-size: 16px; }
.report-top { color: #b45309; margin-left: 8px; font-size: 13px; }
dialog { border: 0; border-radius: 8px; padding: 0; width: min(430px, calc(100vw - 32px)); box-shadow: 0 22px 60px rgba(16,24,40,.24); }
dialog::backdrop { background: rgba(16,24,40,.42); }
dialog form { padding: 20px; display: grid; gap: 12px; }
dialog h2 { margin: 0; font-size: 18px; }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; margin: 4px 0 0; padding: 0; }
/* ---------- 登录页：全屏分栏 + 动态水波 ---------- */
#loginDialog { width: 100vw; height: 100dvh; max-width: none; max-height: none; border-radius: 0; overflow: hidden; }
#loginDialog::backdrop { background: #0b1b26; }
#loginDialog[open] { animation: login-in .5s cubic-bezier(.22, 1, .36, 1) both; }
@keyframes login-in { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
#loginDialog form { grid-template-columns: minmax(0, 11fr) minmax(0, 9fr); gap: 0; padding: 0; height: 100dvh; overflow: hidden; }

.login-hero {
  position: relative; overflow: hidden; color: #eaf3f8;
  background:
    radial-gradient(58% 46% at 78% 4%, rgba(56, 150, 182, .30), transparent 68%),
    radial-gradient(46% 40% at 6% 92%, rgba(217, 119, 6, .13), transparent 70%),
    linear-gradient(162deg, #0c2130 0%, #173243 52%, #1e4258 100%);
  display: flex; flex-direction: column; justify-content: space-between;
  padding: clamp(28px, 4.5vw, 60px);
}
.login-hero-inner { position: relative; z-index: 2; max-width: 460px; }
.login-logo {
  width: 54px; height: 54px; display: grid; place-items: center; border-radius: 12px;
  background: linear-gradient(145deg, #e78a12, #c76e04);
  box-shadow: 0 14px 30px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .28);
}
.login-logo svg { width: 26px; height: 26px; }
.login-hero h2 { margin: 22px 0 0; font-size: clamp(26px, 2.6vw, 34px); line-height: 1.25; letter-spacing: .5px; }
/* 公司名主标题 + 系统名副题：长名称拆两行，副题拉开字距保持体面层级 */
.login-title span {
  display: block;
  margin-top: 9px;
  font-size: clamp(14px, 1.25vw, 17px);
  font-weight: 500;
  letter-spacing: 5px;
  color: #a9c6d6;
}
.login-tagline { margin: 10px 0 0; color: #a9c6d6; font-size: 14px; }
.login-features { list-style: none; margin: clamp(26px, 4.5vh, 48px) 0 0; padding: 0; display: grid; gap: 18px; }
.login-features li { display: flex; gap: 13px; align-items: flex-start; }
.login-features svg { flex: 0 0 auto; width: 19px; height: 19px; margin-top: 2px; color: #7fc4dd; }
.login-features strong { display: block; font-size: 14.5px; color: #f2f8fb; }
.login-features span { display: block; margin-top: 2px; font-size: 12.5px; color: #93b2c4; }
.login-hero-foot { position: relative; z-index: 2; margin: 18px 0 0; font-size: 12px; color: #7fa0b3; letter-spacing: .4px; }

.login-waves { position: absolute; inset: auto 0 -2px; height: clamp(120px, 24vh, 210px); z-index: 1; pointer-events: none; }
.login-waves svg { position: absolute; bottom: 0; left: 0; width: 200%; height: 100%; }
.wave-a { animation: wave-drift 17s linear infinite; }
.wave-b { animation: wave-drift 11s linear infinite reverse; }
@keyframes wave-drift { from { transform: translateX(0); } to { transform: translateX(-50%); } }
@media (prefers-reduced-motion: reduce) {
  .wave-a, .wave-b, #loginDialog[open] { animation: none; }
}

.login-panel {
  background: #fbfcfd; display: grid; align-content: center; justify-items: stretch;
  gap: 14px; padding: clamp(28px, 5vh, 56px) clamp(26px, 5vw, 90px);
  border-left: 1px solid #e8edf1;
}
.login-panel header { display: block; margin: 0 0 10px; }
.login-panel small { color: #8a97a6; letter-spacing: 2px; font-size: 12px; }
.login-panel h3 { margin: 6px 0 0; font-size: clamp(24px, 2.2vw, 30px); color: #14293a; }
.login-field { display: grid; gap: 7px; font-size: 13px; color: #475467; font-weight: 600; }
.login-input { position: relative; }
.login-field input {
  min-height: 48px; padding: 10px 44px 10px 42px;
  border: 1.5px solid #d8e0e7; border-radius: 10px; background: white;
  transition: border-color .18s, box-shadow .18s;
}
.login-field input::placeholder { color: #a5b3c0; font-weight: 400; }
.login-field input:focus { outline: none; border-color: #2c5e79; box-shadow: 0 0 0 4px rgba(44, 94, 121, .14); }
.login-input > svg { position: absolute; left: 14px; bottom: 15px; width: 17px; height: 17px; color: #8fa4b3; pointer-events: none; }
#loginPasswordToggle { position: absolute; right: 9px; bottom: 9px; width: 32px; height: 32px; display: grid; place-items: center; border: 0; border-radius: 7px; background: transparent; color: #667085; }
#loginPasswordToggle:hover { background: #eef2f6; color: #173243; }
#loginPasswordToggle svg { width: 17px; height: 17px; }
#loginPasswordToggle .hide-password { display: none; }
#loginPasswordToggle[data-visible="true"] .show-password { display: none; }
#loginPasswordToggle[data-visible="true"] .hide-password { display: block; }
.login-panel menu { margin: 8px 0 0; }
.login-panel .primary {
  width: 100%; min-height: 48px; border-radius: 10px; font-size: 15px; font-weight: 600;
  background: linear-gradient(180deg, #1d415a, #173243);
  box-shadow: 0 12px 26px -12px rgba(23, 50, 67, .65);
  transition: transform .15s, box-shadow .15s, background .15s;
}
.login-panel .primary:hover {
  background: linear-gradient(180deg, #255573, #1d415a);
  box-shadow: 0 16px 30px -12px rgba(23, 50, 67, .7);
  transform: translateY(-1px);
}
.login-panel .primary:active { transform: translateY(0); }
.login-foot { margin: 4px 0 0; text-align: center; font-size: 12px; color: #98a2b3; }
.login-field input:-webkit-autofill { -webkit-box-shadow: 0 0 0 1000px #fff inset; }
#toast { position: fixed; z-index: 120; top: calc(18px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); display: none; width: max-content; max-width: calc(100vw - 32px); padding: 11px 16px; border: 1px solid rgba(255,255,255,.16); border-radius: 7px; color: white; background: #173243; box-shadow: 0 10px 30px rgba(16,24,40,.25); text-align: center; }
#toast.error { background: #b42318; }
.confirm-dialog { position: fixed; inset: 0; margin: auto; width: min(440px, calc(100vw - 32px)); max-height: calc(100dvh - 36px); border: 1px solid #e4e8ec; border-radius: 8px; padding: 0; color: #1f2937; box-shadow: 0 18px 48px rgba(16,24,40,.24); }
.confirm-dialog::backdrop { background: rgba(16,24,40,.42); }
.confirm-dialog-content { padding: 22px; display: grid; justify-items: center; gap: 10px; text-align: center; }
.confirm-dialog-mark { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50%; color: #1d5269; background: #eaf3f7; }
.confirm-dialog-mark svg { width: 21px; height: 21px; }
.confirm-dialog h2 { margin: 0; font-size: 17px; }
.confirm-dialog p { margin: 0; color: #475467; line-height: 1.65; overflow-wrap: anywhere; }
.confirm-dialog-actions { width: 100%; display: flex; justify-content: center; gap: 10px; margin-top: 6px; }
.confirm-dialog-actions button { min-width: 104px; min-height: 40px; }
.confirm-dialog-actions .danger { background: #b42318; }

@media (max-width: 1200px) {
  .stats-grid, .panel-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; padding: 12px; }
  .brand { border: 0; padding: 0; }
  #nav { display: flex; overflow-x: auto; margin-top: 10px; }
  #nav button { white-space: nowrap; }
  main { padding: 18px 14px 40px; }
  header { align-items: start; flex-direction: column; }
  .stats-grid, .panel-grid, .form-grid { grid-template-columns: 1fr; }
  .panel-head, .inline-controls { align-items: stretch; flex-direction: column; }
  .inline-controls input, .inline-controls select { width: 100%; }
  .list-footer { align-items: flex-start; flex-direction: column; }
  .list-footer > div { width: 100%; justify-content: space-between; }
  #loginDialog form { grid-template-columns: 1fr; grid-template-rows: auto 1fr; overflow: auto; }
  .login-hero { padding: 20px 20px 96px; }
  .login-features, .login-hero-foot { display: none; }
  .login-hero h2 { margin-top: 14px; font-size: 22px; }
  .login-tagline { margin-top: 6px; font-size: 12.5px; }
  .login-waves { height: 88px; }
  .login-panel { border-left: 0; padding: 26px 20px 34px; }
}

/* Utility and customer history dialog */
[hidden] { display: none !important; }
#customerStatementDialog { width: min(1100px, calc(100vw - 32px)); max-height: min(820px, calc(100vh - 32px)); overflow: auto; }
#customerStatementDialog > section { padding: 20px; }
#customerStatementDialog h3 { margin: 18px 0 8px; font-size: 15px; }
#customerStatementSummary { margin: 8px 0 16px; color: #344054; }

/* BOM / 配方页面提示与操作区 */
.form-hint { grid-column: 1 / -1; margin: 0; color: #667085; font-size: 13px; line-height: 1.65; }
#boms .panel > .form-hint { margin-top: 6px; }
#boms .inline-rows { margin-top: 12px; }
#boms .inline-row input { min-width: 180px; }

/* Responsive layout and touch-device refinements */
:root {
  --surface: #ffffff;
  --surface-subtle: #f8fafc;
  --border: #e4e8ec;
  --text-muted: #667085;
  --sidebar: #173243;
}

html { min-width: 0; background: #f4f6f8; }
body { min-width: 0; overflow-x: hidden; -webkit-tap-highlight-color: transparent; }
button, input, select { max-width: 100%; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 3px solid rgba(56, 117, 139, .36);
  outline-offset: 2px;
}
.app { grid-template-columns: 244px minmax(0, 1fr); }
.sidebar { z-index: 10; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
main { width: 100%; min-width: 0; margin: 0 auto; }
.view, .panel, .panel-grid, .stats-grid, .panel-head, .header-actions { min-width: 0; }
.panel { box-shadow: 0 1px 2px rgba(16, 24, 40, .025); }
.panel-head > * { min-width: 0; }
.form-grid > .form-actions { grid-column: 1 / -1; }
.table-wrap { max-width: 100%; overscroll-behavior-inline: contain; -webkit-overflow-scrolling: touch; scrollbar-color: #b6c2cb transparent; scrollbar-width: thin; }
.table-wrap > table { width: max-content; min-width: 100%; }
.table-wrap > table th:first-child, .table-wrap > table td:first-child { padding-left: 11px; }
.table-wrap > table th:last-child, .table-wrap > table td:last-child { padding-right: 11px; }
.inline-controls { min-width: 0; }
.inline-controls > * { flex: 0 1 auto; }
.form-actions { flex-wrap: wrap; }
dialog { max-height: calc(100dvh - 32px); overflow: auto; }
#toast { z-index: 50; }

@media (max-width: 1024px) {
  main { padding: 22px 22px 42px; }
  .panel-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 820px) {
  .app { display: block; }
  .sidebar {
    position: sticky;
    top: 0;
    height: auto;
    max-height: none;
    padding: 10px 12px 0;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(16, 34, 46, .18);
  }
  .brand { min-width: 0; padding: 0 2px 9px; }
  .brand-mark { flex: 0 0 auto; width: 34px; height: 34px; }
  .brand small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #nav {
    display: flex;
    gap: 7px;
    margin: 0 -12px;
    padding: 0 12px 10px;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x proximity;
    scrollbar-width: thin;
    scrollbar-color: rgba(215, 233, 241, .55) transparent;
  }
  #nav button {
    width: auto;
    min-height: 40px;
    flex: 0 0 auto;
    padding: 8px 11px;
    border: 1px solid rgba(224, 239, 245, .14);
    background: rgba(255, 255, 255, .045);
    scroll-snap-align: start;
    white-space: nowrap;
  }
  #nav button:hover, #nav button.active { background: #27536c; border-color: rgba(224, 239, 245, .16); }
  #nav svg { width: 16px; height: 16px; }
  main { padding: 16px 12px 32px; }
  header { align-items: flex-start; gap: 12px; margin-bottom: 16px; }
  h1 { font-size: 22px; line-height: 1.3; }
  #viewSubtitle { line-height: 1.45; }
  .header-actions { width: 100%; flex-wrap: wrap; gap: 8px 12px; }
  .header-actions #operator { margin-right: auto; }
  .header-actions button { min-height: 38px; }
  .panel { padding: 14px; border-radius: 9px; }
  .panel h2 { margin-bottom: 11px; }
  .panel-grid { grid-template-columns: 1fr; gap: 12px; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { min-width: 0; padding: 13px; }
  .stat strong { font-size: 20px; overflow-wrap: anywhere; }
  .form-grid { grid-template-columns: 1fr; gap: 11px; }
  .form-hint { font-size: 12px; }
  input, select { min-height: 42px; padding: 8px 10px; }
  .primary, .ghost, .danger { min-height: 42px; }
  .panel-head { align-items: stretch; flex-direction: column; gap: 10px; }
  .panel-head > select { width: 100%; }
  .inline-controls { width: 100%; align-items: stretch; flex-direction: column; gap: 8px; }
  .inline-controls input, .inline-controls select, .inline-controls button { width: 100%; min-height: 42px; }
  .inline-row { grid-template-columns: minmax(0, 1fr) 42px; gap: 8px; }
  .inline-row select { grid-column: 1 / -1; }
  .inline-row button { min-width: 42px; min-height: 42px; padding: 6px; }
  .inline-row input { min-width: 0; }
  #boms .inline-row input { min-width: 0; }
  .form-actions { justify-content: stretch; gap: 8px; margin-top: 4px; }
  .form-actions > button { flex: 1 1 145px; }
  .row-actions { min-width: max-content; gap: 7px; }
  .row-actions button, .row-action { min-height: 36px; padding: 6px 10px; }
  .return-detail { min-width: 180px; gap: 10px; }
  .list-footer { gap: 10px; }
  .list-footer button { min-height: 36px; padding: 6px 10px; }
  th, td { padding: 9px 8px; }
  th { position: static; }
  dialog { width: calc(100vw - 24px); max-height: calc(100dvh - 24px); border-radius: 10px; }
  dialog form { padding: 16px; }
  dialog menu { flex-wrap: wrap; }
  dialog menu button { flex: 1 1 120px; min-height: 42px; }
  #customerStatementDialog { width: calc(100vw - 24px); max-height: calc(100dvh - 24px); }
  #customerStatementDialog > section { padding: 16px; }
  #toast { top: calc(12px + env(safe-area-inset-top)); width: calc(100vw - 24px); max-width: 440px; }
  .confirm-dialog { width: calc(100vw - 24px); }
  .confirm-dialog-content { padding: 18px 16px; }
}

@media (max-width: 480px) {
  body { font-size: 13px; }
  .sidebar { padding-inline: 10px; }
  #nav { margin-inline: -10px; padding-inline: 10px; }
  .brand strong { font-size: 14px; }
  .brand small { font-size: 11px; }
  main { padding: 14px 10px 28px; }
  header { gap: 10px; }
  .header-actions { font-size: 12px; }
  #today { width: 100%; order: 3; white-space: normal; color: var(--text-muted); }
  .stats-grid { grid-template-columns: 1fr; }
  .stat { padding: 12px 13px; }
  .panel { padding: 12px; }
  .panel h2 { font-size: 15px; }
  .form-actions > button { flex-basis: 100%; }
  .list-footer > div { gap: 6px; flex-wrap: wrap; }
  .list-footer > div button { flex: 1 1 auto; }
  .login-hero { padding: 18px 16px 78px; }
  .login-panel { padding: 22px 16px 28px; }
}

@media (hover: none) {
  tbody tr:hover { background: transparent; }
  .primary:hover { background: #166534; }
  .login-panel .primary:hover { background: linear-gradient(180deg, #1d415a, #173243); transform: none; }
}

/* 下脚料 / 多维统计 / 财务页面 */
.tag.scrap { background: #fef3c7; color: #92400e; }
.bar-cell { position: relative; min-width: 150px; }
.bar-cell .bar { display: block; height: 12px; border-radius: 3px; background: linear-gradient(90deg, #38789b, #5ba3c4); margin: 3px 0; }
.bar-cell small { color: #667085; font-size: 12px; }
.dim-group td { font-weight: 600; background: #f8fafc; }
.dim-indent td:first-child { padding-left: 26px; color: #475467; }
.dim-indent-2 td:first-child { padding-left: 48px; color: #667085; }
.journal-lines .journal-line { grid-template-columns: 1fr 130px 130px 1fr 36px; }
#finance .table-wrap > table { width: max-content; min-width: 100%; }
#saleKgHint { color: #0f766e; }

/* UI refresh: restrained warehouse palette, clearer navigation and data density. */
:root {
  color-scheme: light;
  --surface: #ffffff;
  --surface-subtle: #f5f7f6;
  --border: #dfe5e2;
  --text-muted: #59665f;
  --sidebar: #192e2b;
  --accent: #13765b;
  --accent-strong: #0d6048;
}
html, body { background: #f3f6f4; color: #17231e; }
body { font-size: 14px; }
.app { grid-template-columns: 252px minmax(0, 1fr); }
.sidebar { background: var(--sidebar); padding: 22px 15px; }
.brand { padding: 0 9px 19px; }
.brand-mark { background: #d48a32; border-radius: 8px; }
.brand strong { font-size: 14px; }
.brand small { font-size: 11px; }
#nav { gap: 3px; margin-top: 16px; }
#nav button { min-height: 42px; padding: 9px 12px; border-radius: 6px; color: #c5d2cc; transition: background-color .16s ease, color .16s ease; }
#nav button:hover { background: rgba(255,255,255,.09); color: #fff; }
#nav button.active { background: #285146; color: #fff; box-shadow: inset 3px 0 #69c19d; }
#nav button.active svg { color: #a5e1c4; }
main { max-width: 1640px; padding: 27px clamp(22px, 3vw, 46px) 52px; }
header { margin-bottom: 24px; }
h1 { font-size: 24px; font-weight: 680; color: #17231e; }
#viewSubtitle, #today { color: #59665f; }
.header-actions #operator { color: #31443b; }
.view.active { gap: 18px; }
.stats-grid, .panel-grid { gap: 14px; }
.stat, .panel { border-color: var(--border); box-shadow: 0 1px 2px rgba(23,35,30,.035); }
.stat { padding: 16px 18px; }
.stat span { color: #59665f; }
.stat strong { color: #17231e; font-size: 22px; }
.panel { border-radius: 7px; padding: 18px; }
.panel h2 { color: #20332b; font-size: 15px; }
.panel-head { margin-bottom: 14px; }
input, select { border-color: #c9d3cd; }
input:focus, select:focus { outline-color: rgba(19,118,91,.25); border-color: var(--accent); }
.primary { background: var(--accent); }
.primary:hover { background: var(--accent-strong); }
.tag.raw { background: #e5f4ec; color: #126246; }
.tag.semi { background: #eaf1f8; color: #315e84; }
.tag.finished { background: #fff0dc; color: #985117; }
.table-wrap { border-radius: 5px; }
th { color: #536159; background: #f4f7f5; }
tbody tr:hover { background: #f5f9f6; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid rgba(19,118,91,.48); outline-offset: 2px; }

/* Character-led sign-in, adapted to the existing username/password session. */
#loginDialog { background: #fff; }
#loginDialog form { grid-template-columns: minmax(0, 1.08fr) minmax(360px, .92fr); }
.login-hero {
  isolation: isolate;
  background: linear-gradient(145deg, #667085 0%, #525d70 54%, #424d60 100%);
  padding: clamp(32px, 5vw, 76px);
}
.login-hero::before { content: ""; position: absolute; z-index: -1; width: 42vw; height: 42vw; right: -13vw; bottom: -23vw; border: 1px solid rgba(255,255,255,.15); border-radius: 50%; box-shadow: 0 0 0 34px rgba(255,255,255,.035), 0 0 0 72px rgba(255,255,255,.025); }
.login-logo { background: #e8d754; color: #2d2d2d; border-radius: 13px; box-shadow: none; }
.login-hero h2 { font-size: clamp(28px, 2.8vw, 38px); letter-spacing: 0; }
.login-title span { letter-spacing: 2px; color: #f0e7a1; }
.login-tagline { color: #f1f3f6; }
.login-features { display: none; }
.login-hero-foot { color: #e1e5eb; letter-spacing: 0; }
.login-waves { display: none; }
.login-characters { position: absolute; right: clamp(0px, 2vw, 30px); bottom: 0; z-index: 2; width: 550px; height: 400px; pointer-events: none; transform-origin: bottom right; }
.character-scene { position: relative; width: 550px; height: 400px; }
.login-character { position: absolute; bottom: 0; transform-origin: bottom center; transition: transform 700ms ease-in-out, height 700ms ease-in-out; }
.character-purple { z-index: 1; left: 70px; width: 180px; height: 400px; border-radius: 10px 10px 0 0; background: #6c3ff5; }
.character-black { z-index: 2; left: 240px; width: 120px; height: 310px; border-radius: 8px 8px 0 0; background: #2d2d2d; }
.character-orange { z-index: 3; left: 0; width: 240px; height: 200px; border-radius: 120px 120px 0 0; background: #ff9b6b; }
.character-yellow { z-index: 4; left: 310px; width: 140px; height: 230px; border-radius: 70px 70px 0 0; background: #e8d754; }
.character-eyes { position: absolute; display: flex; align-items: center; transition: transform 700ms ease-in-out; }
.eyes-purple { left: 45px; top: 40px; gap: 32px; }
.eyes-black { left: 26px; top: 32px; gap: 24px; }
.eyes-orange { left: 82px; top: 90px; gap: 32px; transition-duration: 200ms; }
.eyes-yellow { left: 52px; top: 40px; gap: 24px; transition-duration: 200ms; }
.character-eye { display: grid; width: 18px; height: 18px; overflow: hidden; place-items: center; border-radius: 50%; background: #fff; transition: height 150ms; }
.eyes-black .character-eye { width: 16px; height: 16px; }
.character-eye i, .eyes-orange i, .eyes-yellow i { display: block; width: 7px; height: 7px; flex: none; border-radius: 50%; background: #2d2d2d; transition: transform 100ms ease-out; }
.eyes-orange i, .eyes-yellow i { width: 12px; height: 12px; }
.character-mouth { position: absolute; left: 40px; top: 88px; width: 80px; height: 4px; border-radius: 99px; background: #2d2d2d; transition: transform 200ms ease-out; }
.character-eye.is-blinking { height: 2px; }
.character-eye.is-blinking i { visibility: hidden; }
#loginForm.is-typing .character-purple, #loginForm.is-hiding-password .character-purple { height: 440px; }
#loginForm.is-typing .character-purple { transform: skewX(-7deg) translateX(22px); }
#loginForm.is-looking-together .character-purple .character-eyes { transform: translate(10px, 25px); }
#loginForm.is-looking-together .character-black { transform: skewX(8deg) translateX(12px); }
#loginForm.is-looking-together .character-black .character-eyes { transform: translate(6px, -18px); }
#loginForm.is-peeking .character-purple .character-eyes { transform: translate(-25px, -5px); }
#loginForm.has-error .character-scene { animation: login-character-error 420ms ease-in-out 2; }
@keyframes login-character-error { 25% { transform: translateX(-7px) rotate(-1deg); } 75% { transform: translateX(7px) rotate(1deg); } }
@media (prefers-reduced-motion: reduce) {
  .login-characters *, .login-characters, .login-character, .login-dialog, .wave-a, .wave-b { animation: none !important; transition: none !important; }
}
.login-panel { background: #fff; border-left-color: #e7ece8; padding-inline: clamp(30px, 5.5vw, 92px); gap: 12px; }
.login-panel header { margin-bottom: 10px; }
.login-panel small { color: #507165; letter-spacing: 1.5px; font-weight: 700; }
.login-panel h3 { font-size: 30px; color: #1a3027; }
.login-intro { margin: 6px 0 0; color: #59665f; }
.login-field { gap: 8px; color: #34463d; }
.login-field input { min-height: 50px; border: 1px solid #cdd8d1; border-radius: 7px; padding-left: 44px; }
.login-field input:focus { border-color: #18815e; box-shadow: 0 0 0 3px rgba(19,118,91,.13); }
.login-input > svg { bottom: 16px; color: #71877b; }
#loginPasswordToggle { width: 36px; height: 36px; bottom: 7px; }
.login-panel menu { padding: 0; margin: 8px 0 0; }
.login-panel .primary { min-height: 48px; border-radius: 7px; background: #176e53; box-shadow: none; }
.login-panel .primary:hover { background: #10583f; box-shadow: none; transform: none; }
.login-foot { color: #59665f; }
.login-error { margin: 0; padding: 9px 11px; border-radius: 5px; color: #9f2d25; background: #fff1ef; font-size: 13px; }
#loginForm.has-error .login-character { animation: character-worry .35s ease-in-out 2; }
@keyframes character-worry { 25% { transform: rotate(-5deg); } 75% { transform: rotate(5deg); } }
@media (prefers-reduced-motion: reduce) {
  .login-characters *, .login-character, .login-dialog, .wave-a, .wave-b { animation: none !important; transition: none !important; }
}

@media (max-width: 1024px) {
  .app { grid-template-columns: 220px minmax(0, 1fr); }
  main { padding-inline: 22px; }
}
@media (min-width: 821px) and (max-width: 1100px) {
  .login-characters { transform: scale(.78); }
}
@media (min-width: 821px) and (max-width: 900px) {
  .login-characters { transform: scale(.66); }
}
@media (max-width: 820px) {
  .app { display: block; }
  .sidebar { padding: 9px 12px 0; background: #192e2b; }
  #nav { padding-bottom: 9px; }
  #nav button { min-height: 44px; }
  main { padding: 16px 14px calc(28px + env(safe-area-inset-bottom)); }
  .panel-grid { grid-template-columns: 1fr; }
  .login-hero { min-height: 280px; padding: 18px 22px 28px; }
  .login-hero-inner { max-width: 68%; }
  .login-hero h2 { margin-top: 10px; font-size: 23px; }
  .login-title span { margin-top: 4px; font-size: 13px; }
  .login-tagline { max-width: 300px; font-size: 12px; }
  .login-hero-foot, .login-waves { display: none; }
  .login-characters { right: 50%; bottom: 0; transform: translateX(50%) scale(.58); transform-origin: bottom center; }
  #loginDialog form { grid-template-columns: 1fr; grid-template-rows: auto 1fr; overflow-y: auto; }
  .login-panel { border: 0; padding: 22px max(22px, calc((100vw - 460px) / 2)) calc(24px + env(safe-area-inset-bottom)); gap: 11px; }
  .login-panel header { margin-bottom: 5px; }
}
@media (max-width: 480px) {
  body { font-size: 14px; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat { padding: 12px; }
  .stat strong { font-size: 18px; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  input, select { min-height: 44px; font-size: 16px; }
  .login-hero { min-height: 370px; padding: 16px 18px; }
  .login-logo { width: 38px; height: 38px; }
  .login-logo svg { width: 20px; height: 20px; }
  .login-hero-inner { max-width: 72%; }
  .login-hero h2 { font-size: 21px; }
  .login-panel { padding-top: 18px; }
  .login-panel h3 { font-size: 25px; }
  .login-characters { right: 50%; transform: translateX(50%) scale(.58); }
}

#extensions,
#extensions > .panel,
#extensions .panel-grid > * {
  min-width: 0;
}
#extensions.view.active {
  grid-template-columns: minmax(0, 1fr);
}
#extensions .panel-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
}
#extensions .form-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr));
}
#extensions .row-actions button.primary {
  background: #166534;
  color: #fff;
  border-color: transparent;
}
#extensions .row-actions button.primary:hover {
  background: #14532d;
}
#extensions .table-wrap {
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  scrollbar-width: thin;
}
#extensions .panel > .table-wrap + .table-wrap {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid #edf0f3;
}
@media (max-width: 1100px) {
  #extensions .panel-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}
