:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-alt: #fafbfc;
  --border: #e4e7eb;
  --border-strong: #d0d5dc;
  --text: #1f232a;
  --text-muted: #6b7280;
  --text-soft: #9aa1ac;
  --brand: #2f6df6;
  --brand-strong: #1e4fc2;
  --brand-soft: #e8efff;
  --success: #0f9d58;
  --success-soft: #e6f5ed;
  --warning: #b77309;
  --warning-soft: #fdf2df;
  --danger: #c0362f;
  --danger-soft: #fbeae9;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 4px 10px rgba(15, 23, 42, 0.04);
  --radius: 10px;
  --radius-sm: 6px;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

code {
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: #2d3748;
  font-family: "SF Mono", "Consolas", "Monaco", monospace;
  font-size: 0.88em;
}

.page-shell {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 24px 40px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--brand);
}

.top-nav {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.top-nav a {
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
}

.top-nav a:hover {
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
}

.top-nav a.active {
  background: var(--brand-soft);
  color: var(--brand-strong);
}

.page-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.page-title h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.page-title p {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 14px;
}

.meta-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
}

.meta-pill code { background: transparent; border: 0; padding: 0; color: var(--text); }

.flash-stack {
  display: grid;
  gap: 8px;
  margin-bottom: 20px;
}

.flash {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 13px;
}

.flash.success { background: var(--success-soft); border-color: #b8e0cd; color: #0c6b3f; }
.flash.warning { background: var(--warning-soft); border-color: #eacc91; color: #8a5508; }
.flash.error   { background: var(--danger-soft); border-color: #ecb7b3; color: #8f2923; }

main { display: grid; gap: 20px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
}

.panel h2 {
  margin: 0 0 4px;
  font-size: 16px;
  font-weight: 600;
}

.panel h3 {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 600;
}

.panel > p {
  margin: 0 0 16px;
  color: var(--text-muted);
  font-size: 13px;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.section-head h2 { margin: 0; }
.section-head p { margin: 0; color: var(--text-muted); font-size: 13px; }

.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: minmax(0, 1.3fr) minmax(280px, 1fr); }
.grid.cards { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.metric {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

.metric .label {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.metric .value {
  margin-top: 6px;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.metric .hint {
  margin-top: 4px;
  color: var(--text-soft);
  font-size: 12px;
}

/* Forms */
input[type="text"],
input[type="search"],
input[type="file"],
select,
textarea {
  width: 100%;
  min-height: 36px;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(47, 109, 246, 0.15);
}

input::placeholder { color: var(--text-soft); }

/* Native file input — styled via ::file-selector-button */
input[type="file"] {
  padding: 0;
  border: 1px dashed var(--border-strong);
  background: var(--surface-alt);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  overflow: hidden;
}

input[type="file"]::file-selector-button,
input[type="file"]::-webkit-file-upload-button {
  padding: 8px 14px;
  margin: 0 12px 0 0;
  border: 0;
  border-right: 1px solid var(--border);
  background: var(--brand-soft);
  color: var(--brand-strong);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 120ms ease;
}

input[type="file"]::file-selector-button:hover,
input[type="file"]::-webkit-file-upload-button:hover {
  background: #d8e4ff;
}

input[type="file"]:hover { border-color: var(--brand); }
input[type="file"]:focus { border-style: solid; }

label.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
}

.field-hint {
  color: var(--text-muted);
  font-size: 12px;
}

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

/* Buttons */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  padding: 6px 16px;
  border: 1px solid var(--brand);
  border-radius: var(--radius-sm);
  background: var(--brand);
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}

.button:hover { background: var(--brand-strong); border-color: var(--brand-strong); }

.button.secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}
.button.secondary:hover { background: var(--surface-alt); }

.button.danger {
  background: var(--surface);
  color: var(--danger);
  border-color: #e2b5b1;
}
.button.danger:hover { background: var(--danger-soft); }

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

.toolbar,
.actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.toolbar > input,
.toolbar > select { max-width: 260px; }

/* Tables */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  padding: 10px 12px;
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: var(--surface-alt);
}

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

td .sub { color: var(--text-muted); font-size: 12px; }

/* Status pills */
.status {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid transparent;
}
.status.upload, .status.present, .status.ready {
  background: var(--success-soft); color: #0c6b3f; border-color: #c3e4d2;
}
.status.overwrite, .status.duplicate-overwrite, .status.archive {
  background: var(--warning-soft); color: #8a5508; border-color: #eacc91;
}
.status.skip, .status.duplicate-skip {
  background: #eef0f3; color: #4a5260; border-color: #d3d7dd;
}
.status.error, .status.delete, .status.missing, .status.invalid, .status.duplicate-error {
  background: var(--danger-soft); color: #8f2923; border-color: #ecb7b3;
}

/* Empty state */
.empty {
  padding: 24px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-alt);
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}

.note { color: var(--text-muted); font-size: 12px; }

/* Upload page */
.upload-layout {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr);
  gap: 20px;
  align-items: start;
}

.upload-form { display: flex; flex-direction: column; gap: 16px; }

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

.drop-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 16px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-alt);
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease;
}

