:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --line: #d9dee7;
  --text: #17202a;
  --muted: #657184;
  --brand: #0f766e;
  --brand-dark: #115e59;
  --danger: #b42318;
  --warn: #a16207;
  --ok: #087443;
}

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

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

button, .button {
  min-height: 34px;
  border: 1px solid var(--brand);
  background: var(--brand);
  color: #fff;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

button.secondary, .button.secondary {
  background: #fff;
  color: var(--brand-dark);
}

button.danger {
  background: var(--danger);
  border-color: var(--danger);
}

button:disabled {
  opacity: .55;
  cursor: not-allowed;
}

input, select, textarea {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 6px 8px;
}

textarea { min-height: 70px; resize: vertical; }

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login form {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
}

.layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 230px 1fr;
}

.sidebar {
  background: #111827;
  color: #e5e7eb;
  padding: 18px 14px;
}

.brand {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 18px;
}

.role-only {
  font-size: 15px;
  line-height: 1.2;
  margin-bottom: 14px;
}

.role-only span {
  display: block;
  margin-top: 6px;
  color: #aab2c0;
  font-size: 12px;
  font-weight: 500;
}

.userbox {
  color: #aab2c0;
  font-size: 13px;
  line-height: 1.7;
  border-bottom: 1px solid #2b3443;
  padding-bottom: 12px;
  margin-bottom: 12px;
}

.nav button {
  width: 100%;
  justify-content: flex-start;
  background: transparent;
  border: 0;
  color: #d8dee9;
  margin: 2px 0;
}

.nav button.active {
  background: #263244;
  color: #fff;
}

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

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

h1 { font-size: 22px; margin: 0; }
h2 { font-size: 17px; margin: 18px 0 10px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 14px;
}

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

.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }

label {
  display: grid;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
}

label span { color: var(--muted); }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 10px 0;
}

.pager {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  margin: 8px 0;
  color: var(--muted);
  font-size: 13px;
}

.pager select {
  width: auto;
  min-height: 30px;
  padding: 4px 28px 4px 8px;
  border-radius: 5px;
}

.hidden { display: none !important; }

.permission-box {
  margin-top: 10px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.permission-box summary {
  cursor: pointer;
  color: var(--brand-dark);
  font-size: 13px;
}

.permission-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 6px 10px;
  margin-top: 10px;
}

.checkline {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
  min-height: 26px;
}

.checkline input {
  width: auto;
  min-height: auto;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 850px;
}

.compact-table {
  min-width: 1320px;
}

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

.compact-table th,
.compact-table td {
  padding: 6px;
  font-size: 12px;
}

.mini-input {
  min-height: 28px;
  padding: 3px 5px;
  border-radius: 4px;
  font-size: 12px;
  margin: 2px 0;
}

.link-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--brand);
  padding: 0;
  min-height: auto;
  font: inherit;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}

.link-btn:hover {
  text-decoration: underline;
}

.detail-panel {
  margin-top: 12px;
}

.detail-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 10px;
}

.compact-filter {
  padding: 8px 10px;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: end;
}

.filter-row label {
  width: 150px;
  gap: 2px;
  font-size: 12px;
}

.filter-row select {
  min-height: 28px;
  padding: 3px 6px;
  border-radius: 4px;
  font-size: 12px;
}

.order-filter-row label {
  width: 132px;
}

.order-filter-row label:first-child {
  width: 260px;
}

th {
  background: #eef2f7;
  color: #374151;
  font-weight: 600;
  white-space: nowrap;
}

tr:last-child td { border-bottom: 0; }

