:root {
  --bg: #f4f7f4;
  --surface: #ffffff;
  --primary: #1a472a;
  --primary-light: #2d6a3e;
  --accent: #e8a838;
  --text: #1a1a1a;
  --muted: #666;
  --border: #dde5dd;
  --danger: #c0392b;
  --success: #27ae60;
  --radius: 12px;
  --nav-h: 64px;
  --header-h: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

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

body {
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.5;
}

.hidden { display: none !important; }

.screen { min-height: 100dvh; }

/* Auth */
.auth-card {
  max-width: 400px;
  margin: 0 auto;
  padding: 2rem 1.25rem;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.auth-card h1 { color: var(--primary); font-size: 1.75rem; }
.subtitle { color: var(--muted); margin-bottom: 1.5rem; }

.tabs { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.tab {
  flex: 1;
  padding: 0.6rem;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  cursor: pointer;
}
.tab.active { background: var(--primary); color: white; border-color: var(--primary); }

.auth-form label, .card label {
  display: block;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
  font-weight: 500;
}

.auth-form input, .card input, .card select, .card textarea,
.toolbar input, dialog input {
  width: 100%;
  padding: 0.65rem 0.75rem;
  margin-top: 0.25rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
}

.invite-box { margin-top: 1.5rem; font-size: 0.9rem; }
.invite-box form { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.invite-box input { flex: 1; }

.error-msg { color: var(--danger); margin-top: 0.75rem; font-size: 0.9rem; }
.status-msg { color: var(--muted); font-size: 0.85rem; margin-top: 0.75rem; text-align: center; }

/* Main layout */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  height: var(--header-h);
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
}

.app-header h1 { font-size: 1.1rem; font-weight: 600; }

.view {
  padding: 1rem;
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 1rem);
  max-width: 720px;
  margin: 0 auto;
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 20;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: none;
  background: none;
  font-size: 0.65rem;
  color: var(--muted);
  cursor: pointer;
  padding: 0.25rem;
}
.nav-btn span { font-size: 0.65rem; }
.nav-btn.active { color: var(--primary); font-weight: 600; }

/* Cards & buttons */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.card h2 { font-size: 1rem; color: var(--primary); margin-bottom: 0.75rem; }

.btn {
  padding: 0.65rem 1rem;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  cursor: pointer;
  font-weight: 500;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:active { background: var(--primary-light); }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-lg { width: 100%; padding: 0.85rem; font-size: 1rem; margin-top: 0.5rem; }
.btn-icon { background: none; border: none; color: white; font-size: 1.2rem; cursor: pointer; padding: 0.5rem; }

.toolbar { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.toolbar input { flex: 1; }
.toolbar-bottom { display: flex; gap: 0.5rem; margin-top: 1rem; flex-wrap: wrap; }
.toolbar-bottom .btn { flex: 1; min-width: 140px; }

.week-display { font-size: 1.25rem; font-weight: 600; }
.week-display span { display: block; }
#month-label { font-size: 0.9rem; color: var(--muted); font-weight: 400; }

/* Preset chips */
.chips { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.75rem; }
.chip {
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.85rem;
  cursor: pointer;
}
.chip.selected { background: var(--primary); color: white; border-color: var(--primary); }

.field-label textarea { resize: vertical; min-height: 72px; }

/* Inventory */
.category-block { margin-bottom: 1.25rem; }
.category-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 0.5rem;
  padding-bottom: 0.25rem;
  border-bottom: 2px solid var(--accent);
}

.product-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 0.35rem;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.product-row input[type="text"],
.product-row input[type="number"] {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  width: 100%;
}

.product-row .qty-input { width: 56px; text-align: center; }
.product-row .unit-input { width: 72px; }
.product-row .btn-delete {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.25rem;
}

.product-name { position: relative; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.product-name:hover .tooltip {
  visibility: visible;
  opacity: 1;
}

.tooltip {
  visibility: hidden;
  opacity: 0;
  position: absolute;
  left: 0;
  top: 100%;
  background: #333;
  color: white;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  font-size: 0.8rem;
  z-index: 5;
  white-space: normal;
  max-width: 240px;
  transition: opacity 0.2s;
}

/* Menu table */
.menu-table-wrap { overflow-x: auto; margin: 1rem 0; }
.menu-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.menu-table th, .menu-table td {
  border: 1px solid var(--border);
  padding: 0.5rem;
  vertical-align: top;
}
.menu-table th { background: var(--primary); color: white; }
.menu-table td[contenteditable="true"]:focus {
  outline: 2px solid var(--accent);
  background: #fffde7;
}

.menu-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; }
.menu-actions .btn { flex: 1; min-width: 140px; }

.menu-section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}
.menu-section h3 { font-size: 0.95rem; color: var(--primary); margin-bottom: 0.5rem; }
.menu-section pre {
  white-space: pre-wrap;
  font-family: inherit;
  font-size: 0.85rem;
  line-height: 1.6;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 2rem 1rem;
}

.menu-actions-bar { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.75rem; }

/* Cookidoo dialog */
dialog {
  border: none;
  border-radius: var(--radius);
  padding: 1.25rem;
  max-width: 520px;
  width: calc(100% - 2rem);
  max-height: 85dvh;
  overflow-y: auto;
}
dialog::backdrop { background: rgba(0,0,0,0.4); }
dialog h2 { font-size: 1.1rem; margin-bottom: 1rem; color: var(--primary); }

.cookidoo-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  margin-bottom: 0.75rem;
}
.cookidoo-item h4 { font-size: 0.9rem; margin-bottom: 0.5rem; }
.cookidoo-option {
  display: block;
  padding: 0.35rem 0;
  font-size: 0.85rem;
  cursor: pointer;
}
.cookidoo-option input { margin-right: 0.5rem; }

.dialog-actions { display: flex; gap: 0.5rem; margin-top: 1rem; }
.dialog-actions .btn { flex: 1; }

/* Scale table */
.scale-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; margin-top: 0.5rem; }
.scale-table th, .scale-table td { border: 1px solid var(--border); padding: 0.4rem; }
.scale-table th { background: #eee; }

/* Loading & toast */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 1rem);
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: white;
  padding: 0.65rem 1.25rem;
  border-radius: 999px;
  font-size: 0.9rem;
  z-index: 50;
  max-width: 90%;
  text-align: center;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

code {
  background: #eee;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.85rem;
}

@media (min-width: 600px) {
  .product-row { grid-template-columns: 2fr 80px 80px auto auto; }
}
