/* TODO: REVIEW AFTER TESTING - iPad zoom prevention */
/* May want to make this iPad-specific via media query or JS detection */
* {
  -webkit-tap-highlight-color: transparent;
}

button, .pad-btn, input[type="text"], input[type="number"], input[type="datetime-local"], select {
  touch-action: manipulation; /* Disables double-tap zoom on touch devices */
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: #f5f7fa;
  margin: 0;
  padding: 0;
  font-size: 16px;
}

#app {
  min-height: 100vh;
  background: #f5f7fa;
}

/* ========================================
   MODERN HEADER STYLES
   ======================================== */

.app-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 2rem 2rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  position: relative;
}

.header-brand h1 {
  margin: 0;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.header-subtitle {
  margin: 0.25rem 0 0 0;
  font-size: 0.95rem;
  opacity: 0.95;
  font-weight: 300;
}

/* Hamburger Menu */
.menu-btn {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  cursor: pointer;
  padding: 0.75rem;
  border-radius: 8px;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: auto;
  margin: 0;
}

.menu-btn .hamburger {
  width: 24px;
  height: 2px;
  background: white;
  border-radius: 2px;
  transition: all 0.3s ease;
}

.menu-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: none;
}

.menu-dropdown {
  display: none;
  position: absolute;
  top: 80px;
  right: 2rem;
  background: white;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  min-width: 220px;
  z-index: 1001;
  padding: 0.5rem;
  overflow: hidden;
}

.menu-dropdown.show {
  display: block;
  animation: slideDown 0.2s ease;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.menu-dropdown .menu-item {
  display: block;
  width: 100%;
  text-align: left;
  margin: 0.25rem 0;
  padding: 0.875rem 1rem;
  font-size: 1rem;
  border: none;
  background: white;
  color: #374151;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
}

.menu-dropdown .menu-item:hover {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  transform: translateX(4px);
}

.menu-section {
  margin: 0.5rem 0;
}

.menu-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #9ca3af;
  padding: 0.5rem 1rem 0.25rem;
}

.menu-divider {
  height: 1px;
  background: #e5e7eb;
  margin: 0.5rem 0;
}

.menu-item-danger {
  color: #dc2626 !important;
}

.menu-item-danger:hover {
  background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%) !important;
  color: white !important;
}

.recent-matches-list {
  max-height: 200px;
  overflow-y: auto;
}

.recent-match-item {
  display: block;
  width: 100%;
  text-align: left;
  margin: 0.25rem 0;
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  border: none;
  background: #f9fafb;
  color: #374151;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.recent-match-item:hover {
  background: #667eea;
  color: white;
}

.recent-match-name {
  font-weight: 600;
  display: block;
  margin-bottom: 0.25rem;
}

.recent-match-details {
  font-size: 0.75rem;
  opacity: 0.8;
}

.no-recent-matches {
  padding: 1rem;
  text-align: center;
  font-size: 0.875rem;
  color: #9ca3af;
  font-style: italic;
}

/* Auto-save indicator */
.auto-save-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(255, 255, 255, 0.2);
  padding: 0.5rem 1rem;
  border-radius: 20px;
  font-size: 0.875rem;
  color: white;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.auto-save-indicator.show {
  opacity: 1;
}

.auto-save-indicator .save-icon {
  font-size: 1rem;
}

.auto-save-indicator .save-text {
  font-weight: 500;
}

/* ========================================
   CONFIGURATION CARD
   ======================================== */

.config-card {
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  padding: 2rem;
  margin: 2rem auto;
  max-width: 1400px;
}

.config-primary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.config-secondary {
  display: flex;
  align-items: flex-end;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.config-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 100px;
}

.config-group-large {
  flex: 1;
  min-width: 250px;
}

.config-group-medium {
  flex: 1;
  min-width: 200px;
}

