:root {
  color-scheme: light;
  --ink-900: #17202c;
  --ink-800: #233247;
  --ink-700: #34465d;
  --ink-600: #4d5f75;
  --ink-500: #65758a;
  --ink-400: #8794a6;
  --ink-300: #b8c1ce;
  --ink-200: #d7dde6;
  --ink-100: #edf1f5;
  --ink-50: #f7f9fb;
  --surface: #ffffff;
  --surface-subtle: #fbfcfd;
  --bg: #eef2f6;
  --primary: #1f3349;
  --primary-2: #2c4662;
  --primary-soft: #e8eef5;
  --accent: #0f766e;
  --accent-soft: #dff4ef;
  --success: #15803d;
  --success-soft: #dcfce7;
  --danger: #c7352d;
  --danger-soft: #fee2e2;
  --warning: #b7791f;
  --warning-soft: #fef3c7;
  --info: #2563eb;
  --info-soft: #dbeafe;
  --line: #dfe5ec;
  --line-strong: #c7d0dc;
  --shadow-sm: 0 1px 2px rgba(23, 32, 44, .06);
  --shadow-md: 0 10px 28px rgba(31, 51, 73, .08);
  --radius: 8px;
  --radius-sm: 6px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink-900);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
}

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

button { cursor: pointer; }

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

:focus-visible {
  outline: 3px solid rgba(37, 99, 235, .22);
  outline-offset: 2px;
}

h1, h2, h3, p { margin-top: 0; }

h2 {
  margin-bottom: var(--space-2);
  color: var(--ink-900);
  font-size: 22px;
  line-height: 1.25;
}

h3 {
  margin-bottom: var(--space-3);
  color: var(--ink-800);
  font-size: 17px;
  line-height: 1.25;
}

a {
  color: var(--info);
  text-decoration: none;
}

a:hover { text-decoration: underline; }

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--space-6);
  background:
    linear-gradient(rgba(23, 32, 44, .76), rgba(23, 32, 44, .82)),
    url("https://images.unsplash.com/photo-1500530855697-b586d89ba3ee?auto=format&fit=crop&w=1600&q=75") center/cover;
}

.login-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, .72);
  border-radius: var(--radius);
  padding: 30px;
  box-shadow: 0 22px 60px rgba(0, 0, 0, .24);
}

.login-card h1 {
  margin-bottom: var(--space-3);
  color: var(--ink-900);
  font-size: 24px;
  line-height: 1.25;
}

.login-card p {
  color: var(--ink-600);
  line-height: 1.7;
}

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

.mobile-menu-backdrop,
.mobile-menu-btn {
  display: none;
}

.side {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: var(--primary);
  color: white;
  padding: var(--space-4) 10px;
  box-shadow: inset -1px 0 rgba(255, 255, 255, .07);
}

.brand {
  padding: var(--space-2) var(--space-2) var(--space-4);
  color: white;
  font-size: 16px;
  font-weight: 800;
  line-height: 1.35;
  white-space: nowrap;
}

