/* Base styles */
:root {
  --primary-color: #007AFF;
  --primary-light: #E5F1FF;
  --secondary-color: #34C759;
  --secondary-light: #E8F7ED;
  --background-color: #F2F2F7;
  --card-background: #FFFFFF;
  --text-color: #000000;
  --text-secondary: #8E8E93;
  --border-color: #C6C6C8;
  --danger-color: #FF3B30;
  --warning-color: #FF9500;
  --success-color: #34C759;
  --info-color: #5856D6;
  --tab-bar-height: 60px;
  --bottom-sheet-height: 80vh;
  --border-radius: 10px;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  --transition: all 0.3s ease;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--background-color);
  color: var(--text-color);
  line-height: 1.5;
  padding-bottom: var(--tab-bar-height);
  min-height: 100vh;
  overflow-x: hidden;
}

/* iOS Safe Area Support */
@supports (padding: max(0px)) {
  body {
    padding-bottom: max(var(--tab-bar-height), env(safe-area-inset-bottom));
  }
}

/* Navigation */
.ios-tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--tab-bar-height);
  background-color: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  justify-content: space-around;
  align-items: center;
  border-top: 1px solid var(--border-color);
  z-index: 1000;
  padding-bottom: max(0px, env(safe-area-inset-bottom));
  height: calc(var(--tab-bar-height) + max(0px, env(safe-area-inset-bottom)));
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 0;
  color: var(--text-secondary);
  font-size: 10px;
  border: none;
  background: none;
  cursor: pointer;
  transition: var(--transition);
}

.tab i {
  font-size: 22px;
  margin-bottom: 4px;
}

.tab.active {
  color: var(--primary-color);
}

.tab:active {
  opacity: 0.7;
}

/* Content Area */
#content {
  padding: 16px;
  padding-bottom: calc(var(--tab-bar-height) + 16px);
  max-width: 800px;
  margin: 0 auto;
}

/* Section Headers */
.section-header {
  margin-bottom: 24px;
  text-align: center;
}

.section-header h2 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text-color);
}

.section-description {
  color: var(--text-secondary);
  font-size: 16px;
}

/* Buttons */
.ios-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 20px;
  border-radius: var(--border-radius);
  font-weight: 600;
  font-size: 16px;
  border: none;
  cursor: pointer;
  transition: var(--transition);
  background-color: var(--primary-color);
  color: white;
}

.ios-button.secondary {
  background-color: var(--primary-light);
  color: var(--primary-color);
}

.ios-button-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--primary-light);
  color: var(--primary-color);
  border: none;
  cursor: pointer;
  transition: var(--transition);
}

.ios-button:active, .ios-button-icon:active {
  opacity: 0.7;
}

.add-button-container {
  margin-bottom: 24px;
  display: flex;
  justify-content: center;
}

.add-button {
  width: 100%;
  max-width: 300px;
}

/* Forms */
.ios-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: relative;
  min-height: 100%;
}

.ios-form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
  position: relative;
}

.ios-label {
  font-weight: 500;
  color: var(--text-color);
}

.ios-input, .ios-select, .ios-textarea {
  padding: 12px 16px;
  border-radius: var(--border-radius);
  border: 1px solid var(--border-color);
  background-color: var(--card-background);
  font-size: 16px;
  color: var(--text-color);
  transition: var(--transition);
  margin-bottom: 10px;
  position: relative;
  -webkit-appearance: none;
  appearance: none;
  min-height: 44px;
}

.ios-input:focus, .ios-select:focus, .ios-textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px var(--primary-light);
}

.ios-textarea {
  min-height: 100px;
  resize: vertical;
}

