/* ============================================
   Meal Planner — Mobile-first
   ============================================ */

:root {
  --bg: #f5f7f5;
  --bg-elevated: #ffffff;
  --text: #14261a;
  --text-muted: #64756a;
  --border: #e3e8e3;

  --primary: #16a34a;
  --primary-hover: #15803d;
  --primary-soft: #dcfce7;
  --primary-text: #14532d;

  --danger: #dc2626;
  --danger-hover: #b91c1c;

  --shadow-sm: 0 1px 2px rgba(20, 38, 26, 0.06);
  --shadow-md: 0 4px 12px rgba(20, 38, 26, 0.08);
  --shadow-lg: 0 12px 32px rgba(20, 38, 26, 0.12);

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;

  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

  --safe-top: env(safe-area-inset-top, 0);
  --safe-bottom: env(safe-area-inset-bottom, 0);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1512;
    --bg-elevated: #1a231e;
    --text: #e7efe9;
    --text-muted: #8fa396;
    --border: #2a3831;

    --primary: #22c55e;
    --primary-hover: #16a34a;
    --primary-soft: #14321f;
    --primary-text: #86efac;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
  }
}

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

html, body {
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  overscroll-behavior-y: none;
}

img, svg { max-width: 100%; display: block; }

/* ============================================
   AUTH (вход)
   ============================================ */

.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  padding-top: calc(20px + var(--safe-top));
  padding-bottom: calc(20px + var(--safe-bottom));
  background:
    radial-gradient(circle at 20% 20%, rgba(34, 197, 94, 0.10), transparent 45%),
    radial-gradient(circle at 80% 80%, rgba(245, 158, 11, 0.10), transparent 45%),
    var(--bg);
}

.card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 24px;
  box-shadow: var(--shadow-lg);
  animation: cardIn 0.4s ease-out;
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.card .logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
}

.card .logo-emoji { font-size: 30px; line-height: 1; }

.card h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.card h2 {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.card form { display: flex; flex-direction: column; gap: 12px; }

input, select, textarea {
  width: 100%;
  padding: 14px 16px;
  font-family: inherit;
  font-size: 16px; /* 16px — важно для iOS, чтобы не зумило */
  color: var(--text);
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-soft);
  background: var(--bg-elevated);
}

input::placeholder, textarea::placeholder { color: var(--text-muted); }

button {
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  padding: 14px 20px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
  box-shadow: var(--shadow-sm);
  user-select: none;
  -webkit-user-select: none;
}
button:hover { background: var(--primary-hover); box-shadow: var(--shadow-md); }
button:active { transform: scale(0.98); }

.btn-primary { background: var(--primary); color: #fff; }
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1.5px solid var(--border);
  box-shadow: none;
  font-weight: 500;
}
.btn-ghost:hover { background: var(--bg); color: var(--danger); border-color: var(--danger); box-shadow: none; }

.btn-danger { background: var(--danger); }
.btn-danger:hover { background: var(--danger-hover); }

.msg {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  font-size: 14px;
  margin-bottom: 16px;
  border: 1px solid transparent;
}
.msg.ok { background: var(--primary-soft); color: var(--primary-text); border-color: rgba(34, 197, 94, 0.3); }
.msg.err { background: rgba(220, 38, 38, 0.08); color: var(--danger); border-color: rgba(220, 38, 38, 0.25); }

.muted { color: var(--text-muted); }
.center { text-align: center; }

a { color: var(--primary); text-decoration: none; font-weight: 500; }
a:hover { text-decoration: underline; }

/* ============================================
   APP HEADER (липкий топбар)
   ============================================ */

.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg-elevated) 85%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
  padding-top: var(--safe-top);
}

.app-header-inner {
  max-width: 980px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.app-header .brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.app-header .brand-emoji { font-size: 22px; }

.header-btn {
  width: 40px;
  height: 40px;
  padding: 0 !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  background: transparent;
  border: 1.5px solid var(--border);
  border-radius: 50%;
  box-shadow: none;
}
.header-btn:hover {
  background: rgba(220, 38, 38, 0.06);
  color: var(--danger);
  border-color: var(--danger);
  box-shadow: none;
}

/* ============================================
   MAIN
   ============================================ */

.app-main {
  max-width: 980px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: calc(40px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.section {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.section-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  letter-spacing: -0.01em;
}

/* ============================================
   FAMILY CARD + TABS
   ============================================ */

.family-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.family-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--primary-soft);
  color: var(--primary-text);
  border-radius: 100px;
  font-size: 13px;
  font-weight: 600;
}
.chip-lg { font-size: 14px; padding: 8px 14px; }

.tabs {
  display: flex;
  gap: 6px;
  background: var(--bg);
  padding: 4px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  flex: 1 0 auto;
  padding: 10px 14px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: calc(var(--radius-md) - 4px);
  cursor: pointer;
  box-shadow: none;
  transition: all 0.15s;
  white-space: nowrap;
  text-align: center;
  min-height: 42px;
}
.tab:hover { background: var(--bg-elevated); color: var(--text); box-shadow: none; }
.tab.active {
  background: var(--bg-elevated);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

/* ============================================
   MEMBER BLOCK
   ============================================ */

.member-block { margin-bottom: 20px; }
.member-block:last-child { margin-bottom: 0; }

.member-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 700;
  color: var(--primary);
  padding-bottom: 10px;
  margin-bottom: 12px;
  border-bottom: 1.5px solid var(--border);
}

.member-title .role {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 100px;
}

/* ============================================
   DAY (аккордеон)
   ============================================ */

.day {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  overflow: hidden;
  transition: border-color 0.15s;
}
.day[open] { border-color: var(--primary); }
.day:last-child { margin-bottom: 0; }

.day-summary {
  list-style: none;
  cursor: pointer;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  user-select: none;
  min-height: 52px;
}
.day-summary::-webkit-details-marker { display: none; }
.day-summary::marker { content: ""; }

.day-num { display: flex; align-items: center; gap: 8px; }
.day-num::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--primary);
}