.config-group label {
  font-size: 0.875rem;
  font-weight: 600;
  color: #374151;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.config-group input,
.config-group select {
  padding: 0.75rem 1rem;
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  font-size: 1rem;
  transition: all 0.2s ease;
  background: white;
  font-family: inherit;
}

.config-group input:focus,
.config-group select:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.config-divider {
  width: 1px;
  height: 40px;
  background: #e5e7eb;
  margin: 0 0.5rem;
}

.btn-next-series {
  flex: 1;
  padding: 1rem 1.5rem;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  font-family: inherit;
}

.btn-next-series:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(102, 126, 234, 0.4);
}

.btn-next-series:disabled {
  background: linear-gradient(135deg, #9ca3af 0%, #6b7280 100%);
  cursor: not-allowed;
  transform: none;
  opacity: 0.6;
}

/* ========================================
   MATCH INFO BANNER
   ======================================== */

.match-info-banner {
  display: flex;
  align-items: center;
  gap: 2rem;
  padding: 1rem 1.5rem;
  background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
  border-radius: 8px;
  margin-bottom: 1.5rem;
}

.info-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.info-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.info-value {
  font-size: 0.95rem;
  color: #1f2937;
  font-weight: 500;
}

.info-divider {
  width: 1px;
  height: 30px;
  background: #d1d5db;
  flex-shrink: 0;
}

/* ========================================
   ACTION BUTTONS ROW
   ======================================== */

.action-buttons {
  display: flex;
  gap: 1rem;
  margin-top: 0.5rem;
}

.btn-view-scores {
  flex: 1;
  padding: 1rem;
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.btn-view-scores:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(16, 185, 129, 0.4);
}

/* ========================================
   TABLE CONTAINER
   ======================================== */

.table-container {
  max-width: 1400px;
  margin: 0 auto 2rem;
  padding: 0 2rem;
}
table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 16px;
  font-size: 14px;
}
th, td {
  border: 1px solid #ccc;
  padding: 12px 8px; /* More padding for touch */
  text-align: center;
}
th {
  background: #f8f9fa;
  font-weight: bold;
  font-size: 15px;
}
.shot-input {
  width: 100%;
  max-width: 200px; /* Increased to prevent "Click to enter shots" cutoff */
  font-family: monospace;
  font-size: 14px;
  padding: 8px;
  border: 2px solid #ddd;
  border-radius: 4px;
  transition: border-color 0.3s ease;
  box-sizing: border-box;
}
.shot-input.complete {
  border-color: #28a745;
  box-shadow: 0 0 0 1px rgba(40, 167, 69, 0.3);
}
.total-display, .count-display {
  font-weight: bold;
  background: #f0f8ff;
  font-size: 16px;
}
.match-total {
  background: #e8f5e8;
  font-weight: bold;
  font-size: 16px;
}
/* Style the datetime picker calendar icon */
input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  cursor: pointer;
  filter: opacity(0.6);
  transition: filter 0.2s;
}
input[type="datetime-local"]::-webkit-calendar-picker-indicator:hover {
  filter: opacity(1);
}
.bay-status {
  padding: 8px;
  border: 2px solid #ddd;
  border-radius: 4px;
  font-size: 14px;
  width: 100%;
  max-width: 100px;
  background: white;
  cursor: pointer;
  font-weight: 500;
}
.bay-status:hover {
  border-color: #0078d4;
}
.bay-status:disabled {
  background: #f0f0f0;
  cursor: not-allowed;
  opacity: 0.6;
}

/* Malfunction Checkbox Styles */
.mal-checkbox {
  width: 20px;
  height: 20px;
  cursor: pointer;
  accent-color: #ff6b35;
}
.mal-checkbox:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}
.malfunction-marked {
  transform: scale(1.1);
}
.makeup-disabled {
  opacity: 0.4;
  pointer-events: none;
}
.malfunction-waiting {
  border-color: #ff6b35;
  background-color: #fff5f0;
  font-style: italic;
  color: #ff6b35;
}

