/* AMKS Meal Planner — Styles v1.4.0 */

:root {
  --bg: #F5F5F5;
  --surface: #FFFFFF;
  --text: #1A1A1A;
  --text-secondary: #666666;
  --accent: #2E7D32;
  --accent-light: #E8F5E9;
  --accent-dark: #1B5E20;
  --ok: #2E7D32;
  --ok-bg: #E8F5E9;
  --danger: #C62828;
  --danger-bg: #FFEBEE;
  --warning: #E68A00;
  --warning-bg: #FFF8E1;
  --border: #E0E0E0;
  --header-bg: #1B5E20;
  --header-text: #FFFFFF;
  --radius: 8px;
  --radius-sm: 4px;
  --input-bg: #FFFFFF;
  --chip-bg: #F0F0F0;
  --chip-active-bg: #E8F5E9;
  --chip-active-text: #2E7D32;
  --kids: #FF9800;
  --kids-bg: #FFF3E0;
  --solo: #1976D2;
  --solo-bg: #E3F2FD;
  --fifo: #7B1FA2;
  --fifo-bg: #F3E5F5;
  --shadow: rgba(0,0,0,0.06);
  --grid-today-bg: rgba(46,125,50,0.08);
  --grid-filled-bg: #E8F5E9;
  --grid-filled-text: #1B5E20;
}

[data-theme="dark"] {
  --bg: #0F1923;
  --surface: #1E2A3A;
  --text: #E0E0E0;
  --text-secondary: #9EAAB8;
  --accent: #4CAF50;
  --accent-light: #1B3A1B;
  --accent-dark: #81C784;
  --ok: #4CAF50;
  --ok-bg: #1B3A1B;
  --danger: #EF5350;
  --danger-bg: #3A1A1A;
  --warning: #FFB74D;
  --warning-bg: #3A2E1B;
  --border: #2A3A4E;
  --header-bg: #0D1520;
  --header-text: #E0E0E0;
  --input-bg: #253040;
  --chip-bg: #253040;
  --chip-active-bg: #1B3A1B;
  --chip-active-text: #4CAF50;
  --kids: #FFB74D;
  --kids-bg: #3A2E1B;
  --solo: #64B5F6;
  --solo-bg: #1A2A3A;
  --fifo: #CE93D8;
  --fifo-bg: #2A1A3A;
  --shadow: rgba(0,0,0,0.3);
  --grid-today-bg: rgba(76,175,80,0.12);
  --grid-filled-bg: #1B3A1B;
  --grid-filled-text: #81C784;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  transition: background 0.3s, color 0.3s;
}

/* ===== HEADER ===== */
header {
  background: var(--header-bg);
  color: var(--header-text);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 2px;
}

.header-title {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 1.5px;
}

.header-icon-btn {
  background: none;
  border: none;
  color: var(--header-text);
  font-size: 18px;
  padding: 6px 8px;
  cursor: pointer;
  line-height: 1;
  opacity: 0.85;
  transition: opacity 0.15s;
  border-radius: var(--radius-sm);
}

.header-icon-btn:active {
  opacity: 1;
  background: rgba(255,255,255,0.1);
}

/* ===== MAIN ===== */
main {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  padding-bottom: 68px;
  -webkit-overflow-scrolling: touch;
  transition: background 0.3s;
}

.page-content {
  max-width: 600px;
  margin: 0 auto;
}

/* ===== BOTTOM NAV ===== */
#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  display: flex;
  border-top: 1px solid var(--border);
  z-index: 100;
  transition: background 0.3s, border-color 0.3s;
}

.nav-btn {
  flex: 1;
  padding: 10px 0;
  background: none;
  border: none;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.8px;
  color: var(--text-secondary);
  cursor: pointer;
  border-top: 2px solid transparent;
  transition: color 0.15s;
}

.nav-btn.active {
  color: var(--accent);
  border-top-color: var(--accent);
}

/* ===== SEARCH BAR ===== */
.search-bar {
  margin-bottom: 12px;
}

.search-bar .form-input {
  width: 100%;
}

/* ===== BUTTONS ===== */
.btn {
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.5px;
  font-family: inherit;
  transition: all 0.15s;
}

