:root {
  color-scheme: light;
  --bg: #f3f6f5;
  --surface: #ffffff;
  --surface-alt: #eef5f2;
  --text: #1f2a27;
  --muted: #68746f;
  --line: #dce4df;
  --accent: #28786d;
  --accent-strong: #155f57;
  --accent-soft: #e8f5f1;
  --warn: #b24132;
  --shadow: 0 18px 42px rgba(22, 48, 42, 0.09);
  --shadow-soft: 0 8px 22px rgba(22, 48, 42, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(232, 245, 241, 0.86), rgba(243, 246, 245, 0.35) 260px),
    var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
}

.login-view {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, #e8f5f1 0%, #f6f8fb 100%);
}

.login-view.active {
  display: grid;
}

.login-card {
  display: grid;
  gap: 14px;
  width: min(380px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  background: white;
  box-shadow: var(--shadow);
}

.login-card h1,
.login-card p {
  margin: 0;
}

.login-card p,
.login-card small {
  color: var(--muted);
}

.app-shell.locked {
  display: none;
}

button,
input,
select {
  font: inherit;
}

button,
.file-button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  min-height: 38px;
  border-radius: 6px;
  padding: 8px 13px;
  cursor: pointer;
  transition: 0.16s ease;
  text-align: center;
  box-shadow: var(--shadow-soft);
}

button:hover,
.file-button:hover {
  background: var(--accent-strong);
}

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

button.danger:hover {
  background: #fff0ed;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  background: white;
  color: var(--text);
  border-radius: 6px;
  min-height: 38px;
  padding: 7px 10px;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

input:focus,
select:focus {
  outline: 0;
  border-color: rgba(40, 120, 109, 0.48);
  box-shadow: 0 0 0 3px rgba(40, 120, 109, 0.12);
}

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

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

.sidebar {
  border-right: 1px solid var(--line);
  background: rgba(251, 252, 251, 0.92);
  backdrop-filter: blur(10px);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #4f9b8e);
  color: white;
  font-weight: 700;
}

.brand h1,
.toolbar h2,
.panel h3 {
  margin: 0;
}

.brand h1 {
  font-size: 18px;
}

.brand p,
.toolbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.sync-status {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
}

.sync-status span {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
  background: var(--surface);
}

.sync-status strong {
  margin-left: 4px;
  color: var(--accent-strong);
}

.nav-tabs,
.sidebar-card {
  display: grid;
  gap: 8px;
}

.nav-tab {
  border-color: transparent;
  background: transparent;
  color: var(--text);
  text-align: left;
  box-shadow: none;
}

.nav-tab.active,
.nav-tab:hover {
  border-color: var(--line);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.sidebar-card {
  margin-top: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface);
}

.sync-panel {
  display: grid;
  gap: 18px;
}

.sync-guide {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.sync-guide article,
.sync-files div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
}

.sync-guide article {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 12px;
  padding: 16px;
}

.sync-guide article > span {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 800;
}

.sync-guide h4 {
  margin: 0 0 8px;
  font-size: 15px;
}

.sync-guide p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.sync-guide code,
.sync-files span {
  font-family: "Consolas", "Monaco", monospace;
}

.sync-files {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.sync-files div {
  display: grid;
  gap: 6px;
  padding: 14px;
}

.sync-files strong {
  color: var(--text);
}

.sync-files span {
  color: var(--accent-strong);
  overflow-wrap: anywhere;
}

#csvInput {
  display: none;
}

.content {
  min-width: 0;
  padding: 24px;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 20px;
  border: 1px solid rgba(220, 228, 223, 0.82);
  border-radius: 10px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: var(--shadow-soft);
}

.filters {
  width: min(980px, 100%);
}

.date-shortcuts {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.date-range {
  min-height: 32px;
  border-color: var(--line);
  background: white;
  color: var(--text);
  padding: 5px 11px;
}

.date-range.active,
.date-range:hover {
  border-color: var(--accent);
  background: #eef7f4;
  color: var(--accent-strong);
}

.shortcut-filter {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  color: var(--muted);
  font-size: 13px;
}

.shortcut-filter select {
  width: auto;
  min-width: 126px;
  min-height: 32px;
  padding: 5px 28px 5px 9px;
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 18px;
}

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

.metrics article,
.panel,
.form-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metrics article {
  padding: 18px;
}

.metrics span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 7px;
}

.metrics strong {
  font-size: 28px;
  line-height: 1.1;
}

.screen-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 380px);
  gap: 18px;
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  background:
    radial-gradient(circle at 94% 18%, rgba(40, 120, 109, 0.13), transparent 30%),
    linear-gradient(135deg, #ffffff 0%, #edf6f3 100%);
  box-shadow: var(--shadow);
}

