:root {
  --green: #1f7a4d;
  --green-2: #e7f4ec;
  --ink: #17202a;
  --muted: #667085;
  --line: #d7dee8;
  --paper: #ffffff;
  --bg: #f5f7fa;
  --soft: #f8fafc;
  --blue: #245b8f;
  --amber: #b76e00;
  --red: #b42318;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
}
button, input, select {
  font: inherit;
}
button, .button-link {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  padding: 0 14px;
  color: #fff;
  background: var(--green);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
button.ghost { background: #eef2f6; color: var(--ink); }
.hidden { display: none !important; }

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #eef5f0;
}
.login-panel {
  width: min(420px, 100%);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 12px 32px rgba(23, 32, 42, 0.08);
}
.login-panel h1 { margin: 0 0 8px; font-size: 28px; }
.login-panel p { margin: 0 0 20px; color: var(--muted); line-height: 1.5; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 14px; }
input, select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: #fff;
  color: var(--ink);
}
.hint { font-size: 13px; }

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 220px 1fr;
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px 14px;
  background: #ffffff;
  border-right: 1px solid var(--line);
  display: grid;
  align-content: start;
  gap: 6px;
}
.brand {
  padding: 8px 4px 16px;
  display: grid;
  gap: 4px;
}
.brand strong { font-size: 20px; }
.brand span { color: var(--muted); font-size: 13px; }
.sidebar button {
  justify-content: flex-start;
  background: transparent;
  color: var(--ink);
  min-height: 38px;
  padding: 0 12px;
}
.sidebar button.active {
  background: var(--green-2);
  color: var(--green);
  font-weight: 700;
}
.content {
  min-width: 0;
  padding: 22px 24px;
  background:
    linear-gradient(180deg, rgba(231, 244, 236, 0.55), rgba(245, 247, 250, 0) 220px),
    var(--bg);
}
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
  padding: 4px 0 2px;
}

