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

:root {
  --bg: #f7f5f2;
  --surface: #ffffff;
  --surface2: #f0ede8;
  --border: #e0dbd3;
  --text: #1a1714;
  --text2: #6b6560;
  --accent: #c8703a;
  --accent-dark: #a85a2e;
  --lunch: #e8f4e8;
  --lunch-border: #7cb87c;
  --dinner: #e8e8f4;
  --dinner-border: #7c7cb8;
  --danger: #c84040;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100dvh; }

/* ─── Layout ─── */
#app { display: flex; flex-direction: column; min-height: 100dvh; }
#app.hidden { display: none; }
.hidden { display: none; }
main { flex: 1; padding: 0 0 80px; max-width: 600px; margin: 0 auto; width: 100%; }

/* ─── Topbar ─── */
.topbar {
  position: sticky; top: 0; z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex; align-items: center; gap: 12px;
}
.topbar h1 { font-size: 1.2rem; font-weight: 700; flex: 1; }
.topbar .user-pill {
  background: var(--surface2); border-radius: 20px;
  padding: 4px 12px; font-size: 0.8rem; color: var(--text2);
}
.offline-badge {
  background: #f5a623; color: #fff;
  border-radius: 4px; padding: 2px 8px; font-size: 0.75rem; font-weight: 600;
  display: none;
}
body.offline .offline-badge { display: inline-block; }

/* ─── Nav tabs ─── */
.nav-tabs {
  display: flex; border-bottom: 1px solid var(--border);
  background: var(--surface); padding: 0 16px;
  position: sticky; top: 57px; z-index: 99;
}
.nav-tab {
  padding: 10px 16px; font-size: 0.9rem; font-weight: 500;
  color: var(--text2); border: none; background: none; cursor: pointer;
  border-bottom: 2px solid transparent; transition: color 0.15s, border-color 0.15s;
}
.nav-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ─── Week view ─── */
.week-scroll { padding: 12px 16px; display: flex; flex-direction: column; gap: 12px; }

.day-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.day-header {
  padding: 10px 16px;
  background: var(--surface2);
  font-weight: 600; font-size: 0.95rem;
  display: flex; justify-content: space-between; align-items: center;
}
.day-header .day-label { color: var(--text); }
.day-header .day-date { color: var(--text2); font-size: 0.8rem; font-weight: 400; }
.day-today .day-header { background: #fff7f2; border-left: 3px solid var(--accent); }

.meal-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; border-top: 1px solid var(--border);
}
.meal-icon {
  font-size: 1.2rem; width: 28px; text-align: center; flex-shrink: 0;
}
.meal-info { flex: 1; min-width: 0; }
.meal-label { font-size: 0.72rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text2); margin-bottom: 2px; }
.meal-dish { font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meal-dish.empty { color: var(--text2); font-style: italic; }
.meal-others { font-size: 0.75rem; color: var(--text2); margin-top: 2px; }
.meal-btn {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 6px 10px;
  font-size: 0.8rem; cursor: pointer; flex-shrink: 0; color: var(--text);
  transition: background 0.15s;
}
.meal-btn:hover { background: var(--border); }
.meal-btn.set { background: var(--accent); color: #fff; border-color: var(--accent); }
.meal-btn.set:hover { background: var(--accent-dark); border-color: var(--accent-dark); }

/* ─── Dishes tab ─── */
.dishes-section { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.search-row { display: flex; gap: 8px; }
.search-row input {
  flex: 1; padding: 10px 14px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 0.95rem; background: var(--surface);
  outline: none; transition: border-color 0.15s;
}
.search-row input:focus { border-color: var(--accent); }
.dishes-list { display: flex; flex-direction: column; gap: 6px; }
.dish-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 14px;
}
.dish-item .dish-name { flex: 1; font-size: 0.95rem; }
.dish-star { font-size: 1rem; cursor: pointer; opacity: 0.4; transition: opacity 0.15s; }
.dish-star.preferred { opacity: 1; }
.filter-row { display: flex; gap: 8px; flex-wrap: wrap; }
.filter-btn {
  padding: 5px 12px; border-radius: 20px; border: 1px solid var(--border);
  background: var(--surface); font-size: 0.8rem; cursor: pointer; transition: all 0.15s;
}
.filter-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ─── Modal / bottom sheet ─── */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  z-index: 200; display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.overlay.open { opacity: 1; pointer-events: auto; }
.sheet {
  background: var(--surface); border-radius: var(--radius) var(--radius) 0 0;
  width: 100%; max-width: 600px; max-height: 85dvh;
  display: flex; flex-direction: column;
  transform: translateY(100%); transition: transform 0.25s cubic-bezier(0.32,0.72,0,1);
}
.overlay.open .sheet { transform: translateY(0); }
.sheet-header {
  padding: 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.sheet-header h2 { flex: 1; font-size: 1rem; font-weight: 600; }
.sheet-close {
  width: 32px; height: 32px; border-radius: 50%; border: none;
  background: var(--surface2); cursor: pointer; font-size: 1.1rem; display: flex;
  align-items: center; justify-content: center;
}
.sheet-search {
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.sheet-search input {
  width: 100%; padding: 10px 14px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 0.95rem; outline: none;
}
.sheet-search input:focus { border-color: var(--accent); }
.sheet-list { overflow-y: auto; flex: 1; padding: 8px; display: flex; flex-direction: column; gap: 4px; }
.sheet-dish-btn {
  width: 100%; text-align: left; padding: 12px 14px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  background: none; font-size: 0.95rem; cursor: pointer; transition: background 0.12s;
  display: flex; align-items: center; gap: 8px;
}
.sheet-dish-btn:hover { background: var(--surface2); }
.sheet-dish-btn .star { opacity: 0.4; font-size: 0.85rem; }
.sheet-dish-btn .star.preferred { opacity: 1; }
.sheet-add-new {
  padding: 12px 16px; border-top: 1px solid var(--border);
  display: flex; gap: 8px;
}
.sheet-add-new input {
  flex: 1; padding: 9px 13px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 0.9rem; outline: none;
}
.sheet-add-new input:focus { border-color: var(--accent); }
.sheet-clear-btn {
  width: 100%; padding: 11px; border-top: 1px solid var(--border);
  border-bottom-left-radius: 0; border-bottom-right-radius: 0;
  border: none; border-top: 1px solid var(--border);
  background: #fff5f5; color: var(--danger); font-size: 0.9rem; cursor: pointer;
}
.sheet-clear-btn:hover { background: #ffe0e0; }

/* ─── Buttons ─── */
.btn {
  padding: 10px 18px; border-radius: var(--radius-sm);
  border: none; font-size: 0.9rem; font-weight: 600; cursor: pointer; transition: all 0.15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-ghost { background: none; color: var(--text2); }

/* ─── Login screen ─── */
#login-screen {
  display: flex; align-items: center; justify-content: center;
  min-height: 100dvh; background: var(--bg);
  padding: 24px;
}
#login-screen .card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 32px 28px;
  width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 20px;
}
#login-screen h1 { font-size: 1.6rem; text-align: center; }
#login-screen .subtitle { text-align: center; color: var(--text2); font-size: 0.9rem; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 0.85rem; font-weight: 500; color: var(--text2); }
.form-group input {
  padding: 11px 14px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 0.95rem; outline: none; transition: border-color 0.15s;
}
.form-group input:focus { border-color: var(--accent); }
.error-msg { color: var(--danger); font-size: 0.85rem; display: none; }
.error-msg.show { display: block; }

/* ─── Picker mode toggle ─── */
.mode-toggle {
  display: flex; gap: 0; padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
}
.mode-btn {
  flex: 1; padding: 8px 12px; border: 1px solid var(--border);
  background: var(--surface); font-size: 0.85rem; cursor: pointer;
  color: var(--text2); transition: all 0.15s; font-weight: 500;
}
.mode-btn:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.mode-btn:last-child  { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; border-left: none; }
.mode-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ─── Archive nav ─── */
.archive-nav {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; gap: 8px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 106px; z-index: 98;
}
.archive-nav-btn {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 6px 12px;
  font-size: 0.82rem; cursor: pointer; color: var(--text);
  transition: background 0.15s; white-space: nowrap;
}
.archive-nav-btn:hover:not(:disabled) { background: var(--border); }
.archive-nav-btn:disabled { opacity: 0.4; cursor: default; }
.archive-range { font-size: 0.85rem; color: var(--text2); font-weight: 500; text-align: center; flex: 1; }
.archive-scroll { padding: 12px 16px; display: flex; flex-direction: column; gap: 12px; }

/* ─── Clickable dish name ─── */
.dish-name-btn {
  flex: 1; text-align: left; background: none; border: none;
  font-size: 0.95rem; color: var(--text); cursor: pointer; padding: 0;
  text-decoration: underline; text-decoration-color: var(--border);
  text-underline-offset: 3px; transition: color 0.15s;
}
.dish-name-btn:hover { color: var(--accent); }

/* ─── Dish history sheet ─── */
.history-list { padding: 8px 0; }
.history-year {
  padding: 6px 16px 2px; font-size: 0.75rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em; color: var(--text2);
}
.history-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; border-bottom: 1px solid var(--border);
}
.history-row:last-child { border-bottom: none; }
.history-icon { font-size: 1.1rem; width: 24px; text-align: center; flex-shrink: 0; }
.history-date { font-size: 0.9rem; flex: 1; }
.history-meal { font-size: 0.75rem; color: var(--text2); text-transform: capitalize; width: 46px; }
.history-user { font-size: 0.8rem; color: var(--text2); white-space: nowrap; }

/* ─── Utility ─── */
.empty-msg { padding: 24px; text-align: center; color: var(--text2); }

/* ─── Sync indicator ─── */
#sync-indicator {
  position: fixed; bottom: 16px; right: 16px;
  background: var(--text); color: #fff;
  border-radius: 20px; padding: 6px 14px; font-size: 0.8rem;
  opacity: 0; transition: opacity 0.3s; pointer-events: none; z-index: 300;
}
#sync-indicator.show { opacity: 1; }

/* ─── Pending dot ─── */
.pending-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: #f5a623; margin-left: 6px; vertical-align: middle;
}
