/* Theme Variables */
:root {
  /* Light Theme (Default) */
  --background-primary: #f2f2f7;
  --background-secondary: #ffffff;
  --text-primary: #000000;
  --text-secondary: #6c6c70;
  --border-color: #e5e5ea;
  --input-background: #ffffff;
  --button-primary: #007aff;
  --button-secondary: #5856d6;
  --button-danger: #ff3b30;
  --success-color: #34c759;
  --card-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

/* Dark Theme */
[data-theme="dark"] {
  --background-primary: #000000;
  --background-secondary: #1c1c1e;
  --text-primary: #ffffff;
  --text-secondary: #8e8e93;
  --border-color: #38383a;
  --input-background: #1c1c1e;
  --button-primary: #0a84ff;
  --button-secondary: #5e5ce6;
  --button-danger: #ff453a;
  --success-color: #32d74b;
  --card-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

/* Base Styles */
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text",
    "SF Pro Display", system-ui, sans-serif;
  background-color: var(--background-primary);
  color: var(--text-primary);
  margin: 0 auto;
  padding: 20px;
  max-width: 700px;
  box-sizing: border-box;
  transition: background-color 0.3s, color 0.3s;
  -webkit-font-smoothing: antialiased;
}

/* Theme Toggle */
.theme-toggle {
  position: relative;
  top: auto;
  right: auto;
}

.theme-switch {
  position: relative;
  display: inline-block;
  width: 51px;
  height: 31px;
}

.theme-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #e5e5ea;
  transition: 0.4s;
  border-radius: 31px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 27px;
  width: 27px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  transition: 0.4s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--button-primary);
}

input:checked + .slider:before {
  transform: translateX(20px);
}

.theme-switch input:focus-visible + .slider {
  outline: 2px solid var(--button-primary);
  outline-offset: 2px;
}

.editable {
  cursor: pointer;
}

.editable:focus-visible {
  outline: 2px solid var(--button-primary);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Input Styles */
input,
select,
textarea {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui,
    sans-serif;
  background-color: var(--input-background);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 17px;
  width: 100%;
  box-sizing: border-box;
  transition: all 0.3s;
  -webkit-appearance: none;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--button-primary);
}

/* Button Styles */
.button {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui,
    sans-serif;
  border: none;
  border-radius: 10px;
  padding: 12px 24px;
  font-size: 17px;
  font-weight: 600;
  color: white;
  background-color: var(--button-primary);
  transition: all 0.3s;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.button:active {
  transform: scale(0.98);
  opacity: 0.9;
}

.timer-button {
  background-color: var(--button-secondary);
}

/* Reset Button Styles */
.reset-button {
  background: none;
  border: none;
  padding: 8px;
  color: var(--button-danger);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s;
}

.reset-button:hover {
  opacity: 0.7;
}

.reset-button ion-icon {
  font-size: 24px;
}

/* Recipe Step Layout */
.recipe-step {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  /* New order: timestamp → description → water → remove */
  align-items: center;
  gap: 12px;
  background-color: var(--background-secondary);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--card-shadow);
}

/* Time container (Column 1) - Timestamp */
.recipe-step .time-container {
  display: flex;
  align-items: center;
  gap: 2px;
  width: 90px;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

/* Time inputs styling - iOS style timestamp picker */
.recipe-step .time-input {
  width: 35px;
  padding: 8px 4px;
  text-align: center;
  font-size: 16px;
  font-weight: 500;
}

.recipe-step .time-separator {
  font-size: 16px;
  font-weight: 500;
  color: var(--text-secondary);
  padding: 0 2px;
}

/* Timestamp editable spans */
.recipe-step .editable.timestamp-minutes,
.recipe-step .editable.timestamp-seconds {
  font-variant-numeric: tabular-nums;
  font-size: 16px;
  font-weight: 500;
  min-width: 35px;
  text-align: center;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* Edit icon for timestamp minutes */
.recipe-step .editable.timestamp-minutes i {
  font-size: 14px;
  opacity: 0.6;
}

/* Description (Column 2) */
.recipe-step input[type="text"] {
  flex: 1;
  min-width: 0;
}

/* Water amount (Column 3) */
.recipe-step input[type="number"]:not(.time-input) {
  width: 80px;
  flex-shrink: 0;
}

/* Remove button */
.recipe-step .remove-step {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.recipe-step .remove-step:hover {
  opacity: 1;
}

/* Section Styles */
.metadata-section,
.recipe-step {
  background-color: var(--background-secondary);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--card-shadow);
}

.form-group {
  margin-bottom: 20px;
}

label {
  display: block;
  color: var(--text-secondary);
  font-size: 15px;
  margin-bottom: 8px;
  font-weight: 500;
}

/* Calculated field indicator - minimal green LED dot */
.input-group {
  position: relative;
  margin-bottom: 20px;
}

.input-group .editable.calculated::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--success-color);
  margin-left: 8px;
  vertical-align: middle;
  box-shadow: 0 0 4px rgba(52, 199, 89, 0.6);
}

/* Timer Display */
.current-timer {
  font-size: 34px;
  font-weight: 700;
  text-align: center;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", system-ui,
    sans-serif;
  margin: 20px 0;
}

/* Header Styles */
.header-container {
  position: sticky;
  top: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  background-color: var(--background-primary);
  z-index: 1000;
  margin: -20px -20px 20px -20px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-color);
  transition: background-color 0.3s, border-color 0.3s;
}

.app-title {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", system-ui,
    sans-serif;
  font-size: 20px;
  font-weight: 600;
  margin: 0;
  color: var(--text-primary);
}