.instance-context {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.instance-context label {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.instance-context select {
  min-width: 120px;
  padding: 6px 8px;
}
.topbar h2 { margin: 0; font-size: 26px; letter-spacing: 0; }
.tab { display: none; }
.tab.active { display: block; }
.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.metrics-fixed,
.metrics-period {
  margin-bottom: 12px;
}
.metrics-fixed {
  grid-template-columns: repeat(3, minmax(160px, 1fr));
}
.metrics-period {
  grid-template-columns: repeat(3, minmax(160px, 1fr));
}
.metrics div {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  display: grid;
  gap: 8px;
  box-shadow: 0 1px 2px rgba(23, 32, 42, 0.04);
}
.metrics span { color: var(--muted); font-size: 13px; }
.metrics strong { font-size: 24px; line-height: 1.1; }
.range-bar {
  display: grid;
  grid-template-columns: 180px 180px 180px auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
}
.dashboard-range-bar {
  padding: 12px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(23, 32, 42, 0.03);
}
.dashboard-range-bar button {
  min-width: 180px;
}
h3 { margin: 18px 0 10px; font-size: 17px; }
.table-wrap {
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(23, 32, 42, 0.04);
}
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}
th, td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  vertical-align: middle;
  font-size: 14px;
  line-height: 1.35;
}
th {
  position: sticky;
  top: 0;
  background: #eef4fa;
  color: #18324a;
  font-weight: 700;
  white-space: nowrap;
}
tbody tr:nth-child(even) td { background: #fcfdff; }
tbody tr:hover td { background: #f7fbf8; }
.status-ok { color: var(--green); font-weight: 700; }
.status-low { color: var(--amber); font-weight: 700; }
.status-short { color: var(--red); font-weight: 700; }
.usage-alert-warning,
.usage-alert-critical {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 9px;
  border-radius: 999px;
  font-weight: 700;
  white-space: nowrap;
}
.usage-alert-warning { color: var(--amber); background: #fff6df; }
.usage-alert-critical { color: var(--red); background: #fff0ef; }
.alert-explanation-cell {
  display: grid;
  gap: 5px;
  min-width: 220px;
  max-width: 360px;
}
.alert-explanation-cell small { color: var(--muted); }
.alert-explanation-cell button { justify-self: start; }
.conversion-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 160px;
}
.unit-price-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.unit-price-grid label {
  display: grid;
  gap: 8px;
  font-weight: 700;
}
.unit-price-grid .wide { grid-column: 1 / -1; }
.alert-explanation-dialog {
  width: min(560px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  color: var(--ink);
  box-shadow: 0 20px 50px rgba(23, 32, 42, 0.24);
}
.alert-explanation-dialog::backdrop { background: rgba(23, 32, 42, 0.45); }
.alert-explanation-form { padding: 20px; }
.alert-explanation-form label { display: grid; gap: 8px; font-weight: 700; }
.alert-explanation-form textarea {
  width: 100%;
  resize: vertical;
  min-height: 120px;
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
}
.empty-note {
  padding: 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
}
.low-groups {
  display: grid;
  gap: 10px;
}
.low-group,
.upload-section {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.low-group summary,
.upload-section summary {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 0 14px;
  cursor: pointer;
  background: #eef4fa;
  color: #18324a;
}
.low-group summary span,
.upload-section summary span {
  color: var(--muted);
}
.low-group summary em {
  font-style: normal;
  margin-left: auto;
}
.low-group summary em + em {
  margin-left: 0;
}
.low-list,
.upload-items {
  display: grid;
}
.low-item,
.upload-item {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 90px 90px;
  gap: 12px;
  align-items: center;
  min-height: 52px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
}
.low-item div {
  display: grid;
  gap: 3px;
}
.low-item span,
.upload-item span {
  color: var(--muted);
}
.upload-detail {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}
.upload-item {
  grid-template-columns: minmax(220px, 1.6fr) minmax(120px, .8fr) minmax(140px, 1fr) 90px 100px minmax(120px, 1fr);
  font-size: 13px;
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}
.wide { grid-column: span 3; }
.search-row {
  display: flex;
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
}
.search-row input { max-width: 360px; }
.daily-toolbar {
  display: grid;
  grid-template-columns: 170px 150px minmax(220px, 1fr) auto auto auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 10px;
}
.notice {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 14px;
}
.daily-wrap {
  max-height: calc(100vh - 280px);
}
.daily-wrap table {
  min-width: 1600px;
}
#materialTable {
  min-width: 1780px;
}
#dailyTable {
  min-width: 1600px;
}
.daily-wrap th {
  top: 0;
  z-index: 2;
}
.sticky-col {
  position: sticky;
  left: 0;
  z-index: 1;
  background: #fff;
  min-width: 92px;
  white-space: nowrap;
}
th.sticky-col {
  z-index: 3;
  background: #eef4fa;
}
.name-col {
  min-width: 280px;
  max-width: 420px;
  white-space: normal;
}
#dailyTable .code-col {
  min-width: 92px;
  white-space: nowrap;
}
#dailyTable .daily-name-sticky {
  position: sticky;
  left: 0;
  z-index: 1;
  min-width: 300px;
  max-width: 360px;
  width: 320px;
  background: #fff;
  box-shadow: 1px 0 0 var(--line), 8px 0 12px rgba(23, 32, 42, 0.06);
  white-space: normal;
}
#dailyTable th.daily-name-sticky {
  z-index: 4;
  background: #eef4fa;
}
#materialTable .material-name-sticky {
  position: sticky;
  left: 0;
  z-index: 1;
  min-width: 300px;
  max-width: 380px;
  width: 330px;
  background: #fff;
  box-shadow: 1px 0 0 var(--line), 8px 0 12px rgba(23, 32, 42, 0.06);
  white-space: normal;
}
#materialTable th.material-name-sticky {
  z-index: 4;
  background: #eef4fa;
}
.unit-cell { min-width: 56px; white-space: nowrap; }
.muted-cell { color: #475467; min-width: 120px; }
.detail-cell {
  min-width: 320px;
  max-width: 520px;
  color: #475467;
}
.daily-qty {
  width: 128px;
}
.daily-note {
  min-width: 260px;
}
.pager {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
  margin: 8px 0;
  color: var(--muted);
}
.pager span {
  min-width: 160px;
  text-align: center;
}
.pager button:disabled {
  opacity: .45;
  cursor: not-allowed;
}
.mode-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.mode-daily {
  color: var(--green);
  background: #e7f4ec;
}
.mode-check {
  color: var(--blue);
  background: #eaf2fb;
}
.mode-edit {
  min-width: 178px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  align-items: center;
}
.mode-edit select {
  min-height: 34px;
  padding: 0 8px;
}
input:disabled {
  background: #f0f3f6;
  color: #667085;
}
.lock {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 6px;
  border-radius: 999px;
  background: #eef2f6;
  color: #667085;
  font-size: 12px;
}
.num {
  text-align: right;
  white-space: nowrap;
}
.small-btn {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 6px;
  white-space: nowrap;
}
.price-summary {
  min-width: 220px;
  display: grid;
  grid-template-columns: repeat(2, minmax(80px, 1fr));
  gap: 4px 12px;
  color: #475467;
  font-size: 13px;
}
.price-summary strong {
  color: var(--ink);
  font-weight: 700;
}
.stock-edit {
  min-width: 360px;
  display: grid;
  grid-template-columns: 96px minmax(150px, 1fr) auto;
  gap: 8px;
  align-items: center;
}
.stock-edit input {
  min-height: 34px;
}
.finance-edit {
  min-width: 220px;
  display: grid;
  grid-template-columns: minmax(120px, 1fr) auto;
  gap: 8px;
  align-items: center;
}
.finance-edit input {
  min-height: 34px;
}
.compact-table table {
  min-width: 560px;
}
.side-panel {
  margin-top: 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  margin-bottom: 12px;
}
.panel-head h3 {
  margin-top: 0;
}
.panel-head p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.5;
}
.price-detail {
  min-height: 34px;
  white-space: nowrap;
}
.upload-box {
  max-width: 760px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  margin-bottom: 14px;
}
.upload-box p { color: var(--muted); line-height: 1.6; }
.self-purchase-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 12px;
  margin: 12px 0;
}
.self-purchase-grid label:nth-child(3),
.self-purchase-grid label:nth-child(6) {
  grid-column: span 2;
}
.account-panel {
  max-width: 760px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
}
.account-panel h3 {
  margin-top: 0;
}
.setup-view {
  min-height: 100vh;
  padding: 32px 20px;
  background: linear-gradient(180deg, #eef6f1 0, #f5f7fa 42%);
}
.setup-panel {
  width: min(980px, 100%);
  margin: 0 auto;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 26px;
  box-shadow: 0 14px 36px rgba(23, 32, 42, 0.08);
}
.setup-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}
.setup-head strong { color: var(--green); font-size: 15px; }
.setup-head h1 { margin: 6px 0; font-size: 28px; }
.setup-head p { margin: 0; color: var(--muted); line-height: 1.6; }
.setup-badge {
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--green-2);
  color: var(--green);
  font-weight: 700;
  white-space: nowrap;
}
.setup-steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 18px 0;
}
.setup-steps span {
  padding: 9px 12px;
  text-align: center;
  background: #f0f3f6;
  border-radius: 6px;
  color: var(--muted);
  font-weight: 700;
}
.setup-steps span.active { color: var(--green); background: var(--green-2); }
.setup-section {
  padding: 18px 0;
  border-top: 1px solid var(--line);
}
.setup-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.compact-form { margin-top: 14px; }
.inline-actions { display: flex; gap: 8px; margin-top: 12px; }
.access-picker {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  color: var(--muted);
}
.access-picker > div { display: flex; flex-wrap: wrap; gap: 8px 14px; }
.access-picker label { display: flex; align-items: center; gap: 6px; color: var(--ink); }
.access-picker input { width: auto; min-height: auto; }
.setup-complete {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}
.setup-complete div { display: grid; gap: 4px; }
.setup-complete span { color: var(--muted); }
.organization-layout { display: grid; gap: 14px; max-width: 1040px; }
.organization-layout .account-panel { max-width: none; margin: 0; }
pre {
  margin-top: 12px;
  white-space: pre-wrap;
  background: #f0f3f6;
  border-radius: 6px;
  padding: 12px;
}
.print-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 12px;
}
.print-tools {
  display: grid;
  grid-template-columns: 180px 180px auto auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
}
.print-card {
  min-height: 86px;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
}
.print-report {
  margin-top: 18px;
}
.print-report-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: end;
}
.print-report-head h3 {
  margin-bottom: 4px;
}
.print-report-head p {
  margin: 0 0 10px;
  color: var(--muted);
}

