:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --surface-tint: #eef5ff;
  --text: #12213a;
  --muted: #63738b;
  --border: #dde6f0;
  --brand: #123f73;
  --brand-strong: #0d2d55;
  --brand-soft: #e7f0fb;
  --accent: #16786f;
  --danger: #b42318;
  --shadow: 0 20px 50px rgba(24, 39, 75, 0.11);
  --radius: 8px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1422;
  --surface: #151f31;
  --surface-soft: #101827;
  --surface-tint: #172640;
  --text: #edf3fb;
  --muted: #a7b4c7;
  --border: #2a3950;
  --brand: #74a8e5;
  --brand-strong: #9ec6f1;
  --brand-soft: #193455;
  --accent: #53c2b5;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.32);
}

[data-theme="blue"] {
  --bg: #eef6fb;
  --surface: #ffffff;
  --surface-soft: #f5fbff;
  --surface-tint: #e5f3fb;
  --text: #0e304a;
  --muted: #517089;
  --border: #cfe1ee;
  --brand: #0f5f91;
  --brand-strong: #0a4167;
  --brand-soft: #dff0fa;
  --accent: #0f766e;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.page-shell {
  width: min(1220px, calc(100% - 32px));
  margin: 24px auto;
  padding-top: 54px;
}

.page-header,
.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 24px;
  background: linear-gradient(135deg, var(--brand-strong), var(--brand));
  color: #ffffff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.title-group h1,
.title-block h1 {
  margin: 0;
  font-size: clamp(1.65rem, 3vw, 2.25rem);
  line-height: 1.12;
  letter-spacing: 0;
}

.title-group p,
.subtitle {
  max-width: 640px;
  margin: 8px 0 0;
  color: rgba(255, 255, 255, 0.82);
  font-size: 0.95rem;
}

.home-layout {
  display: block;
  margin-top: 18px;
}

.sidebar-panel,
.content-panel,
.info-card,
.status-legend,
.preview-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 28px rgba(24, 39, 75, 0.06);
}

.sidebar-panel {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 20;
  width: 280px;
  padding: 16px;
}

.sidebar-panel.profile-collapsed {
  width: 58px;
  min-height: 58px;
  padding: 7px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.sidebar-panel.profile-collapsed .panel-header {
  padding-bottom: 0;
  border-bottom: 0;
}

.profile-summary {
  display: none;
  align-items: center;
  gap: 12px;
}

.avatar-circle {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--brand));
  color: #ffffff;
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.avatar-meta {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.avatar-meta .name,
.avatar-meta .email {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.avatar-meta .name {
  font-weight: 800;
}

.avatar-meta .email {
  color: var(--muted);
  font-size: 0.82rem;
}

.profile-menu-toggle {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--brand));
  color: #ffffff;
  cursor: pointer;
  box-shadow: 0 10px 22px rgba(24, 39, 75, 0.16);
}

.profile-menu-toggle span {
  display: none;
  transition: transform 0.18s ease, opacity 0.18s ease;
}

.profile-menu-toggle::before {
  content: attr(data-initials);
  font-size: 0.86rem;
  font-weight: 900;
  letter-spacing: 0.02em;
}

.sidebar-panel.profile-collapsed .sidebar-nav,
.sidebar-panel.profile-collapsed .panel-note {
  display: none;
}

.sidebar-nav {
  margin-top: 14px;
}

.sidebar-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.sidebar-tab {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 8px 10px;
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 750;
}

.sidebar-tab.active {
  background: var(--surface);
  color: var(--brand);
  box-shadow: 0 2px 8px rgba(24, 39, 75, 0.08);
}

.sidebar-tab-panel {
  padding-top: 14px;
}

.profile-card {
  display: grid;
  gap: 12px;
}

.profile-field {
  display: grid;
  gap: 6px;
}

.field-label,
.sidebar-section-title {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.profile-input,
.form-row input,
.form-row select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 10px 11px;
  outline: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.profile-input:focus,
.form-row input:focus,
.form-row select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 16%, transparent);
}

.profile-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-save,
.btn,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 9px 14px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 800;
  text-decoration: none;
  transition: transform 0.12s ease, background 0.16s ease, border-color 0.16s ease;
}

.btn-save,
.btn-primary,
.button.primary {
  background: var(--brand);
  color: #ffffff;
}

.btn-save:hover,
.btn-primary:hover,
.button.primary:hover {
  background: var(--brand-strong);
  transform: translateY(-1px);
}

.btn-compare {
  min-width: 176px;
  background: var(--accent);
  box-shadow: 0 10px 20px rgba(15, 118, 110, 0.18);
}

.btn-compare:hover {
  background: #0f665f;
}

.btn-compare:disabled {
  background: #a8b5c5;
  box-shadow: none;
  color: #f8fafc;
  cursor: not-allowed;
  opacity: 0.72;
  transform: none;
}

