/* styles.css */

:root {
  --color-primary: #00796b;
  --color-primary-dark: #004d40;
  --color-primary-light: #e0f2f1;
  --color-accent: #f59e0b;
  --color-success: #10b981;
  --color-danger: #ef4444;
  --color-text: #1a1a2e;
  --color-text-muted: #64748b;
  --color-bg: #f8fafc;
  --color-card: #ffffff;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
}

* {
  box-sizing: border-box;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: -webkit-fill-available;
  background: linear-gradient(135deg, #f5f7fa 0%, #e4e8ec 100%);
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  color: #1a1a2e;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

html {
  height: -webkit-fill-available;
}

/* Top Navigation */
.top-nav {
  display: flex;
  background: #f1f5f9;
  padding: 6px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
  gap: 4px;
}

.nav-button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px 8px;
  background: transparent;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all 0.2s ease;
  gap: 4px;
  border-radius: var(--radius-md);
}

.nav-button.active {
  background-color: var(--color-primary);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.nav-button:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.nav-button:hover:not(.active) {
  background: rgba(0, 121, 107, 0.1);
  color: var(--color-text);
}

.nav-button:active {
  transform: scale(0.98);
}

.nav-icon {
  font-size: 1.75em;
}

.nav-label {
  font-size: 1.1em;
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* Page Structure */
.page {
  display: none;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.page.active {
  display: flex;
  flex-direction: column;
}

.page-content {
  background-color: var(--color-card);
  padding: 20px;
  margin: 12px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  text-align: center;
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.04);
}

.page-subtitle {
  color: #666;
  font-size: 0.95em;
  margin-top: -5px;
  margin-bottom: 15px;
}
  
  @keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
  }

  @keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
  }

  @keyframes popIn {
    0% { transform: scale(0.8); opacity: 0; }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
  }

  .stat-card.pulse {
    animation: pulse 0.4s ease;
  }

  .punch-dot.just-filled {
    animation: popIn 0.3s ease forwards;
  }

  /* Toast notification */
  .toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--color-primary-dark);
    color: #fff;
    padding: 12px 24px;
    border-radius: var(--radius-lg);
    font-size: 0.9em;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    opacity: 0;
    transition: all 0.3s ease;
  }

  .toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
  }
  
  .page-content h1 {
    color: #00796b;
    margin-bottom: 16px;
    margin-top: 0;
    font-weight: 700;
    font-size: 1.75em;
    letter-spacing: -0.02em;
  }
  
  .page-content p {
    font-size: 1.2em;
    margin: 5px 0;
    color: #004d40;
  }

  /* Stats Grid */
  .stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 20px;
    align-items: stretch;
  }

  .stats-grid-2 {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Inline stats badges */
  .stats-inline {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-bottom: 16px;
  }

  .stat-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.85em;
    border: none;
    box-shadow: none;
  }

  .stat-badge .stat-value {
    font-weight: 600;
  }

  .stat-badge .stat-label {
    color: inherit;
  }

  .stat-badge.stat-unredeemed {
    background: #fefce8;
    color: #a16207;
  }

  .stat-badge.stat-redeemed {
    background: #ecfdf5;
    color: #047857;
  }

  .stat-card {
    background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
    border-radius: 12px;
    padding: 16px 12px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    border: 1px solid rgba(0, 0, 0, 0.04);
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  .stat-card .stat-value {
    font-size: 2em;
    font-weight: 700;
    line-height: 1;
    letter-spacing: -0.02em;
  }

  .stat-card .stat-label {
    font-size: 0.8em;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #666;
    font-weight: 600;
  }

  .stat-punches .stat-value {
    color: #00796b;
  }

  .stat-unredeemed .stat-value {
    color: var(--color-accent);
  }

  .stat-redeemed .stat-value {
    color: #10b981;
  }

  /* Punch dots visualization */
  .punch-dots {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: nowrap;
  }

  .punch-dot {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background-color: var(--color-primary);
    opacity: 0.2;
    transition: all 0.3s ease;
  }

  .punch-dot.filled {
    opacity: 1;
    transform: scale(1.15);
    box-shadow: 0 2px 4px rgba(0, 121, 107, 0.3);
  }
  
  .page-content button:not(.tab-button):not(.workout-tab):not(.bar-edit-btn) {
    padding: 10px 20px;
    font-size: 1em;
    color: #fff;
    background-color: #00796b;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.3s ease;
  }
  
  .page-content button:not(.tab-button):not(.workout-tab):not(.bar-edit-btn):hover {
    background-color: #004d40;
  }
  
  .input-container {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
  }
  
  .input-container input, .input-container select {
    flex: 1;
    padding: 12px 14px;
    font-size: 0.95em;
    font-family: inherit;
    border: 2px solid #e2e8f0;
    border-radius: var(--radius-sm);
    background-color: #fff;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
  }
  
  .input-container input:focus, .input-container select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(0, 121, 107, 0.1);
  }
  
  .input-container button {
    flex: 0 0 155px;
    width: 155px;
    padding: 12px 16px;
    font-size: 0.95em;
    font-weight: 600;
    border-radius: var(--radius-sm);
    white-space: nowrap;
    overflow: visible;
  }

  /* Redeem button - distinct amber/gold style */
  .input-container button[onclick="redeemReward()"] {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    box-shadow: 0 2px 4px rgba(217, 119, 6, 0.2);
  }

  .input-container button[onclick="redeemReward()"]:hover {
    background: linear-gradient(135deg, #d97706 0%, #b45309 100%);
  }

  .input-container button[onclick="redeemReward()"]:disabled {
    background: #e5e7eb;
    box-shadow: none;
  }
  
  .activity-buttons {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
  }
  
  .activity-buttons button {
    flex: 1;
    padding: 14px 8px;
    font-size: 0.65em;
    font-weight: 600;
    color: #fff;
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 4px;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm), 0 2px 4px rgba(0, 121, 107, 0.2);
    position: relative;
    overflow: hidden;
    min-width: 0;
  }
  
  .activity-buttons button::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.1) 0%, transparent 100%);
    opacity: 0;
    transition: opacity 0.2s ease;
  }
  
  .activity-buttons button:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md), 0 4px 8px rgba(0, 121, 107, 0.25);
  }
  
  .activity-buttons button:hover::before {
    opacity: 1;
  }
  
  .activity-buttons button:active {
    transform: translateY(0) scale(0.98);
    box-shadow: var(--shadow-sm);
  }

  .activity-buttons button:focus-visible {
    outline: 2px solid var(--color-primary-dark);
    outline-offset: 2px;
  }
  
  .activity-buttons button span {
    font-size: 1em;
  }
  
  #activityDropdown, #rewardDropdown {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-color: #fff;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 10px;
    font-size: 1em;
    background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20viewBox%3D%220%200%204%205%22%3E%3Cpath%20fill%3D%22%23000%22%20d%3D%22M2%200L0%202h4L2%200zM2%205L0%203h4L2%205z%22/%3E%3C/svg%3E');
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 10px;
  }
  
  .tab-container {
    display: flex;
    justify-content: center;
    margin-top: 16px;
    margin-bottom: 8px;
    background: #f1f5f9;
    border-radius: var(--radius-lg);
    padding: 4px;
    gap: 4px;
  }
  
  .tab-container .tab-button {
    flex: 1;
    padding: 10px 20px;
    font-size: 0.9em;
    font-weight: 600;
    border: none;
    background: transparent;
    color: var(--color-text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
    border-radius: var(--radius-md);
  }
  
  .tab-container .tab-button:hover:not(.active) {
    color: var(--color-text);
    background: rgba(0, 121, 107, 0.1);
  }
  
  .tab-container .tab-button.active {
    background: var(--color-primary);
    color: #fff;
    box-shadow: var(--shadow-sm);
  }

  .tab-container .tab-button:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
  }
  
  .tab-content {
    display: none;
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 8px 4px;
  }
  
  .tab-content.active {
    display: block;
    animation: fadeIn 0.2s ease;
  }
  
  #historyList {
    list-style-type: none;
    padding: 0;
    text-align: left;
  }

  #historyList:empty::before {
    content: 'No activity yet. Add a punch to get started!';
    display: block;
    text-align: center;
    color: var(--color-text-muted);
    padding: 24px 16px;
    font-size: 0.95em;
  }
  
  #historyList li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    border-left: 3px solid transparent;
    border-bottom: 1px solid #f1f5f9;
  }
  
  #historyList li:has(.punch) {
    border-left-color: var(--color-primary);
  }
  
  #historyList li:has(.reward) {
    border-left-color: var(--color-accent);
  }
  
  .history-item {
    display: flex;
    align-items: center;
    gap: 6px;
  }
  
  .history-details {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9em;
  }

  .history-date {
    min-width: 75px;
    display: inline-block;
  }
  
  .history-buttons {
    display: flex;
    gap: 6px;
  }
  
  .history-item.reward .history-details {
    color: #b45309;
  }
  
  .history-item.punch .history-details {
    color: var(--color-primary-dark);
  }
  
  .edit-link, .delete-link {
    font-size: 0.8em;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
  }
  
  .edit-link {
    color: var(--color-primary);
    background: var(--color-primary-light);
  }
  
  .edit-link:hover {
    background: var(--color-primary);
    color: #fff;
  }
  
  .delete-link {
    color: var(--color-danger);
    background: #fef2f2;
  }
  
  .delete-link:hover {
    background: var(--color-danger);
    color: #fff;
  }
  
  .history-header {
    display: none;
  }
  
  .icon {
    font-size: 1.1em;
    line-height: 1;
  }

  /* Chart container for responsive sizing */
  .chart-container {
    position: relative;
    width: 100%;
    min-height: 250px;
    max-height: 350px;
  }

  .chart-container canvas {
    width: 100% !important;
    height: 100% !important;
  }
  
  /* Calculate Weights Tab Styles */

  /* Bar weight badge */
  .bar-weight-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #f1f5f9;
    padding: 8px 12px;
    border-radius: var(--radius-lg);
    margin-bottom: 16px;
    font-size: 0.9em;
  }

  .bar-weight-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 16px;
  }

  .bar-weight-row .bar-weight-badge {
    margin-bottom: 0;
  }

  .bar-weight-row .bar-weight-options {
    margin-bottom: 0;
  }

  .bar-weight-badge .bar-label {
    color: var(--color-text-muted);
    font-weight: 500;
  }

  .bar-weight-badge .bar-value {
    font-weight: 700;
    color: var(--color-primary);
    font-size: 1.1em;
  }

  .bar-weight-badge .bar-unit {
    color: var(--color-text-muted);
  }

  .bar-weight-badge .bar-edit-btn {
    background: transparent;
    border: none;
    color: var(--color-primary);
    font-size: 0.85em;
    font-weight: 500;
    cursor: pointer;
    padding: 2px 8px;
    margin-left: 4px;
    border-radius: 4px;
    transition: background 0.15s;
  }

  .bar-weight-badge .bar-edit-btn:hover {
    background: rgba(0, 121, 107, 0.1);
  }

  .bar-weight-options {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: center;
  }

  .bar-weight-options select,
  .bar-weight-options input {
    padding: 8px 12px;
    font-size: 0.9em;
    border: 2px solid #e2e8f0;
    border-radius: var(--radius-sm);
    font-family: inherit;
  }

  .bar-weight-options select {
    appearance: none;
    -webkit-appearance: none;
    background-color: #fff;
    background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20viewBox%3D%220%200%204%205%22%3E%3Cpath%20fill%3D%22%23000%22%20d%3D%22M2%200L0%202h4L2%200zM2%205L0%203h4L2%205z%22/%3E%3C/svg%3E');
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 8px;
    padding-right: 28px;
  }

  /* Grid layout for exercises */
  .weights-layout {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-width: 500px;
    margin: 0 auto;
    width: 100%;
  }

  /* Exercise group - card style */
  .exercise-group {
    display: contents;
  }

  .exercise-group-header {
    display: contents;
  }

  .weights-layout label {
    font-size: 0.95em;
    color: var(--color-primary);
    font-weight: 600;
    text-align: left;
  }

  /* Desktop: inline row layout */
  @media (min-width: 481px) {
    .exercise-group {
      display: flex;
      align-items: center;
      gap: 12px;
      padding: 12px 16px;
      background: #f8fafc;
      border-radius: var(--radius-md);
      border: 1px solid #e2e8f0;
    }

    .exercise-group-header {
      display: flex;
      align-items: center;
      gap: 12px;
      flex-shrink: 0;
    }

    .weights-layout label {
      width: 110px;
      min-width: 110px;
    }

    .exercise-result {
      flex: 1;
    }
  }

  /* Input with unit label */
  .input-with-unit {
    display: flex;
    align-items: center;
    background: #fff;
    border: 2px solid #e2e8f0;
    border-radius: var(--radius-sm);
    overflow: hidden;
    transition: border-color 0.15s, box-shadow 0.15s;
  }

  .input-with-unit:focus-within {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(0, 121, 107, 0.1);
  }

  .input-with-unit input[type="number"] {
    width: 60px;
    padding: 10px 6px;
    font-size: 1.1em;
    border: none;
    text-align: center;
    background: transparent;
    font-family: inherit;
  }

  .input-with-unit input[type="number"]:focus {
    outline: none;
  }

  .input-with-unit .unit-label {
    padding-right: 10px;
    color: var(--color-text-muted);
    font-size: 0.85em;
    font-weight: 500;
  }

  .weights-layout input[type="number"]:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(0, 121, 107, 0.1);
  }

  /* Plate legend */
  .plate-legend {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid #e2e8f0;
  }

  .legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85em;
    color: var(--color-text-muted);
  }

  .legend-dot {
    width: 12px;
    height: 12px;
    border-radius: 3px;
  }

  .legend-dot.teal {
    background-color: var(--color-primary);
  }

  .legend-dot.orange {
    background-color: #ff9800;
  }

  .legend-dot.gray {
    background-color: #78909c;
  }

  .exercise-result {
    display: flex;
    gap: 5px;
    min-height: 22px;
    align-items: center;
  }

  .exercise-result:empty::before {
    content: '—';
    color: #b0bec5;
    font-weight: 400;
  }

  .exercise-result .plate {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 38px;
    background-color: #00796b;
    color: #fff;
    border-radius: 6px;
    font-size: 1em;
    font-weight: 700;
  }

  .exercise-result .plate.empty {
    background: transparent;
    width: 42px;
  }

  .exercise-result .plate.changed {
    background-color: #ff9800;
  }

  .exercise-result .plate.dumbbell-plate {
    background-color: #78909c;
    width: auto;
    padding: 0 14px;
  }

  /* Workout A/B tabs */
  .workout-tabs {
    display: flex;
    justify-content: center;
    margin-bottom: 16px;
    background: #f1f5f9;
    border-radius: var(--radius-lg);
    padding: 4px;
    gap: 4px;
  }

  .workout-tabs .workout-tab {
    flex: 1;
    padding: 10px 20px;
    font-size: 0.9em;
    font-weight: 600;
    border: none;
    background: transparent;
    color: var(--color-text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
    border-radius: var(--radius-md);
  }

  .workout-tabs .workout-tab:hover:not(.active) {
    color: var(--color-text);
    background: rgba(0, 121, 107, 0.1);
  }

  .workout-tabs .workout-tab.active {
    background: var(--color-primary);
    color: #fff;
    box-shadow: var(--shadow-sm);
  }

  .workout-tab:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
  }

  /* Weights page specific - compact layout */
  #page-weights .page-content {
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  /* Mobile responsive styles */
  @media (max-width: 480px) {
    .weights-layout {
      display: flex;
      flex-direction: column;
      gap: 10px;
    }

    /* Two-line card layout */
    .exercise-group {
      display: flex;
      flex-direction: column;
      gap: 10px;
      background: #f8fafc;
      border-radius: var(--radius-md);
      padding: 12px 14px;
      border: 1px solid #e2e8f0;
    }

    /* Row 1: label left, input right */
    .exercise-group-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      width: 100%;
    }

    .weights-layout label {
      text-align: left;
      margin: 0;
      font-size: 1em;
      font-weight: 600;
    }

    .input-with-unit {
      min-width: unset;
    }

    .input-with-unit input[type="number"] {
      width: 55px;
      padding: 10px 6px;
      font-size: 1em;
    }

    .input-with-unit .unit-label {
      font-size: 0.85em;
      padding-right: 10px;
    }

    /* Row 2: plates left-aligned */
    .exercise-result {
      display: flex;
      flex-wrap: wrap;
      gap: 6px;
      justify-content: flex-start;
    }

    .exercise-result .plate {
      width: 42px;
      height: 38px;
      font-size: 0.95em;
    }

    .exercise-result:empty::before {
      content: 'No plates needed';
      color: #aaa;
      font-size: 0.85em;
    }

    .plate-legend {
      flex-wrap: wrap;
      gap: 8px 14px;
      margin-top: 14px;
      padding-top: 12px;
    }

    /* Tighter spacing for pages on mobile */
    .page-content h1 {
      font-size: 1.4em;
      margin-bottom: 10px;
    }

    .workout-tabs {
      margin-bottom: 10px;
    }

    .bar-weight-badge {
      margin-bottom: 12px;
      padding: 6px 10px;
    }
  }