* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  display: flex;
  flex-direction: column;
  /* gap: 10px; */
  /* background: linear-gradient(135deg, #0f7c41 0%, #764ba2 100%); */
  background: #f9fafa;
  /* padding: 20px; */
  min-height: 100dvh;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* ============================================
   CONTAINER
   ============================================ */
.container {
  /* flex: 1; */
  margin: 20px auto auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
  border-radius: 12px;
  background: white;
  width: calc(100vw - 40px);
  overflow: hidden;
}

/* ============================================
   HEADER
   ============================================ */
.header {
  /* background: linear-gradient(135deg, #0f7c41 0%, #764ba2 100%); */
  background: linear-gradient(-90deg, #50a74d, #165932);
  padding: 30px;
  color: white;
  text-align: center;
}

.header h1 {
  margin-bottom: 10px;
  font-size: 2.5em;
}

.header p {
  opacity: 0.9;
  font-size: 1em;
}

/* ============================================
   UPLOAD SECTION
   ============================================ */
.upload-section {
  padding: 40px;
}

.upload-container {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 30px;
  margin-bottom: 30px;
}

.upload-box {
  flex: 1;
  max-width: 400px;
}

.upload-area {
  transition: all 0.3s;
  border: 3px dashed #ddd;
  border-radius: 12px;
  background: #fafafa;
  padding: 40px 20px;
  text-align: center;
}

.upload-area:hover {
  border-color: #0f7c41;
  background: #f0f4ff;
}

.upload-icon {
  margin-bottom: 15px;
  font-size: 3em;
}

.upload-area h3 {
  margin-bottom: 20px;
  color: #333;
}

.upload-area button {
  transition: all 0.3s;
  cursor: pointer;
  border: none;
  border-radius: 6px;
  background: #0f7c41;
  padding: 12px 30px;
  color: white;
  font-size: 1em;
}

.upload-area button:hover {
  transform: translateY(-2px);
  /* background: #5568d3; */
  filter: brightness(80%);
}

.file-name {
  margin-top: 15px;
  color: #666;
  font-size: 0.9em;
  word-break: break-all;
}

.upload-divider {
  color: #0f7c41;
  font-weight: bold;
  font-size: 1.5em;
}

.compare-btn {
  display: block;
  transition: all 0.3s;
  cursor: pointer;
  margin: 0 auto;
  border: none;
  border-radius: 8px;
  background: #0f7c41;
  padding: 15px 50px;
  color: white;
  font-size: 1.1em;
}

.compare-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(40, 167, 69, 0.3);
  filter: brightness(80%);
}

.compare-btn:disabled {
  cursor: not-allowed;
  background: #ccc;
}

/* ============================================
   SUMMARY SECTION
   ============================================ */
.summary-section {
  padding: 40px;
}

.summary-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
}

.summary-header h2 {
  color: #333;
}

.back-btn {
  transition: all 0.3s;
  cursor: pointer;
  border: none;
  border-radius: 6px;
  background: #0f7c41;
  padding: 10px 20px;
  color: white;
}

.back-btn:hover {
  filter: brightness(80%);
}

.file-info {
  margin-bottom: 30px;
  border-radius: 8px;
  background: #e4f0eb;
  padding: 20px;
}

.file-info-item {
  margin-bottom: 10px;
  color: #006645;
  font-size: 1em;
}

.file-info-item:last-child {
  margin-bottom: 0;
}

.sheet-changes h3 {
  margin-bottom: 15px;
  color: #333;
}

#sheetChangesList {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sheet-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: all 0.3s;
  cursor: pointer;
  border: 2px solid #e9ecef;
  border-radius: 8px;
  background: white;
  padding: 15px 20px;
}