.chev {
  color: var(--text-muted);
  transition: transform 0.2s;
  font-size: 12px;
}
.day[open] .chev { transform: rotate(180deg); }

.day-body { padding: 0 16px 14px; }

/* ============================================
   MEAL ROW
   ============================================ */

.meal-row {
  padding: 12px 0;
  border-top: 1px dashed var(--border);
}
.meal-row:first-child { border-top: none; padding-top: 0; }

.meal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.meal-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.meal-actions { display: flex; gap: 4px; flex-shrink: 0; }

.icon-btn {
  width: 36px;
  height: 36px;
  padding: 0 !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 400;
  box-shadow: none;
  cursor: pointer;
  transition: all 0.15s;
  margin: 0;
}
.icon-btn:hover {
  background: var(--primary-soft);
  color: var(--primary-text);
  box-shadow: none;
}
.icon-btn.delete:hover {
  background: rgba(220, 38, 38, 0.1);
  color: var(--danger);
}

.meal-text {
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  word-break: break-word;
}

/* ============================================
   COMMENTS
   ============================================ */

.comments-inline {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.comment-item {
  background: var(--bg-elevated);
  border-left: 3px solid var(--primary);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  position: relative;
}

.comment-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 11.5px;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.comment-author { font-weight: 600; color: var(--primary-text); }
.comment-body { line-height: 1.45; word-break: break-word; }

.comment-list {
  max-height: 40vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 2px;
  -webkit-overflow-scrolling: touch;
}
.comment-list .comment-item { padding-right: 44px; }
.comment-list .icon-btn.delete {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 32px;
  height: 32px;
}

/* ============================================
   SHOPPING LIST
   ============================================ */

.shopping-list {
  list-style: none;
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.shopping-list li {
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  transition: all 0.15s;
}
.shopping-list li:active {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.shopping-list li::before {
  content: '🛒';
  font-size: 15px;
  flex-shrink: 0;
}

/* ============================================
   SHEET (модалки снизу)
   ============================================ */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 20, 15, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s, visibility 0.25s;
  z-index: 100;
  padding: 0;
}

@media (min-width: 640px) {
  .sheet-backdrop { align-items: center; padding: 20px; }
}

.sheet-backdrop.show { opacity: 1; visibility: visible; }

.sheet {
  background: var(--bg-elevated);
  border-radius: 20px 20px 0 0;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  padding: 8px 20px calc(20px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  max-height: 92vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

@media (min-width: 640px) {
  .sheet {
    border-radius: var(--radius-lg);
    padding: 24px;
    transform: translateY(16px) scale(0.98);
    transition: opacity 0.2s, transform 0.2s;
    opacity: 0;
  }
  .sheet-backdrop.show .sheet {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

.sheet-backdrop.show .sheet { transform: translateY(0); }

.sheet-handle {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 6px auto 8px;
}
@media (min-width: 640px) { .sheet-handle { display: none; } }

.sheet h3 {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
  color: var(--text);
}

.sheet textarea {
  min-height: 100px;
  resize: vertical;
  font-size: 16px;
  line-height: 1.5;
}

.sheet-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
  padding-top: 4px;
}
.sheet-actions button { flex: 1 1 auto; min-height: 46px; }

/* ============================================
   TOAST
   ============================================ */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--bg-elevated);
  padding: 12px 20px;
  border-radius: 100px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  visibility: hidden;
  transition: all 0.25s;
  z-index: 200;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.show {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}
.toast.ok { background: var(--primary); color: #fff; }
.toast.err { background: var(--danger); color: #fff; }

/* ============================================
   SKELETON
   ============================================ */

.skeleton {
  background: linear-gradient(90deg, var(--border) 25%, var(--bg) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--radius-sm);
  height: 16px;
  margin: 8px 0;
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ============================================
   FADE-IN
   ============================================ */

.fade-in { animation: fadeIn 0.3s ease-out; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================
   DESKTOP: улучшения (≥ 768px)
   ============================================ */

@media (min-width: 768px) {
  .app-main { padding: 24px; gap: 20px; }
  .section { padding: 24px; }
  .family-card { padding: 20px 24px; }
  .tabs { padding: 5px; }
  .tab { padding: 10px 20px; font-size: 14px; }

  .shopping-list { grid-template-columns: repeat(2, 1fr); }
  .day-body { padding: 0 20px 18px; }
  .meal-row { padding: 14px 0; }
  .meal-label { font-size: 12.5px; }
  .meal-text { font-size: 14.5px; }
}

@media (min-width: 1024px) {
  .shopping-list { grid-template-columns: repeat(3, 1fr); }
}

/* ============================================
   iOS: избегаем авто-зума и подгоняем шрифты
   ============================================ */

@supports (-webkit-touch-callout: none) {
  input, textarea, select {
    font-size: 16px;
  }
}

/* Landscape на телефоне */
@media (max-height: 500px) and (orientation: landscape) {
  .sheet { max-height: 85vh; }
  .auth-wrap { padding: 12px; }
  .card { padding: 24px 20px; }
}