.metric-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.metric {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.metric b {
  display: block;
  font-size: 24px;
  margin-bottom: 4px;
}

.muted { color: var(--muted); }
.error { color: var(--danger); margin-top: 8px; }
.diff-qty { color: var(--danger); font-weight: 700; }
.clip-name {
  display: inline-block;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

.compact-meta {
  display: inline-block;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.short-url {
  display: inline-block;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

.fee-input {
  width: 58px;
  min-width: 58px;
}

.compact-remark-input {
  width: 86px;
  min-width: 86px;
}
.ok { color: var(--ok); }
.warn { color: var(--warn); }

.item-editor {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  margin-top: 10px;
}

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eef2f7;
}

.compact-order-form {
  padding: 10px;
}

.order-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 13px;
}

.demand-entry-table {
  min-width: 1180px;
}

.demand-entry-table .item-editor {
  border: 0;
  border-radius: 0;
  padding: 0;
  margin: 0;
}

.demand-entry-table th,
.demand-entry-table td {
  padding: 5px;
}

.purchase-toolbar {
  padding: 8px 10px;
}

.purchase-filter-row {
  gap: 6px;
  margin-bottom: 8px;
}

.purchase-filter-row label {
  width: 126px;
}

.receipt-strip {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.receipt-chip {
  display: grid;
  grid-template-columns: auto auto;
  gap: 2px 8px;
  min-width: 210px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  background: #f8fafc;
  font-size: 11px;
  color: var(--muted);
}

.receipt-chip b,
.receipt-chip strong {
  color: var(--text);
}

.receipt-chip em {
  grid-column: 1 / -1;
  font-style: normal;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.purchase-table {
  min-width: 1120px;
}

.purchase-table th,
.purchase-table td {
  padding: 5px;
}

.purchase-grid {
  display: grid;
  grid-template-columns: 1.45fr repeat(3, minmax(72px, .8fr));
  gap: 3px;
  min-width: 520px;
}

.purchase-grid .wide {
  min-width: 130px;
}

.qty-input {
  width: 82px;
  display: block;
  margin-top: 4px;
}

.small-btn {
  min-height: 30px;
  padding: 5px 10px;
  white-space: nowrap;
}

.receipt-match-panel {
  padding: 8px 10px;
}

.receipt-form {
  display: grid;
  grid-template-columns: .95fr .8fr .75fr .7fr .75fr .8fr 1fr .62fr .62fr .62fr;
  gap: 6px;
  align-items: end;
}

.receipt-form label {
  gap: 2px;
  font-size: 12px;
}

.receipt-form input,
.match-actions input,
.match-actions select {
  min-height: 28px;
  padding: 3px 6px;
  border-radius: 4px;
  font-size: 12px;
}

.match-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin: 8px 0;
}

.match-actions #demandSearch {
  flex: 0 1 360px;
  width: 360px;
}

.match-actions #quickQtyMode {
  flex: 0 0 118px;
  width: 118px;
  min-width: 118px;
  padding-right: 20px;
}

.receipt-match-table {
  min-width: 1180px;
}

.receipt-match-table th,
.receipt-match-table td {
  padding: 5px;
  vertical-align: middle;
}

.receipt-match-table .jp-name-input {
  width: 180px;
}

.receipt-match-table .price-input,
.receipt-match-table .qty-input {
  width: 86px;
}

.receipt-match-table .remark-input {
  width: 160px;
}

.master-forms {
  align-items: start;
}

.compact-master-form {
  padding: 10px;
}

.compact-master-form h2 {
  margin-bottom: 8px;
  font-size: 16px;
}

.compact-master-form label {
  margin-bottom: 6px;
}

.purchase-preview-panel {
  padding: 10px;
}

.compact-preview {
  padding: 7px 9px;
}

.preview-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: end;
  margin-bottom: 6px;
}

.preview-toolbar label {
  width: 128px;
  gap: 2px;
  font-size: 12px;
}

.preview-toolbar label:has(#purchasedSearch) {
  width: 260px;
}

.preview-toolbar input {
  min-height: 28px;
  padding: 3px 6px;
  border-radius: 4px;
  font-size: 12px;
}

.purchase-day-preview h2 {
  font-size: 13px;
  margin-bottom: 4px;
}

.purchase-day-preview-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.purchased-preview-section .table-wrap {
  max-height: 520px;
}

.purchased-preview-section th {
  position: sticky;
  top: 0;
  z-index: 2;
  box-shadow: 0 1px 0 var(--line);
}

.purchased-preview-section table {
  min-width: 1500px;
}

.day-demand-panel {
  margin-top: 12px;
}

.day-demand-panel h2 {
  font-size: 16px;
  margin-bottom: 8px;
}

.compact-day-detail {
  border-top: 1px solid var(--line);
  padding-top: 5px;
}

.compact-day-detail summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--brand-dark);
  margin-bottom: 5px;
}

.mini-preview-list .table-wrap {
  max-height: 520px;
}

.mini-preview-list table {
  min-width: 900px;
}

.mini-preview-list th,
.mini-preview-list td {
  padding: 5px;
  font-size: 12px;
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .grid, .grid.two, .grid.three, .metric-row { grid-template-columns: 1fr; }
  .main { padding: 12px; }
}
