:root {
  --purple-950: #271229;
  --purple-900: #351638;
  --purple-800: #4b1f4d;
  --purple-700: #612963;
  --purple-100: #f1e7f1;
  --lime-500: #8cac3f;
  --lime-100: #eef5dd;
  --ink: #211f25;
  --muted: #716d77;
  --line: #e6e1e7;
  --surface: #ffffff;
  --canvas: #f7f6f8;
  --danger: #b43c46;
  --warning: #a66712;
  --success: #28734a;
  --shadow: 0 16px 40px rgba(53, 22, 56, .09);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--canvas); }
button, input, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.eyebrow { display: block; font-size: 12px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.eyebrow.purple { color: var(--purple-700); }

.login-screen { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(420px, .85fr); background: #fff; }
.login-brand { position: relative; overflow: hidden; display: flex; align-items: flex-end; padding: clamp(40px, 6vw, 90px); color: #fff; background: radial-gradient(circle at 78% 22%, rgba(140,172,63,.45), transparent 23%), linear-gradient(145deg, var(--purple-950), var(--purple-700)); }
.login-brand::before { content: ""; position: absolute; inset: 0; opacity: .09; background-image: linear-gradient(120deg, transparent 35%, #fff 36%, transparent 37%), linear-gradient(30deg, transparent 63%, #fff 64%, transparent 65%); background-size: 110px 110px; }
.login-copy { position: relative; z-index: 2; max-width: 720px; }
.login-copy h1 { max-width: 670px; margin: 16px 0 20px; font-family: Georgia, serif; font-size: clamp(44px, 5.4vw, 76px); line-height: 1.02; letter-spacing: -.04em; }
.login-copy p { max-width: 610px; font-size: 19px; line-height: 1.6; color: rgba(255,255,255,.78); }
.feature-pills { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 30px; }
.feature-pills span { padding: 9px 14px; border: 1px solid rgba(255,255,255,.23); border-radius: 999px; background: rgba(255,255,255,.08); font-size: 13px; }
.brand-orbit { position: absolute; border: 1px solid rgba(255,255,255,.14); border-radius: 50%; }
.orbit-one { width: 460px; height: 460px; right: -140px; top: -120px; }
.orbit-two { width: 650px; height: 650px; right: -210px; top: -210px; }
.login-panel { min-width: 0; display: grid; place-items: center; padding: 36px; }
.login-card { width: 100%; max-width: 420px; display: grid; gap: 18px; }
.login-card h2 { margin: 8px 0 6px; font-size: 32px; }
.login-card p { margin: 0; }
.compact-logo { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 15px; background: var(--purple-800); color: #fff; font-family: Georgia, serif; font-weight: 800; box-shadow: inset 0 -4px 0 rgba(140,172,63,.5); }
.compact-logo.inverse { background: #fff; color: var(--purple-800); }
label { display: grid; gap: 8px; color: #4e4952; font-size: 13px; font-weight: 700; }
input, select { width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; color: var(--ink); background: #fff; outline: none; transition: border-color .18s, box-shadow .18s; }
input:focus, select:focus { border-color: var(--purple-700); box-shadow: 0 0 0 4px rgba(97,41,99,.1); }
.primary-button, .secondary-button, .ghost-button, .danger-button { min-height: 42px; border: 0; border-radius: 11px; padding: 10px 17px; font-weight: 750; }
.primary-button { color: #fff; background: var(--purple-800); box-shadow: 0 8px 18px rgba(75,31,77,.2); }
.primary-button:hover { background: var(--purple-700); }
.secondary-button { color: var(--purple-800); background: var(--purple-100); }
.ghost-button { color: var(--purple-800); background: transparent; border: 1px solid var(--line); }
.danger-button { color: var(--danger); background: #fff0f1; }
.full { width: 100%; }
.form-error { min-height: 18px; color: var(--danger); font-size: 13px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 272px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 26px 18px; color: #fff; background: linear-gradient(180deg, var(--purple-950), var(--purple-800)); }
.sidebar-brand { display: flex; align-items: center; gap: 13px; padding: 0 8px 30px; }
.sidebar-brand strong, .sidebar-brand small { display: block; }
.sidebar-brand small { margin-top: 3px; color: rgba(255,255,255,.58); font-size: 11px; }
nav { display: grid; gap: 5px; }
.nav-item { width: 100%; display: flex; align-items: center; gap: 13px; padding: 12px 13px; border: 0; border-radius: 11px; color: rgba(255,255,255,.68); background: transparent; text-align: left; font-weight: 650; }
.nav-item span { width: 22px; text-align: center; font-size: 21px; }
.nav-item:hover, .nav-item.active { color: #fff; background: rgba(255,255,255,.11); }
.nav-item.active { box-shadow: inset 3px 0 0 var(--lime-500); }
.sidebar-footer { margin-top: auto; display: grid; gap: 14px; padding: 18px 8px 0; border-top: 1px solid rgba(255,255,255,.1); }
.user-chip { min-width: 0; display: flex; align-items: center; gap: 10px; }
.user-chip strong, .user-chip small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip small { margin-top: 2px; color: rgba(255,255,255,.58); font-size: 11px; }
.avatar { flex: 0 0 auto; width: 38px; height: 38px; display: grid; place-items: center; border-radius: 12px; color: var(--purple-900); background: var(--lime-500); font-size: 13px; font-weight: 900; }
.avatar.small { width: 32px; height: 32px; }
.inverse-text { color: rgba(255,255,255,.78); border-color: rgba(255,255,255,.18); }
.mobile-header { display: none; }
.main-content { min-width: 0; padding: clamp(24px, 4vw, 52px); }
.page-wrap { max-width: 1400px; margin: 0 auto; }
.page-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; margin-bottom: 28px; }
.page-header h1 { margin: 5px 0 0; font-family: Georgia, serif; font-size: clamp(32px, 4vw, 48px); letter-spacing: -.03em; }
.page-header p { max-width: 680px; margin: 9px 0 0; color: var(--muted); }
.header-actions { display: flex; align-items: center; gap: 10px; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 28px; }
.stat-card, .panel { border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: 0 1px 1px rgba(30,20,31,.02); }
.stat-card { position: relative; overflow: hidden; min-height: 142px; padding: 22px; }
.stat-card::after { content: ""; position: absolute; width: 86px; height: 86px; right: -26px; bottom: -30px; border-radius: 50%; background: var(--purple-100); }
.stat-card.green::after { background: var(--lime-100); }
.stat-card small { display: block; color: var(--muted); font-weight: 650; }
.stat-card strong { display: block; margin-top: 19px; font-family: Georgia, serif; font-size: 36px; }
.panel { padding: 22px; }
.panel + .panel { margin-top: 18px; }
.panel-header { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 18px; }
.panel-header h2 { margin: 0; font-size: 19px; }
.two-columns { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(300px, .6fr); gap: 20px; align-items: start; }
.quick-card { padding: 24px; border-radius: 16px; color: #fff; background: linear-gradient(135deg, var(--purple-800), var(--purple-700)); }
.quick-card h3 { margin: 0 0 10px; font-size: 23px; }
.quick-card p { color: rgba(255,255,255,.72); line-height: 1.55; }
.quick-card .primary-button { color: var(--purple-900); background: #fff; }

.search-panel { display: grid; grid-template-columns: minmax(240px, 1fr) 170px 170px auto; gap: 12px; align-items: end; margin-bottom: 20px; }
.search-input { position: relative; }
.search-input input { padding-left: 42px; }
.search-input::before { content: "⌕"; position: absolute; left: 15px; bottom: 8px; z-index: 1; color: var(--purple-700); font-size: 24px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 16px; background: #fff; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 15px 16px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--muted); background: #fbfafb; font-size: 11px; letter-spacing: .05em; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fdfcfd; }
.name-cell strong, .name-cell small { display: block; }
.name-cell small { margin-top: 4px; color: var(--muted); }
.actions { display: flex; justify-content: flex-end; gap: 8px; white-space: nowrap; }
.actions button, .actions a { min-height: 36px; display: inline-flex; align-items: center; justify-content: center; border-radius: 9px; padding: 8px 11px; text-decoration: none; font-size: 12px; font-weight: 750; }
.actions a { color: var(--purple-800); background: var(--purple-100); }
.actions a:last-child { color: #fff; background: var(--purple-800); }
.badge { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 6px 9px; font-size: 11px; font-weight: 800; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ready, .badge.confirmed { color: var(--success); background: #e8f5ee; }
.badge.found { color: var(--success); background: #e8f5ee; }
.badge.processing { color: #466499; background: #edf2fb; }
.badge.needs_review, .badge.unpaired, .badge.missing { color: var(--warning); background: #fff4e1; }
.badge.extra { color: #8b4c20; background: #fff0df; }
.badge.failed, .badge.rejected { color: var(--danger); background: #fff0f1; }
.result-meta { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin: 12px 2px; color: var(--muted); font-size: 13px; }
.pagination { display: flex; gap: 8px; }

.upload-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.drive-link-field { grid-column: 1 / -1; }
.drive-integration { margin: 18px 0; padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; background: #faf8fa; line-height: 1.5; overflow-wrap: anywhere; }
.upload-mode-switch { width: fit-content; display: flex; gap: 5px; margin-bottom: 18px; padding: 5px; border: 1px solid var(--line); border-radius: 14px; background: #f5f1f5; }
.upload-mode { min-height: 42px; border: 0; border-radius: 10px; padding: 9px 16px; color: var(--muted); background: transparent; font-weight: 750; }
.upload-mode.active { color: var(--purple-900); background: #fff; box-shadow: 0 4px 12px rgba(63,31,65,.1); }
.dropzone { min-height: 190px; display: grid; place-items: center; padding: 24px; border: 1.5px dashed #cfc5d0; border-radius: 16px; background: #fcfbfc; text-align: center; transition: .18s; }
.dropzone:hover, .dropzone.has-file { border-color: var(--purple-700); background: var(--purple-100); }
.dropzone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.dropzone .file-icon { width: 48px; height: 48px; display: grid; place-items: center; margin: 0 auto 12px; border-radius: 14px; color: var(--purple-800); background: #fff; font-size: 24px; box-shadow: var(--shadow); }
.dropzone strong, .dropzone small { display: block; }
.dropzone small { margin-top: 7px; color: var(--muted); }
.upload-meta { display: grid; grid-template-columns: 180px 1fr; gap: 14px; margin-bottom: 18px; }
.upload-footer { display: flex; justify-content: space-between; align-items: center; gap: 18px; margin-top: 18px; }
.upload-note { max-width: 700px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.batch-download { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.batch-download a { display: inline-flex; align-items: center; text-decoration: none; }
.progress-box { margin-top: 18px; padding: 18px; border-radius: 14px; background: var(--purple-100); }
.progress-line { height: 8px; overflow: hidden; border-radius: 999px; background: #ddd1de; }
.progress-line span { display: block; width: 38%; height: 100%; border-radius: inherit; background: var(--purple-700); animation: progress 1.2s ease-in-out infinite alternate; }
.progress-line.determinate span { animation: none; transition: width .2s ease; }
@keyframes progress { to { transform: translateX(160%); } }

.empty-state { padding: 54px 24px; text-align: center; color: var(--muted); }
.empty-state strong { display: block; margin-bottom: 7px; color: var(--ink); font-size: 18px; }
.empty-icon { width: 54px; height: 54px; display: grid; place-items: center; margin: 0 auto 14px; border-radius: 16px; color: var(--purple-700); background: var(--purple-100); font-size: 28px; }
.user-form { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr auto; gap: 12px; align-items: end; }
.review-pair { display: grid; grid-template-columns: 1fr 54px 1fr auto; align-items: center; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.review-pair:last-child { border-bottom: 0; }
.review-file { min-width: 0; padding: 12px; border-radius: 11px; background: #faf8fa; }
.review-file strong, .review-file small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.review-file small { margin-top: 4px; color: var(--muted); }
.score { text-align: center; color: var(--warning); font-size: 12px; font-weight: 850; }
.comparison-panel .panel-header p { margin: 6px 0 0; }
.comparison-legend { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.comparison-legend span { border-radius: 999px; padding: 7px 10px; font-size: 12px; font-weight: 750; }
.comparison-found { color: var(--success); background: #e8f5ee; }
.comparison-missing { color: var(--warning); background: #fff4e1; }
.comparison-extra { color: #8b4c20; background: #fff0df; }
.comparison-row.missing { background: #fffcf6; }
.comparison-row.extra { background: #fffaf4; }
.comparison-upload-form { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 18px; align-items: center; }
.comparison-upload-form .dropzone { min-height: 150px; }
.comparison-upload-form .primary-button { width: 100%; margin-top: 14px; }
.toast-region { position: fixed; z-index: 100; right: 20px; bottom: 20px; display: grid; gap: 10px; }
.toast { max-width: 380px; padding: 14px 17px; border-radius: 12px; color: #fff; background: var(--purple-900); box-shadow: var(--shadow); animation: toast-in .2s ease-out; }
.toast.error { background: var(--danger); }
@keyframes toast-in { from { transform: translateY(12px); opacity: 0; } }
.skeleton { min-height: 100px; border-radius: 16px; background: linear-gradient(90deg, #f2eff2 25%, #faf9fa 38%, #f2eff2 52%); background-size: 400% 100%; animation: shimmer 1.3s infinite; }
@keyframes shimmer { to { background-position: -100% 0; } }

@media (max-width: 1080px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .two-columns { grid-template-columns: 1fr; }
  .search-panel { grid-template-columns: 1fr 1fr; }
  .user-form { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 800px) {
  .login-screen { grid-template-columns: 1fr; }
  .login-brand { min-height: 360px; padding: 42px 28px; }
  .login-copy h1 { font-size: 44px; }
  .login-panel { padding: 38px 24px; }
  .app-shell { display: block; }
  .sidebar { position: fixed; z-index: 30; left: 0; width: 272px; transform: translateX(-105%); transition: transform .2s ease-out; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .mobile-header { position: sticky; z-index: 20; top: 0; display: flex; align-items: center; justify-content: space-between; padding: 12px 18px; background: rgba(255,255,255,.95); border-bottom: 1px solid var(--line); backdrop-filter: blur(10px); }
  .icon-button { border: 0; background: transparent; font-size: 22px; }
  .main-content { padding: 25px 18px; }
  .page-header { align-items: flex-start; flex-direction: column; }
  .header-actions { width: 100%; flex-wrap: wrap; }
  .upload-grid, .upload-meta { grid-template-columns: 1fr; }
  .comparison-upload-form { grid-template-columns: 1fr; }
  .upload-mode-switch { width: 100%; }
  .upload-mode { flex: 1; }
  .review-pair { grid-template-columns: 1fr; }
  .score { text-align: left; }
}
@media (max-width: 560px) {
  .login-brand { min-height: 320px; }
  .login-copy h1 { font-size: 36px; }
  .login-copy p { font-size: 16px; }
  .stats-grid { grid-template-columns: 1fr; }
  .search-panel, .user-form { grid-template-columns: 1fr; }
  .upload-footer, .result-meta { align-items: stretch; flex-direction: column; }
  .upload-mode-switch { align-items: stretch; flex-direction: column; }
  .batch-panel-header { align-items: stretch; flex-direction: column; }
  .batch-download { justify-content: space-between; white-space: normal; }
  th:nth-child(3), td:nth-child(3) { display: none; }
  .actions { flex-direction: column; }
}