/* Makeup Series Dropdown Styling */
select option[value^="makeup-"] {
  color: #ff6b35;
}

/* General button styles for table inputs */
button {
  border: none;
  cursor: pointer;
  font-size: 16px;
  font-weight: 500;
  min-height: 44px;
  user-select: none;
  -webkit-touch-callout: none;
  font-family: inherit;
}

button:focus {
  outline: 2px solid #ff6b35;
  outline-offset: 2px;
}

/* Table input styles */
input[type="text"] {
  padding: 8px 12px;
  border: 2px solid #e5e7eb;
  border-radius: 6px;
  font-size: 16px;
  font-family: inherit;
  box-sizing: border-box;
}

input[type="text"]:focus {
  border-color: #667eea;
  outline: none;
  box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.1);
}

/* Name input - constrained width with ellipsis */
.name-input {
  width: 100%;
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#result {
  margin-top: 24px;
  padding: 16px;
  background: #e7f4e4;
  border-radius: 6px;
  display: none;
  font-size: 15px;
}

/* Responsive design for tablets */
@media (max-width: 1024px) {
  #app {
    margin: 10px;
    padding: 16px;
  }
  
  table {
    font-size: 13px;
  }
  
  th, td {
    padding: 10px 6px;
  }
}

/* Portrait tablet optimization */
@media (max-width: 768px) {
  h1 {
    font-size: 24px;
  }
  
  button {
    padding: 10px 16px;
    font-size: 15px;
    margin: 6px 4px;
  }
  
  input[type="number"], input[type="text"], select {
    padding: 10px;
    font-size: 15px;
  }
}

/* Landscape orientation optimizations */
@media (orientation: landscape) and (max-width: 1024px) {
  #app {
    max-width: 95%;
    margin: 10px auto;
  }
}

/* Floating Scoring Pad */
#scoringPad {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #fff;
  border-top: 3px solid #0078d4;
  box-shadow: 0 -4px 12px rgba(0,0,0,0.2);
  padding: 12px 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#padHeader {
  text-align: center;
  font-weight: bold;
  font-size: 18px;
  color: #0078d4;
  padding: 6px;
  background: #f0f8ff;
  border-radius: 6px;
}

#padButtons {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  max-width: 800px;
  margin: 0 auto;
}

.pad-btn {
  padding: 16px 12px;
  font-size: 18px;
  font-weight: bold;
  min-height: 56px;
  border: 2px solid #0078d4;
  background: #0078d4;
  color: #fff;
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
  -webkit-touch-callout: none;
  transition: all 0.2s ease;
}

.pad-btn:hover, .pad-btn:active {
  background: #005fa3;
  border-color: #005fa3;
  transform: scale(0.95);
}

.pad-btn:focus {
  outline: 2px solid #ff6b35;
  outline-offset: 2px;
}

#padControls {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.control-btn {
  background: #6c757d;
  border-color: #6c757d;
  flex: 1;
  max-width: 200px;
}

.control-btn:hover, .control-btn:active {
  background: #5a6268;
  border-color: #5a6268;
}

#padClear {
  background: #dc3545;
  border-color: #dc3545;
}

#padClear:hover, #padClear:active {
  background: #c82333;
  border-color: #c82333;
}

#padBackspace {
  background: #ffc107;
  border-color: #ffc107;
  color: #000;
}

#padBackspace:hover, #padBackspace:active {
  background: #e0a800;
  border-color: #e0a800;
}

#padNextBay {
  background: #28a745;
  border-color: #28a745;
}

#padNextBay:hover, #padNextBay:active {
  background: #218838;
  border-color: #218838;
}

/* Active field highlighting */
.shot-input.active-field {
  border-color: #ff6b35;
  border-width: 3px;
  box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.3);
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% {
    box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.3);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(255, 107, 53, 0.2);
  }
}

/* Add padding to body to prevent content being hidden behind pad */
body {
  padding-bottom: 280px;
}

