/* ========================================
   UNIVERSAL RESPONSIVE STYLES FOR DONATION SYSTEM
   Fixed: Table scrolling ONLY (card doesn't scroll)
   ======================================== */

/* Base improvements for all screens */
* {
  box-sizing: border-box;
}

body {
  overflow-x: hidden;
}

/* Card - NO overflow */
.card {
  background: white;
  padding: 25px;
  border-radius: 12px;
  margin-bottom: 25px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  overflow: visible; /* Changed from overflow-x: auto */
}

/* Table wrapper with scroll - THIS is what scrolls */
.table-wrapper {
  width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  margin-top: 15px;
  position: relative;
  border: 1px solid #e9ecef;
  border-radius: 8px;
}

/* If table is direct child of card - add scrolling container */
.card > table {
  display: block;
  width: 100%;
  overflow-x: auto; /* Table itself scrolls */
  -webkit-overflow-scrolling: touch;
  margin-top: 15px;
  border: 1px solid #e9ecef;
  border-radius: 8px;
}

/* Table styling - prevent text overlap */
table {
  width: 100%;
  min-width: max-content;
  border-collapse: collapse;
  background: white;
}

thead {
  position: sticky;
  top: 0;
  background: #f8f9fa;
  z-index: 10;
}

th, td {
  padding: 14px 16px;
  text-align: left;
  font-size: 14px;
  white-space: nowrap;
  border-bottom: 1px solid #e9ecef;
}

th {
  background: #f8f9fa;
  font-weight: 600;
  color: #555;
  border-bottom: 2px solid #e9ecef;
}

tbody tr {
  border-bottom: 1px solid #f1f1f1;
}

tbody tr:hover {
  background: #f8f9fa;
}

/* Specific column minimum widths */
th:nth-child(1), td:nth-child(1) { min-width: 100px; }
th:nth-child(2), td:nth-child(2) { min-width: 140px; }
th:nth-child(3), td:nth-child(3) { min-width: 90px; }
th:nth-child(4), td:nth-child(4) { min-width: 120px; }
th:nth-child(5), td:nth-child(5) { min-width: 140px; }
th:nth-child(6), td:nth-child(6) { min-width: 120px; }
th:nth-child(7), td:nth-child(7) { min-width: 120px; }
th:nth-child(8), td:nth-child(8) { min-width: 100px; }
th:nth-child(9), td:nth-child(9) { min-width: 140px; }
th:nth-child(10), td:nth-child(10) { min-width: 150px; }

/* Action buttons */
.action-btn {
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  margin-right: 5px;
  white-space: nowrap;
  display: inline-block;
}

/* Scroll indicator for tables */
.scroll-indicator {
  position: absolute;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  background: rgba(47, 122, 62, 0.9);
  color: white;
  padding: 10px;
  border-radius: 4px 0 0 4px;
  font-size: 12px;
  pointer-events: none;
  z-index: 5;
  transition: opacity 0.3s;
}

.scroll-indicator.hidden {
  opacity: 0;
}

/* iPad and Tablet (768px - 1024px) */
@media screen and (min-width: 768px) and (max-width: 1024px) {
  .card {
    padding: 20px;
    overflow: visible; /* Card doesn't scroll */
  }
  
  .widgets-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
  }
  
  .form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
  }
  
  .form-row .form-group {
    flex: 1;
    min-width: calc(50% - 10px);
  }
  
  .filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 15px;
  }
  
  .filter-bar input,
  .filter-bar select {
    flex: 1;
    min-width: 160px;
  }
  
  .filter-bar .search-box {
    flex: 2;
    min-width: 220px;
  }
  
  .filter-bar .actions {
    display: flex;
    gap: 8px;
  }
  
  .stats-row {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
  }
  
  .stat-item {
    flex: 1;
    min-width: calc(50% - 10px);
  }
  
  th, td {
    font-size: 13px;
    padding: 12px 14px;
  }
  
  .action-btn {
    padding: 7px 14px;
    font-size: 12px;
  }
}

