/* ============================================================
   style.css — Планировщик питания
   Палитра: тёплый молочный фон, зелёный акцент, шрифт-пара
   Nunito (UI) + Georgia (заголовки)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;500;600;700&display=swap');

/* ---------- Токены ---------- */
:root {
  --bg:          #F7F5F0;       /* молочный */
  --surface:     #FFFFFF;
  --surface-2:   #F0EDE6;
  --border:      #E2DDD6;
  --border-focus:#4A7C59;

  --green:       #4A7C59;       /* акцент — лесной зелёный */
  --green-light: #E8F2EC;
  --green-dark:  #345940;

  --amber:       #D4845A;       /* предупреждение / мало белка */
  --red:         #C0392B;

  --text:        #1E1C18;
  --text-2:      #5A5550;
  --text-3:      #9A958E;

  --radius-sm:   6px;
  --radius:      12px;
  --radius-lg:   18px;

  --shadow-sm:   0 1px 3px rgba(0,0,0,.08);
  --shadow:      0 4px 16px rgba(0,0,0,.10);
  --shadow-lg:   0 12px 40px rgba(0,0,0,.16);

  --font:        'Nunito', system-ui, sans-serif;
  --font-serif:  Georgia, 'Times New Roman', serif;

  --transition:  .18s ease;
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
}
button { cursor: pointer; font-family: var(--font); }
input, textarea, select { font-family: var(--font); font-size: 1rem; }
img { max-width: 100%; display: block; }

/* ---------- Header ---------- */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
  box-shadow: var(--shadow-sm);
}
.header-inner {
  max-width: 1200px; margin: 0 auto;
  padding: 14px 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.header-brand { display: flex; align-items: center; gap: 12px; }
.header-icon { font-size: 2rem; line-height: 1; }
.header-brand h1 {
  font-family: var(--font-serif);
  font-size: 1.45rem; font-weight: normal;
  letter-spacing: -.3px;
}
.header-sub { font-size: .78rem; color: var(--text-3); margin-top: 1px; }
.header-actions { display: flex; align-items: center; gap: 12px; }

/* ---------- Week Tabs ---------- */
.week-tabs {
  display: flex; background: var(--surface-2); border-radius: var(--radius-sm);
  padding: 3px;
}
.week-tab {
  background: none; border: none;
  padding: 6px 18px; border-radius: var(--radius-sm);
  font-size: .875rem; font-weight: 600; color: var(--text-2);
  transition: background var(--transition), color var(--transition);
}
.week-tab.active {
  background: var(--surface);
  color: var(--green);
  box-shadow: var(--shadow-sm);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 18px; border-radius: var(--radius-sm);
  font-size: .875rem; font-weight: 600; border: none;
  transition: background var(--transition), color var(--transition), transform .1s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-dark); }
.btn-secondary {
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); }
.btn-ghost { background: none; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--red); color: #fff; }
.btn-icon {
  background: none; border: none;
  padding: 4px 6px; border-radius: var(--radius-sm);
  color: var(--text-3); font-size: .9rem;
}
.btn-icon:hover { background: var(--surface-2); color: var(--red); }

/* ---------- Main ---------- */
.app-main {
  max-width: 1200px; margin: 0 auto; padding: 24px;
}

/* ---------- Week Summary ---------- */
.week-summary {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 24px;
  margin-bottom: 20px;
  display: flex; align-items: center; gap: 32px; flex-wrap: wrap;
}
.summary-item { display: flex; flex-direction: column; }
.summary-label { font-size: .75rem; color: var(--text-3); text-transform: uppercase; letter-spacing: .06em; }
.summary-value { font-size: 1.3rem; font-weight: 700; color: var(--green); margin-top: 2px; }
.summary-value.muted { color: var(--text-2); }
.summary-progress {
  flex: 1; min-width: 160px;
  display: flex; align-items: center; gap: 10px;
}
.progress-bar {
  flex: 1; height: 8px; background: var(--surface-2);
  border-radius: 99px; overflow: hidden;
}
.progress-fill {
  height: 100%; background: var(--green);
  border-radius: 99px; transition: width .4s ease;
}
.progress-pct { font-size: .85rem; font-weight: 700; color: var(--green); min-width: 40px; }

/* ---------- Plan Table ---------- */
.plan-table-wrap { overflow-x: auto; border-radius: var(--radius); }
.plan-table {
  width: 100%; border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--border);
}
.plan-table thead tr { background: var(--surface-2); }
.plan-table th {
  padding: 12px 16px; text-align: left;
  font-size: .75rem; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-2); font-weight: 700;
  border-bottom: 1px solid var(--border);
}
.col-day { width: 110px; }
.col-meal { /* flex остальное */ }
.col-protein { width: 90px; text-align: right; }