.brand span {
  display: inline-flex;
  margin-top: var(--space-1);
  color: rgba(255, 255, 255, .66) !important;
  font-size: 12px !important;
  font-weight: 700;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-group {
  display: grid;
  gap: 2px;
}

.nav-title {
  padding: 3px 8px 4px;
  color: rgba(255, 255, 255, .86);
  font-size: 14px;
  font-weight: 850;
  letter-spacing: 0;
}

.nav button {
  width: calc(100% - 18px);
  min-height: 31px;
  margin-left: 18px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: rgba(255, 255, 255, .74);
  text-align: left;
  padding: 5px 10px;
  font-size: 13px;
  font-weight: 650;
  transition: background .16s ease, color .16s ease;
}

.nav-group:first-child .nav button {
  width: 100%;
  min-height: 34px;
  margin-left: 0;
  padding: 6px 8px;
  font-size: 14px;
  font-weight: 750;
}

.nav button.active,
.nav button:hover {
  background: rgba(255, 255, 255, .13);
  color: white;
}

main {
  min-width: 0;
}

.top {
  position: sticky;
  top: 0;
  z-index: 5;
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: 0 var(--space-6);
  background: rgba(255, 255, 255, .92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.top strong {
  color: var(--ink-900);
  font-size: 17px;
}

.top > div {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--ink-500);
  white-space: nowrap;
}

.top-title {
  min-width: 0;
}

.content {
  max-width: 1680px;
  padding: var(--space-6);
}

.card {
  margin-bottom: var(--space-4);
  padding: var(--space-4);
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.card.compact {
  padding: var(--space-3) var(--space-4);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.card-head h3 {
  margin: 0;
}

.grid {
  display: grid;
  gap: var(--space-4);
}

.stats {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: var(--space-4);
}

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

.two .card {
  min-height: 154px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.stat-label {
  color: var(--ink-500);
  font-size: 12px;
  font-weight: 700;
}

.stat-value {
  margin: 7px 0 3px;
  color: var(--primary);
  font-size: 28px;
  font-weight: 850;
  line-height: 1.15;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field label {
  color: var(--ink-700);
  font-size: 12px;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  background: var(--surface);
  color: var(--ink-900);
  transition: border-color .14s ease, box-shadow .14s ease, background .14s ease;
}

input:hover,
select:hover,
textarea:hover {
  border-color: #aeb9c8;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--info);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
  outline: 0;
}

input[type="file"] {
  padding: 6px 8px;
  color: var(--ink-600);
}

input[type="date"],
input[type="datetime-local"],
input[type="time"],
input[type="month"] {
  display: block;
  max-width: 100%;
  min-width: 0;
  line-height: 1.2;
}

input[type="date"]::-webkit-date-and-time-value,
input[type="datetime-local"]::-webkit-date-and-time-value,
input[type="time"]::-webkit-date-and-time-value,
input[type="month"]::-webkit-date-and-time-value {
  min-width: 0;
  text-align: left;
}

textarea { min-height: 76px; }

small,
.muted {
  color: var(--ink-500);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-3);
}

.form-grid .wide { grid-column: span 2; }

.weigh-section {
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--line);
}

.notice + .weigh-section,
form > .weigh-section:first-child {
  border-top: 0;
  padding-top: 0;
}

.weigh-section h3 {
  margin-bottom: var(--space-3);
}

.weigh-section .actions {
  margin-top: var(--space-3);
}

.weigh-section [id$="-result"],
#upload-result {
  margin-top: var(--space-3);
}

.static-field {
  min-height: 38px;
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  background: var(--ink-50);
  color: var(--ink-800);
  font-weight: 750;
}

.checkline {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--ink-700);
  font-size: 13px;
  font-weight: 800;
}

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

.permission-grid {
  display: flex;
  align-items: center;
  gap: var(--space-2) var(--space-4);
  flex-wrap: wrap;
  min-height: 38px;
}

.permission-groups {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
}

.permission-group {
  display: grid;
  gap: var(--space-2);
}

.permission-title {
  color: var(--ink-800);
  font-size: 12px;
  font-weight: 850;
}

.actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: nowrap;
}

.btn {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 8px 13px;
  background: var(--primary);
  color: white;
  font-weight: 750;
  line-height: 1.1;
  white-space: nowrap;
  box-shadow: 0 1px 1px rgba(23, 32, 44, .06);
  transition: background .14s ease, border-color .14s ease, color .14s ease, box-shadow .14s ease, transform .08s ease;
}

.btn:hover {
  background: var(--primary-2);
  text-decoration: none;
}

.btn:active {
  transform: translateY(1px);
}

.btn.secondary {
  background: var(--surface);
  color: var(--primary);
  border-color: var(--line-strong);
}

.btn.secondary:hover {
  background: var(--primary-soft);
  border-color: #b9c5d2;
}

.btn.danger {
  background: var(--danger);
  color: white;
}

.btn.danger:hover {
  background: #a92720;
}

.btn.warning {
  background: var(--warning);
  color: white;
}

.btn.small {
  min-height: 30px;
  height: 30px;
  padding: 5px 9px;
  font-size: 12px;
}

table {
  width: 100%;
  min-width: 1080px;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}

th,
td {
  height: 46px;
  border-bottom: 1px solid var(--line);
  padding: 8px 10px;
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
  line-height: 1.35;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--ink-50);
  color: var(--ink-600);
  font-size: 12px;
  font-weight: 850;
}

td {
  max-width: 200px;
  overflow: hidden;
  color: var(--ink-900);
  text-overflow: ellipsis;
}

