:root {
  --primary: #b5432a;
  --primary-dark: #8f3220;
  --bg: #faf6f1;
  --card: #ffffff;
  --border: #e6ddd2;
  --text: #2b2118;
  --muted: #7a6f62;
  --warn-bg: #fff4e5;
  --warn-border: #f0b459;
  --err-bg: #fde8e8;
  --err-border: #e05555;
  --ok: #3a8b4f;
  font-family: "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  background: var(--primary);
  color: #fff;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}
.topbar h1 { font-size: 18px; margin: 0; }

.tabs { display: flex; gap: 8px; }
.tab-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}
.tab-btn.active { background: #fff; color: var(--primary-dark); font-weight: 600; }

main { padding: 20px; max-width: 1200px; margin: 0 auto; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.panel-header {
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px;
  margin-bottom: 12px;
}
.panel-header h2 { margin: 0; font-size: 18px; }

.filters { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 14px; }
.filters label { display: flex; align-items: center; gap: 6px; }

input, select, textarea, button {
  font-family: inherit;
  font-size: 14px;
}
input, select, textarea {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  background: #fff;
  color: var(--text);
}
textarea { width: 100%; resize: vertical; }

.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  padding: 7px 14px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text);
}
.btn-ghost:hover { background: #f1ece4; }
.btn-danger { background: #fff; color: var(--err-border); border: 1px solid var(--err-border); border-radius: 6px; padding: 5px 10px; cursor: pointer; }
.btn-small { padding: 4px 10px; font-size: 13px; border-radius: 5px; }

.table-wrap { overflow-x: auto; background: var(--card); border-radius: 8px; border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
th { background: #f3ece2; color: var(--muted); font-weight: 600; }
tr:hover td { background: #fbf7f1; }
tr.clickable { cursor: pointer; }

.hint { color: var(--muted); font-size: 13px; margin: 0 0 10px; }

.warnings { margin-bottom: 14px; }
.warn-item, .err-item {
  padding: 8px 12px; border-radius: 6px; margin-bottom: 6px; font-size: 13.5px;
}
.warn-item { background: var(--warn-bg); border: 1px solid var(--warn-border); }
.err-item { background: var(--err-bg); border: 1px solid var(--err-border); }
.ok-item { background: #eaf6ec; border: 1px solid var(--ok); color: var(--ok); padding: 8px 12px; border-radius: 6px; font-size: 13.5px; }

.monthly-slots { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.slot-card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 14px; }
.slot-card h3 { margin: 0 0 10px; font-size: 15px; }
.slot-item { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px dashed var(--border); font-size: 13.5px; }
.slot-item:last-child { border-bottom: none; }
.tag { display: inline-block; padding: 1px 7px; border-radius: 10px; background: #f1ece4; color: var(--muted); font-size: 11.5px; margin-left: 6px; }
.tag.variant { background: #e3f0e6; color: var(--ok); }
.add-slot-row { display: flex; gap: 6px; margin-top: 10px; }
.add-slot-row select { flex: 1; }

#monthlyCalendar { overflow-x: auto; }
.calendar-table { width: 100%; min-width: 760px; border-collapse: collapse; table-layout: fixed; background: var(--card); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.calendar-table th {
  background: #f3ece2; color: var(--muted); font-weight: 600; font-size: 12.5px;
  padding: 8px 4px; border-bottom: 1px solid var(--border); text-align: center;
}
.calendar-table td { border: 1px solid var(--border); vertical-align: top; padding: 6px; width: 14.28%; }
.cal-cell { cursor: pointer; }
.cal-cell:hover { background: #fbf7f1; }
.cal-empty { background: #faf6f1; }
.cal-date { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.cal-dishes { list-style: none; margin: 4px 0 0; padding: 0; font-size: 11px; color: var(--text); }
.cal-dishes li { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.6; }
.cal-dishes li.hint { color: var(--muted); }

.day-badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 10px; }
.day-badge.ok { background: #eaf6ec; color: var(--ok); }
.day-badge.warn { background: var(--warn-bg); color: #a06a0a; }
.day-badge.empty { background: #f1ece4; color: var(--muted); }

.month-repeat-summary { background: var(--warn-bg); border: 1px solid var(--warn-border); border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; font-size: 13.5px; }
.month-repeat-summary ul { margin: 6px 0 0; padding-left: 20px; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(30,20,10,0.45);
  display: flex; align-items: flex-start; justify-content: center; padding: 30px 16px;
  overflow-y: auto; z-index: 50;
}
.modal-backdrop.hidden { display: none; }
.modal { background: #fff; border-radius: 10px; width: 100%; max-width: 640px; box-shadow: 0 12px 40px rgba(0,0,0,0.25); }
.modal-lg { max-width: 820px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-close { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--muted); }
.modal-body { padding: 18px; max-height: 75vh; overflow-y: auto; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; margin-bottom: 8px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px 12px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13.5px; color: var(--muted); }
label.block { display: flex; flex-direction: column; margin: 10px 0; }
.checkbox-row { display: flex; gap: 18px; flex-wrap: wrap; font-size: 13.5px; }
.checkbox-row label { flex-direction: row; align-items: center; gap: 6px; color: var(--text); }

fieldset { border: 1px solid var(--border); border-radius: 8px; margin: 12px 0; padding: 10px 12px; }
legend { font-size: 13px; color: var(--muted); padding: 0 6px; }

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

.ingredient-row { display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: 8px; margin-bottom: 6px; align-items: center; }

.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 20px; font-size: 13.5px; margin-bottom: 14px; }
.detail-grid div span { color: var(--muted); margin-right: 4px; }

.menu-item-row { display: grid; grid-template-columns: 100px 1fr 100px auto; gap: 8px; align-items: center; margin-bottom: 6px; }
.menu-summary { display: flex; justify-content: space-between; align-items: center; margin: 10px 0; font-weight: 600; }
.menu-summary.over { color: var(--err-border); }

.status-badge { padding: 2px 8px; border-radius: 10px; font-size: 12px; }
.status-pending { background: #f1ece4; color: var(--muted); }
.status-draft { background: var(--warn-bg); color: #a06a0a; }
.status-confirmed { background: #eaf6ec; color: var(--ok); }

.ingredient-table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 13px; }
.ingredient-table th, .ingredient-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #2b2118; color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 13.5px; z-index: 100;
}
.toast.hidden { display: none; }
.toast.error { background: var(--err-border); }

.section-title { font-weight: 600; margin: 14px 0 6px; font-size: 14px; }