/* Cards */
.card {
  background-color: var(--card-background);
  border-radius: var(--border-radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.chicken-card {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.chicken-info {
  flex: 1;
}

.chicken-info h3 {
  font-size: 18px;
  margin-bottom: 4px;
  color: var(--text-color);
}

.chicken-status {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  margin-bottom: 8px;
}

.status-laying {
  background-color: var(--success-light);
  color: var(--success-color);
}

.status-molting {
  background-color: var(--warning-light);
  color: var(--warning-color);
}

.status-retired {
  background-color: var(--text-secondary);
  color: white;
}

.status-escaped {
  background-color: var(--danger-light);
  color: var(--danger-color);
}

.chicken-notes {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 8px;
}

.chicken-actions {
  display: flex;
  gap: 8px;
}

.egg-card {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.egg-info {
  flex: 1;
}

.egg-info h3 {
  font-size: 18px;
  margin-bottom: 4px;
  color: var(--text-color);
}

.egg-details {
  display: flex;
  gap: 16px;
  margin-bottom: 8px;
}

.egg-detail {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--text-secondary);
  font-size: 14px;
}

.egg-status {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  margin-bottom: 8px;
}

.status-normal {
  background-color: var(--success-light);
  color: var(--success-color);
}

.status-double-yolk {
  background-color: var(--info-light);
  color: var(--info-color);
}

.status-strange {
  background-color: var(--warning-light);
  color: var(--warning-color);
}

.status-broken {
  background-color: var(--danger-light);
  color: var(--danger-color);
}

.feed-card {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.feed-info {
  flex: 1;
}

.feed-info h3 {
  font-size: 18px;
  margin-bottom: 4px;
  color: var(--text-color);
}

.feed-details {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
}

.feed-detail {
  color: var(--text-secondary);
  font-size: 14px;
}

.health-card {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.health-info {
  flex: 1;
}

.health-info h3 {
  font-size: 18px;
  margin-bottom: 4px;
  color: var(--text-color);
}

.health-type {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  margin-bottom: 8px;
}

.type-vaccination {
  background-color: var(--primary-light);
  color: var(--primary-color);
}

.type-examination {
  background-color: var(--info-light);
  color: var(--info-color);
}

.type-injury {
  background-color: var(--danger-light);
  color: var(--danger-color);
}

.type-behavior {
  background-color: var(--warning-light);
  color: var(--warning-color);
}

.health-notes {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 8px;
}

/* Bottom Sheet */
.ios-bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: var(--card-background);
  border-radius: var(--border-radius) var(--border-radius) 0 0;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
  z-index: 1001;
  transform: translateY(100%);
  transition: transform 0.3s ease;
  max-height: var(--bottom-sheet-height);
  overflow-y: auto;
  display: none;
  transform-origin: bottom;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.ios-bottom-sheet.active {
  transform: translateY(0);
  bottom: 0;
}

.ios-bottom-sheet.keyboard-open {
  position: fixed;
  bottom: 0;
  max-height: 60vh;
  transform: translateY(0);
}

.ios-bottom-sheet-handle {
  width: 36px;
  height: 5px;
  background-color: var(--border-color);
  border-radius: 3px;
  margin: 8px auto;
}

.ios-bottom-sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  background-color: var(--card-background);
  z-index: 3;
}

.ios-bottom-sheet-header h3 {
  font-size: 18px;
  font-weight: 600;
}

.ios-bottom-sheet-content {
  padding: 16px;
  padding-bottom: 100px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
  padding-top: 20px;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}

.ios-bottom-sheet.keyboard-open .ios-bottom-sheet-content {
  padding-bottom: 200px;
  height: auto;
  max-height: calc(60vh - 120px);
}

.ios-bottom-sheet-actions {
  display: flex;
  justify-content: space-between;
  padding: 16px;
  border-top: 1px solid var(--border-color);
  background-color: var(--card-background);
  z-index: 2;
  position: relative;
  width: 100%;
}

.ios-bottom-sheet.keyboard-open .ios-bottom-sheet-actions {
  position: relative;
  bottom: auto;
}

.ios-bottom-sheet-button {
  padding: 12px 20px;
  border-radius: var(--border-radius);
  font-weight: 600;
  font-size: 16px;
  border: none;
  cursor: pointer;
  transition: var(--transition);
  flex: 1;
  text-align: center;
}

.ios-bottom-sheet-button.cancel {
  background-color: transparent;
  color: var(--text-color);
  margin-right: 8px;
}

.ios-bottom-sheet-button.add {
  background-color: var(--primary-color);
  color: white;
  margin-left: 8px;
}

.ios-bottom-sheet-button.add:disabled {
  background-color: var(--secondary-color);
  opacity: 0.5;
  cursor: not-allowed;
}

/* Overlay */
.ios-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: var(--transition);
}

.ios-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-secondary);
}

.empty-state i {
  font-size: 48px;
  margin-bottom: 16px;
  color: var(--border-color);
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stats-card {
  background-color: var(--card-background);
  border-radius: var(--border-radius);
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 16px;
}

.stats-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background-color: var(--primary-light);
  color: var(--primary-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}

.stats-info h3 {
  font-size: 16px;
  margin-bottom: 4px;
  color: var(--text-secondary);
}

.stats-info p {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-color);
}

/* Summary Cards */
.summary-card {
  background-color: var(--card-background);
  border-radius: var(--border-radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.summary-card h3 {
  font-size: 18px;
  margin-bottom: 16px;
  color: var(--text-color);
}

.summary-table {
  width: 100%;
  border-collapse: collapse;
}

.summary-table th, .summary-table td {
  padding: 8px;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.summary-table th {
  font-weight: 600;
  color: var(--text-secondary);
}

.summary-table tr:last-child td {
  border-bottom: none;
}

/* Responsive Design */
@media (min-width: 768px) {
  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  
  .chicken-list, .egg-list, .feed-list, .health-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
  }
  
  .chicken-card, .egg-card, .feed-card, .health-card {
    margin-bottom: 0;
  }

  /* Center content on iPad and larger screens */
  main#content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
  }

  .section-header {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
  }

  .add-button-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
  }

  .chicken-list, .egg-list, .feed-list, .health-list {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
  }

  .summary-card {
    max-width: 1200px;
    margin: 0 auto 16px;
    padding: 16px 20px;
  }
}

@media (min-width: 1024px) {
  .chicken-list, .egg-list, .feed-list, .health-list {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Add a class to ensure the form is visible when keyboard is open */
.ios-form.keyboard-open {
  padding-bottom: 200px;
}

/* Add styles to prevent content jumping */
.ios-bottom-sheet-content {
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

/* Add styles to fix content jumping when keyboard appears */
.ios-bottom-sheet.keyboard-open .ios-bottom-sheet-content {
  height: auto;
  overflow-y: auto;
  position: relative;
  padding-bottom: 80px;
  padding-top: 30px;
}