@media (max-width: 760px) {
  .setup-view { padding: 14px; }
  .setup-panel { padding: 18px; }
  .setup-head, .setup-complete { align-items: stretch; flex-direction: column; }
  .setup-grid { grid-template-columns: 1fr; }
  .setup-steps { grid-template-columns: 1fr; }
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    grid-template-columns: repeat(3, 1fr);
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .brand { grid-column: 1 / -1; padding-bottom: 8px; }
  .sidebar button { justify-content: center; padding: 0 8px; font-size: 14px; }
  .content { padding: 12px; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .low-item,
  .upload-item {
    grid-template-columns: 1fr;
  }
  .low-group summary,
  .upload-section summary {
    flex-wrap: wrap;
    padding: 10px 12px;
  }
  .range-bar { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .self-purchase-grid { grid-template-columns: 1fr; }
  .self-purchase-grid label:nth-child(3),
  .self-purchase-grid label:nth-child(6) { grid-column: auto; }
  .wide { grid-column: auto; }
  .search-row { display: grid; }
  .daily-toolbar { grid-template-columns: 1fr; }
  .daily-wrap {
    max-height: none;
    -webkit-overflow-scrolling: touch;
  }
  #dailyTable {
    min-width: 720px;
  }
  #dailyTable .daily-name-sticky {
    min-width: 170px;
    max-width: 190px;
    width: 180px;
  }
  #dailyTable th:nth-child(n+10),
  #dailyTable td:nth-child(n+10) {
    display: none;
  }
  #dailyTable th:nth-child(6),
  #dailyTable td:nth-child(6),
  #dailyTable th:nth-child(7),
  #dailyTable td:nth-child(7),
  #dailyTable th:nth-child(8),
  #dailyTable td:nth-child(8) {
    display: none;
  }
  .daily-qty {
    width: 108px;
  }
  .daily-note {
    min-width: 150px;
  }
  .unit-price-grid { grid-template-columns: 1fr; }
  .unit-price-grid .wide { grid-column: auto; }
  #materialTable .material-name-sticky {
    min-width: 210px;
    max-width: 230px;
    width: 220px;
  }
  #dailyTable .code-col {
    min-width: 78px;
  }
  .pager {
    justify-content: stretch;
    display: grid;
    grid-template-columns: 1fr;
  }
  .pager span {
    min-width: 0;
  }
  .print-tools { grid-template-columns: 1fr; }
  .search-row input { max-width: none; }
  .print-grid { grid-template-columns: 1fr; }
}

@media print {
  .sidebar, .topbar, button, .search-row, .daily-toolbar, .upload-box, .print-tools, .print-grid { display: none !important; }
  .shell { display: block; }
  .content { padding: 0; }
  .tab { display: block; }
  .tab:not(.active) { display: none; }
  .table-wrap { border: 0; overflow: visible; }
  table { min-width: 0; }
  .metrics { grid-template-columns: repeat(4, 1fr); }
  .metrics div { padding: 8px; }
  .metrics strong { font-size: 18px; }
  body { background: #fff; }
}
