:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #6f7b8e;
  --line: #dbe1ea;
  --line-strong: #c8d0dc;
  --surface: #ffffff;
  --canvas: #f5f7fa;
  --brand: #169bd5;
  --brand-dark: #0e84ba;
  --sidebar: #182033;
  --danger: #c53b49;
  --danger-bg: #fff0f1;
  --success: #18794e;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--canvas); color: var(--ink); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--canvas); }
.login-card { width: min(420px, 100%); background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 36px; box-shadow: 0 24px 70px rgba(38, 46, 69, .12); }
.brand-mark { display: inline-flex; padding: 7px 11px; border-radius: 8px; background: #e8f6fc; color: var(--brand-dark); font-weight: 800; }
.login-card h1 { margin: 22px 0 8px; font-size: 28px; }
.login-card p { color: var(--muted); line-height: 1.6; }
label { display: grid; gap: 7px; color: #475268; font-size: 13px; font-weight: 650; }
.login-card label { margin-top: 18px; }
input, textarea, select { width: 100%; border: 1px solid #ccd3df; border-radius: 9px; padding: 11px 12px; color: var(--ink); background: #fff; outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(22, 155, 213, .13); }
input:read-only { background: #f2f4f7; color: #687386; }
input.invalid, textarea.invalid, select.invalid { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(197, 59, 73, .13); }

.primary-button, .secondary-button, .danger-button, .danger-outline-button { min-height: 40px; border-radius: 8px; padding: 9px 17px; font-weight: 750; }
.primary-button { color: #fff; background: var(--brand); border: 1px solid var(--brand); }
.primary-button:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.secondary-button { color: #38445a; background: #fff; border: 1px solid #cbd2de; }
.secondary-button:hover { border-color: #9faabc; background: #fafbfc; }
.danger-button { color: #fff; background: var(--danger); border: 1px solid var(--danger); }
.danger-outline-button { color: var(--danger); background: #fff; border: 1px solid #e4a8ae; }
.danger-outline-button:hover { background: var(--danger-bg); border-color: var(--danger); }
button:disabled { opacity: .48; cursor: not-allowed; }
.login-card .primary-button { width: 100%; margin-top: 16px; padding: 13px; }
.form-error { min-height: 20px; margin: 12px 0 0 !important; color: var(--danger) !important; }

.admin-shell { min-height: 100vh; display: grid; grid-template-columns: 220px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 24px 14px; color: #e9ecf5; background: var(--sidebar); }
.sidebar-brand { padding: 0 13px 25px; display: grid; gap: 4px; }
.sidebar-brand span { font-size: 22px; font-weight: 850; }
.sidebar-brand small { color: #99a4b9; }
.sidebar nav { display: grid; gap: 5px; }
.sidebar nav button { text-align: left; color: #bac3d3; border: 0; border-radius: 9px; padding: 11px 13px; background: transparent; }
.sidebar nav button:hover, .sidebar nav button.active { color: #fff; background: #2b3550; }
.sidebar-footer { margin-top: auto; padding: 16px 13px 0; border-top: 1px solid #303a52; display: grid; gap: 8px; color: #aeb8ca; }
.text-button { padding: 0; border: 0; background: none; text-align: left; color: #d6dbea; }

.content { min-width: 0; padding: 32px clamp(24px, 3.5vw, 58px) 70px; }
.content-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.content-header h1 { margin: 0 0 8px; font-size: 27px; }
.content-header p { margin: 0; color: var(--muted); }
.control-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 14px; }
.control-row > input { max-width: 430px; }
.venue-filters { display: flex; align-items: center; gap: 10px; }
.venue-filters select { width: 180px; }
.mapping-date-filters { display: flex; align-items: center; gap: 8px; }
.mapping-date-filters select { width: 145px; }
.mapping-date-filters input { width: 145px; }
.mapping-date-filters span { color: var(--muted); font-size: 13px; }
.mapping-date-filters .text-button { white-space: nowrap; }
.history-control { margin-left: auto; display: flex; align-items: center; grid-template-columns: auto minmax(220px, 330px); white-space: nowrap; }

.mapping-panel { min-height: 620px; overflow: hidden; border: 1px solid var(--line-strong); background: #fff; }
.mapping-toolbar { min-height: 64px; display: flex; align-items: center; padding: 12px 24px; border-bottom: 1px solid var(--line); }
.mapping-toolbar .primary-button { min-width: 112px; }
.table-scroll { overflow-x: auto; padding: 0 24px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
.mapping-table { table-layout: fixed; min-width: 1120px; }
th, td { padding: 13px 14px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: #556176; background: #f7f8fa; font-weight: 750; }
.mapping-table th:first-child, .mapping-table td:first-child { width: 14%; }
.mapping-table th:last-child, .mapping-table td:last-child { width: 105px; }
.mapping-table td { height: 51px; overflow: hidden; text-overflow: ellipsis; color: #354056; }
.mapping-table .timestamp-cell { width: 145px; color: #657187; font-size: 12px; }
.mapping-table tbody tr:hover { background: #fafcfd; }
.aliases-cell { max-width: 270px; }
.notes-cell { max-width: 220px; color: var(--muted) !important; }
.actions-cell { display: flex; align-items: center; gap: 13px; overflow: visible !important; }
.table-action { padding: 0; border: 0; color: #167aaa; background: none; font-weight: 700; }
.table-action:hover { color: var(--brand-dark); text-decoration: underline; }
.table-action.danger { color: var(--danger); }
.table-empty { height: 160px !important; text-align: center; color: var(--muted) !important; }

.pagination { min-height: 66px; display: flex; justify-content: flex-end; align-items: center; gap: 6px; padding: 12px 24px; }
.pagination button { min-width: 36px; height: 36px; padding: 0 10px; border: 1px solid var(--line); border-radius: 7px; background: #fff; color: #4e5a6e; }
.pagination button:hover:not(:disabled), .pagination button.active { color: #fff; border-color: var(--brand); background: var(--brand); }
.page-total { margin-right: 8px; color: var(--muted); font-size: 13px; }
.page-ellipsis { padding: 0 4px; color: var(--muted); }

.status-message { margin-bottom: 14px; border-radius: 9px; padding: 13px 15px; line-height: 1.5; }
.status-message.success { background: #e9f7ef; color: var(--success); }
.status-message.error { background: var(--danger-bg); color: var(--danger); }

dialog { padding: 0; border: 0; }
dialog::backdrop { background: rgba(6, 12, 24, .68); }
.modal-dialog { width: min(680px, calc(100vw - 32px)); max-height: calc(100vh - 48px); overflow: auto; border-radius: 12px; background: #fff; box-shadow: 0 24px 80px rgba(0, 0, 0, .28); }
.modal-dialog form { padding: 28px 32px 26px; }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.modal-header h2, .confirm-content h2 { margin: 0 0 7px; font-size: 24px; }
.modal-header p, .confirm-content p { margin: 0; color: var(--muted); line-height: 1.6; }
.icon-button { width: 34px; height: 34px; border: 0; border-radius: 7px; color: #637086; background: #f2f4f7; font-size: 24px; line-height: 1; }
.modal-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.modal-field { gap: 8px; font-size: 14px; }
.modal-field > span { color: #354056; }
.modal-field.wide { grid-column: 1 / -1; }
.readonly-field input { background: #f3f5f7; }
.modal-fields textarea { resize: vertical; line-height: 1.55; }
.checkbox-control { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.checkbox-control input { width: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 26px; }
.modal-actions button { min-width: 108px; }

.confirm-dialog { width: min(460px, calc(100vw - 32px)); border-radius: 12px; background: #fff; box-shadow: 0 24px 80px rgba(0, 0, 0, .28); }
.confirm-content { padding: 28px 30px; }

.toast-region { position: fixed; z-index: 1000; top: 22px; right: 24px; width: min(390px, calc(100vw - 32px)); display: grid; gap: 10px; pointer-events: none; }
.toast { transform: translateY(-8px); opacity: 0; border: 1px solid var(--line); border-left: 4px solid var(--success); border-radius: 9px; padding: 14px 16px; color: #254236; background: #fff; box-shadow: 0 12px 36px rgba(31, 42, 63, .16); line-height: 1.5; transition: opacity .2s ease, transform .2s ease; }
.toast.error { border-left-color: var(--danger); color: #732b34; }
.toast.visible { transform: translateY(0); opacity: 1; }

.summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 20px; }
.summary-card { display: grid; gap: 8px; padding: 18px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.summary-card span { color: var(--muted); font-size: 13px; }
.summary-card strong { font-size: 20px; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.pill { display: inline-flex; border-radius: 999px; padding: 3px 8px; font-weight: 700; }
.pill.ok { color: var(--success); background: #e9f7ef; }
.pill.bad { color: var(--danger); background: var(--danger-bg); }
.pill.warn { color: #8a5a00; background: #fff5d8; }

.candidate-controls { display: grid; grid-template-columns: minmax(280px, 1fr) 190px 190px auto; gap: 10px; margin-bottom: 16px; }
.candidate-summary { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.candidate-bulk-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #f8fafc; }
.candidate-bulk-bar span { margin-right: auto; color: #354056; font-weight: 700; }
.candidate-bulk-bar .text-button { color: #526077; }
.candidate-table-wrap { border-radius: 0; }
.candidate-table { min-width: 1230px; table-layout: fixed; }
.candidate-table th:nth-child(1) { width: 48px; }
.candidate-table th:nth-child(2) { width: 82px; }
.candidate-table th:nth-child(3) { width: 105px; }
.candidate-table th:nth-child(4) { width: 245px; }
.candidate-table th:nth-child(5) { width: 220px; }
.candidate-table th:nth-child(6) { width: 180px; }
.candidate-table th:nth-child(7) { width: 150px; }
.candidate-table th:nth-child(8) { width: 130px; }
.candidate-table th:nth-child(9) { width: 72px; }
.candidate-table td { overflow: hidden; text-overflow: ellipsis; }
.candidate-table .candidate-check-cell { padding-left: 12px; padding-right: 8px; text-align: center; }
.candidate-check-cell input { width: 17px; height: 17px; margin: 0; padding: 0; box-shadow: none; cursor: pointer; }
.candidate-check-cell input:disabled { cursor: not-allowed; }
.candidate-title-cell { font-weight: 700; color: #263247; }
.candidate-artists-cell { color: #546176; }
.confidence-text { display: block; margin-top: 5px; color: var(--muted); }
.workflow-status { display: inline-flex; border-radius: 999px; padding: 4px 9px; font-weight: 700; color: #475268; background: #eef1f5; }
.status-verified { color: var(--success); background: #e9f7ef; }
.status-excluded, .status-rejected { color: var(--danger); background: var(--danger-bg); }
.status-pending_verification { color: #8a5a00; background: #fff5d8; }
.status-duplicate { color: #3a5d9a; background: #edf3ff; }

.candidate-dialog { width: min(920px, calc(100vw - 32px)); max-height: calc(100vh - 40px); overflow: auto; border-radius: 12px; background: #fff; box-shadow: 0 24px 80px rgba(0, 0, 0, .28); }
.candidate-dialog-content { padding: 28px 32px 26px; }
.candidate-facts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.candidate-facts > div { display: grid; gap: 7px; min-width: 0; padding: 13px; border: 1px solid var(--line); border-radius: 9px; background: #fafbfc; }
.candidate-facts span, .candidate-block > span { color: var(--muted); font-size: 12px; font-weight: 700; }
.candidate-facts strong { overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.candidate-block { display: grid; gap: 8px; margin-top: 18px; }
.candidate-block ul { margin: 0; padding-left: 20px; color: #475268; line-height: 1.7; }
.performer-tags { display: flex; flex-wrap: wrap; gap: 7px; }
.performer-tag { display: inline-flex; gap: 5px; border-radius: 999px; padding: 6px 9px; background: #edf4fb; color: #315271; font-size: 13px; }
.performer-tag small { color: #74869a; }
.related-links { display: grid; gap: 6px; word-break: break-all; }
.candidate-review-form { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 24px; padding-top: 22px; border-top: 1px solid var(--line); }
.candidate-review-form > label:last-child { grid-column: 1 / -1; }
.verified-fields { display: flex; flex-wrap: wrap; align-content: flex-start; gap: 10px 18px; margin: 0; border: 1px solid var(--line); border-radius: 9px; padding: 11px 13px; }
.verified-fields legend { padding: 0 5px; color: #475268; font-size: 12px; font-weight: 700; }
.verified-fields label { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.verified-fields input { width: auto; margin: 0; }
.candidate-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 9px; margin-top: 24px; }
.candidate-bulk-preview { max-height: 220px; overflow: auto; margin: 18px 0 0; border: 1px solid var(--line); border-radius: 9px; background: #fafbfc; }
.candidate-bulk-preview > div { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 12px; padding: 10px 13px; border-bottom: 1px solid var(--line); }
.candidate-bulk-preview > div:last-of-type { border-bottom: 0; }
.candidate-bulk-preview strong { color: #526077; font-size: 13px; }
.candidate-bulk-preview span { overflow: hidden; color: #263247; text-overflow: ellipsis; white-space: nowrap; }
.candidate-bulk-preview p { margin: 0; border-top: 1px solid var(--line); padding: 9px 13px; color: var(--muted); font-size: 13px; }

@media (max-width: 900px) {
  .admin-shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  .sidebar nav { grid-template-columns: repeat(3, 1fr); }
  .sidebar-footer { margin-top: 18px; }
  .control-row { align-items: stretch; flex-direction: column; }
  .control-row > input { max-width: none; }
  .venue-filters { width: 100%; }
  .venue-filters select { width: 50%; }
  .mapping-date-filters { flex-wrap: wrap; width: 100%; }
  .history-control { margin-left: 0; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .candidate-controls { grid-template-columns: 1fr 1fr; }
  .candidate-controls > input { grid-column: 1 / -1; }
  .candidate-summary { grid-template-columns: repeat(3, 1fr); }
  .candidate-facts { grid-template-columns: 1fr 1fr; }
  .candidate-bulk-bar { flex-wrap: wrap; }
}

@media (max-width: 560px) {
  .content { padding: 22px 14px 50px; }
  .sidebar nav { grid-template-columns: 1fr 1fr; }
  .history-control { display: grid; grid-template-columns: 1fr; }
  .venue-filters { flex-direction: column; }
  .venue-filters select { width: 100%; }
  .mapping-date-filters { align-items: stretch; flex-direction: column; }
  .mapping-date-filters select, .mapping-date-filters input { width: 100%; }
  .mapping-panel { min-height: 480px; }
  .mapping-toolbar, .table-scroll, .pagination { padding-left: 14px; padding-right: 14px; }
  .pagination { justify-content: flex-start; overflow-x: auto; }
  .page-total { display: none; }
  .modal-dialog form { padding: 24px 20px 22px; }
  .modal-fields, .summary-grid { grid-template-columns: 1fr; }
  .modal-field.wide { grid-column: auto; }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions button { width: 100%; }
  .login-card { padding: 26px 22px; }
  .candidate-controls, .candidate-summary, .candidate-review-form, .candidate-facts { grid-template-columns: 1fr; }
  .candidate-controls > input, .candidate-review-form > label:last-child { grid-column: auto; }
  .candidate-actions { flex-direction: column; }
  .candidate-actions button { width: 100%; }
  .candidate-bulk-bar span { flex-basis: 100%; }
  .candidate-bulk-bar button { flex: 1; }
  .candidate-bulk-preview > div { grid-template-columns: 1fr; gap: 4px; }
  .candidate-dialog-content { padding: 24px 20px 22px; }
}
