*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-w: 220px;
  --sidebar-collapsed: 60px;
  --c-bg: #f5f7fa;
  --c-white: #fff;
  --c-border: #e1e4e8;
  --c-text: #24292e;
  --c-muted: #6a737d;
  --c-primary: #0366d6;
  --c-danger: #d73a49;
  --c-warning: #f0ad4e;
  --c-info: #0366d6;
  --c-success: #22863a;
  --c-summary-bg: #f0f7ff;
  --c-gray: #999;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  color: var(--c-text);
  background: var(--c-bg);
  line-height: 1.5;
}

/* Layout */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: #1b1f23;
  color: #fff;
  display: flex; flex-direction: column;
  position: fixed; top: 0; bottom: 0; left: 0;
  z-index: 100;
  transition: width .2s;
  overflow: hidden;
}
.sidebar.collapsed { width: var(--sidebar-collapsed); }

.sidebar-toggle {
  position: absolute; top: 12px; right: 12px;
  width: 28px; height: 28px; border: none; background: #2f363d;
  color: #8b949e; border-radius: 4px; cursor: pointer; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  z-index: 10;
}
.sidebar-toggle:hover { color: #fff; background: #444c56; }

.sidebar-brand {
  padding: 16px; font-size: 18px; font-weight: 700;
  border-bottom: 1px solid #2f363d; white-space: nowrap;
}
.sidebar.collapsed .sidebar-brand { font-size: 0; padding: 16px 8px; text-align: center; }
.sidebar.collapsed .sidebar-brand::after { content: "📋"; font-size: 20px; }

.sidebar-nav { flex: 1; padding: 8px 0; }
.nav-item {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px; color: #8b949e; text-decoration: none; font-size: 14px;
  transition: background .15s; white-space: nowrap;
}
.sidebar.collapsed .nav-item { padding: 10px 12px; }
.sidebar.collapsed .nav-item span:not(.nav-icon) { display: none; }

.nav-item:hover { background: #2f363d; color: #fff; }
.nav-item.active { background: #0366d6; color: #fff; }
.nav-icon { font-size: 16px; flex-shrink: 0; }
.sidebar-footer {
  padding: 12px 16px; border-top: 1px solid #2f363d; font-size: 12px;
  display: flex; justify-content: space-between; align-items: center; white-space: nowrap;
}
.sidebar.collapsed .sidebar-footer { flex-direction: column; gap: 8px; padding: 12px 8px; }
.sidebar.collapsed .nav-user, .sidebar.collapsed .nav-logout { font-size: 10px; }
.nav-user { color: #8b949e; }
.nav-logout { color: #8b949e; text-decoration: none; }
.nav-logout:hover { color: #fff; }

.main {
  margin-left: var(--sidebar-w);
  flex: 1; padding: 24px 32px; overflow-x: auto;
  transition: margin-left .2s;
}
.main.expanded { margin-left: var(--sidebar-collapsed); }

/* Login */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: #f0f2f5; }
.login-box {
  background: #fff; padding: 40px; border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0,0,0,.08); width: 360px;
}
.login-box h1 { text-align: center; margin-bottom: 24px; font-size: 22px; }

/* Forms */
.form-group { margin-bottom: 12px; }
.form-group label { display: block; font-weight: 600; font-size: 12px; color: var(--c-muted); margin-bottom: 4px; }
.form-input, .form-select {
  width: 100%; padding: 8px 12px; border: 1px solid var(--c-border);
  border-radius: 6px; font-size: 14px; font-family: inherit;
  background: var(--c-white);
}
.form-input:focus, .form-select:focus { outline: none; border-color: var(--c-primary); box-shadow: 0 0 0 2px rgba(3,102,214,.2); }
.form-select { cursor: pointer; }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.form-row .form-group { flex: 1; min-width: 140px; }

/* Checkbox */
.checkbox-cell { width: 40px; text-align: center; }
.checkbox-cell input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; }

/* Buttons */
.btn {
  display: inline-block; padding: 8px 16px; border: 1px solid var(--c-border);
  border-radius: 6px; font-size: 14px; font-family: inherit; cursor: pointer;
  text-decoration: none; background: var(--c-white); color: var(--c-text);
  transition: all .15s; white-space: nowrap;
}
.btn:hover { background: #f3f4f6; }
.btn-primary { background: var(--c-primary); color: #fff; border-color: var(--c-primary); }
.btn-primary:hover { background: #0256b3; }
.btn-secondary { background: #f3f4f6; }
.btn-secondary:hover { background: #e5e7eb; }
.btn-danger { color: var(--c-danger); border-color: var(--c-danger); }
.btn-danger:hover { background: #fff0f0; }
.btn-success { color: #22863a; border-color: #22863a; }
.btn-success:hover { background: #e6ffec; }
.btn-warning { color: #856404; border-color: #f0ad4e; }
.btn-warning:hover { background: #fff3cd; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-lg { padding: 10px 24px; font-size: 15px; }
.btn-full { width: 100%; }

/* Floating action bar */
.action-bar {
  position: fixed; bottom: 0; left: var(--sidebar-w); right: 0;
  background: #1b1f23; color: #fff; padding: 12px 32px;
  display: flex; align-items: center; gap: 16px;
  z-index: 50; transition: left .2s;
  box-shadow: 0 -2px 8px rgba(0,0,0,.15);
}
.main.expanded ~ .action-bar { left: var(--sidebar-collapsed); }
.action-bar .selected-count { font-size: 15px; }
.action-bar .btn { margin-left: auto; }

/* Tables */
.data-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
  background: var(--c-white); border-radius: 8px; overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.data-table th {
  background: #f6f8fa; padding: 10px 12px; text-align: left;
  font-weight: 600; border-bottom: 2px solid var(--c-border); white-space: nowrap;
}
.data-table td { padding: 8px 12px; border-bottom: 1px solid var(--c-border); }
.data-table tbody tr:hover { background: #f6fbff; }
.data-table tbody tr.selected { background: #e8f0fe; outline: 2px solid var(--c-primary); outline-offset: -2px; }
.data-table tbody tr.assigned { color: var(--c-gray); }
.data-table tbody tr.received-unassigned { font-weight: 700; }
.data-table tbody tr:nth-child(even):not(.assigned):not(.selected):not(.unreceived) { background: #fafbfc; }
.data-table tbody tr.unreceived { color: var(--c-muted); font-style: italic; }
.data-table tfoot tr {
  background: var(--c-summary-bg);
  border-top: 2px solid var(--c-primary);
}
.data-table tfoot td { padding: 10px 12px; font-weight: 700; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table .col-name { max-width: 240px; word-break: break-all; }
.data-table .col-date { white-space: nowrap; min-width: 90px; }
.data-table .actions { white-space: nowrap; display: flex; gap: 4px; }
.data-table .actions .btn { font-size: 12px; padding: 3px 8px; }

/* Nested batch list */
.batch-group { margin-bottom: 16px; }
.batch-group-header {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: #f6f8fa; border: 1px solid var(--c-border);
  border-radius: 6px 6px 0 0; cursor: pointer; font-weight: 600;
}
.batch-group-header:hover { background: #eef1f5; }
.batch-group-header .expand-icon { font-size: 12px; transition: transform .2s; }
.batch-group-header .expand-icon.open { transform: rotate(90deg); }
.batch-group-items { display: none; }
.batch-group-items.open { display: block; }
.batch-group-items table { border-radius: 0 0 6px 6px; }
.batch-group-items table thead th { background: #fafbfc; }

/* Batch actions in group header */
.batch-group-actions { margin-left: auto; display: flex; gap: 8px; }

/* Batch detail (reconciliation) */
.detail-card {
  background: var(--c-white); border-radius: 8px; padding: 24px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06); margin-bottom: 16px;
}
.detail-card h3 { margin-bottom: 16px; padding-bottom: 8px; border-bottom: 1px solid var(--c-border); }
.detail-meta { display: flex; gap: 24px; margin-bottom: 16px; flex-wrap: wrap; }
.detail-meta .meta-item { display: flex; flex-direction: column; }
.detail-meta .meta-label { font-size: 11px; color: var(--c-muted); }
.detail-meta .meta-value { font-size: 15px; font-weight: 600; }

/* Badges */
.badge { display: inline-block; padding: 2px 10px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.badge-warning { background: #fff3cd; color: #856404; }
.badge-info { background: #dbedff; color: #0366d6; }
.badge-gray { background: #e8e8e8; color: #666; }
.badge-new { background: #fef9e7; color: #b08800; border: 1px solid #f0d060; }

/* Filters & Toolbar */
.filter-bar, .toolbar {
  display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap;
}
.filter-bar .form-select { width: auto; min-width: 140px; }
.filter-stats { margin-left: auto; font-size: 13px; color: var(--c-muted); }
.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form .form-input { width: 200px; }

/* Summary */
.batch-summary { margin-top: 16px; }
.summary-grid {
  display: flex; gap: 20px; flex-wrap: wrap; justify-content: flex-end;
  padding: 14px 20px; background: #f9f9f9; border-radius: 8px;
}
.summary-item { display: flex; flex-direction: column; align-items: flex-end; }
.summary-label { font-size: 11px; color: var(--c-muted); }
.summary-value { font-size: 15px; font-weight: 700; }
.summary-item.highlight { border-left: 2px solid #ddd; padding-left: 16px; }

/* Section */
.section { margin: 24px 0; }
.section h3 { font-size: 16px; margin-bottom: 12px; padding-bottom: 8px; border-bottom: 1px solid var(--c-border); }

/* Flash */
.flash { padding: 10px 16px; border-radius: 6px; margin-bottom: 12px; font-size: 13px; }
.flash-success { background: #e6ffec; color: #22863a; border: 1px solid #b7ebc7; }
.flash-error { background: #ffeef0; color: #d73a49; border: 1px solid #f4c1c6; }

/* Empty state */
.empty-state { padding: 40px; text-align: center; color: var(--c-muted); font-size: 15px; }

/* Text colors */
.text-warning { color: #856404; }
.text-info { color: #0366d6; }
.text-success { color: #22863a; }
.text-danger { color: #d73a49; }

/* Num inputs in table */
.data-table input.form-input.num { width: 90px; text-align: right; padding: 4px 8px; }

.nav-divider {
  border-top: 1px solid var(--border);
  margin: 8px 12px;
}
.nav-section-label {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--muted);
  padding: 4px 16px;
  letter-spacing: 0.5px;
}

/* Modal overlay */
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4);
  z-index: 200; align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: #fff; border-radius: 10px; padding: 32px; width: 560px;
  max-height: 80vh; overflow-y: auto; box-shadow: 0 8px 30px rgba(0,0,0,.15);
}

/* Admin & form helpers */
.form-hint {
  font-size: 12px;
  color: var(--muted);
  display: block;
  margin-top: 2px;
}
.btn-row {
  display: flex;
  gap: 6px;
  align-items: center;
}