tbody tr {
  background: var(--surface);
}

tbody tr:hover {
  background: var(--surface-subtle);
}

td.actions {
  max-width: none;
  overflow: visible;
  display: table-cell;
  white-space: nowrap;
}

td.actions .btn {
  vertical-align: middle;
}

td.actions .btn + .btn {
  margin-left: 6px;
}

.num {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.badge {
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 10px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}

.badge.success { background: var(--success-soft); color: var(--success); }
.badge.info { background: var(--info-soft); color: #1d4ed8; }
.badge.warning { background: var(--warning-soft); color: #92400e; }
.badge.danger { background: var(--danger-soft); color: #991b1b; }

.notice {
  margin-bottom: var(--space-3);
  padding: 10px 12px;
  border: 1px solid #f2d48a;
  border-radius: var(--radius-sm);
  background: #fff8df;
  color: #8a5a12;
  font-size: 13px;
  line-height: 1.55;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: var(--space-4);
  background: rgba(23, 32, 44, .46);
  backdrop-filter: blur(4px);
}

.modal {
  width: min(440px, 100%);
  max-height: min(76vh, 620px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, .72);
  border-radius: var(--radius);
  box-shadow: 0 24px 72px rgba(23, 32, 44, .26);
}

.modal-head {
  padding: var(--space-4) var(--space-4) 0;
}

.modal-head h3 {
  margin: 0;
}

.modal-body {
  padding: var(--space-3) var(--space-4);
  overflow: auto;
  color: var(--ink-700);
  line-height: 1.7;
  word-break: break-word;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4) var(--space-4);
  border-top: 1px solid var(--line);
  background: var(--surface-subtle);
}

.seg {
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.seg button {
  min-height: 34px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--primary);
  padding: 8px 12px;
  font-weight: 800;
}

.seg button:last-child {
  border-right: 0;
}

.seg button.active {
  background: var(--primary);
  color: white;
}

.chart-wrap {
  width: 100%;
  overflow: hidden;
}

.chart-wrap svg {
  width: 100%;
  min-height: 250px;
  display: block;
}

.axis {
  stroke: var(--line-strong);
  stroke-width: 1.2;
}

.trend-line {
  fill: none;
  stroke: var(--primary-2);
  stroke-width: 3;
}

.trend-dot {
  fill: #d88a1d;
  stroke: white;
  stroke-width: 1.5;
}

.trend-hit {
  fill: transparent;
  cursor: crosshair;
}

.chart-tip {
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s ease;
}

.chart-tip rect {
  fill: var(--ink-900);
}

.chart-tip text {
  fill: white;
  font-size: 12px;
  font-weight: 800;
}

.chart-point:hover .chart-tip { opacity: 1; }
.chart-point:hover .trend-dot { fill: var(--accent); }
.chart-label { fill: var(--ink-500); font-size: 12px; }

.todo-list {
  display: grid;
  gap: var(--space-2);
}

.todo-item {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  color: var(--ink-700);
  text-align: left;
  padding: 9px 12px;
}

button.todo-item:hover {
  background: #f1f7f6;
  border-color: #cae3df;
}

.preview img {
  max-width: 100%;
  max-height: 320px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
}

.mobile-cards { display: none; }

.record-card {
  display: grid;
  gap: var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--space-3);
  background: var(--surface);
}

.record-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
}

.record-card-head strong {
  color: var(--ink-900);
  font-size: 14px;
}

.record-card-head span {
  display: block;
  margin-top: 3px;
  color: var(--ink-500);
  font-size: 12px;
}

.record-card-body {
  display: grid;
  gap: var(--space-2);
}

.record-row,
.detail-row {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
}

.record-row span,
.detail-row span {
  color: var(--ink-500);
  font-size: 12px;
  font-weight: 750;
}

.record-row strong,
.detail-row strong {
  min-width: 0;
  color: var(--ink-800);
  text-align: right;
  font-weight: 750;
  overflow-wrap: anywhere;
}

.record-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding-top: var(--space-2);
  border-top: 1px solid var(--line);
}

.record-empty {
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: var(--space-4);
  color: var(--ink-500);
  text-align: center;
  background: var(--surface-subtle);
}

.detail-panel {
  border-left: 4px solid var(--primary-2);
}