.sheet-item:hover {
  transform: translateX(5px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  border-color: #0f7c41;
}

.sheet-item-name {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
}

/* Sheet Status Badges */
.sheet-status {
  border-radius: 20px;
  padding: 5px 12px;
  font-weight: 500;
  font-size: 0.85em;
}

.status-unchanged {
  background: #d4edda;
  color: #155724;
}

.status-modified {
  background: #fff3cd;
  color: #856404;
}

.status-added {
  background: #d1ecf1;
  color: #0c5460;
}

.status-removed {
  background: #f8d7da;
  color: #721c24;
}

.status-renamed {
  background: #e7d4f5;
  color: #5a1a7a;
}

.hint {
  margin: 20px 0px;
  color: #666;
  font-style: italic;
  text-align: center;
}

/* ============================================
   DIFF SECTION
   ============================================ */
.diff-section {
  padding: 20px;
}

.diff-header {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 20px;
  padding: 0 20px;
}

.diff-header h2 {
  color: #333;
}

/* ============================================
   SHEET NAVIGATION BAR
   ============================================ */
.sheet-nav-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  border-radius: 8px;
  background: #f8f9fa;
  padding: 10px 20px;
  overflow-x: auto;
  white-space: nowrap;
}

.sheet-tab {
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.3s;
  cursor: pointer;
  border: 2px solid #dee2e6;
  border-radius: 6px;
  background: white;
  padding: 10px 20px;
}

.sheet-tab:hover {
  border-color: #0f7c41;
}

.sheet-tab.active {
  border-color: #0f7c41;
  background: #0f7c41;
  color: white;
}

/* Sheet Tab Status Indicators */
.sheet-tab.has-changes::after {
  content: '✏️';
}

.sheet-tab.added::after {
  content: '➕';
}

.sheet-tab.removed::after {
  content: '❌';
}

/* ============================================
   DIFF CONTAINER & TABLES
   ============================================ */
.diff-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  /* margin-bottom: 20px; */
}

.diff-pane {
  position: relative; /* Required for shadow overlay */
  border: 2px solid #dee2e6;
  border-radius: 8px;
  overflow: hidden;
}

.pane-header {
  border-bottom: 2px solid #dee2e6;
  background: #f8f9fa;
  padding: 15px 20px;
}

.pane-header h3 {
  margin-bottom: 5px;
  color: #333;
}

.pane-header span {
  color: #666;
  font-size: 0.9em;
}

.table-wrapper {
  position: relative;
  max-height: calc(100dvh - 560px);
  overflow: auto;
  /* Safari scroll optimization */
  -webkit-overflow-scrolling: touch;
  transform: translateZ(0); /* Enable hardware acceleration */
  will-change: scroll-position;
}

.diff-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.9em;
}

.diff-table th {
  position: sticky;
  top: 0;
  z-index: 10;
  border: 1px solid #dee2e6;
  background: #e9ecef;
  padding: 10px;
  font-weight: 600;
  text-align: left;
}

.diff-table td {
  border: 1px solid #dee2e6;
  padding: 10px;
  min-width: 100px;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.diff-table .row-header {
  position: sticky;
  left: 0;
  z-index: 5;
  background: #e9ecef;
  min-width: 50px;
  font-weight: 600;
  text-align: center;
}

/* ============================================
   CELL COLORS (Diff Highlighting)
   ============================================ */
.cell-added {
  background: #d4edda !important;
  color: #155724;
}

.cell-removed {
  background: #f8d7da !important;
  color: #721c24;
}

.cell-modified {
  background: #fff3cd !important;
  color: #856404;
}

.cell-unchanged {
  background: white;
  color: #333;
}

.cell-empty {
  background: #f8f9fa;
  color: #6c757d;
  font-style: italic;
}

/* ============================================
   LEGEND
   ============================================ */
.legend {
  display: flex;
  justify-content: center;
  gap: 30px;
  margin-bottom: 20px;
  border-radius: 8px;
  background: #f8f9fa;
  padding: 10px 20px;
}

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

.legend-color {
  border: 1px solid #dee2e6;
  border-radius: 4px;
  width: 20px;
  height: 20px;
}

.legend-color.added {
  background: #d4edda;
}

.legend-color.removed {
  background: #f8d7da;
}

.legend-color.modified {
  background: #fff3cd;
}

.legend-color.unchanged {
  background: white;
}

/* ============================================
   LOADING OVERLAY
   ============================================ */
.loading-overlay {
  display: flex;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.7);
}