.plan-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.plan-table tbody tr:last-child { border-bottom: none; }
.plan-table tbody tr:hover { background: var(--surface-2); }

.cell-day {
  padding: 12px 16px;
  font-weight: 700; font-size: .9rem;
}
.cell-day .day-num {
  font-size: .72rem; color: var(--text-3);
  font-weight: 400; margin-top: 2px;
}

.cell-meal {
  padding: 8px 10px;
  border-left: 1px solid var(--border);
  vertical-align: top;
}

/* Слот приёма пищи */
.slot {
  min-height: 64px; border-radius: var(--radius-sm);
  border: 1.5px dashed var(--border);
  padding: 8px 10px; cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  position: relative;
}
.slot:hover { border-color: var(--green); background: var(--green-light); }
.slot.filled {
  border-style: solid; border-color: var(--border);
  background: var(--surface);
}
.slot.filled:hover { border-color: var(--green); }

.slot-empty-hint {
  display: flex; align-items: center; justify-content: center;
  height: 100%; min-height: 48px;
  color: var(--text-3); font-size: .78rem;
}

.slot-dish {
  display: flex; align-items: center; gap: 8px;
}
.slot-dish-img {
  width: 40px; height: 40px; border-radius: 6px;
  object-fit: cover; flex-shrink: 0;
}
.slot-dish-img-placeholder {
  width: 40px; height: 40px; border-radius: 6px;
  background: var(--surface-2); display: flex; align-items: center;
  justify-content: center; font-size: 1.2rem; flex-shrink: 0;
}
.slot-dish-info { min-width: 0; }
.slot-dish-name {
  font-size: .82rem; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.slot-dish-protein { font-size: .72rem; color: var(--text-3); margin-top: 1px; }

.slot-note {
  font-size: .82rem; color: var(--text-2); font-style: italic;
  padding: 4px 0;
}

.cell-protein {
  padding: 12px 16px; text-align: right;
  font-weight: 700; font-size: .92rem;
  border-left: 1px solid var(--border);
  vertical-align: middle;
}
.protein-ok { color: var(--green); }
.protein-warn { color: var(--amber); }
.protein-none { color: var(--text-3); }

/* ---------- Modals ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  animation: fade-in .15s ease;
}
.modal-overlay[hidden] { display: none; }

@keyframes fade-in { from { opacity: 0; } }

.modal {
  background: var(--surface); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 540px;
  max-height: 90vh; overflow-y: auto;
  animation: slide-up .2s ease;
}
.modal-wide { max-width: 800px; }

@keyframes slide-up {
  from { opacity: 0; transform: translateY(20px); }
}

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.modal-header h2 {
  font-family: var(--font-serif); font-size: 1.3rem; font-weight: normal;
}
.modal-close {
  background: var(--surface-2); border: none;
  width: 32px; height: 32px; border-radius: 50%;
  font-size: 1rem; color: var(--text-2);
  display: flex; align-items: center; justify-content: center;
  transition: background var(--transition);
}
.modal-close:hover { background: var(--border); }

.modal-body { padding: 20px 24px 24px; }

/* ---------- Dish picker modal ---------- */
.search-row {
  display: flex; gap: 10px; margin-bottom: 16px;
}
.search-row input {
  flex: 1; padding: 9px 14px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); outline: none;
  transition: border-color var(--transition);
}
.search-row input:focus { border-color: var(--border-focus); }

.dish-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px; margin-bottom: 24px;
  max-height: 320px; overflow-y: auto;
}
.dish-card {
  border: 1.5px solid var(--border); border-radius: var(--radius);
  overflow: hidden; cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition), transform .12s;
  background: var(--surface);
}
.dish-card:hover {
  border-color: var(--green); box-shadow: var(--shadow);
  transform: translateY(-2px);
}
.dish-card-img {
  width: 100%; aspect-ratio: 4/3; object-fit: cover;
  background: var(--surface-2);
}
.dish-card-img-placeholder {
  width: 100%; aspect-ratio: 4/3;
  background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
  font-size: 2rem;
}
.dish-card-info { padding: 8px 10px 10px; }
.dish-card-name {
  font-size: .82rem; font-weight: 700; line-height: 1.3;
}
.dish-card-protein {
  font-size: .72rem; color: var(--green); margin-top: 3px; font-weight: 600;
}

/* ---------- Note section ---------- */
.note-section {
  border-top: 1px solid var(--border); padding-top: 16px;
  display: flex; flex-direction: column; gap: 8px;
}
.note-label { font-size: .82rem; color: var(--text-2); font-weight: 600; }
.note-section textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); resize: vertical; outline: none;
  transition: border-color var(--transition);
}
.note-section textarea:focus { border-color: var(--border-focus); }