.flow-note {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-2);
  margin: var(--space-3) 0 var(--space-4);
  padding: var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-subtle);
}

.flow-note div {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.flow-note span {
  color: var(--ink-500);
  font-size: 12px;
  font-weight: 850;
}

.flow-note strong {
  color: var(--ink-800);
  font-size: 13px;
  font-weight: 750;
  line-height: 1.45;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-3);
}

.detail-block {
  display: grid;
  gap: var(--space-2);
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  background: var(--surface-subtle);
}

.detail-block h4 {
  margin: 0 0 var(--space-1);
  color: var(--ink-800);
  font-size: 13px;
}

.export-scope {
  margin-top: var(--space-3);
  color: var(--ink-500);
  font-size: 12px;
  font-weight: 750;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.page-head h2 {
  margin-bottom: 5px;
  color: var(--ink-900);
}

.page-head p {
  margin: 0;
  color: var(--ink-500);
}

.filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-3);
  align-items: end;
  margin: -2px 0 var(--space-4);
  padding: var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-subtle);
}

.filters .wide { grid-column: span 2; }

.filter-actions {
  min-height: 60px;
  display: flex;
  align-items: end;
  gap: var(--space-2);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: var(--space-3);
  color: var(--ink-500);
  font-size: 13px;
}

@media (max-width: 1180px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid,
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .shell {
    display: block;
  }

  .mobile-menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: block;
    border: 0;
    background: rgba(15, 23, 42, .42);
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s ease;
  }

  .mobile-menu-backdrop.open {
    opacity: 1;
    pointer-events: auto;
  }

  .mobile-menu-btn {
    width: 40px;
    min-width: 40px;
    height: 40px;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
  }

  .mobile-menu-btn span {
    width: 18px;
    height: 2px;
    border-radius: 2px;
    background: var(--primary);
  }

  .side {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 40;
    width: min(76vw, 286px);
    height: 100vh;
    height: 100dvh;
    max-height: 100dvh;
    overflow-y: auto;
    padding: var(--space-4) 10px calc(var(--space-6) + env(safe-area-inset-bottom));
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    touch-action: pan-y;
    transform: translateX(-104%);
    transition: transform .2s ease;
    box-shadow: 16px 0 34px rgba(15, 23, 42, .22);
  }

  .side.open {
    transform: translateX(0);
  }

  .brand {
    padding: var(--space-1) var(--space-2) var(--space-4);
  }

  .nav {
    display: grid;
    gap: 9px;
  }

  .nav-group {
    display: grid;
    gap: 2px;
  }

  .nav-title {
    display: block;
    padding: 3px 8px 4px;
    color: rgba(255, 255, 255, .86);
    font-size: 14px;
    font-weight: 850;
  }

  .nav button {
    width: calc(100% - 18px);
    min-height: 34px;
    margin-left: 18px;
    padding: 6px 10px;
    text-align: left;
    font-size: 13px;
  }

  .nav-group:first-child .nav button {
    width: 100%;
    min-height: 34px;
    margin-left: 0;
    padding: 6px 8px;
    font-size: 14px;
  }

  .top {
    position: static;
    min-height: 58px;
    padding: 10px 12px;
    align-items: flex-start;
    flex-direction: column;
  }

  .top-title {
    width: 100%;
    display: flex;
    align-items: center;
    gap: var(--space-2);
  }

  .top-title strong {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .content {
    padding: var(--space-3);
  }

  .stats,
  .two,
  .form-grid,
  .filters {
    grid-template-columns: 1fr;
  }

  .form-grid .wide,
  .filters .wide {
    grid-column: auto;
  }

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

  .actions {
    flex-wrap: wrap;
  }

  table {
    display: table;
    min-width: 980px;
  }

  .mobile-cards {
    display: grid;
    gap: 10px;
  }

  .table-scroll.has-mobile-cards {
    display: none;
  }

  .record {
    display: grid;
    gap: 8px;
  }

  .row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    color: var(--ink-500);
    font-size: 13px;
  }

  .row strong {
    color: var(--ink-900);
    text-align: right;
  }

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

  .detail-grid {
    grid-template-columns: 1fr;
  }

  .record-row,
  .detail-row {
    align-items: flex-start;
  }

  .flow-note {
    grid-template-columns: 1fr;
  }

  .record-actions .btn {
    min-height: 36px;
  }
}
