:root {
  --bg: #f4f5f1;
  --surface: #ffffff;
  --surface-soft: #f8f9f6;
  --ink: #202522;
  --muted: #717973;
  --line: #dfe3dd;
  --green: #2d7558;
  --green-dark: #215b44;
  --green-soft: #e5f0e9;
  --coral: #df785f;
  --coral-soft: #faebe6;
  --gold: #d6a23f;
  --blue: #4f7da0;
  --danger: #ad3d37;
  --shadow: 0 8px 28px rgba(37, 48, 40, 0.06);
  --radius: 8px;
  font-family: Inter, "Yu Gothic UI", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--bg); }

body { margin: 0; min-height: 100vh; background: var(--bg); }

button, input, select { font: inherit; }

button, select { cursor: pointer; }

button:focus-visible, input:focus-visible, select:focus-visible, label.data-action:focus-within {
  outline: 3px solid rgba(45, 117, 88, 0.2);
  outline-offset: 2px;
}

.app-shell { min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
  width: 224px;
  display: flex;
  flex-direction: column;
  padding: 28px 18px 22px;
  color: #eef5f1;
  background: #263a31;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 10px 30px;
  color: white;
  line-height: 1;
}

.brand > span:last-child { display: flex; align-items: baseline; gap: 4px; }
.brand strong { font-size: 19px; font-weight: 750; letter-spacing: 0; }
.brand small { color: #aac5b7; font-size: 13px; }

.brand-mark {
  width: 29px;
  height: 29px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 3px;
  padding: 6px;
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 50%;
}

.brand-mark span { display: block; width: 3px; background: #8ac2a5; border-radius: 2px; }
.brand-mark span:nth-child(1) { height: 7px; }
.brand-mark span:nth-child(2) { height: 14px; background: #f1bd58; }
.brand-mark span:nth-child(3) { height: 10px; }

.main-nav { display: grid; gap: 5px; }

.nav-item {
  width: 100%;
  height: 46px;
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 0 14px;
  border: 0;
  border-radius: 6px;
  color: #b9c8c0;
  background: transparent;
  text-align: left;
  font-weight: 650;
}

.nav-item:hover { color: white; background: rgba(255,255,255,.06); }
.nav-item.is-active { color: white; background: rgba(255,255,255,.11); }
.nav-icon { width: 18px; color: #83b99e; text-align: center; font-size: 14px; }

.sidebar-bottom { margin-top: auto; padding: 0 10px; }
.storage-note { display: flex; align-items: center; gap: 7px; margin: 0 0 10px; color: #9fb2a8; font-size: 11px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #70bb90; box-shadow: 0 0 0 4px rgba(112,187,144,.1); }
.text-button { padding: 0; border: 0; color: #d6e1db; background: none; font-size: 12px; text-decoration: underline; text-underline-offset: 3px; }

.main-content { min-height: 100vh; margin-left: 224px; }

.topbar {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 38px;
  border-bottom: 1px solid var(--line);
  background: rgba(247,248,245,.94);
  position: sticky;
  top: 0;
  z-index: 15;
  backdrop-filter: blur(12px);
}

.client-switcher { display: flex; align-items: center; gap: 10px; min-width: 0; }
.client-avatar { width: 32px; height: 32px; flex: 0 0 32px; display: grid; place-items: center; border-radius: 50%; color: var(--green-dark); background: var(--green-soft); font-weight: 800; font-size: 13px; }
.client-switcher select { min-width: 170px; max-width: 280px; border: 0; color: var(--ink); background: transparent; font-weight: 700; }
.mobile-menu { display: none; border: 0; background: transparent; font-size: 22px; }

.view { display: none; max-width: 1280px; margin: 0 auto; padding: 38px; }
.view.is-visible { display: block; }

.view-header { min-height: 62px; display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 25px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(25px, 3vw, 34px); line-height: 1.2; letter-spacing: 0; }
h2 { margin-bottom: 0; font-size: 17px; line-height: 1.35; letter-spacing: 0; }
.eyebrow, .section-kicker { margin-bottom: 6px; color: var(--green); font-size: 10px; font-weight: 800; letter-spacing: .12em; }

.date-stepper { height: 40px; display: grid; grid-template-columns: 38px 142px 38px; align-items: stretch; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: var(--surface); }
.date-stepper button { border: 0; color: var(--green-dark); background: var(--surface-soft); font-size: 23px; }
.date-stepper button:hover { background: var(--green-soft); }
.date-stepper input { width: 100%; border: 0; border-inline: 1px solid var(--line); color: var(--ink); background: white; text-align: center; font-size: 12px; font-weight: 700; }

.button { min-height: 40px; display: inline-flex; align-items: center; justify-content: center; gap: 5px; padding: 9px 15px; border: 1px solid transparent; border-radius: 6px; font-weight: 750; font-size: 13px; white-space: nowrap; }
.button-primary { color: white; background: var(--green); }
.button-primary:hover { background: var(--green-dark); }
.button-secondary { border-color: var(--line); color: #3e4943; background: white; }
.button-secondary:hover { border-color: #bdc6bf; background: var(--surface-soft); }
.button-danger { border-color: #e5c6c2; color: var(--danger); background: white; }
.button-small { min-height: 34px; padding: 6px 11px; font-size: 12px; }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(300px, .8fr); gap: 18px; }
.dashboard-wide { grid-column: 1 / -1; }

.panel { min-width: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 22px 24px 0; }
.meal-heading-row { padding-bottom: 16px; }
.status-pill { padding: 5px 9px; border-radius: 999px; color: var(--muted); background: var(--surface-soft); font-size: 11px; font-weight: 700; }
.status-pill.good { color: var(--green-dark); background: var(--green-soft); }
.status-pill.over { color: #914534; background: var(--coral-soft); }

.calorie-body { display: grid; grid-template-columns: 190px 1fr; align-items: center; gap: 26px; padding: 18px 24px 27px; }
.calorie-ring { --progress: 0deg; width: 176px; aspect-ratio: 1; display: grid; place-items: center; border-radius: 50%; background: conic-gradient(var(--green) var(--progress), #e6eae5 0); position: relative; }
.calorie-ring::before { content: ""; position: absolute; inset: 14px; border-radius: 50%; background: white; }
.calorie-ring.over { background: conic-gradient(var(--coral) var(--progress), #e6eae5 0); }
.ring-center { position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; }
.ring-center strong { font-size: 34px; line-height: 1; }
.ring-center span { margin-top: 3px; color: var(--muted); font-size: 11px; }
.ring-center small { margin-top: 8px; color: var(--green); font-weight: 800; }
.calorie-numbers { display: grid; gap: 0; }
.calorie-numbers > div { display: flex; justify-content: space-between; gap: 12px; padding: 13px 0; border-bottom: 1px solid #edf0ec; }
.calorie-numbers > div:last-child { border: 0; }
.calorie-numbers span { color: var(--muted); font-size: 12px; }
.calorie-numbers strong { font-size: 12px; }
.calorie-numbers b { font-size: 16px; }

.macro-list { display: grid; gap: 21px; padding: 24px; }
.macro-item > div:first-child { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.macro-item span { color: #465149; font-size: 12px; font-weight: 700; }
.macro-item strong { font-size: 11px; }
.macro-item strong b { font-size: 17px; }
.macro-item small { display: block; margin-top: 6px; color: var(--muted); font-size: 10px; text-align: right; }
.progress-track { height: 7px; margin-top: 8px; border-radius: 6px; overflow: hidden; background: #e9ece8; }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; transition: width .25s ease; }
.protein .progress-track span { background: var(--green); }
.fat .progress-track span { background: var(--gold); }
.carbs .progress-track span { background: var(--blue); }

.meal-groups { border-top: 1px solid #edf0ec; }
.meal-group { display: grid; grid-template-columns: 130px 1fr; min-height: 74px; border-bottom: 1px solid #edf0ec; }
.meal-group:last-child { border-bottom: 0; }
.meal-group-title { padding: 18px 24px; background: var(--surface-soft); }
.meal-group-title strong { display: block; font-size: 13px; }
.meal-group-title span { color: var(--muted); font-size: 11px; }
.meal-items { min-width: 0; }
.meal-item { min-height: 54px; display: grid; grid-template-columns: minmax(120px, 1fr) 92px 120px 32px; align-items: center; gap: 12px; padding: 10px 18px; border-bottom: 1px solid #f0f2ef; }
.meal-item:last-child { border-bottom: 0; }
.meal-item-name strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.meal-item-name small, .meal-item-macros { color: var(--muted); font-size: 10px; }
.meal-item-calories { text-align: right; font-size: 12px; }
.meal-item-calories b { font-size: 15px; }
.meal-item-actions { display: flex; justify-content: flex-end; }
.row-action { width: 28px; height: 28px; border: 0; border-radius: 4px; color: var(--muted); background: transparent; font-size: 18px; }
.row-action:hover { color: var(--danger); background: #faeeee; }
.empty-meal { display: flex; align-items: center; min-height: 73px; padding: 12px 22px; color: #909690; font-size: 12px; }

.week-panel { padding-bottom: 18px; }
.chart-legend { margin: 0; color: var(--muted); font-size: 10px; }
.chart-legend span { display: inline-block; width: 14px; margin-right: 5px; border-top: 1px dashed #9aa29c; vertical-align: middle; }
.week-chart { height: 190px; display: grid; grid-template-columns: repeat(7, minmax(36px, 1fr)); align-items: end; gap: 14px; margin: 22px 24px 0; padding: 16px 10px 0; border-bottom: 1px solid var(--line); position: relative; }
.week-chart::before { content: ""; position: absolute; inset: var(--target-line, 50%) 0 auto; border-top: 1px dashed #aeb6b0; }
.day-column { height: 100%; display: grid; grid-template-rows: 1fr 34px; align-items: end; justify-items: center; gap: 7px; position: relative; }
.day-bar-wrap { width: min(34px, 70%); height: 100%; display: flex; align-items: end; }
.day-bar { width: 100%; min-height: 2px; border-radius: 4px 4px 0 0; background: #8eb6a2; position: relative; transition: height .25s ease; }
.day-column.active .day-bar { background: var(--green); }
.day-bar.over { background: var(--coral); }
.day-bar-value { position: absolute; top: -17px; left: 50%; transform: translateX(-50%); color: var(--muted); font-size: 9px; white-space: nowrap; }
.day-label { display: flex; flex-direction: column; align-items: center; color: var(--muted); font-size: 9px; }
.day-label b { color: #3f4943; font-size: 11px; }

.history-grid { display: grid; grid-template-columns: minmax(360px, .8fr) minmax(500px, 1.2fr); gap: 18px; }
.weight-panel, .records-panel { min-width: 0; }
.weight-change { color: var(--green); font-size: 14px; }
.weight-chart { height: 240px; margin: 20px 24px 0; border-bottom: 1px solid var(--line); }
.weight-chart svg { width: 100%; height: 100%; overflow: visible; }
.chart-empty { height: 100%; display: grid; place-items: center; color: var(--muted); font-size: 12px; }
.inline-form { display: grid; grid-template-columns: 1fr 1fr auto; align-items: end; gap: 10px; padding: 20px 24px 24px; }

label { color: #59635d; font-size: 11px; font-weight: 700; position: relative; }
input, select { width: 100%; height: 42px; margin-top: 7px; padding: 9px 12px; border: 1px solid #ccd3cd; border-radius: 5px; color: var(--ink); background: white; font-size: 13px; }
input:hover, select:hover { border-color: #aeb8b0; }
.input-unit { position: absolute; right: 12px; bottom: 13px; color: var(--muted); font-size: 10px; pointer-events: none; }
label:has(.input-unit) input { padding-right: 44px; }

.month-picker input { width: 140px; height: 34px; margin: 0; font-size: 11px; }
.record-table-wrap { overflow-x: auto; padding: 18px 24px 24px; }
.record-table { width: 100%; border-collapse: collapse; white-space: nowrap; }
.record-table th { padding: 0 10px 10px; border-bottom: 1px solid var(--line); color: var(--muted); text-align: left; font-size: 10px; font-weight: 700; }
.record-table td { padding: 13px 10px; border-bottom: 1px solid #edf0ec; font-size: 11px; }
.record-table td strong { font-size: 13px; }
.record-table .empty-row td { height: 130px; color: var(--muted); text-align: center; }
.ratio-cell { min-width: 110px; }
.mini-progress { width: 80px; height: 4px; display: inline-block; margin-left: 6px; border-radius: 5px; overflow: hidden; background: #e9ece8; vertical-align: middle; }
.mini-progress span { display: block; height: 100%; background: var(--green); }
.open-day { border: 0; color: var(--green); background: transparent; font-weight: 800; }

.profile-layout { display: grid; grid-template-columns: minmax(420px, 1.1fr) minmax(320px, .7fr); gap: 18px; align-items: start; }
.profile-form { padding-bottom: 24px; }
.save-state { color: var(--green); font-size: 10px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px 14px; padding: 22px 24px; }
.full-width { grid-column: 1 / -1; }
.profile-measurements { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.form-actions { display: flex; justify-content: space-between; gap: 12px; padding: 0 24px; }
.calculation-column { display: grid; gap: 14px; }
.result-panel { padding-bottom: 20px; }
.result-main { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; margin: 20px 24px 10px; padding: 18px; color: white; background: var(--green); border-radius: 6px; }
.result-main span { font-size: 11px; }
.result-main strong { font-size: 12px; }
.result-main b { font-size: 27px; }
.result-section-title { margin: 17px 24px 3px; color: var(--muted); font-size: 9px; font-weight: 800; letter-spacing: .08em; }
.result-section-title.target-title { color: var(--green-dark); }
.result-list { margin: 0; padding: 0 24px; }
.result-list > div { display: flex; justify-content: space-between; gap: 15px; padding: 12px 0; border-bottom: 1px solid #edf0ec; }
.result-list dt { color: var(--muted); font-size: 11px; }
.result-list dd { margin: 0; font-size: 11px; }
.result-list b { font-size: 14px; }
.result-list dd span { margin-left: 4px; color: var(--muted); font-size: 9px; }
.target-result-list { margin: 0 14px; padding: 0 10px 4px; border-radius: 6px; background: var(--green-soft); }
.target-result-list > div { border-bottom-color: rgba(45,117,88,.12); }
.target-result-list > div:last-child { border-bottom: 0; }
.target-result-list dt, .target-result-list dd { color: var(--green-dark); }
.calculation-note { margin: 14px 24px 0; color: var(--muted); font-size: 10px; line-height: 1.7; }
.info-strip { padding: 17px 19px; border-left: 3px solid var(--gold); background: #fffaf0; }
.info-strip strong { font-size: 11px; }
.info-strip p { margin: 5px 0 0; color: #68665e; font-size: 10px; line-height: 1.7; }

.modal { width: min(600px, calc(100vw - 28px)); max-height: calc(100vh - 40px); padding: 0; border: 0; border-radius: 8px; color: var(--ink); background: white; box-shadow: 0 25px 80px rgba(22,31,26,.25); overflow: auto; }
.modal::backdrop { background: rgba(25,35,29,.5); backdrop-filter: blur(3px); }
.modal form { margin: 0; }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 15px; padding: 23px 24px 17px; border-bottom: 1px solid var(--line); }
.icon-button { width: 34px; height: 34px; display: grid; place-items: center; border: 0; border-radius: 4px; color: #59635d; background: var(--surface-soft); font-size: 21px; }
.modal-grid { padding-bottom: 14px; }
.nutrition-fields { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 0 24px; padding: 15px; border: 1px solid var(--line); border-radius: 6px; }
.nutrition-fields legend { padding: 0 6px; color: var(--muted); font-size: 10px; }
.calculation-preview { display: grid; grid-template-columns: 1fr auto; align-items: baseline; margin: 17px 24px 0; padding: 15px 17px; border-radius: 6px; background: var(--green-soft); }
.calculation-preview span { color: var(--green-dark); font-size: 11px; font-weight: 700; }
.calculation-preview strong { color: var(--green-dark); font-size: 11px; }
.calculation-preview b { font-size: 22px; }
.calculation-preview small { grid-column: 1 / -1; margin-top: 6px; color: #627268; font-size: 10px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 20px 24px 24px; }
.compact-modal { width: min(450px, calc(100vw - 28px)); }
.dialog-label { display: block; margin: 22px 24px 0; }
.data-actions { display: grid; gap: 10px; padding: 20px 24px 8px; }
.data-action { display: flex; flex-direction: column; gap: 5px; padding: 16px; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); background: white; text-align: left; cursor: pointer; }
.data-action:hover { border-color: #9fb1a5; background: var(--surface-soft); }
.data-action strong { font-size: 12px; }
.data-action span { color: var(--muted); font-size: 10px; }
.data-action input { display: none; }
.data-warning { margin: 8px 24px 22px; color: var(--muted); font-size: 10px; line-height: 1.6; }

.toast { position: fixed; z-index: 50; right: 24px; bottom: 24px; max-width: calc(100vw - 48px); padding: 11px 16px; border-radius: 6px; color: white; background: #263a31; box-shadow: var(--shadow); font-size: 12px; opacity: 0; transform: translateY(12px); pointer-events: none; transition: .2s ease; }
.toast.is-visible { opacity: 1; transform: translateY(0); }
.is-hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 1000px) {
  .sidebar { width: 188px; }
  .main-content { margin-left: 188px; }
  .view, .topbar { padding-left: 24px; padding-right: 24px; }
  .dashboard-grid, .history-grid { grid-template-columns: 1fr; }
  .calorie-overview, .macro-panel { grid-column: 1; }
  .profile-layout { grid-template-columns: 1fr; }
  .calculation-column { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 760px) {
  .sidebar { width: 220px; transform: translateX(-100%); transition: transform .2s ease; box-shadow: 18px 0 50px rgba(25,35,29,.2); }
  .sidebar.is-open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .mobile-menu { display: block; }
  .topbar { height: 62px; padding: 0 16px; }
  .client-switcher { margin-right: auto; }
  .client-switcher select { min-width: 110px; max-width: 150px; }
  #add-client-top { width: 34px; min-width: 34px; padding: 0; font-size: 0; }
  #add-client-top span { font-size: 18px; }
  .view { padding: 24px 16px 36px; }
  .view-header { min-height: 54px; margin-bottom: 18px; }
  .view-header h1 { font-size: 25px; }
  .date-stepper { grid-template-columns: 34px 118px 34px; }
  .date-stepper input { font-size: 10px; }
  .calorie-body { grid-template-columns: 145px 1fr; gap: 16px; padding-left: 18px; padding-right: 18px; }
  .calorie-ring { width: 140px; }
  .ring-center strong { font-size: 28px; }
  .panel-heading { padding-left: 18px; padding-right: 18px; }
  .meal-heading-row { align-items: flex-end; }
  .meal-group { grid-template-columns: 86px 1fr; }
  .meal-group-title { padding: 18px 12px; }
  .meal-item { grid-template-columns: minmax(90px, 1fr) 78px 30px; gap: 8px; padding: 9px 10px; }
  .meal-item-macros { display: none; }
  .week-chart { gap: 5px; margin-left: 14px; margin-right: 14px; }
  .history-grid { grid-template-columns: minmax(0, 1fr); }
  .record-table-wrap { padding-left: 12px; padding-right: 12px; }
  .calculation-column { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .view-header { flex-wrap: wrap; }
  .date-stepper { order: 2; width: 100%; grid-template-columns: 38px 1fr 38px; }
  .dashboard-grid { gap: 12px; }
  .calorie-body { grid-template-columns: 1fr; justify-items: center; }
  .calorie-numbers { width: 100%; }
  .meal-group { grid-template-columns: 1fr; }
  .meal-group-title { display: flex; justify-content: space-between; padding: 12px 14px; }
  .meal-item { grid-template-columns: minmax(100px, 1fr) 82px 28px; }
  .meal-heading-row .button { min-width: 40px; padding: 9px; font-size: 0; }
  .meal-heading-row .button span { font-size: 18px; }
  .week-chart { height: 170px; }
  .day-bar-value { display: none; }
  .inline-form { grid-template-columns: 1fr 1fr; }
  .inline-form .button { grid-column: 1 / -1; }
  .form-grid { grid-template-columns: 1fr; padding-left: 18px; padding-right: 18px; }
  .full-width { grid-column: 1; }
  .profile-measurements { grid-template-columns: 1fr; }
  .form-actions { flex-direction: column; padding-left: 18px; padding-right: 18px; }
  .form-actions .button { width: 100%; }
  .nutrition-fields { grid-template-columns: 1fr; }
  .modal-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