.btn-secondary,
.button.secondary {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.btn-secondary:hover,
.button.secondary:hover {
  border-color: var(--brand);
  color: var(--brand);
}

.save-feedback {
  min-width: 52px;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 800;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.save-feedback.show {
  opacity: 1;
}

.profile-note,
.panel-note {
  color: var(--muted);
  font-size: 0.78rem;
}

.profile-note {
  padding: 9px 10px;
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.panel-note {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.theme-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.theme-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 10px 11px;
  cursor: pointer;
  font-weight: 750;
}

.theme-chip.active {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--brand);
}

.chip-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0;
}

.theme-chip.active .chip-indicator {
  opacity: 1;
}

.right-panel {
  display: grid;
  gap: 14px;
}

.content-panel {
  padding: 20px;
}

.content-panel h3,
.info-card h4 {
  margin: 0 0 14px;
  color: var(--text);
}

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

.upload-box {
  position: relative;
  display: grid;
  gap: 7px;
  min-height: 172px;
  padding: 18px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface-soft);
  cursor: pointer;
  transition: border-color 0.16s ease, background 0.16s ease, transform 0.12s ease;
}

.upload-box:hover,
.upload-box.dragover {
  border-color: var(--brand);
  background: var(--brand-soft);
  transform: translateY(-1px);
}

.upload-box span {
  color: var(--brand);
  font-size: 0.75rem;
  font-weight: 850;
  letter-spacing: 0.08em;
}

.upload-box strong {
  font-size: 1.08rem;
}

.upload-box small {
  color: var(--muted);
}

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

.upload-box input[type="file"]:disabled {
  cursor: not-allowed;
}

.upload-box:has(input[type="file"]:disabled) {
  opacity: 0.58;
  cursor: not-allowed;
}

.file-name {
  align-self: end;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--brand);
  padding: 6px 8px;
  font-size: 0.82rem;
  font-weight: 750;
}

.file-selection {
  position: relative;
  z-index: 2;
  align-self: end;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.clear-file-btn {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--danger);
  padding: 6px 9px;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 850;
}

.clear-file-btn:hover:not(:disabled) {
  border-color: var(--danger);
  background: #fff5f3;
}

.clear-file-btn:disabled {
  cursor: not-allowed;
  opacity: 0.44;
}

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 16px;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.form-row label {
  display: grid;
  gap: 6px;
  min-width: 190px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.info-card {
  padding: 16px;
}

.info-card ul {
  display: grid;
  gap: 8px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.info-card li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.86rem;
}

.info-card li:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.info-card strong {
  color: var(--text);
}

.status-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 12px;
  font-size: 0.82rem;
}

.legend-label {
  color: var(--muted);
  font-weight: 850;
}

.legend-item,
.status-chip {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  padding: 5px 10px;
  font-size: 0.78rem;
  font-weight: 800;
}

.value-changed,
.status-value-changed {
  background: #fff7d6;
}

.record-matched,
.status-record-matched {
  background: #e7f8ee;
}

.missing-record,
.status-not-found-in-updated-file {
  background: #fff0e7;
}

.new-record,
.status-new-record-added-in-updated-file {
  background: #e9f2ff;
}

.preview-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 24px auto;
}

.preview-header {
  margin-bottom: 18px;
}

.actions {
  display: flex;
  gap: 10px;
}

.result-tabs,
.sheet-tabs-wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.result-tabs {
  justify-content: center;
}

.result-tabs a,
.sheet-tabs a {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  padding: 8px 13px;
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 850;
}

.result-tabs a.active,
.sheet-tabs a.active {
  border-color: var(--brand);
  background: var(--brand);
  color: #ffffff;
}

.sheet-tabs-wrap .label {
  color: var(--muted);
  font-weight: 850;
}

.sheet-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.preview-card {
  overflow: hidden;
}

.sheet-title {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 900;
}

.preview-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-soft);
}

.preview-search {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  flex: 1 1 460px;
}

.preview-search input[type="search"] {
  min-width: min(340px, 100%);
  flex: 1 1 260px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 9px 11px;
  outline: none;
}

.preview-search input[type="search"]:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 16%, transparent);
}

.preview-search input[type="search"].searching {
  background:
    linear-gradient(var(--surface), var(--surface)) padding-box,
    linear-gradient(90deg, var(--accent), var(--brand), var(--accent)) border-box;
  border-color: transparent;
}

.search-result-count {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.table-wrap {
  max-height: 520px;
  overflow: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

.data-table th,
.data-table td {
  padding: 9px 11px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

.data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-soft);
  color: var(--text);
}

.pager,
.download-corner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.88rem;
}

.pager-links,
.download-corner {
  justify-content: flex-end;
}

.pager-links {
  display: flex;
  gap: 8px;
}

.empty {
  padding: 24px 16px;
  color: var(--muted);
}

