* {
  box-sizing: border-box;
  font-family: system-ui, sans-serif;
}

html {
  height: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  background: #f7f7f7;
  color: #222;
  min-height: 100vh;
  overflow-x: hidden;
}

.app-header {
  padding: 12px 16px;
  background: #1f2937;
  color: white;
  text-align: left;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.app-header h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
}

.app-main {
  padding: 16px;
  padding-bottom: 180px; /* Significantly increased bottom padding */
  min-height: calc(100vh - 60px); /* Reduced header height */
}

.upload-section {
  background: white;
  padding: 16px;
  border-radius: 6px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.file-upload-area {
  border: 2px dashed #d1d5db;
  border-radius: 6px;
  padding: 24px 16px;
  text-align: center;
  background: #fafafa;
  transition: all 0.2s ease;
  cursor: pointer;
}

.file-upload-area:hover {
  border-color: #1f2937;
  background: #f3f4f6;
}

.file-upload-area.dragover {
  border-color: #3b82f6;
  background: #eff6ff;
}

.upload-icon {
  font-size: 24px;
  margin-bottom: 8px;
  opacity: 0.7;
}

.upload-text h3 {
  margin: 0 0 4px 0;
  font-size: 15px;
  color: #374151;
  font-weight: 500;
}

.upload-text p {
  margin: 0;
  color: #6b7280;
  font-size: 13px;
}

.upload-link {
  color: #1f2937;
  text-decoration: underline;
  cursor: pointer;
  font-weight: 500;
}

.upload-link:hover {
  color: #3b82f6;
}

.upload-formats {
  margin-top: 8px;
  font-size: 11px;
  color: #9ca3af;
}

input[type="file"] {
  width: 100%;
  padding: 10px;
  font-size: 14px;
}

.hint {
  margin-top: 6px;
  font-size: 13px;
  color: #666;
}

.status {
  margin-top: 12px;
  font-size: 13px;
}

.column-selector {
  background: white;
  padding: 24px;
  border-radius: 12px;
  margin-top: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.column-selector-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.column-selector-header h2 {
  margin: 0;
}

.btn-toggle {
  background: #f3f4f6;
  border: 1px solid #d1d5db;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s ease;
}

.btn-toggle:hover {
  background: #e5e7eb;
}

.column-count {
  background: #1f2937;
  color: white;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

.column-controls {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.column-search {
  flex: 1;
  min-width: 200px;
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 14px;
}

.column-search:focus {
  outline: none;
  border-color: #1f2937;
  box-shadow: 0 0 0 2px rgba(31, 41, 55, 0.1);
}

.quick-actions {
  display: flex;
  gap: 8px;
}

.btn-quick {
  background: #f3f4f6;
  border: 1px solid #d1d5db;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
}

.btn-quick:hover {
  background: #e5e7eb;
}

.column-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 12px;
  margin: 16px 0;
  transition: all 0.3s ease;
  overflow: hidden;
}

.column-list.collapsed {
  max-height: 0;
  margin: 0;
  opacity: 0;
}

.column-list.expanded {
  max-height: 1000px;
  opacity: 1;
}

.column-item {
  display: flex;
  align-items: center;
  padding: 12px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #f9fafb;
  transition: all 0.2s ease;
}

.column-item.hidden {
  display: none;
}

.column-item:hover {
  background: #f3f4f6;
  border-color: #d1d5db;
}

/* Mobile responsiveness */
@media (max-width: 768px) {
  .app-header {
    padding: 8px 12px;
  }
  
  .app-header h1 {
    font-size: 16px;
  }
  
  .app-main {
    padding: 12px;
    padding-bottom: 80px; /* Reduced mobile bottom padding */
  }
  
  .upload-section {
    padding: 12px;
  }
  
  .file-upload-area {
    padding: 16px 12px;
  }
  
  .upload-icon {
    font-size: 20px;
    margin-bottom: 6px;
  }
  
  .upload-text h3 {
    font-size: 14px;
    margin-bottom: 3px;
  }
  
  .upload-text p {
    font-size: 12px;
  }
  
  .upload-formats {
    font-size: 10px;
    margin-top: 6px;
  }
  
  .column-selector,
  .dashboard,
  .charts-section {
    padding: 16px;
  }
  
  .column-selector h2,
  .dashboard h2,
  .charts-header h2 {
    font-size: 18px;
    margin-bottom: 12px;
  }
  
  .filters-section {
    padding: 12px;
  }
  
  .filters-section h3 {
    font-size: 14px;
    margin-bottom: 8px;
  }
  
  .filter-item label {
    font-size: 11px;
  }
  
  .filter-item input,
  .filter-item select {
    padding: 4px 6px;
    font-size: 12px;
  }
  
  .btn-secondary {
    padding: 6px 12px;
    font-size: 12px;
  }
  
  .pagination-controls {
    padding: 8px;
    margin: 12px 0;
  }
  
  .pagination-info {
    font-size: 12px;
  }
  
  .btn-pagination {
    padding: 4px 8px;
    font-size: 12px;
  }
  
  .rows-per-page {
    font-size: 12px;
  }
  
  .rows-per-page select {
    padding: 2px 4px;
    font-size: 12px;
  }
  
  .data-table th,
  .data-table td {
    padding: 6px 8px;
    font-size: 12px;
  }
  
  .column-list {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  
  .column-item {
    padding: 8px;
  }
  
  .column-name {
    font-size: 13px;
  }
  
  .column-type {
    font-size: 10px;
  }
  
  .column-selector-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  
  .btn-toggle {
    align-self: stretch;
    justify-content: center;
    padding: 6px 12px;
    font-size: 12px;
  }
  
  .column-count {
    font-size: 10px;
    padding: 1px 6px;
  }
  
  .column-controls {
    flex-direction: column;
    align-items: stretch;
  }
  
  .column-search {
    min-width: auto;
    padding: 6px 8px;
    font-size: 12px;
  }
  
  .quick-actions {
    justify-content: center;
  }
  
  .btn-quick {
    padding: 4px 8px;
    font-size: 11px;
  }
  
  .action-buttons {
    flex-direction: column;
  }
  
  .action-buttons button {
    width: 100%;
    padding: 10px 16px;
    font-size: 14px;
  }
  
  .status {
    font-size: 12px;
  }
}

/* Tablet specific adjustments */
@media (min-width: 769px) and (max-width: 1024px) {
  .app-main {
    padding: 16px;
    padding-bottom: 200px; /* Much more bottom padding for tablets */
  }
  
  .column-list {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  }
}

/* Ensure proper scrolling on all devices */
@media (max-height: 800px) {
  .app-main {
    padding-bottom: 100px; /* Reduced padding for shorter screens */
  }
}

/* Additional fix for iOS Safari and tablet browsers */
@media (max-width: 1024px) {
  body {
    padding-bottom: env(safe-area-inset-bottom, 0px); /* Handle notch/home indicator */
  }
  
  .dashboard {
    margin-bottom: 20px; /* Reduced margin for dashboard section */
  }
}

/* Phase 4: Charts Section Styles */
.charts-section {
  background: white;
  padding: 24px;
  border-radius: 12px;
  margin-top: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.charts-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.charts-header h2 {
  margin: 0;
}

.chart-controls {
  background: #f9fafb;
  padding: 20px;
  border-radius: 8px;
  margin-bottom: 24px;
  border: 1px solid #e5e7eb;
}

.chart-config {
  display: flex;
  gap: 16px;
  align-items: end;
  flex-wrap: wrap;
}

.chart-type-selector {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 180px;
}

.chart-configuration {
  display: flex;
  gap: 16px;
  align-items: end;
  flex-wrap: wrap;
  flex: 1;
}

.config-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 150px;
}

.chart-type-selector label,
.config-group label {
  font-size: 14px;
  font-weight: 500;
  color: #374151;
}

.chart-type-selector select,
.config-group select {
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 14px;
  background: white;
}

.chart-hint {
  font-size: 12px;
  color: #6b7280;
  font-style: italic;
  margin-top: 2px;
}

.chart-example {
  font-size: 11px;
  color: #9ca3af;
  margin-top: 1px;
}

.chart-container {
  min-height: 400px;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chart-placeholder {
  text-align: center;
  color: #6b7280;
  font-size: 16px;
}

.chart-canvas {
  max-width: 100%;
  max-height: 400px;
}

@media (max-width: 768px) {
  .charts-header {
    flex-direction: column;
    align-items: stretch;
  }
  
  .chart-config {
    flex-direction: column;
    align-items: stretch;
  }
  
  .chart-configuration {
    flex-direction: column;
    align-items: stretch;
  }
  
  .chart-type-selector,
  .config-group {
    min-width: auto;
  }
}

.column-item {
  display: flex;
  align-items: center;
  padding: 12px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #f9fafb;
}

.column-item input[type="checkbox"] {
  margin-right: 8px;
}

.column-info {
  flex: 1;
}

.column-name {
  font-weight: 500;
  margin-bottom: 4px;
}

.column-type {
  font-size: 12px;
  color: #666;
  background: #e5e7eb;
  padding: 2px 6px;
  border-radius: 4px;
}

.btn-primary {
  background: #1f2937;
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
}

.btn-primary:hover {
  background: #374151;
}

.action-buttons {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.btn-secondary-action {
  background: #6b7280;
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
}

.btn-secondary-action:hover {
  background: #4b5563;
}

@media (max-width: 768px) {
  .action-buttons {
    flex-direction: column;
  }
  
  .action-buttons button {
    width: 100%;
  }
}

.dashboard {
  background: white;
  padding: 24px;
  border-radius: 12px;
  margin-top: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.data-table {
  overflow-x: auto;
  margin-bottom: 20px; /* Ensure space after table */
  -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

.data-table table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 16px;
  min-width: 600px; /* Prevent table from being too narrow */
}

.data-table th,
.data-table td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid #e5e7eb;
}

.data-table th {
  background: #e5e7eb;
  font-weight: 600;
  color: #374151;
  border-bottom: 2px solid #d1d5db;
}

/* Phase 2: Filters and Pagination Styles */
.filters-section {
  margin-bottom: 20px;
  padding: 16px;
  background: #f9fafb;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
}

.filters-section h3 {
  margin: 0 0 12px 0;
  font-size: 16px;
}

.filters-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.filter-item {
  display: flex;
  flex-direction: column;
}

.filter-item label {
  font-size: 12px;
  font-weight: 500;
  margin-bottom: 4px;
  color: #374151;
}

.filter-item input,
.filter-item select {
  padding: 6px 8px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  font-size: 14px;
}

.date-range-filter {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.date-range-filter input[type="date"] {
  flex: 1;
  min-width: 120px;
}

.date-separator {
  font-size: 12px;
  color: #6b7280;
  white-space: nowrap;
}

@media (max-width: 480px) {
  .date-range-filter {
    flex-direction: column;
    align-items: stretch;
  }
  
  .date-separator {
    text-align: center;
    margin: 4px 0;
  }
}

.btn-secondary {
  background: #6b7280;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}

.btn-secondary:hover {
  background: #4b5563;
}

.pagination-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
  margin-bottom: 30px; /* Reduced bottom margin */
  padding: 12px;
  background: #f9fafb;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
}

.pagination-info {
  font-size: 14px;
  color: #374151;
  white-space: nowrap;
}

.pagination-buttons {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.btn-pagination {
  background: white;
  border: 1px solid #d1d5db;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
}

.btn-pagination:hover:not(:disabled) {
  background: #f3f4f6;
}

.btn-pagination:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.rows-per-page {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  white-space: nowrap;
}

.rows-per-page select {
  padding: 4px 8px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
}

/* Mobile pagination adjustments */
@media (max-width: 768px) {
  .pagination-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  
  .pagination-info {
    text-align: center;
    order: 1;
  }
  
  .pagination-buttons {
    justify-content: center;
    order: 2;
  }
  
  .rows-per-page {
    justify-content: center;
    order: 3;
  }
  
  .btn-pagination {
    flex: 1;
    min-width: 60px;
    text-align: center;
  }
}