.drop-card:hover { border-color: var(--brand); background: #fff; }

.drop-card.active { border-style: solid; border-color: var(--brand); background: var(--brand-soft); }

.drop-card.drag-hover {
  border-style: solid;
  border-color: var(--brand-strong);
  background: #d8e4ff;
  box-shadow: 0 0 0 3px rgba(47, 109, 246, 0.18);
}

.drop-card.drag-busy { opacity: 0.7; cursor: progress; }

.drop-card input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.drop-title { font-weight: 600; font-size: 13px; color: var(--text); }
.drop-hint { color: var(--text-muted); font-size: 12px; }
.drop-meta { margin-top: 6px; color: var(--text-soft); font-size: 12px; }
.drop-meta.active { color: var(--brand-strong); font-weight: 500; }

.selection-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-muted);
}

.selection-bar.active { background: var(--brand-soft); color: var(--brand-strong); border-color: #b9cef7; }

.progress-shell {
  display: grid;
  gap: 6px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  font-size: 13px;
}

.progress-bar {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: #e8eaee;
  overflow: hidden;
}

.progress-bar span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--brand);
  transition: width 150ms ease;
}

.progress-shell[data-mode="success"] .progress-bar span { background: var(--success); }
.progress-shell[data-mode="error"]   .progress-bar span { background: var(--danger); }
.progress-shell[data-mode="error"]   { border-color: #ecb7b3; background: var(--danger-soft); color: #8f2923; }

/* Dashboard recent list */
.event-list { display: grid; gap: 8px; }

.event-item {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  font-size: 13px;
}

.event-item .head { display: flex; gap: 8px; align-items: center; }

ul.plain { margin: 0; padding-left: 18px; color: var(--text-muted); font-size: 13px; }
ul.plain li { margin: 2px 0; }

.formula {
  display: block;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: #1f232a;
  color: #e6edf7;
  font-family: "SF Mono", "Consolas", monospace;
  font-size: 13px;
  overflow-x: auto;
}

/* Bulk action bar */
.bulk-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  font-size: 13px;
  color: var(--text-muted);
}

.bulk-bar.active {
  background: var(--brand-soft);
  border-color: #b9cef7;
  color: var(--brand-strong);
}

.bulk-bar.active .bulk-count { font-weight: 600; }

.row-check {
  width: 40px;
  text-align: center;
  padding: 10px 6px;
}

.row-check input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  cursor: pointer;
  accent-color: var(--brand);
  vertical-align: middle;
}

tbody tr.row-selected { background: var(--brand-soft); }
tbody tr.row-selected:hover { background: #d8e4ff; }

/* Pagination */
.pagination {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: flex-end;
  margin-top: 14px;
  flex-wrap: wrap;
}

.pagination a, .pagination span {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
}

.pagination a:hover { border-color: var(--brand); color: var(--brand); text-decoration: none; }
.pagination .current { background: var(--brand); color: #fff; border-color: var(--brand); }
.pagination .disabled { color: var(--text-soft); background: var(--surface-alt); }

.pagination .summary { border: 0; background: transparent; color: var(--text-muted); margin-right: auto; }
.pagination .ellipsis { border: 0; background: transparent; color: var(--text-soft); padding: 4px 4px; }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(2px);
  animation: modal-fade 140ms ease-out;
}

.modal-backdrop[hidden] { display: none; }

body.modal-open { overflow: hidden; }

.modal-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.18);
  padding: 22px 24px 18px;
  animation: modal-pop 160ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.modal-title {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.modal-body {
  margin: 0 0 18px;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.55;
  word-break: break-all;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

@keyframes modal-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modal-pop {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.upload-modal-card {
  max-width: 480px;
}

.upload-progress {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.upload-progress .progress-bar { height: 8px; }

.upload-progress-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  color: var(--text-muted);
}

.upload-progress-percent {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--text);
}

.upload-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 6px 0 14px;
}

.upload-stats > div {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
}

.upload-stats .num {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.upload-stats .num.err { color: var(--danger); }

.upload-stats .lbl {
  font-size: 12px;
  color: var(--text-muted);
}

.upload-error-list {
  max-height: 160px;
  overflow-y: auto;
  margin-bottom: 14px;
  padding: 8px 10px;
  border: 1px solid #ecb7b3;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  font-size: 12px;
  color: #8f2923;
}

.upload-error-title {
  font-weight: 600;
  margin-bottom: 4px;
}

.upload-error-item {
  padding: 2px 0;
  border-top: 1px solid rgba(143, 41, 35, 0.12);
  word-break: break-all;
}

.upload-error-item:first-of-type { border-top: 0; }

#upload-modal[data-state="success"] #upload-modal-fill { background: var(--success); }
#upload-modal[data-state="partial"] #upload-modal-fill { background: var(--warning); }
#upload-modal[data-state="error"] #upload-modal-fill { background: var(--danger); }

@media (max-width: 980px) {
  .grid.two, .upload-layout { grid-template-columns: 1fr; }
  .grid.cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .drop-grid, .field-grid.two, .field-grid.three { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .app-header { flex-direction: column; align-items: flex-start; gap: 10px; }
  .grid.cards { grid-template-columns: 1fr; }
  .page-shell { padding: 0 14px 30px; }
}