.spinner {
  animation: spin 1s linear infinite;
  border: 5px solid #f3f3f3;
  border-top: 5px solid #0f7c41;
  border-radius: 50%;
  width: 50px;
  height: 50px;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.loading-overlay p {
  margin-top: 20px;
  color: white;
  font-size: 1.2em;
}

/* ============================================
   SCROLL SHADOW OVERLAY
   ============================================ */
.diff-pane::after {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  opacity: 0;
  z-index: 10;
  transition: opacity 0.3s;
  background: linear-gradient(to left, rgba(0, 0, 0, 0.15), transparent);
  width: 30px;
  pointer-events: none;
  content: '';
}

/* Show shadow when table is scrollable */
.diff-pane:has(.table-wrapper.scrollable)::after {
  opacity: 1;
}

/* ============================================
   SYNC CONTROL BUTTON
   ============================================ */
.sync-control {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sync-button {
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.3s ease;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
  border: none;
  border-radius: 8px;
  background: linear-gradient(-90deg, #50a74d, #165932);
  padding: 10px 20px;
  color: white;
  font-weight: 600;
  font-size: 14px;
}

.sync-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.sync-button:active {
  transform: translateY(0);
}

.sync-button.active {
  background: linear-gradient(-90deg, #50a74d, #165932);
}

.sync-button.active .sync-icon::before {
  content: '🔗';
}

.sync-button:not(.active) {
  background: linear-gradient(135deg, #bbb 0%, #999 100%);
}

.sync-button:not(.active) .sync-icon::before {
  content: '🔓';
}

.sync-icon {
  display: flex;
  align-items: center;
  font-size: 18px;
}

.sync-text {
  user-select: none;
}

/* Sync active indicator pulse animation */
.sync-button::after {
  display: inline-block;
  animation: pulse 1s ease-in-out infinite;
  margin-left: 8px;
  border-radius: 50%;
  background: #59f675;
  opacity: 0.2;
  width: 8px;
  height: 8px;
  content: '';
}

.sync-button:not(.active)::after {
  animation: none;
  background: white;
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.2);
    opacity: 0.2;
  }
}

/* ============================================
   FOOTER
   ============================================ */
footer {
  padding: 12px 0px;
  color: #333;
  font-size: 12px;
  text-align: center;
}

footer a {
  color: #0f7c41;
  text-decoration: none;
}

/* ============================================
   CUSTOM TOOLTIP
   ============================================ */
.custom-tooltip {
  position: fixed;
  background: rgba(0, 0, 0, 0.9);
  color: white;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.4;
  white-space: pre-line;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 10000;
  max-width: 300px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.custom-tooltip.visible {
  opacity: 1;
}

/* ============================================
   CELL HOVER EFFECTS
   ============================================ */
.diff-table tbody td:not(.row-header):hover {
  outline: 2px solid #4caf50;
  outline-offset: -1px;
  cursor: help;
}

.diff-table tbody td.cell-modified:hover {
  outline-color: #ff9800;
}

.diff-table tbody td.cell-added:hover {
  outline-color: #4caf50;
}

.diff-table tbody td.cell-removed:hover {
  outline-color: #f44336;
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */
@media (max-width: 768px) {
  .upload-container {
    flex-direction: column;
  }

  .upload-divider {
    transform: rotate(90deg);
  }

  .diff-container {
    grid-template-columns: 1fr;
  }

  .sheet-nav-bar {
    flex-wrap: wrap;
  }

  .sync-button {
    padding: 8px 16px;
    font-size: 12px;
  }

  .sync-icon {
    font-size: 16px;
  }
}