.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: white; }
.btn-secondary { background: var(--chip-bg); color: var(--text); border: 1px solid var(--border); }
.btn-outline { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-outline:active { background: var(--chip-bg); }
.btn-danger { background: var(--danger); color: white; }
.btn-block { display: block; width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 11px; }

/* ===== FAB ===== */
.fab {
  position: fixed;
  bottom: 68px;
  right: 16px;
  width: 52px;
  height: 52px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 50%;
  font-size: 26px;
  cursor: pointer;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  transition: transform 0.15s;
}

.fab:active { transform: scale(0.92); }

/* ===== FORM ELEMENTS ===== */
.form-group { margin-bottom: 16px; }

.form-group > label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 6px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.form-group > label .muted {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

.form-input, .form-select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: var(--input-bg);
  color: var(--text);
  font-family: inherit;
  transition: background 0.3s, border-color 0.3s, color 0.3s;
}

.form-input:focus, .form-select:focus {
  outline: none;
  border-color: var(--accent);
}

.form-input::placeholder { color: var(--text-secondary); }

textarea.form-input { resize: vertical; min-height: 60px; }

.form-actions {
  display: flex;
  gap: 8px;
  margin-top: 20px;
}

.form-actions .btn { flex: 1; }

/* ===== RECIPE LIST ===== */
.recipe-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.recipe-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: background 0.15s, border-color 0.3s;
  box-shadow: 0 1px 3px var(--shadow);
}

.recipe-card:active {
  opacity: 0.9;
  background: var(--chip-bg);
}

.recipe-card-main {
  flex: 1;
  min-width: 0;
}

.recipe-card-title {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.recipe-card-meta {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.recipe-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  flex-shrink: 0;
}

.recipe-card::after {
  content: '\203A';
  font-size: 20px;
  color: var(--text-secondary);
  flex-shrink: 0;
  font-weight: 300;
}

/* ===== TAGS ===== */
.tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--accent-light);
  color: var(--accent);
  letter-spacing: 0.3px;
  text-transform: lowercase;
  white-space: nowrap;
}

/* ===== RECIPE DETAIL ===== */
.detail-page h2 {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 8px;
}

.detail-page h3 {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  margin-top: 16px;
}

.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.ingredient-list {
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.ingredient-list li {
  padding: 10px 14px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.ingredient-list li::before {
  content: '\2022';
  color: var(--accent);
  font-weight: 700;
  flex-shrink: 0;
}

.ingredient-list li:last-child { border-bottom: none; }

.detail-actions {
  display: flex;
  gap: 8px;
  margin-top: 24px;
}

.detail-actions .btn { flex: 1; }

.muted {
  color: var(--text-secondary);
  font-style: italic;
}

/* ===== RECIPE FORM ===== */
.form-page h2 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 16px;
}

/* Ingredient rows in form */
.ing-row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
}

.ing-row .ing-qty {
  width: 55px;
  flex-shrink: 0;
  padding: 8px 6px;
  text-align: center;
  font-size: 13px;
}

.ing-row .ing-unit {
  width: 72px;
  flex-shrink: 0;
  padding: 8px 4px;
  font-size: 13px;
}

.ing-row .ing-name {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  font-size: 13px;
}

.ing-remove {
  width: 32px;
  height: 36px;
  border: none;
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: var(--radius-sm);
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s;
}

.ing-remove:active { opacity: 0.7; }

/* ===== PLANNER ===== */
.week-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 8px;
}

.week-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  width: 36px;
  height: 36px;
  font-size: 20px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}

.week-btn:active { background: var(--chip-bg); }

.week-label {
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  flex: 1;
}

/* Context selector (Kids / Solo / FIFO) */
.context-selector {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
}

.ctx-btn {
  flex: 1;
  padding: 8px 4px;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  color: var(--text-secondary);
  transition: all 0.15s;
  text-align: center;
}

.ctx-btn:active { opacity: 0.8; }
.ctx-btn.active { background: var(--accent-light); color: var(--accent); }

/* ===== PLANNER GRID TABLE ===== */

.planner-page .page-content {
  max-width: none;
}

.grid-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -12px;
  padding: 0 12px;
}

.planner-grid {
  width: 100%;
  min-width: 500px;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 1px 3px var(--shadow);
  table-layout: fixed;
}

/* Header cells — day columns */
.planner-grid thead th {
  padding: 8px 4px;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  background: var(--chip-bg);
  border-bottom: 2px solid var(--border);
  letter-spacing: 0.3px;
  vertical-align: middle;
}

.grid-meal-col {
  width: 72px;
  min-width: 72px;
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--chip-bg) !important;
}

.grid-day-col {
  min-width: 58px;
}

.grid-day-col.today {
  background: var(--grid-today-bg) !important;
}

