/* Raphael Menu Mini App — styles.
 *
 * Colors follow Telegram's Web App theme variables so the app switches to
 * dark mode when the user's Telegram client is dark. Falls back to a warm
 * neutral palette when the SDK isn't initialized.
 */

:root {
  --bg: var(--tg-theme-bg-color, #f7f5f1);
  --surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #222);
  --hint: var(--tg-theme-hint-color, #888);
  --link: var(--tg-theme-link-color, #2d7cf0);
  --accent: var(--tg-theme-button-color, #2d7cf0);
  --accent-text: var(--tg-theme-button-text-color, #fff);
  --ok: #2e8b57;
  --warn: #d27b00;
  --error: #b94a3c;
  --border: rgba(0, 0, 0, 0.08);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

[data-theme="dark"] {
  --border: rgba(255, 255, 255, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-left { display: flex; align-items: baseline; gap: 12px; }
.topbar-right { display: flex; gap: 6px; }
.week { color: var(--hint); font-size: 13px; }

.banner {
  padding: 8px 16px;
  font-size: 13px;
  color: var(--hint);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.banner.constraint { padding: 6px 16px; }
.constraint-line { font-size: 12px; }

/* Panels layout */
.panels {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 0;
  min-height: 0;
}
.panels.single-col {
  grid-template-columns: 1fr;
}

/* Library panel */
.library {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 56px);
  overflow: hidden;
}
.library.collapsed .library-body { display: none; }
.library-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.library-header h2 { margin: 0; font-size: 15px; }
.library-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px;
}
.search {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  margin-bottom: 8px;
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}
.chip {
  padding: 4px 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
}
.chip.active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

/* Dish cards */
.dish-list { display: flex; flex-direction: column; gap: 6px; }
.dish-card {
  display: flex;
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, opacity 0.15s;
}
.dish-card:hover { border-color: var(--accent); }
.dish-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(45, 124, 240, 0.15);
}
.dish-card.assigned { opacity: 0.55; }
.dish-thumb {
  width: 44px; height: 44px;
  border-radius: 6px;
  background: var(--border) center / cover no-repeat;
  flex-shrink: 0;
}
.dish-meta { flex: 1; min-width: 0; }
.dish-name { font-size: 14px; font-weight: 600; }
.dish-sub { font-size: 12px; color: var(--hint); }
.dish-hearts { display: flex; gap: 4px; margin-top: 2px; }
.heart {
  display: inline-flex;
  align-items: center; justify-content: center;
  width: 18px; height: 18px;
  border-radius: 9px;
  background: var(--border);
  color: var(--hint);
  font-size: 10px;
  font-weight: 700;
}
.heart.on {
  background: #ffd1d1;
  color: #b94a3c;
}
.empty { color: var(--hint); font-size: 13px; padding: 12px 4px; }

/* Grid panel */
.grid {
  padding: 12px;
  overflow: auto;
}
.grid table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 4px;
  table-layout: fixed;
}
.grid col.col-slot { width: 72px; }
.grid col.col-day  { width: auto; }
.grid th,
.grid td {
  word-break: break-word;
}
.grid th {
  font-weight: 500;
  font-size: 12px;
  color: var(--hint);
  padding: 4px 2px;
  text-align: center;
}
.grid th.slot-label {
  text-align: right;
  font-weight: 600;
  color: var(--text);
  min-width: 72px;
}
.slot-cell {
  min-height: 64px;
  padding: 8px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: var(--surface);
  vertical-align: top;
  cursor: pointer;
  position: relative;
  font-size: 12px;
  text-align: center;
  transition: background 0.12s, border-color 0.12s;
}
.slot-cell.hot { border-color: var(--accent); border-style: solid; }
.slot-cell.filled {
  border-style: solid;
  background: var(--bg);
}
.slot-dish {
  display: block;
  line-height: 1.3;
}
.clear {
  position: absolute;
  top: 2px; right: 6px;
  font-size: 16px;
  color: var(--hint);
  opacity: 0.7;
}
.clear:hover { opacity: 1; color: var(--error); }

/* Actions row */
.actions {
  display: flex;
  gap: 10px;
  padding: 16px 4px;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.readonly-note {
  padding: 16px 4px;
  color: var(--hint);
  text-align: right;
  font-size: 13px;
}
button {
  font: inherit;
  cursor: pointer;
}
button.primary {
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 600;
}
button.secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 500;
}
button.ghost {
  background: transparent;
  border: none;
  color: var(--text);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 14px;
}
button.ghost:hover { background: var(--border); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.collapse-btn {
  font-size: 13px;
  padding: 2px 8px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 80px;
  transform: translateX(-50%);
  padding: 10px 14px;
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  border-radius: 8px;
  font-size: 13px;
  z-index: 100;
}

/* Responsive — on narrow screens stack library above grid */
@media (max-width: 720px) {
  .panels { grid-template-columns: 1fr; }
  .library { max-height: none; border-right: none; border-bottom: 1px solid var(--border); }
  .grid { padding: 10px 8px; }
  .slot-cell { min-height: 56px; padding: 6px; font-size: 11px; }
}