/* Mobile and Small Tablets (max 767px) */
@media screen and (max-width: 767px) {
  
  /* Page header */
  .page-header {
    margin-bottom: 20px;
  }
  
  .page-header h1 {
    font-size: 22px;
    margin-bottom: 5px;
  }
  
  .page-header p {
    font-size: 13px;
    color: #666;
  }
  
  /* Card adjustments - NO OVERFLOW */
  .card {
    padding: 15px;
    margin-bottom: 20px;
    border-radius: 10px;
    overflow: visible; /* Card doesn't scroll */
  }
  
  .card-header {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 15px;
  }
  
  .card-title {
    font-size: 16px;
    font-weight: 600;
  }
  
  /* Table scroll container - THIS scrolls */
  .card > table {
    display: block;
    width: 100%;
    overflow-x: auto; /* Only table scrolls */
    -webkit-overflow-scrolling: touch;
    margin-top: 15px;
    border: 1px solid #e9ecef;
    border-radius: 6px;
  }
  
  /* Scroll hint */
  .card > table::before {
    content: '← Swipe to see all columns →';
    display: block;
    text-align: center;
    padding: 8px;
    background: #fff3cd;
    color: #856404;
    font-size: 12px;
    border-bottom: 1px solid #ffc107;
    position: sticky;
    left: 0;
    width: 100%;
  }
  
  /* Table styling for mobile */
  table {
    width: auto;
    min-width: 100%;
  }
  
  th, td {
    font-size: 12px;
    padding: 10px 12px;
    white-space: nowrap; 
  }
  
  /* Widgets - single column */
  .widgets-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
  }
  
  .widget {
    padding: 18px;
  }
  
  .widget-value {
    font-size: 24px;
  }
  
  .widget-icon {
    width: 40px;
    height: 40px;
    font-size: 20px;
  }
  
  /* Forms */
  .form-row {
    display: flex;
    flex-direction: column;
    gap: 0;
  }
  
  .form-row .form-group {
    width: 100%;
    margin-bottom: 15px;
  }
  
  .form-group {
    margin-bottom: 15px;
  }
  
  .form-group label {
    font-size: 13px;
    margin-bottom: 6px;
    display: block;
    font-weight: 500;
  }
  
  input, select, textarea {
    width: 100%;
    padding: 11px 12px;
    font-size: 14px;
    border: 1px solid #ddd;
    border-radius: 6px;
  }
  
  button {
    width: 100%;
    padding: 12px;
    font-size: 14px;
    border-radius: 6px;
  }
  
  /* Filter bar - vertical stack */
  .filter-bar {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 15px;
  }
  
  .filter-bar input,
  .filter-bar select {
    width: 100%;
    min-width: 100%;
  }
  
  .filter-bar .search-box {
    width: 100%;
  }
  
  .filter-bar .actions {
    display: flex;
    gap: 8px;
    width: 100%;
    margin-left: 0;
  }
  
  .filter-bar .actions button {
    flex: 1;
  }
  
  /* Export controls */
  .export-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
    margin-bottom: 15px;
    background-color: #f8f9fa;
    border-radius: 8px;
  }
  
  .export-controls label {
    font-size: 13px;
    font-weight: 500;
  }
  
  .export-controls input {
    width: 100%;
  }
  
  .export-controls .actions {
    display: flex;
    gap: 8px;
    width: 100%;
    margin-left: 0;
  }
  
  .export-controls .actions button {
    flex: 1;
  }
  
  /* Stats row - vertical */
  .stats-row {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }
  
  .stat-item {
    width: 100%;
    padding: 14px 16px;
  }
  
  .stat-value {
    font-size: 22px;
  }
  
  .stat-label {
    font-size: 12px;
  }
  
  /* Action buttons in table */
  .action-btn {
    padding: 6px 12px;
    font-size: 11px;
    margin: 2px;
    white-space: nowrap;
  }
  
  .btn-export {
    background: #007bff;
    color: white;
  }
  
  /* Pagination */
  .pagination {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: stretch;
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #e9ecef;
  }
  
  .pagination-info {
    text-align: center;
    font-size: 12px;
    color: #666;
  }
  
  .pagination-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
  }
  
  .page-btn {
    padding: 8px 12px;
    font-size: 12px;
    border: 1px solid #ddd;
    background: white;
    border-radius: 4px;
  }
  
  .page-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }
  
  .page-input {
    width: 55px;
    padding: 6px;
    text-align: center;
    border: 1px solid #ddd;
    border-radius: 4px;
  }
  
  /* Modal */
  .modal-content {
    width: 95%;
    max-width: 95%;
    margin: 20px auto;
    padding: 15px;
    border-radius: 10px;
  }
  
  .modal-header {
    padding: 12px;
  }
  
  .modal-title {
    font-size: 16px;
  }
  
  .modal-body {
    padding: 15px 12px;
  }
  
  .modal-footer {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  
  .modal-footer button {
    width: 100%;
    margin: 0;
  }
  
  /* Login page */
  .login-container {
    margin: 40px 15px;
    padding: 20px;
    max-width: 100%;
  }
  
  .login-container h2 {
    font-size: 20px;
    margin-bottom: 20px;
  }
}

/* Very small phones (max 480px) */
@media screen and (max-width: 480px) {
  .page-header h1 {
    font-size: 20px;
  }
  
  .card {
    padding: 12px;
    overflow: visible; /* Card doesn't scroll */
  }
  
  .card > table::before {
    font-size: 11px;
    padding: 6px;
  }
  
  th, td {
    font-size: 11px;
    padding: 8px 10px;
  }
  
  .widget-value {
    font-size: 20px;
  }
  
  .stat-value {
    font-size: 18px;
  }
  
  .action-btn {
    padding: 5px 10px;
    font-size: 10px;
  }
  
  .page-btn {
    padding: 6px 10px;
    font-size: 11px;
  }
  
  .page-input {
    width: 50px;
  }
}

/* Landscape mode */
@media screen and (max-height: 500px) and (orientation: landscape) {
  .card {
    padding: 15px;
    overflow: visible; /* Card doesn't scroll */
  }
}

/* Print styles */
@media print {
  .no-print,
  .filter-bar,
  .export-controls,
  .pagination,
  .action-btn,
  .card > table::before {
    display: none !important;
  }
  
  .card {
    box-shadow: none !important;
    padding: 0 !important;
    page-break-inside: avoid;
  }
  
  table {
    display: table !important;
    width: 100% !important;
    overflow: visible !important;
    page-break-inside: auto;
  }
  
  tr {
    page-break-inside: avoid;
    page-break-after: auto;
  }
  
  thead {
    display: table-header-group;
  }
  
  th, td {
    font-size: 10px !important;
    padding: 4px !important;
  }
}