.grid-day-name {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.grid-day-date {
  display: block;
  font-size: 10px;
  font-weight: 400;
  color: var(--text-secondary);
  margin-top: 1px;
}

/* Meal label column — sticky left */
.grid-meal-label {
  width: 72px;
  min-width: 72px;
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--surface);
  padding: 6px 6px;
  text-align: center;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.grid-meal-icon {
  display: block;
  font-size: 16px;
  line-height: 1;
  margin-bottom: 2px;
}

.grid-meal-text {
  display: block;
  font-size: 9px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Grid cells */
.grid-cell {
  padding: 4px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  vertical-align: middle;
  text-align: center;
  height: 56px;
  min-height: 56px;
}

.grid-cell.today {
  background: var(--grid-today-bg);
}

.grid-cell:last-child {
  border-right: none;
}

tbody tr:last-child .grid-cell,
tbody tr:last-child .grid-meal-label {
  border-bottom: none;
}

/* Empty cell — add button */
.grid-add {
  width: 100%;
  height: 100%;
  min-height: 40px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: 18px;
  font-weight: 300;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.grid-add:active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}

/* Filled cell — recipe assigned */
.grid-filled {
  width: 100%;
  height: 100%;
  min-height: 40px;
  background: var(--grid-filled-bg);
  border-radius: var(--radius-sm);
  padding: 4px 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  position: relative;
  transition: opacity 0.15s;
}

.grid-filled:active {
  opacity: 0.7;
}

.grid-recipe-name {
  font-size: 10px;
  font-weight: 600;
  color: var(--grid-filled-text);
  line-height: 1.2;
  text-align: center;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-word;
}

.grid-remove {
  font-size: 12px;
  color: var(--danger);
  opacity: 0.5;
  line-height: 1;
}

/* ===== SHOPPING LIST ===== */
.list-section {
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 1px 3px var(--shadow);
}

.list-section-header {
  font-size: 12px;
  font-weight: 700;
  padding: 10px 14px;
  background: var(--chip-bg);
  border-bottom: 1px solid var(--border);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.shopping-items {
  list-style: none;
}

.shopping-items li {
  padding: 10px 14px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}

.shopping-items li:last-child { border-bottom: none; }

/* Copy button at bottom */
.list-page > .btn-block {
  margin-top: 8px;
  margin-bottom: 16px;
}

/* ===== CUSTOM ITEMS (Other section) ===== */
.custom-add-row {
  display: flex;
  gap: 6px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

.custom-add-row .form-input {
  flex: 1;
  padding: 8px 10px;
  font-size: 13px;
}

.custom-add-row .btn {
  flex-shrink: 0;
  width: 40px;
  padding: 0;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.custom-items li {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.custom-item.checked .custom-name {
  text-decoration: line-through;
  opacity: 0.5;
}

.custom-check {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  flex: 1;
  min-width: 0;
}

.checkmark {
  font-size: 18px;
  flex-shrink: 0;
}

.custom-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.custom-remove {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  flex-shrink: 0;
  opacity: 0.6;
  transition: opacity 0.15s, color 0.15s;
}

.custom-remove:active {
  color: var(--danger);
  opacity: 1;
}

/* ===== RECIPE PICKER MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex;
  align-items: flex-end;
}

.modal-content {
  background: var(--surface);
  width: 100%;
  padding: 16px;
  border-radius: var(--radius) var(--radius) 0 0;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 24px;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
}

.modal-close:active { color: var(--text); }

.modal-content > .form-input {
  margin-bottom: 12px;
}

.picker-list {
  max-height: 50vh;
  overflow-y: auto;
}

.picker-item {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
  transition: background 0.1s;
}

.picker-item:active { background: var(--chip-bg); }

.picker-meta {
  font-size: 12px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.picker-empty {
  text-align: center;
  padding: 24px;
  color: var(--text-secondary);
  font-size: 14px;
}

/* ===== SETTINGS ===== */
.settings-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.settings-info span:first-child {
  color: var(--text-secondary);
  font-weight: 500;
}

.settings-info span:last-child {
  font-weight: 600;
}

.settings-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
}

.page-content h2 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 16px;
}

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-text { font-size: 14px; margin-bottom: 8px; font-weight: 600; }
.empty-sub { font-size: 12px; }

/* ===== COPY TOAST ===== */
.copy-toast {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ok);
  color: white;
  padding: 8px 20px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  z-index: 300;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.copy-toast.show { opacity: 1; }

/* ===== RESPONSIVE ===== */
@media (min-width: 600px) {
  main { max-width: 640px; margin: 0 auto; }

  .planner-page main {
    max-width: none;
  }
}

/* On wider screens, grid doesn't need to scroll */
@media (min-width: 560px) {
  .planner-grid {
    min-width: auto;
  }
}