/* ---------- Dish library list ---------- */
.toolbar {
  display: flex; gap: 10px; margin-bottom: 16px;
}
.toolbar input {
  flex: 1; padding: 9px 14px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); outline: none;
}
.toolbar input:focus { border-color: var(--border-focus); }

.dish-list {
  display: flex; flex-direction: column; gap: 8px;
  max-height: 500px; overflow-y: auto;
}
.dish-list-item {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface);
  transition: background var(--transition);
}
.dish-list-item:hover { background: var(--surface-2); }
.dish-list-img {
  width: 48px; height: 48px; border-radius: 8px;
  object-fit: cover; flex-shrink: 0; background: var(--surface-2);
}
.dish-list-img-placeholder {
  width: 48px; height: 48px; border-radius: 8px;
  background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; flex-shrink: 0;
}
.dish-list-info { flex: 1; min-width: 0; }
.dish-list-name { font-weight: 700; font-size: .92rem; }
.dish-list-protein { font-size: .78rem; color: var(--green); margin-top: 2px; }
.dish-list-actions { display: flex; gap: 6px; }

/* ---------- Dish form ---------- */
.dish-form { display: flex; flex-direction: column; gap: 16px; }
.form-row { display: flex; flex-direction: column; gap: 6px; }
.form-row label { font-size: .82rem; font-weight: 600; color: var(--text-2); }
.form-row input[type="text"],
.form-row textarea,
.form-row input[type="number"] {
  padding: 9px 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); outline: none; width: 100%;
  transition: border-color var(--transition);
}
.form-row input:focus, .form-row textarea:focus { border-color: var(--border-focus); }
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.image-preview-wrap { margin-top: 8px; }
.image-preview-wrap img {
  width: 100%; max-height: 180px; object-fit: cover;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
}

/* ---------- Ingredients section ---------- */
.ing-section { display: flex; flex-direction: column; gap: 12px; }
.ing-header {
  display: flex; align-items: center; justify-content: space-between;
}
.ing-header h3 { font-size: 1rem; font-weight: 700; }
.protein-badge {
  background: var(--green-light); color: var(--green);
  font-weight: 700; font-size: .82rem;
  padding: 4px 10px; border-radius: 99px;
}
.ing-add-row {
  display: flex; gap: 8px; align-items: flex-start; position: relative;
}
.ing-add-row input[type="text"] {
  flex: 1; padding: 9px 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); outline: none;
}
.ing-add-row input[type="text"]:focus { border-color: var(--border-focus); }
.ing-add-row input[type="number"] {
  padding: 9px 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); outline: none;
}

/* Выпадашка ингредиентов */
.ing-dropdown {
  position: absolute; top: 100%; left: 0;
  width: calc(100% - 8px - 80px - 8px - 90px);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow);
  z-index: 50; max-height: 200px; overflow-y: auto;
}
.ing-dropdown[hidden] { display: none; }
.ing-dropdown-item {
  padding: 9px 14px; cursor: pointer; font-size: .88rem;
  transition: background var(--transition);
  display: flex; justify-content: space-between; align-items: center;
}
.ing-dropdown-item:hover { background: var(--surface-2); }
.ing-dropdown-item span { font-size: .74rem; color: var(--text-3); }

.ing-table { width: 100%; border-collapse: collapse; }
.ing-table th {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-3); padding: 6px 8px; text-align: left;
  border-bottom: 1px solid var(--border);
}
.ing-table td {
  padding: 7px 8px; font-size: .86rem;
  border-bottom: 1px solid var(--border);
}
.ing-table tbody tr:last-child td { border-bottom: none; }

.form-actions {
  display: flex; gap: 10px; justify-content: flex-end;
  padding-top: 8px; border-top: 1px solid var(--border);
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff;
  padding: 12px 22px; border-radius: 99px;
  font-size: .88rem; font-weight: 600;
  box-shadow: var(--shadow-lg); z-index: 9999;
  animation: toast-in .2s ease;
  white-space: nowrap;
}
.toast[hidden] { display: none; }
.toast.error { background: var(--red); }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(12px); }
}

/* ---------- Empty / Loading states ---------- */
.empty-state {
  text-align: center; padding: 48px 24px;
  color: var(--text-3); font-size: .92rem;
}
.empty-state p { margin-top: 8px; }
.spinner {
  text-align: center; padding: 24px;
  color: var(--text-3); font-size: .9rem;
}

/* ---------- Responsive ---------- */
@media (max-width: 700px) {
  .header-inner { flex-direction: column; align-items: flex-start; gap: 10px; }
  .app-main { padding: 16px; }
  .week-summary { gap: 16px; }
  .plan-table th, .plan-table td { font-size: .8rem; }
  .form-row-2 { grid-template-columns: 1fr; }
  .modal-wide { max-width: 100%; }
  .dish-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
}