.live-search-empty {
  border-top: 1px solid var(--border);
}

.app-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.72rem;
}

.loader-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(10, 22, 38, 0.48);
  backdrop-filter: blur(8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.loader-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.loader-overlay.complete .loader-orbit {
  animation: none;
  background:
    linear-gradient(var(--surface), var(--surface)) padding-box,
    conic-gradient(var(--accent), var(--accent)) border-box;
}

.loader-overlay.complete .loader-orbit::after {
  content: "";
  position: absolute;
  left: 31px;
  top: 37px;
  width: 28px;
  height: 14px;
  border-left: 4px solid var(--accent);
  border-bottom: 4px solid var(--accent);
  transform: rotate(-45deg);
}

.loader-overlay.complete .loader-track span {
  width: 100%;
  animation: none;
  transform: none;
  background: var(--accent);
}

.loader-card {
  width: min(420px, 100%);
  display: grid;
  justify-items: center;
  gap: 18px;
  padding: 28px 26px 24px;
  border: 1px solid color-mix(in srgb, var(--brand) 18%, var(--border));
  border-radius: 14px;
  background: color-mix(in srgb, var(--surface) 94%, white);
  color: var(--text);
  box-shadow: 0 28px 80px rgba(5, 14, 28, 0.28);
  text-align: center;
}

.loader-orbit {
  position: relative;
  width: 92px;
  height: 92px;
  border-radius: 50%;
  background:
    linear-gradient(var(--surface), var(--surface)) padding-box,
    conic-gradient(from 0deg, var(--accent), var(--brand), #f4b942, var(--accent)) border-box;
  border: 4px solid transparent;
  animation: loaderSpin 1.6s linear infinite;
}

.loader-orbit::before {
  content: "";
  position: absolute;
  inset: 17px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-soft);
}

.loader-orbit span {
  position: absolute;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 18%, transparent);
}

.loader-orbit span:nth-child(1) {
  top: 5px;
  left: 50%;
  transform: translateX(-50%);
}

.loader-orbit span:nth-child(2) {
  right: 10px;
  bottom: 16px;
  background: var(--brand);
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--brand) 18%, transparent);
}

.loader-orbit span:nth-child(3) {
  left: 10px;
  bottom: 16px;
  background: #f4b942;
  box-shadow: 0 0 0 6px rgba(244, 185, 66, 0.18);
}

.loader-copy {
  display: grid;
  gap: 6px;
}

.loader-copy strong {
  font-size: 1.12rem;
}

.loader-copy p {
  margin: 0;
  min-height: 22px;
  color: var(--muted);
  font-size: 0.92rem;
}

.loader-track {
  width: 100%;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
}

.loader-track span {
  display: block;
  width: 42%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--brand), #f4b942);
  animation: loaderSweep 1.25s ease-in-out infinite;
}

.loader-steps {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.loader-summary {
  width: 100%;
  display: grid;
  gap: 14px;
}

.loader-summary[hidden] {
  display: none;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  width: 100%;
}

.summary-stat {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 11px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-soft);
  text-align: left;
}

.summary-stat > div {
  display: grid;
  gap: 2px;
}

.summary-stat strong {
  font-size: 1.22rem;
  line-height: 1.1;
}

.summary-stat span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 850;
}

.summary-open {
  flex: 0 0 auto;
  border: 1px solid rgba(30, 122, 108, 0.24);
  background: #ffffff;
  color: #1e7a6c;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 0.72rem;
  font-weight: 850;
  text-decoration: none;
}

.summary-open:hover {
  border-color: #1e7a6c;
  background: #e8f6f3;
}

.summary-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.summary-actions .button {
  min-height: 38px;
}

body.is-loading {
  cursor: progress;
}

@keyframes loaderSpin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes loaderSweep {
  0% {
    transform: translateX(-110%);
  }
  55% {
    transform: translateX(75%);
  }
  100% {
    transform: translateX(240%);
  }
}

@media (max-width: 860px) {
  .page-header,
  .preview-header,
  .home-layout,
  .upload-grid {
    grid-template-columns: 1fr;
  }

  .page-header,
  .preview-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .version-badge {
    text-align: left;
  }

  .home-layout {
    display: block;
  }

  .sidebar-panel {
    position: fixed;
  }

  .form-actions,
  .preview-tools,
  .pager,
  .download-corner {
    flex-direction: column;
    align-items: stretch;
  }

  .btn,
  .button,
  .preview-search input[type="search"] {
    width: 100%;
  }
}

@media (max-width: 560px) {
  .page-shell,
  .preview-shell {
    width: min(100% - 20px, 1180px);
    margin: 10px auto;
  }

  .page-header,
  .preview-header,
  .content-panel,
  .sidebar-panel {
    padding: 14px;
  }

  .form-row {
    display: grid;
  }

  .loader-card {
    padding: 24px 18px 20px;
  }
}
