:root {
  color-scheme: light;
  --bg: #eef2f3;
  --panel: #ffffff;
  --line: #d5dfe1;
  --line-strong: #bccacd;
  --text: #152326;
  --muted: #61747a;
  --brand: #0d756d;
  --brand-dark: #0a554f;
  --warn: #b45309;
  --danger: #b91c1c;
  --ok: #15803d;
  --soft: #e7f3f1;
  --sidebar: #17383a;
  --sidebar-muted: #b9cdcf;
  --focus: rgba(13, 117, 109, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 1080px;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

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

button {
  border: 0;
  border-radius: 6px;
  min-height: 36px;
  padding: 7px 14px;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  font-weight: 600;
  transition: background 150ms ease, border-color 150ms ease, box-shadow 150ms ease, color 150ms ease;
}

button:hover {
  background: var(--brand-dark);
}

button.secondary {
  border: 1px solid var(--line);
  background: #f4f7f7;
  color: #2f464b;
}

button.secondary:hover {
  border-color: var(--line-strong);
  background: #e8eeee;
  color: var(--text);
}

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

button.danger:hover {
  background: #991b1b;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 0;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--focus);
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: #fff;
  color: var(--text);
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

input:hover,
select:hover,
textarea:hover {
  border-color: var(--line-strong);
}

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

.login-shell {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 32px;
  background: #eaf0f1;
}

.login-panel {
  width: 440px;
  padding: 30px 32px 32px;
  border: 1px solid var(--line);
  border-top: 4px solid var(--brand);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 48px rgba(21, 50, 54, 0.13);
}

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

.login-panel p {
  margin: 0 0 24px;
  color: var(--muted);
}

.layout {
  display: grid;
  grid-template-columns: 216px minmax(0, 1fr);
  min-height: 100vh;
}

.layout > main {
  min-width: 0;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: var(--sidebar);
  color: #edf7f6;
  padding: 20px 12px;
  border-right: 1px solid #102d2f;
}

.brand {
  padding: 6px 10px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}

.brand strong {
  display: block;
  font-size: 18px;
}

.brand span {
  display: block;
  margin-top: 5px;
  color: var(--sidebar-muted);
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 5px;
  margin-top: 18px;
}

.nav button {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  min-height: 40px;
  padding: 9px 12px 9px 16px;
  background: transparent;
  color: #d8e9e8;
  text-align: left;
  font-weight: 500;
}

.nav button.active,
.nav button:hover {
  background: rgba(255, 255, 255, 0.11);
  color: #fff;
}

.nav button.active::before {
  position: absolute;
  top: 9px;
  bottom: 9px;
  left: 5px;
  width: 3px;
  border-radius: 2px;
  background: #55c8bc;
  content: "";
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.topbar h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
}

.userbar {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
}

.content {
  width: 100%;
  max-width: 1680px;
  margin: 0 auto;
  padding: 24px 28px 40px;
}

.section {
  margin-bottom: 16px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 36px;
  margin-bottom: 16px;
}

.section-title h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.section-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.grid {
  display: grid;
  gap: 14px;
}

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

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

.grid.cols-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.grid.cols-5 {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.dashboard-summary {
  margin-bottom: 16px;
}

.dashboard-insights {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(520px, 1.35fr);
  gap: 16px;
  margin-bottom: 16px;
}

.dashboard-insights .section {
  min-width: 0;
  margin-bottom: 0;
}

.pie-visual {
  position: relative;
  min-height: 270px;
}

.pie-chart {
  display: block;
  width: 100%;
  height: 270px;
  overflow: visible;
}

.pie-slice {
  cursor: pointer;
  transform-box: fill-box;
  transform-origin: center;
  transition: filter 160ms ease, transform 160ms ease;
}

.pie-slice path,
.pie-slice circle {
  stroke: #fff;
  stroke-width: 1;
}

.pie-slice.active {
  filter: brightness(1.08) drop-shadow(0 3px 4px rgba(23, 35, 38, 0.22));
  transform: scale(1.025);
}

.pie-callout {
  pointer-events: none;
}

.pie-callout polyline {
  stroke: #829196;
  stroke-width: 1.3;
  transition: stroke 160ms ease, stroke-width 160ms ease;
}

.pie-callout text {
  fill: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.pie-callout.active polyline {
  stroke: var(--brand);
  stroke-width: 2;
}

.pie-callout.active text {
  fill: var(--brand-dark);
}

.pie-tooltip {
  position: absolute;
  z-index: 2;
  display: none;
  min-width: 132px;
  padding: 9px 11px;
  border: 1px solid rgba(23, 35, 38, 0.12);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 8px 24px rgba(14, 49, 52, 0.18);
  pointer-events: none;
}

.pie-tooltip.visible {
  display: grid;
  gap: 4px;
}

.pie-tooltip span {
  color: var(--muted);
  font-size: 12px;
}

.today-metrics {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.metric {
  position: relative;
  min-height: 104px;
  padding: 17px 18px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
}

.metric span {
  display: block;
  color: var(--muted);
}

.metric strong {
  display: block;
  margin-top: 7px;
  font-size: 27px;
  line-height: 1.2;
}

.dashboard-summary .metric::before,
.today-metrics .metric::before {
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: #7b8c91;
  content: "";
}

.dashboard-summary .metric:nth-child(2)::before {
  background: #16a34a;
}

.dashboard-summary .metric:nth-child(3)::before {
  background: #2563eb;
}

.dashboard-summary .metric:nth-child(4)::before {
  background: #64748b;
}

.dashboard-summary .metric:nth-child(5)::before {
  background: #d97706;
}

.today-metrics .metric:nth-child(1)::before {
  background: #0d9488;
}

.today-metrics .metric:nth-child(2)::before {
  background: #2563eb;
}

.today-metrics .metric:nth-child(3)::before {
  background: #d97706;
}

.today-metrics .metric:nth-child(4)::before {
  background: #dc2626;
}

.metric-warn {
  border-color: #f2d4ad;
  background: #fffaf4;
}

.metric-danger {
  border-color: #efc7c7;
  background: #fff8f8;
}

.exception-warning {
  border-left: 4px solid #d97706;
}

.exception-danger {
  border-left: 4px solid #dc2626;
}

.exception-warning .section-title h2 {
  color: #92400e;
}

.exception-danger .section-title h2 {
  color: #991b1b;
}

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  align-items: end;
  gap: 12px;
}

.filters > button {
  justify-self: start;
  min-width: 76px;
}

.filter-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-actions button {
  min-width: 76px;
}

.actions {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}

.field {
  min-width: 0;
}

.field.wide {
  min-width: 260px;
}

.section > .field.wide {
  width: min(100%, 920px);
}

.grid.cols-2 > .field.wide,
.grid.cols-2 > .adjust-preview,
.grid.cols-2 > .form-actions,
.grid.cols-2 > .message,
.grid.cols-2 > [id$="Message"] {
  grid-column: 1 / -1;
}

.input-action {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.input-action button {
  white-space: nowrap;
}

.adjust-preview {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fbfb;
}

.adjust-current {
  padding: 16px;
}

.adjust-current > strong {
  display: block;
  margin-bottom: 12px;
}

.adjust-transition {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 58px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: #fff;
}

.adjust-transition > strong {
  color: var(--muted);
  font-size: 20px;
}

.adjust-transition small {
  margin-left: auto;
  color: var(--muted);
}

.import-file input[type="file"] {
  height: auto;
  padding: 7px;
  background: #f8fbfb;
}

.import-file input[type="file"]::file-selector-button {
  min-height: 32px;
  margin-right: 10px;
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

.field label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.filters > label.field > span {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 500;
}

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

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  background: #fff;
}

th,
td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

th {
  background: #f2f6f6;
  color: #3b5358;
  font-size: 13px;
  font-weight: 600;
}

tbody tr {
  transition: background 120ms ease;
}

tbody tr:nth-child(even) {
  background: #fbfcfc;
}

tbody tr:hover {
  background: #f1f7f6;
}

tbody td:first-child {
  color: #23383c;
  font-weight: 600;
}

td button {
  min-height: 30px;
  padding: 4px 9px;
  font-size: 13px;
}

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

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.pagination-summary {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 13px;
}

.pagination-controls,
.pagination-pages,
.pagination-jump,
.pagination-size,
.pagination-jump label {
  display: flex;
  align-items: center;
}

.pagination-controls {
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: wrap;
}

.pagination-pages {
  gap: 4px;
}

.pagination-controls button {
  min-width: 36px;
  min-height: 34px;
  padding: 6px 10px;
}

.pagination-page {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
}

.pagination-page:hover,
.pagination-page.active {
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
}

.pagination-size,
.pagination-jump {
  gap: 6px;
  margin-left: 6px;
  color: var(--muted);
  font-size: 13px;
}

.pagination-size select {
  width: 78px;
  min-height: 34px;
  padding: 5px 7px;
}

.pagination-jump label {
  gap: 5px;
  white-space: nowrap;
}

.pagination-jump input {
  width: 58px;
  min-height: 34px;
  padding: 5px 7px;
  text-align: center;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--soft);
  color: var(--brand-dark);
  font-size: 12px;
}

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

.tag.danger {
  background: #fef2f2;
  color: var(--danger);
}

.tag.ok {
  background: #ecfdf5;
  color: var(--ok);
}

.tag.status-full {
  background: #dcfce7;
  color: #166534;
}

.tag.status-in-use {
  background: #dbeafe;
  color: #1d4ed8;
}

.tag.status-empty {
  background: #f3f4f6;
  color: #374151;
}

.tag.status-remaining {
  background: #fef3c7;
  color: #92400e;
}

.tag.status-recycled {
  background: #fee2e2;
  color: #991b1b;
}

.muted {
  color: var(--muted);
}

.message {
  margin: 12px 0;
  padding: 11px 13px;
  border-left: 3px solid var(--brand);
  border-radius: 6px;
  background: #eef8f7;
  color: var(--brand-dark);
}

.message.error {
  border-left-color: var(--danger);
  background: #fef2f2;
  color: var(--danger);
}

.drawer {
  position: fixed;
  inset: 0;
  display: none;
  background: rgba(8, 23, 25, 0.42);
  z-index: 10;
}

.drawer.open {
  display: block;
}

.drawer-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: 620px;
  max-width: 100%;
  height: 100%;
  overflow: auto;
  padding: 0 24px 28px;
  border-left: 1px solid var(--line);
  background: #fff;
  box-shadow: -16px 0 32px rgba(0, 0, 0, 0.16);
}

.drawer-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 64px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.drawer-head h2 {
  margin: 0;
  font-size: 17px;
}

.drawer-panel > .section {
  padding: 0;
  border: 0;
  background: transparent;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.empty {
  padding: 32px 22px;
  color: var(--muted);
  text-align: center;
}

.master-tab.active {
  border-color: var(--brand);
  background: var(--soft);
  color: var(--brand-dark);
}

#csvText {
  min-height: 250px;
  font-family: Consolas, "Microsoft YaHei", monospace;
  line-height: 1.65;
}

@media (max-width: 1360px) {
  .today-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .pie-chart {
    height: 250px;
  }
}

@media (max-width: 1180px) {
  body {
    min-width: 960px;
  }

  .layout {
    grid-template-columns: 196px 1fr;
  }

  .topbar {
    padding: 0 22px;
  }

  .content {
    padding: 20px 22px 32px;
  }

  .grid.cols-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dashboard-insights {
    grid-template-columns: 1fr;
  }

  .today-metrics {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .pagination {
    align-items: flex-start;
    flex-direction: column;
  }

  .pagination-controls {
    justify-content: flex-start;
  }

  .adjust-current .grid.cols-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
