:root {
  --red-900: #7f1d1d;
  --red-800: #991b1b;
  --red-700: #b91c1c;
  --red-600: #dc2626;
  --red-100: #fee2e2;
  --red-50: #fff7f7;
  --ink: #172033;
  --muted: #667085;
  --line: #e5e7eb;
  --panel: #ffffff;
  --page: #f5f6f8;
  --green: #15803d;
  --green-soft: #dcfce7;
  --amber: #b45309;
  --amber-soft: #fef3c7;
  --blue-soft: #eaf2ff;
  --shadow: 0 10px 30px rgba(20, 28, 45, .07);
  --radius: 16px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--ink);
  font-size: 14px;
}
button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 248px;
  background: linear-gradient(180deg, #8f1717 0%, #6f1010 100%);
  color: white;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  z-index: 30;
  box-shadow: 8px 0 30px rgba(81, 10, 10, .15);
}
.brand { display: flex; align-items: center; gap: 12px; padding: 3px 8px 24px; border-bottom: 1px solid rgba(255,255,255,.15); }
.brand-mark {
  width: 45px; height: 45px; border-radius: 13px;
  display: grid; place-items: center;
  background: white; color: var(--red-700); font-weight: 900; letter-spacing: -1px;
  box-shadow: 0 5px 14px rgba(0,0,0,.17);
}
.brand strong { display: block; font-size: 18px; letter-spacing: .4px; }
.brand span { display: block; font-size: 10px; letter-spacing: 3.6px; opacity: .8; margin-top: 1px; }
.nav-list { display: grid; gap: 8px; margin-top: 26px; }
.nav-item {
  border: 0; background: transparent; color: rgba(255,255,255,.79);
  display: flex; align-items: center; gap: 12px; text-align: left;
  border-radius: 11px; padding: 12px 13px; font-weight: 650;
}
.nav-item:hover, .nav-item.active { background: rgba(255,255,255,.14); color: white; }
.nav-icon { width: 22px; text-align: center; font-size: 18px; }
.sidebar-note {
  margin-top: auto; display: flex; gap: 10px; align-items: flex-start;
  background: rgba(255,255,255,.1); padding: 13px; border-radius: 12px;
}
.sidebar-note strong { display: block; font-size: 12px; }
.sidebar-note span { display: block; font-size: 11px; opacity: .72; margin-top: 3px; line-height: 1.4; }
.dot-live { width: 9px; height: 9px; border-radius: 50%; background: #86efac; box-shadow: 0 0 0 5px rgba(134,239,172,.13); margin-top: 4px; }

.main-content { margin-left: 248px; min-width: 0; }
.topbar {
  min-height: 88px; background: #fff; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 16px; padding: 16px 28px; position: sticky; top: 0; z-index: 20;
}
.topbar h1 { margin: 0; font-size: 22px; letter-spacing: -.35px; }
.topbar p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.topbar-actions { margin-left: auto; display: flex; gap: 9px; }
.section-block { margin: 24px 28px; scroll-margin-top: 110px; }

.notice-banner {
  display: flex; gap: 12px; align-items: center; background: #fff;
  border: 1px solid #f1d3d3; border-left: 4px solid var(--red-600);
  padding: 13px 16px; border-radius: 12px; box-shadow: 0 5px 18px rgba(20,28,45,.03);
  color: #5b2630;
}
.notice-icon { width: 25px; height: 25px; border-radius: 50%; background: var(--red-100); color: var(--red-700); display: grid; place-items: center; font-weight: 800; flex: 0 0 auto; }

.upload-grid { display: grid; grid-template-columns: 1fr 1fr .86fr; gap: 16px; margin-top: 18px; }
.upload-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); min-height: 234px;
}
.upload-card.source-ghuv { border-top: 4px solid var(--red-600); }
.upload-card.source-partner { border-top: 4px solid #334155; }
.upload-card.source-rule { border-top: 4px solid #64748b; background: linear-gradient(145deg, #fff, #f8fafc); }
.upload-card-head { display: flex; align-items: center; gap: 12px; }
.upload-symbol { width: 46px; height: 46px; border-radius: 13px; background: var(--red-100); color: var(--red-700); display: grid; place-items: center; font-weight: 900; }
.partner-symbol { background: #e2e8f0; color: #334155; }
.rule-symbol { background: #edf2f7; color: #475569; font-size: 23px; }
.upload-card h2, .panel h2 { margin: 2px 0 0; font-size: 18px; }
.upload-card > p { color: var(--muted); line-height: 1.55; min-height: 65px; }
.eyebrow { color: var(--red-700); font-size: 10px; font-weight: 800; letter-spacing: 1.35px; }
.field-label { display: block; font-size: 12px; font-weight: 700; color: #475467; margin: 15px 0 7px; }
.rule-list { padding-left: 20px; margin: 22px 0 0; color: #475467; line-height: 1.72; }
.rule-list li + li { margin-top: 5px; }

.button {
  border: 1px solid transparent; border-radius: 10px; padding: 10px 14px; font-weight: 750;
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}
.button:hover { transform: translateY(-1px); }
.button:disabled { cursor: not-allowed; opacity: .45; transform: none; }
.button-primary { background: var(--red-700); color: #fff; box-shadow: 0 8px 18px rgba(185,28,28,.2); }
.button-primary:hover { background: var(--red-800); }
.button-dark { background: #273244; color: white; }
.button-light { background: #fff; color: #344054; border-color: #d0d5dd; }
.button-success { background: #167a3f; color: #fff; }
.button-danger-outline { background: #fff; color: var(--red-700); border-color: #f1baba; }
.full-width { width: 100%; }
.text-button { border: 0; background: transparent; color: var(--red-700); font-weight: 750; padding: 7px; }
.icon-button { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: #fff; display: grid; place-items: center; font-size: 20px; color: #475467; }
.select-control, .form-field input, .form-field select {
  width: 100%; min-height: 42px; border: 1px solid #d0d5dd; border-radius: 10px; background: #fff; color: var(--ink); padding: 9px 11px; outline: none;
}
.select-control:focus, .form-field input:focus, .form-field select:focus { border-color: #e06d6d; box-shadow: 0 0 0 3px rgba(220,38,38,.08); }

.stats-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 13px; margin: 18px 0; }
.stat-card { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 16px; box-shadow: 0 5px 20px rgba(20,28,45,.04); }
.stat-card span { display: block; color: #475467; font-weight: 700; font-size: 12px; }
.stat-card strong { display: block; font-size: 26px; margin: 8px 0 3px; letter-spacing: -.6px; }
.stat-card small { color: #98a2b3; }
.stat-card.danger strong { color: var(--red-700); }
.stat-card.warning strong { color: var(--amber); }

.panel { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.filter-panel, .table-panel, .history-panel, .guide-panel { padding: 20px; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.panel-heading p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.filter-grid { display: grid; grid-template-columns: 1.5fr 1fr 1fr 1fr 1fr 1.25fr; gap: 12px; margin-top: 18px; }
.form-field { display: grid; gap: 7px; }
.form-field > span { font-size: 11px; font-weight: 750; color: #475467; }
.span-2 { grid-column: span 1; }
.diff-filter-row { display: flex; align-items: center; flex-wrap: wrap; gap: 9px 16px; border-top: 1px solid var(--line); margin-top: 16px; padding-top: 15px; }
.diff-filter-row label { display: flex; align-items: center; gap: 6px; color: #475467; font-weight: 650; }
.diff-filter-title { color: #344054; font-weight: 800; }
.diff-check { accent-color: var(--red-700); width: 16px; height: 16px; }
.table-panel { margin-top: 18px; padding: 0; overflow: hidden; }
.table-heading { padding: 20px 20px 14px; }
.table-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.legend-row { display: flex; gap: 22px; flex-wrap: wrap; padding: 0 20px 13px; color: #667085; font-size: 12px; }
.legend-row span { display: flex; align-items: center; gap: 7px; }
.legend-box { width: 15px; height: 15px; border-radius: 4px; border: 1px solid var(--line); display: inline-block; }
.mismatch-box { background: #fee2e2; border-color: #fca5a5; }
.missing-box { background: #f2f4f7; border-color: #d0d5dd; }
.table-scroll { overflow: auto; border-top: 1px solid var(--line); }
.data-table { width: 100%; border-collapse: separate; border-spacing: 0; min-width: 2550px; font-size: 12px; }
.data-table th, .data-table td { border-right: 1px solid #eaecf0; border-bottom: 1px solid #eaecf0; padding: 9px 8px; text-align: center; white-space: nowrap; }
.data-table thead th { position: sticky; top: 0; z-index: 5; background: #f8fafc; color: #344054; font-weight: 800; }
.data-table thead tr:nth-child(2) th { top: 42px; background: #fbfcfd; }
.data-table tbody tr:hover td { background: #fffafa; }
.data-table tbody tr { cursor: pointer; }
.data-table td.sticky-col, .data-table th.sticky-col { position: sticky; left: 0; z-index: 6; background: #fff; }
.data-table thead th.sticky-col { background: #f8fafc; z-index: 8; }
.col-index { min-width: 55px; }
.cell-mismatch { background: #fee2e2 !important; color: #991b1b; font-weight: 800; }
.cell-missing { background: #f2f4f7 !important; color: #98a2b3; }
.delta-positive { color: #b42318; }
.delta-negative { color: #175cd3; }
.code-pair { display: grid; gap: 3px; min-width: 155px; text-align: left; }
.code-line { display: flex; align-items: center; gap: 7px; }
.source-tag { min-width: 25px; border-radius: 5px; padding: 2px 4px; text-align: center; font-size: 9px; font-weight: 900; background: #fee2e2; color: #991b1b; }
.source-tag.partner { background: #e2e8f0; color: #334155; }
.code-value { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.badge { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 5px 8px; font-size: 10px; font-weight: 800; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.matched { background: var(--green-soft); color: var(--green); }
.badge.mismatch { background: var(--red-100); color: var(--red-700); }
.badge.pending { background: var(--amber-soft); color: var(--amber); }
.match-method { display: block; color: #98a2b3; font-size: 9px; margin-top: 4px; }
.pagination { display: flex; justify-content: center; align-items: center; gap: 16px; padding: 15px; }
.pagination span { min-width: 110px; text-align: center; color: #475467; font-weight: 700; }
.empty-state { padding: 45px !important; color: #98a2b3; font-size: 14px; }

.history-panel, .guide-panel { margin-top: 28px; }
.compact-scroll { margin-top: 16px; border: 1px solid var(--line); border-radius: 11px; }
.compact-table { min-width: 900px; }
.compact-table thead tr:nth-child(2) th { top: 0; }
.compact-table tbody tr { cursor: default; }
.guide-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-top: 18px; }
.guide-grid article { border: 1px solid var(--line); border-radius: 13px; padding: 17px; background: #fafbfc; }
.guide-grid article > span { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: var(--red-100); color: var(--red-700); font-weight: 900; }
.guide-grid h3 { margin: 13px 0 7px; font-size: 15px; }
.guide-grid p { margin: 0; line-height: 1.55; color: var(--muted); font-size: 12px; }
.production-note { margin-top: 16px; border-left: 4px solid #334155; background: #f8fafc; padding: 14px 16px; border-radius: 10px; color: #475467; }

.modal-dialog { border: 0; padding: 0; border-radius: 17px; width: min(1100px, calc(100vw - 28px)); box-shadow: 0 24px 80px rgba(0,0,0,.22); }
.modal-dialog::backdrop { background: rgba(17,24,39,.55); backdrop-filter: blur(3px); }
.modal-card { background: #fff; padding: 22px; max-height: 88vh; overflow: auto; }
.modal-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; border-bottom: 1px solid var(--line); padding-bottom: 15px; }
.modal-header h2 { margin: 3px 0 0; }
.modal-header p { margin: 5px 0 0; color: var(--muted); }
.mapping-note { background: #fff8e5; color: #7a4b08; border: 1px solid #f5d89a; border-radius: 10px; padding: 11px 13px; margin-top: 15px; }
.mapping-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 11px; margin-top: 15px; }
.mapping-item { display: grid; gap: 6px; }
.mapping-item label { font-size: 11px; color: #475467; font-weight: 800; }
.mapping-item select { min-height: 40px; border: 1px solid #d0d5dd; border-radius: 9px; padding: 8px; background: #fff; }
.mapping-item.required label::after { content: " *"; color: var(--red-600); }
.preview-wrap { margin-top: 18px; }
.preview-wrap h3 { margin: 0 0 8px; font-size: 14px; }
.preview-wrap .data-table { min-width: 1000px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 9px; border-top: 1px solid var(--line); margin-top: 18px; padding-top: 15px; }
.detail-dialog { width: min(980px, calc(100vw - 28px)); }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 16px; }
.detail-side { border: 1px solid var(--line); border-radius: 13px; overflow: hidden; }
.detail-side h3 { margin: 0; padding: 12px 14px; background: #f8fafc; border-bottom: 1px solid var(--line); font-size: 14px; }
.detail-list { display: grid; grid-template-columns: 145px 1fr; }
.detail-list dt, .detail-list dd { margin: 0; padding: 9px 12px; border-bottom: 1px solid #f0f2f5; }
.detail-list dt { color: #667085; }
.detail-list dd { font-weight: 700; text-align: right; word-break: break-word; }
.detail-diff-summary { margin-top: 14px; border: 1px solid #f3c3c3; background: #fff8f8; border-radius: 12px; padding: 13px; }
.detail-diff-summary h3 { margin: 0 0 9px; font-size: 14px; color: var(--red-700); }
.detail-diff-summary ul { margin: 0; padding-left: 20px; line-height: 1.7; }

.toast { position: fixed; right: 20px; bottom: 20px; z-index: 100; min-width: 260px; max-width: 420px; background: #182230; color: #fff; border-radius: 11px; padding: 13px 15px; box-shadow: 0 15px 40px rgba(0,0,0,.22); opacity: 0; transform: translateY(15px); pointer-events: none; transition: .22s ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #991b1b; }
.toast.success { background: #166534; }
.mobile-only { display: none; }

@media (max-width: 1300px) {
  .upload-grid { grid-template-columns: 1fr 1fr; }
  .source-rule { grid-column: 1 / -1; min-height: auto; }
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
  .filter-grid { grid-template-columns: repeat(3, 1fr); }
  .guide-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .mobile-only { display: grid; }
  .topbar { padding: 13px 15px; }
  .topbar h1 { font-size: 18px; }
  .topbar p { display: none; }
  .topbar-actions .button-danger-outline { display: none; }
  .section-block { margin: 16px 12px; }
  .upload-grid, .stats-grid, .filter-grid, .guide-grid, .mapping-grid, .detail-grid { grid-template-columns: 1fr; }
  .source-rule { grid-column: auto; }
  .panel-heading, .table-heading { flex-direction: column; }
  .table-actions { justify-content: flex-start; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-card:last-child { grid-column: 1 / -1; }
}

@media (max-width: 560px) {
  .topbar-actions .button-light { display: none; }
  .upload-card, .filter-panel, .history-panel, .guide-panel { padding: 16px; }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 9px; }
  .stat-card { padding: 13px; }
  .stat-card strong { font-size: 22px; }
  .notice-banner { align-items: flex-start; }
  .modal-card { padding: 16px; }
  .detail-list { grid-template-columns: 115px 1fr; }
}

/* Production hosting additions */
a.button { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.user-actions { align-items: center; }
.user-chip { display: grid; min-width: 135px; padding: 7px 11px; border: 1px solid var(--line); border-radius: 10px; background: #f8fafc; }
.user-chip span { font-size: 12px; font-weight: 800; color: #344054; }
.user-chip small { color: #98a2b3; font-size: 10px; margin-top: 2px; }
.import-status { display: inline-flex; border-radius: 999px; padding: 5px 8px; font-size: 10px; font-weight: 800; }
.import-status.completed { background: var(--green-soft); color: var(--green); }
.import-status.processing { background: var(--amber-soft); color: var(--amber); }
.import-status.failed { background: var(--red-100); color: var(--red-700); }
.loading-overlay { position: fixed; inset: 0; z-index: 200; background: rgba(17,24,39,.62); display: grid; place-items: center; backdrop-filter: blur(4px); }
.loading-overlay[hidden] { display: none; }
.loading-card { width: min(360px, calc(100vw - 32px)); background: #fff; border-radius: 16px; padding: 25px; display: grid; justify-items: center; text-align: center; box-shadow: 0 24px 80px rgba(0,0,0,.3); }
.loading-card strong { margin-top: 14px; font-size: 17px; }
.loading-card span { margin-top: 6px; color: #667085; line-height: 1.5; }
.spinner { width: 42px; height: 42px; border: 4px solid #f2c5c5; border-top-color: var(--red-700); border-radius: 50%; animation: spin .75s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.small-modal { width: min(520px, calc(100vw - 28px)); }
.password-fields { display: grid; gap: 13px; margin-top: 17px; }
.detail-notice { margin-top: 16px; }
.detail-ok { border-color: #bbdfc6; background: #f3fff6; }
.detail-ok h3 { color: #15803d; }

.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at top left, rgba(185,28,28,.12), transparent 32%), linear-gradient(135deg, #f8fafc, #fff7f7); }
.auth-card { width: min(460px, 100%); background: #fff; border: 1px solid var(--line); border-radius: 20px; padding: 28px; box-shadow: 0 26px 80px rgba(20,28,45,.14); }
.install-card { width: min(820px, 100%); }
.auth-brand { display: flex; align-items: center; gap: 12px; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.auth-brand .brand-mark { background: var(--red-700); color: #fff; }
.auth-brand strong { display: block; font-size: 17px; color: #7f1d1d; }
.auth-brand span { display: block; color: #98a2b3; font-size: 9px; letter-spacing: 2px; margin-top: 3px; }
.auth-card h1 { margin: 23px 0 7px; font-size: 24px; }
.auth-card h2 { margin: 24px 0 12px; font-size: 15px; color: #344054; }
.auth-subtitle { margin: 0 0 20px; color: #667085; line-height: 1.55; }
.auth-card form { display: grid; gap: 14px; }
.auth-submit { margin-top: 5px; min-height: 46px; }
.auth-error { background: #fff1f1; color: #991b1b; border: 1px solid #fecaca; border-radius: 10px; padding: 11px 13px; margin-bottom: 16px; line-height: 1.55; }
.auth-success { text-align: center; padding-top: 10px; }
.auth-success p { color: #667085; margin-bottom: 20px; }
.auth-footnote { color: #98a2b3; text-align: center; font-size: 11px; line-height: 1.55; margin: 18px 0 0; }
.install-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.span-full { grid-column: 1 / -1; }

@media (max-width: 1000px) {
  .user-chip { display: none; }
}
@media (max-width: 900px) {
  .user-actions .button-dark { padding: 9px 11px; }
  .user-actions { gap: 6px; }
}
@media (max-width: 650px) {
  .install-grid { grid-template-columns: 1fr; }
  .span-full { grid-column: auto; }
  .auth-card { padding: 21px; }
  .topbar-actions #passwordBtn { display: none; }
}
