:root {
  --bg: #f4f6f2;
  --ink: #1f2a24;
  --muted: #68756c;
  --line: #d8ded5;
  --panel: #ffffff;
  --green: #18864b;
  --yellow: #b7791f;
  --red: #c2413a;
  --blue: #2f6f9f;
  --head: #c95b0b;
  --sticky-top: 86px;
  --table-head-gap: 16px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: "Segoe UI", "Malgun Gothic", system-ui, sans-serif; }
header {
  background: #fff;
  border-bottom: 1px solid var(--line);
  padding: 14px clamp(14px, 3vw, 34px);
  position: sticky;
  top: 0;
  z-index: 200;
}
.topbar { display: grid; grid-template-columns: minmax(0, 1fr) minmax(260px, 420px); gap: 18px; align-items: center; }
.brand { min-width: 0; }
.brand-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.traffic-light-logo {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 9px;
  border: 2px solid #1f2a24;
  border-radius: 999px;
  background: #ffffff;
  box-shadow: 0 2px 5px rgba(31,42,36,0.16);
  line-height: 1;
}
.traffic-light-logo .lamp {
  width: 18px;
  height: 18px;
  display: inline-block;
  border: 2px solid #1f2a24;
  border-radius: 50%;
}
.traffic-light-logo .lamp.red { background: #e84c3d; }
.traffic-light-logo .lamp.yellow { background: #f2c230; }
.traffic-light-logo .lamp.blue { background: #2f8fd8; }
h1 { margin: 0; font-size: 28px; }
h2 { margin: 0 0 12px; font-size: 20px; }
.sub { margin-top: 6px; color: var(--muted); }
.section-desc { margin: -4px 0 12px; color: var(--muted); font-size: 13px; line-height: 1.5; white-space: pre-line; }
.section-desc:empty { display: none; }

/* 인쇄/PDF 요일 선택 모달 */
.print-modal { position: fixed; inset: 0; background: rgba(31,42,36,0.4); display: none; align-items: center; justify-content: center; z-index: 600; }
.print-modal.open { display: flex; }
.print-modal-box { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 20px 22px; width: min(380px, 92vw); box-shadow: 0 14px 34px rgba(31,42,36,0.22); }
.print-modal-box h3 { margin: 0 0 12px; font-size: 17px; }
.print-select-all { display: flex; align-items: center; gap: 6px; font-weight: 700; margin-bottom: 8px; }
.print-days { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 6px 0 4px; }
.print-days label { display: flex; align-items: center; gap: 5px; font-size: 14px; color: var(--ink); }
.print-msg { min-height: 18px; margin: 6px 0 0; color: var(--red); font-size: 13px; }
.print-modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

/* 인쇄용 렌더 영역: 화면에서는 숨기고 인쇄 시에만 표시 */
#printArea { display: none; }
.print-doc { color: #000; }
.print-title { font-size: 20px; margin: 0 0 4px; }
.print-meta, .print-profile, .print-weekly { font-size: 12px; margin: 2px 0; line-height: 1.5; }
.print-weekly { font-weight: 700; }
.print-day { margin-top: 14px; page-break-inside: avoid; }
.print-day h2 { font-size: 15px; margin: 0 0 6px; padding-bottom: 3px; border-bottom: 1.5px solid #000; }
.print-table { width: 100%; border-collapse: collapse; }
.print-table th, .print-table td { border: 1px solid #999; padding: 4px 6px; font-size: 11px; text-align: left; vertical-align: top; }
.print-table th { background: #eee; }
.print-day-summary { margin-top: 5px; font-size: 12px; font-weight: 700; }
.print-note { margin-top: 16px; font-size: 11px; color: #333; }

@media print {
  header, #toast, main, .print-modal { display: none !important; }
  #printArea { display: block !important; }
  body { background: #fff; }
  @page { size: A4; margin: 14mm; }
}
.editable { outline: 1px dashed transparent; border-radius: 6px; padding: 3px 5px; }
.editable:focus { outline-color: var(--blue); background: #f1f8fb; }
.editable[contenteditable="false"] { cursor: default; }
main { display: grid; grid-template-columns: minmax(360px, 390px) minmax(0, 1fr); gap: 16px; padding: 16px clamp(14px, 3vw, 34px); align-items: start; }
aside, section { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
aside { padding: 16px; align-self: start; position: sticky; top: calc(var(--sticky-top) + 12px); max-height: calc(100vh - var(--sticky-top) - 24px); overflow: auto; }
.content { display: grid; gap: 14px; }
.bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; }
.calc-note { margin: 12px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.table-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.table-head h2 { margin: 0; }
.table-head #printBtn { min-height: 34px; padding: 6px 14px; white-space: nowrap; }
.day-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 12px; }
.day-tab { min-height: 34px; padding: 6px 12px; background: #fff; color: var(--ink); border-color: var(--line); }
.day-tab.active { background: var(--ink); color: #fff; border-color: var(--ink); }
label { display: grid; gap: 5px; color: var(--muted); font-size: 13px; }
input, select, button { min-height: 38px; border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; background: #fff; color: var(--ink); }
button { background: var(--ink); color: #fff; border-color: var(--ink); cursor: pointer; }
button.secondary { background: #fff; color: var(--ink); }
.pad { padding: 14px; }
.score { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
.metric { border: 1px solid var(--line); border-radius: 8px; padding: 11px; }
.metric strong { display: block; font-size: 22px; }
.warnbox { display: grid; gap: 8px; margin-bottom: 12px; }
.sentence { border-left: 5px solid var(--red); background: #fff5f2; padding: 10px; border-radius: 6px; }
table {
  width: auto;
  min-width: 980px;
  max-width: 1180px;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}
th {
  background: var(--head);
  color: #fff;
  padding: 8px;
  font-size: 13px;
  border: 1px solid #b64f08;
  position: sticky;
  top: calc(var(--sticky-top) + var(--table-head-gap));
  z-index: 150;
  background-clip: padding-box;
  box-shadow: 0 2px 0 rgba(0,0,0,0.08);
}
thead { position: sticky; top: calc(var(--sticky-top) + var(--table-head-gap)); z-index: 150; }
td { border: 1px solid var(--line); padding: 6px; vertical-align: middle; }
tr.row-added { animation: rowFlash 1.6s ease-out; }
@keyframes rowFlash {
  0% { background: #fff3c4; box-shadow: inset 0 0 0 2px #d99b16; }
  100% { background: transparent; box-shadow: inset 0 0 0 0 rgba(217,155,22,0); }
}
td input, td select { width: 100%; min-height: 34px; }
.num { width: 44px; text-align: center; }
.mealcol { width: 76px; }
.foodcol { width: 210px; }
.keycol { width: 150px; }
.gramcol { width: 96px; }
.delcol { width: 48px; }
.signals { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; }
.sig { border: 1px solid var(--line); border-radius: 8px; padding: 10px; display: grid; gap: 4px; }
.sig.good { border-left: 6px solid var(--green); }
.sig.warn { border-left: 6px solid var(--yellow); }
.sig.bad { border-left: 6px solid var(--red); }
.sig.muted { border-left: 6px solid #9aa39c; }
.sig small { color: var(--muted); }
.toast {
  position: fixed;
  right: clamp(12px, 3vw, 28px);
  top: calc(var(--sticky-top) + 12px);
  z-index: 500;
  display: none;
  max-width: min(360px, calc(100vw - 24px));
  border: 1px solid var(--line);
  border-left: 5px solid var(--blue);
  border-radius: 8px;
  background: #f4f9ff;
  color: var(--ink);
  padding: 10px 12px;
  box-shadow: 0 10px 24px rgba(31,42,36,0.16);
  font-size: 14px;
  line-height: 1.45;
}
.toast.show { display: block; }
.toast.success { border-left-color: var(--green); background: #f1fbf5; }
.toast.error { border-left-color: var(--red); background: #fff5f2; }
.foodlist { display: grid; gap: 6px; max-height: 44vh; overflow: auto; margin-top: 8px; }
.fooditem { display: flex; justify-content: space-between; gap: 8px; border-bottom: 1px solid var(--line); padding: 6px 0; font-size: 13px; cursor: pointer; }
.fooditem:hover { color: var(--blue); }
.food-search-box { position: relative; z-index: 5; display: grid; gap: 8px; }
#foodSearch { display: block; width: 100%; position: relative; z-index: 6; pointer-events: auto; user-select: text; }
.hint { color: var(--muted); font-size: 13px; line-height: 1.45; }
.guide { display: grid; gap: 8px; margin-bottom: 12px; }
.guide ol { margin: 0; padding-left: 20px; color: var(--muted); line-height: 1.55; }
.tipcol { width: 300px; }
.sourcecol { width: 105px; }
.videocol { width: 82px; text-align: center; }
.video-link { color: var(--blue); font-weight: 700; text-decoration: none; }
.adbox { border: 1px solid #f0c27b; background: #fff9ed; border-radius: 8px; padding: 10px; display: grid; gap: 8px; }
.header-ad { justify-self: stretch; }
.adbox strong { color: #9a4a05; }
.adbox a { color: var(--blue); font-weight: 700; }
.adrow { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.admin-fields { display: none; }
.profile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.profile-grid label, .template-label { min-width: 0; }
.template-label { margin-top: 10px; }
.template-label select { width: 100%; }
.family-panel { display: none; gap: 8px; margin-top: 10px; border-top: 1px solid var(--line); padding-top: 10px; }
.family-panel.open { display: grid; }
.member-card { border: 1px solid var(--line); border-radius: 8px; padding: 8px; display: grid; gap: 8px; background: #fbfcfa; }
.member-head { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.member-fields { display: grid; grid-template-columns: 1fr; gap: 8px; }
.member-fields label { width: 100%; }
#familyPanel > button { width: 100%; }
.mini { min-height: 32px; padding: 5px 8px; font-size: 12px; }
.input-warning { display: none; border-left: 5px solid var(--red); background: #fff5f2; color: var(--red); padding: 9px; border-radius: 6px; margin-top: 8px; font-size: 13px; line-height: 1.45; }
.admin-mode .admin-fields { display: grid; gap: 6px; }
@media (max-width: 980px) {
  main { grid-template-columns: 1fr; }
  aside { position: static; max-height: none; overflow: visible; }
  .score { grid-template-columns: repeat(2, 1fr); }
  .tablewrap { overflow-x: auto; }
}
@media (max-width: 720px) {
  .topbar { grid-template-columns: 1fr; }
  .toast { top: 10px; right: 10px; left: 10px; max-width: none; }
  header { position: static; }
  main { padding: 10px; }
  .pad { padding: 10px; }
  .score { grid-template-columns: 1fr 1fr; }
  .profile-grid, .member-fields { grid-template-columns: 1fr; }
  .tablewrap { overflow: visible; }
  table, thead, tbody, tr, td { display: block; width: 100%; }
  table { min-width: 0; max-width: none; }
  thead { display: none; }
  tr {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 10px;
    background: #fff;
  }
  td {
    border: 0;
    padding: 5px 0;
    display: grid;
    grid-template-columns: 98px minmax(0, 1fr);
    gap: 8px;
    align-items: center;
  }
  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 13px;
  }
  td.num {
    display: none;
  }
  td.videocol { text-align: left; }
}