/* Icon Button Styles */
.icon-button {
  background: none;
  border: none;
  padding: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  transition: opacity 0.2s;
}

.icon-button:hover {
  opacity: 0.7;
}

.icon-button ion-icon {
  font-size: 24px;
}

/* Add Step Button */
#add-step {
  margin: 16px auto;
  display: flex;
  justify-content: center;
}

/* Share Container */
.share-container {
  display: flex;
  justify-content: center;
  margin: 20px 0;
}

/* Timer Control Styles */
.timer-controls {
  display: none; /* Hidden by default, shown when steps are added */
  flex-direction: column;
  align-items: center;
  gap: 16px;
  margin: 24px 0;
  padding: 20px;
  background-color: var(--background-secondary);
  border-radius: 14px;
  box-shadow: var(--card-shadow);
}

.timer-display {
  text-align: center;
  width: 100%;
}

.timer-stats {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  margin-bottom: 8px;
}

.timer-stat {
  font-size: 24px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
  flex: 1;
}

.timer-stat:first-child {
  text-align: left;
}

.timer-stat:last-child {
  text-align: right;
}

.current-timer {
  font-size: 48px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
  margin: 0;
  flex: 1;
}

.accumulated-grams {
  font-size: 32px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
  margin: 12px 0;
}

.grams-chart {
  display: block;
  width: 100%;
  height: 64px;
  margin: 4px 0 12px;
}

.grams-chart-target-fill {
  fill: var(--border-color);
  opacity: 0.6;
}

.grams-chart-target-line {
  fill: none;
  stroke: var(--text-secondary);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.grams-chart-progress-fill {
  fill: var(--button-primary);
  opacity: 0.25;
}

.grams-chart-progress-line {
  fill: none;
  stroke: var(--button-primary);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.grams-chart-water-target {
  fill: none;
  stroke: var(--text-secondary);
  stroke-width: 1;
  stroke-dasharray: 4 3;
  vector-effect: non-scaling-stroke;
}

.step-indicator {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  margin-top: 8px;
}

.step-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}

.water-budget {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.water-budget.over-budget {
  color: var(--button-danger);
}

.required-marker {
  color: var(--button-danger);
  font-weight: 700;
}

.timer-buttons {
  display: flex;
  justify-content: center;
  gap: 24px;
  align-items: center;
}

.timer-icon {
  font-size: 24px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background-color: var(--background-primary);
  color: var(--text-primary);
  transition: all 0.2s ease;
}

.timer-icon:hover {
  transform: scale(1.1);
  background-color: var(--border-color);
}

.timer-icon:active {
  transform: scale(0.95);
}

.timer-icon:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* Initially disable back/forward buttons if no steps */
#prev-step:disabled,
#next-step:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.icon-button {
  background: none;
  border: none;
  padding: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  transition: opacity 0.2s;
}

.icon-button i {
  font-size: 24px;
}

.reset-button i {
  font-size: 24px;
}

.timer-button i {
  margin-right: 8px;
}

.remove-step i {
  font-size: 16px;
}

/* Mobile Optimization */
@media screen and (max-width: 375px) {
  body {
    padding: 16px;
  }

  .header-container {
    padding: 12px 16px;
    margin: -16px -16px 16px -16px;
  }

  .app-title {
    font-size: 18px;
  }

  .recipe-step {
    grid-template-columns: auto 1fr auto;
    grid-template-areas:
      "time water remove"
      "desc desc desc";
    row-gap: 8px;
  }

  .recipe-step .time-container {
    grid-area: time;
    width: auto;
  }

  .recipe-step input[type="text"],
  .recipe-step .editable:has(+ input[type="text"]) {
    grid-area: desc;
  }

  .recipe-step input[type="number"]:not(.time-input),
  .recipe-step .editable:has(+ input[type="number"]:not(.time-input)) {
    grid-area: water;
  }

  .recipe-step .remove-step {
    grid-area: remove;
  }

  input,
  select,
  textarea {
    font-size: 16px;
    padding: 10px 14px;
  }

  .current-timer {
    font-size: 28px;
  }
  
  .timer-stat {
    font-size: 18px;
  }
  
  .accumulated-grams {
    font-size: 24px;
  }

  .grams-chart {
    height: 48px;
  }

  .timer-buttons {
    flex-direction: row;
    gap: 8px;
  }

  .timer-icon {
    font-size: 20px;
    width: 40px;
    height: 40px;
  }

  .button {
    width: 100%;
    padding: 14px 20px;
  }
}

/* Recipe Details Container */
.recipe-details-container {
  display: flex;
  flex-direction: row;
  gap: 24px;
  margin-bottom: 32px;
  flex-wrap: wrap; /* Allow wrapping on smaller screens */
  width: auto; /* Ensure it fits within the screen width */
  box-sizing: border-box; /* Include padding and border in the element's width and height */
}

.recipe-details-column {
  flex: 1;
  min-width: 0; /* Allows columns to shrink below content size */
  background-color: var(--background-secondary);
  border-radius: 14px;
  padding: 20px;
  box-shadow: var(--card-shadow);
}

/* Mobile Responsiveness */
@media screen and (max-width: 768px) {
  .recipe-details-container {
    flex-direction: column;
    gap: 16px;
  }

  .recipe-details-column {
    width: auto;
  }
}

/* Additional specific mobile optimizations for very small screens */
@media screen and (max-width: 375px) {
  .recipe-details-container {
    padding: 0 16px; /* Add padding to fit within small screen width */
  }

  .recipe-details-column {
    padding: 16px; /* Adjust padding for small screens */
  }
}