.hero-period-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.hero-period-metrics article {
  display: grid;
  gap: 7px;
  min-height: 136px;
  border: 1px solid rgba(40, 120, 109, 0.16);
  border-radius: 8px;
  padding: 18px;
  background: rgba(255, 255, 255, 0.86);
}

.screen-total-card {
  display: grid;
  gap: 8px;
  align-content: center;
  border-radius: 8px;
  padding: 20px;
  background: #173f3a;
  color: white;
}

.screen-total-card span,
.screen-total-card small {
  color: rgba(255, 255, 255, 0.72);
}

.screen-total-card b,
.screen-metrics b,
.hero-period-metrics b {
  color: inherit;
  font-weight: 700;
}

.screen-total-card strong {
  font-size: 34px;
  line-height: 1.1;
}

.screen-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}

.screen-metrics article {
  display: grid;
  gap: 7px;
  min-height: 124px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}

.metric-card.today-card {
  border-color: #badfd2;
  background: linear-gradient(135deg, #f4fbf8 0%, #e1f3eb 100%);
}

.metric-card.yesterday-card {
  border-color: #bfd5ea;
  background: linear-gradient(135deg, #f6faff 0%, #e4f0fb 100%);
}

.metric-card.total-card {
  background: linear-gradient(135deg, #173f3a 0%, #24665d 100%);
}

.metric-card.last7-card {
  border-color: #d7dfc0;
  background: linear-gradient(135deg, #fbfcf5 0%, #eef4d9 100%);
}

.metric-card.previous7-card {
  border-color: #d8d2ea;
  background: linear-gradient(135deg, #faf8ff 0%, #ece7f7 100%);
}

.metric-card.current-month-card {
  border-color: #c6dfd9;
  background: linear-gradient(135deg, #f5fbfa 0%, #e2f1ee 100%);
}

.metric-card.previous-month-card {
  border-color: #d8d7cc;
  background: linear-gradient(135deg, #fcfbf6 0%, #eeeeE3 100%);
}

.metric-card.refund-card {
  border-color: #efc7c1;
  background: linear-gradient(135deg, #fff8f6 0%, #f9e5e1 100%);
}

.screen-metrics article:hover,
.panel:hover {
  transform: translateY(-1px);
  box-shadow: 0 20px 44px rgba(22, 48, 42, 0.11);
}

.screen-metrics span,
.screen-metrics small,
.hero-period-metrics span,
.hero-period-metrics small {
  color: var(--muted);
  font-size: 13px;
}

.screen-metrics strong,
.hero-period-metrics strong {
  font-size: 24px;
  line-height: 1.15;
}

.comparison-grid,
.ranking-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
}

.ranking-stack {
  grid-template-columns: 1fr;
}

.comparison-panel {
  min-height: 190px;
}

.trend-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  border-radius: 999px;
  padding: 4px 12px;
  background: #eef7f4;
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 700;
}

.comparison-bars {
  display: grid;
  gap: 18px;
  padding: 18px;
}

.comparison-bars > div {
  display: grid;
  gap: 8px;
}

.comparison-bars span {
  color: var(--muted);
  font-size: 13px;
}

.compare-track {
  height: 18px;
  border-radius: 999px;
  background: #e1ece8;
  overflow: hidden;
}

.compare-track i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.2s ease;
}

.compare-track.muted i {
  background: #9fb2ab;
}

.ranking-table {
  min-width: 980px;
  border-collapse: separate;
  border-spacing: 0 2px;
}

.ranking-stack .table-wrap {
  overflow-x: auto;
}

.ranking-stack .panel {
  min-width: 0;
}

.ranking-table th,
.ranking-table td {
  padding-left: 14px;
  padding-right: 14px;
}

.ranking-grid .panel:first-child .table-wrap {
  padding-left: 8px;
  padding-right: 8px;
}

.rank-index {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #eef7f4;
  color: var(--accent-strong);
  font-weight: 700;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
}

.panel {
  overflow: hidden;
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.panel-head input {
  max-width: 280px;
}

.table-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: flex-end;
  gap: 8px;
  width: min(760px, 100%);
}

.table-tools label {
  min-width: 94px;
}

.table-tools button {
  min-height: 38px;
}

.table-tools button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
  table-layout: fixed;
}

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

th {
  position: relative;
  background: #f8faf8;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  min-width: 92px;
  user-select: none;
}

th[data-sort-key] {
  cursor: pointer;
  padding-right: 26px;
}

th[data-sort-key]::after {
  content: "↕";
  position: absolute;
  right: 10px;
  color: #9aaaa4;
  font-size: 12px;
}

th[data-sort-key].sorted::after {
  content: "↑";
  color: var(--accent-strong);
}

th[data-sort-key].sorted[data-sort-dir="desc"]::after {
  content: "↓";
}

td.numeric,
th.numeric {
  text-align: right;
}

td.actions {
  display: flex;
  gap: 8px;
}

td.actions button {
  min-height: 32px;
  padding: 5px 9px;
}

.editable-table {
  min-width: 2800px;
}

.editable-table th:last-child,
.editable-table td:last-child {
  width: 88px;
  min-width: 88px;
}

.inline-new-row {
  background: #f4fbf8;
}

.inline-input {
  width: 100%;
  min-width: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  padding: 6px 4px;
  color: var(--text);
}

.inline-input:focus {
  outline: 2px solid rgba(40, 120, 109, 0.22);
  background: white;
}

.readonly-cell {
  color: var(--accent-strong);
  font-weight: 700;
  background: #f7fbf9;
}

.inline-input.numeric {
  text-align: right;
}

.resize-handle {
  position: absolute;
  top: 0;
  right: -3px;
  z-index: 1;
  width: 7px;
  height: 100%;
  cursor: col-resize;
}

.resize-handle::after {
  content: "";
  position: absolute;
  top: 25%;
  right: 3px;
  width: 1px;
  height: 50%;
  background: var(--line);
}

.form-panel {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 12px;
  padding: 16px;
}

.user-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.user-form label:has(input[type="checkbox"]) {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-form input[type="checkbox"] {
  width: auto;
  min-height: auto;
}

.computed-panel {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f8faf8;
}

.computed-panel article {
  display: grid;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px;
  background: white;
}

.computed-panel span {
  color: var(--muted);
  font-size: 13px;
}

.computed-panel strong {
  font-size: 20px;
  line-height: 1.1;
}

.form-actions {
  display: flex;
  align-items: end;
  gap: 8px;
}

.form-actions button {
  width: 100%;
}

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

.daily-cards {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.daily-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  overflow: hidden;
}

.daily-card summary {
  display: grid;
  grid-template-columns: 140px 90px repeat(4, minmax(110px, 1fr));
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  cursor: pointer;
  list-style: none;
}

.daily-card summary::-webkit-details-marker {
  display: none;
}

.daily-card summary::after {
  content: "展开厂家分布";
  justify-self: end;
  color: var(--accent-strong);
  font-size: 13px;
}

.daily-card[open] summary {
  border-bottom: 1px solid var(--line);
  background: #f7faf8;
}

.daily-card[open] summary::after {
  content: "收起";
}

.daily-date {
  font-weight: 700;
  font-size: 16px;
}

.daily-platform {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  min-width: 54px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  background: white;
  color: var(--accent-strong);
  font-weight: 600;
}

.daily-card-body {
  display: grid;
  gap: 14px;
  padding: 14px;
}

.daily-kpis {
  display: grid;
  grid-template-columns: repeat(6, minmax(110px, 1fr));
  gap: 10px;
}

.daily-kpis article {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 11px;
}

.daily-kpis span,
.daily-factories {
  color: var(--muted);
  font-size: 13px;
}

.daily-kpis strong {
  display: block;
  margin-top: 5px;
  font-size: 18px;
}

.daily-section-title {
  margin: 4px 0 0;
  font-size: 15px;
}

.share-chart {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.share-row {
  display: grid;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px;
  background: #fbfcfb;
}

.share-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}

.share-head strong {
  font-size: 16px;
}

.share-head span {
  color: var(--muted);
  font-size: 13px;
}

.share-bar {
  display: grid;
  grid-template-columns: 90px minmax(120px, 1fr) 70px;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.share-bar span {
  color: var(--muted);
}

.share-track {
  height: 12px;
  border-radius: 999px;
  background: #e6ece8;
  overflow: hidden;
}

.share-track i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #62a392);
}

.share-bar b {
  text-align: right;
  font-weight: 600;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav-tabs {
    grid-template-columns: repeat(3, 1fr);
  }

  .sidebar-card {
    margin-top: 0;
    grid-template-columns: repeat(4, 1fr);
  }

  .toolbar,
  .dashboard-grid,
  .screen-hero,
  .comparison-grid,
  .ranking-grid {
    grid-template-columns: 1fr;
    display: grid;
  }

  .filters,
  .metrics,
  .screen-metrics,
  .hero-period-metrics,
  .sync-guide,
  .sync-files,
  .form-panel,
  .computed-panel,
  .daily-kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

@media (max-width: 640px) {
  .content,
  .sidebar {
    padding: 16px;
  }

  .nav-tabs,
  .sidebar-card,
  .filters,
  .metrics,
  .screen-metrics,
  .hero-period-metrics,
  .sync-guide,
  .sync-files,
  .form-panel,
  .computed-panel,
  .daily-kpis,
  .daily-card summary {
    grid-template-columns: 1fr;
  }

  .metrics strong {
    font-size: 23px;
  }

  .screen-total-card strong {
    font-size: 28px;
  }

  .share-head,
  .share-bar {
    grid-template-columns: 1fr;
    display: grid;
  }

  .share-bar b {
    text-align: left;
  }
}