/* ========================================
   RESPONSIVE DESIGN
   ======================================== */

/* iPad Air and similar devices (820px width in portrait) */
@media (max-width: 820px) {
  .app-header {
    padding: 1.5rem 1rem;
  }
  
  .header-brand h1 {
    font-size: 1.5rem;
  }
  
  .header-subtitle {
    font-size: 0.85rem;
  }
  
  .config-card {
    padding: 1.5rem;
    margin: 1rem;
  }
  
  .config-primary {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
  
  .config-secondary {
    flex-direction: column;
    align-items: stretch;
  }
  
  .config-divider {
    display: none;
  }
  
  .match-info-banner {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }
  
  .info-divider {
    display: none;
  }
  
  .action-buttons {
    flex-direction: column;
    gap: 0.75rem;
  }
  
  .table-container {
    padding: 0 1rem;
  }
  
  /* Apply fixed table layout for iPad to prevent overflow */
  table {
    table-layout: fixed;
  }
  
  th, td {
    overflow: hidden;
  }
  
  /* Table column adjustments for iPad */
  #scoreTable th:nth-child(1), 
  #scoreTable td:nth-child(1) {
    width: 50px; /* Bay - fixed */
  }

  #scoreTable th:nth-child(2), 
  #scoreTable td:nth-child(2) {
    width: 100px; /* Name - fixed and shorter */
  }

  #scoreTable th:nth-child(3), 
  #scoreTable td:nth-child(3) {
    width: 210px; /* Shot Entry - reduced to give space to Status */
  }

  #scoreTable th:nth-child(4), 
  #scoreTable td:nth-child(4) {
    width: auto; /* Series Total - flexible */
  }

  #scoreTable th:nth-child(5), 
  #scoreTable td:nth-child(5) {
    width: auto; /* Match Total - flexible */
  }

  #scoreTable th:nth-child(6), 
  #scoreTable td:nth-child(6) {
    width: 45px; /* M checkbox - fixed */
  }

  #scoreTable th:nth-child(7), 
  #scoreTable td:nth-child(7) {
    width: 90px; /* Status - fixed, wide enough for "Active" */
  }

  .name-input {
    max-width: 90px;
    font-size: 0.85rem;
  }

  .shot-input {
    max-width: 200px; /* Reduced to fit in 210px column */
    padding: 0.6rem;
    font-size: 0.95rem;
  }
}

/* Smaller tablets and phones */
@media (max-width: 768px) {
  .app-header {
    padding: 1.5rem 1rem;
  }
  
  .header-brand h1 {
    font-size: 1.5rem;
  }
  
  .header-subtitle {
    font-size: 0.85rem;
  }
  
  .config-card {
    padding: 1.5rem;
    margin: 1rem;
  }
  
  .config-primary {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
  
  .config-secondary {
    flex-direction: column;
    align-items: stretch;
  }
  
  .config-group {
    width: 100%;
  }
  
  .config-divider {
    display: none;
  }
  
  .match-info-banner {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }
  
  .info-divider {
    display: none;
  }
  
  .btn-next-series {
    width: 100%;
  }
  
  .table-container {
    padding: 0 1rem;
  }
  
  /* Further reduce name column on smaller tablets */
  #scoreTable th:nth-child(2), 
  #scoreTable td:nth-child(2) {
    width: 90px; /* Name - even shorter */
  }

  .name-input {
    max-width: 80px;
    font-size: 0.8rem;
    padding: 0.4rem;
  }

/* Tablet optimizations for scoring pad */
  #padButtons {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
  }
  
  .pad-btn {
    padding: 14px 10px;
    font-size: 16px;
    min-height: 52px;
  }
  
  body {
    padding-bottom: 300px;
  }
}

@media (max-width: 480px) {
  #padButtons {
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
  }
  
  .pad-btn {
    padding: 12px 8px;
    font-size: 15px;
    min-height: 48px;
  }
  
  body {
    padding-bottom: 320px;
  }
}
