:root {
  font-family: "Noto Sans JP", "Hiragino Kaku Gothic ProN", "Yu Gothic", system-ui, sans-serif;
  font-synthesis: none;
  color: #1d342b;
  background: #f6f5f0;
  --ink: #1d342b;
  --muted: #617168;
  --green: #234a39;
  --green-dark: #183b2c;
  --green-soft: #eaf3ea;
  --line: #e1e7df;
  --surface: #fff;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; }
button, input, select, textarea { font: inherit; }
button { min-height: 43px; border: 1px solid var(--green); border-radius: 10px; padding: .66rem 1rem; background: var(--green); color: #fff; font-weight: 700; cursor: pointer; transition: background .16s ease, transform .16s ease; }
button:hover { background: var(--green-dark); transform: translateY(-1px); }
button.secondary { border-color: #d7e2d8; background: #edf3ec; color: var(--green); }
button.secondary:hover { background: #e1ece0; }
button.danger { border-color: #f3d4d0; background: #fff3f1; color: #a2423c; }
button.danger:hover { background: #fae6e3; }
button:disabled { border-color: #d4ded4; background: #e4e9e2; color: #67786c; cursor: not-allowed; transform: none; }
input, select, textarea { width: 100%; min-height: 43px; border: 1px solid #cbd8cd; border-radius: 9px; padding: .65rem .8rem; background: #fff; color: var(--ink); }
input::placeholder, textarea::placeholder { color: #839088; }
textarea { min-height: 130px; resize: vertical; }
label { display: flex; flex-direction: column; gap: .42rem; min-width: 0; color: #3f5549; font-size: .88rem; font-weight: 700; }
form { display: grid; gap: .9rem; }
a { color: #24604a; text-underline-offset: 3px; }
:focus-visible { outline: 3px solid #d99966; outline-offset: 3px; }
[hidden], .hidden { display: none !important; }

.topbar { position: relative; z-index: 10; display: flex; align-items: center; justify-content: space-between; min-height: 72px; padding: .7rem clamp(1rem, 2.4vw, 2.4rem); border-bottom: 1px solid var(--line); background: #fff; }
.brand-lockup { display: flex; align-items: center; gap: .7rem; min-width: 0; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--green); color: #fff; font-family: Georgia, serif; font-size: 1.3rem; font-weight: 700; }
.brand { color: var(--ink); font-size: 1.35rem; font-weight: 800; letter-spacing: -.04em; text-decoration: none; }
.brand-caption { margin-left: .3rem; padding-left: 1rem; border-left: 1px solid var(--line); color: #758279; font-size: .78rem; }
.logout-button { min-height: 35px; border-color: var(--line); background: #fff; color: var(--green); font-size: .84rem; }
.logout-button:hover { background: #f1f6f0; }
main { min-height: calc(100vh - 72px); }
.app-layout { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: calc(100vh - 72px); }
.sidebar { position: sticky; top: 0; align-self: start; display: flex; flex-direction: column; min-height: calc(100vh - 72px); padding: 2rem 1rem 1.3rem; background: #1e3c30; color: #e8f0e8; }
.sidebar-heading { padding: 0 .75rem 1.7rem; border-bottom: 1px solid #ffffff2c; }
.sidebar-kicker, .eyebrow { display: block; color: #668574; font-size: .72rem; font-weight: 800; letter-spacing: .16em; }
.sidebar-kicker { color: #a3bea7; }
.sidebar-heading strong { display: block; margin-top: .45rem; font-size: 1.15rem; }
.sidebar-heading p { margin: .55rem 0 0; color: #c0d1c4; font-size: .78rem; line-height: 1.6; }
.sidebar nav { display: grid; gap: .24rem; margin-top: 1.25rem; }
.nav-label { margin: 1rem .75rem .32rem; color: #a9c1ad; font-size: .7rem; font-weight: 800; letter-spacing: .08em; }
.sidebar nav a { display: flex; align-items: center; gap: .78rem; min-height: 44px; border-radius: 10px; padding: .55rem .75rem; color: #dce9dc; font-size: .87rem; font-weight: 650; text-decoration: none; white-space: nowrap; }
.sidebar nav a:hover { background: #ffffff14; }
.sidebar nav a[aria-current="page"] { background: #f4f8f1; color: var(--green-dark); box-shadow: 0 8px 20px #0d2a1f26; }
.nav-glyph { display: grid; place-items: center; width: 28px; height: 28px; flex: 0 0 28px; border: 1px solid #ffffff40; border-radius: 8px; color: #b8d2be; font-size: .65rem; font-weight: 800; }
.sidebar nav a[aria-current="page"] .nav-glyph { border-color: #d9e9d8; background: #e7f1e5; color: var(--green); }
.sidebar-note { margin: auto .75rem 0; padding-top: 1.6rem; color: #b7cbbd; font-size: .72rem; line-height: 1.65; }
.workspace { width: min(1260px, 100%); min-width: 0; margin: 0 auto; padding: clamp(1.5rem, 3.1vw, 3rem) clamp(1rem, 3.2vw, 3rem) 4rem; }
.page-section { animation: page-in .18s ease-out; }
@keyframes page-in { from { opacity: .65; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.page-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.6rem; }
.page-heading .eyebrow { margin: 0 0 .6rem; }
h1, h2, h3 { color: var(--ink); }
h1 { margin: 0; font-size: clamp(1.8rem, 3vw, 2.5rem); letter-spacing: -.055em; line-height: 1.25; }
h2 { margin: 0; font-size: 1.15rem; letter-spacing: -.03em; line-height: 1.4; }
h3 { margin: 0; font-size: .99rem; }
.section-intro { max-width: 680px; margin: .65rem 0 0; color: var(--muted); font-size: .92rem; line-height: 1.65; }
.page-number { flex: 0 0 auto; padding: .45rem .7rem; border: 1px solid #dae7da; border-radius: 99px; color: #50715b; background: #edf3ea; font-size: .74rem; font-weight: 800; letter-spacing: .05em; }
.panel { min-width: 0; margin: 0 0 1rem; border: 1px solid var(--line); border-radius: 16px; padding: clamp(1.1rem, 2vw, 1.55rem); background: var(--surface); box-shadow: 0 8px 28px #2446330a; }
.panel-heading { display: flex; align-items: flex-start; gap: .8rem; margin-bottom: 1.2rem; }
.panel-heading p { margin: .3rem 0 0; color: var(--muted); font-size: .78rem; line-height: 1.55; }
.step-mark, .search-type-mark { display: grid; place-items: center; width: 32px; height: 32px; flex: 0 0 32px; border-radius: 10px; background: #e7f1e7; color: var(--green); font-size: .78rem; font-weight: 850; }
.search-type-mark { background: #e5eee8; }
.food-mark { background: #fbefdf; color: #926333; }
.field-hint { margin: .7rem 0 0; color: #68786d; font-size: .78rem; line-height: 1.6; }
.status { min-height: 1.3rem; color: #36644b; }
.muted { color: var(--muted); font-size: .85rem; }
.warning { color: #a8443d; }
.text-link { display: inline-flex; align-items: center; gap: .3rem; margin-top: .3rem; font-size: .83rem; font-weight: 750; text-decoration: none; }
.text-link:hover { text-decoration: underline; }
.workspace-note { margin: 2rem 0 0; padding-top: 1.3rem; border-top: 1px solid var(--line); color: #79877e; font-size: .75rem; line-height: 1.6; }

.login-panel { width: min(440px, calc(100% - 2rem)); margin: clamp(2rem, 8vh, 5rem) auto; padding: clamp(1.5rem, 4vw, 2.4rem); }
.login-panel h1 { margin: .7rem 0 0; font-size: clamp(1.6rem, 4vw, 2rem); }
.login-panel form { margin-top: 1.7rem; }
.login-panel button { margin-top: .3rem; }

.date-panel { display: flex; align-items: end; justify-content: space-between; gap: 1rem; padding: 1rem 1.25rem; background: linear-gradient(105deg, #f5f9f3, #fff); }
.date-control { display: flex; align-items: end; gap: .7rem; }
.date-control label { width: 180px; }
.day-overview { padding: .45rem 0; color: #315943; font-size: .85rem; font-weight: 750; text-align: right; }
.daily-columns { display: grid; grid-template-columns: minmax(0, 1fr) 300px; grid-template-areas: "record aside" "summary aside"; align-items: start; gap: 1rem; }
.daily-main { display: contents; }
.daily-aside { grid-area: aside; min-width: 0; }
.record-panel { grid-area: record; }
.summary-panel { grid-area: summary; }
.record-form { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(100px, .65fr) minmax(85px, .6fr); align-items: end; gap: .7rem; }
.record-form button { justify-self: start; grid-column: 1 / -1; }
.apply-panel { background: #f2f7ef; border-color: #d8e6d5; }
.apply-panel > button { width: 100%; }
.source-status-grid { display: grid; gap: .75rem; }
.source-status-card { min-width: 0; padding: 1.05rem; border: 1px solid var(--line); border-radius: 14px; background: #fff; }
.source-status-heading { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.source-status-card > p { min-height: 2.3em; margin: .65rem 0 .8rem; line-height: 1.55; }
.source-status-actions { display: grid; gap: .45rem; }
.source-status-actions button { min-height: 39px; font-size: .78rem; }
.state-badge { display: inline-flex; align-items: center; min-height: 25px; border-radius: 99px; padding: .25rem .6rem; background: #edf0ec; color: #5c6a61; font-size: .72rem; font-weight: 750; white-space: nowrap; }
.state-in_progress { background: #fff1d7; color: #8c631e; }
.state-complete, .state-no-intake { background: #e1f2e5; color: #2c7146; }
.state-not_started { background: #edf0ec; color: #5c6a61; }
.records-card { margin: 1.2rem 0 1.4rem; border: 1px solid #e4eae1; border-radius: 12px; padding: .3rem 1rem; background: #fbfcfa; }
.records-card h3 { padding: .8rem 0; }
.record-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: .6rem; border-top: 1px solid var(--line); padding: .65rem 0; }
.record-item { min-width: 0; overflow-wrap: anywhere; font-size: .86rem; font-weight: 650; }
.record-amount { color: #4f6256; font-size: .82rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.record-row button { min-height: 32px; padding: .35rem .65rem; font-size: .75rem; }
.nutrient-section-title { margin: 1.5rem 0 .35rem; font-size: 1.02rem; }
.nutrient-group { margin: .5rem 0; border: 1px solid var(--line); border-radius: 11px; background: #fff; }
.nutrient-group > summary { padding: .82rem 1rem; color: var(--green); font-size: .87rem; font-weight: 750; }
.nutrient-group[open] > summary { border-bottom: 1px solid var(--line); }
.nutrient-group .data-list { padding: .25rem .9rem .75rem; }
.data-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .25rem .75rem; }
.data-row { min-width: 0; border-bottom: 1px solid #edf0eb; padding: .75rem .3rem; font-size: .81rem; overflow-wrap: anywhere; }
.data-row strong { display: block; margin-bottom: .3rem; }
.data-row p { margin: .45rem 0 0; }

.search-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(240px, .8fr); gap: 1rem; }
.search-grid .panel { height: calc(100% - 1rem); }
.search-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: end; gap: .75rem; }
.search-form label:has(input[name="product_url"]) { grid-column: 1 / -1; }
.search-form button { justify-self: start; }
#food-search-form { grid-template-columns: 1fr; }
.results-panel #search-results { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); align-items: start; gap: .75rem; }
.empty-state { grid-column: 1 / -1; margin: 0; border: 1px dashed #d5e1d3; border-radius: 11px; padding: 1.7rem; color: #7b8b7e; background: #fafcf8; font-size: .85rem; text-align: center; }
.card { min-width: 0; margin: .55rem 0; border: 1px solid var(--line); border-radius: 12px; padding: 1rem; background: #fff; overflow-wrap: anywhere; }
.card h3 { margin: .1rem 0 .6rem; line-height: 1.5; }
.card p { margin: .45rem 0; color: #526459; font-size: .81rem; line-height: 1.6; }
.card p.warning { color: #a8443d; }
.card button { margin-top: .65rem; }
.search-status { display: flex; align-items: center; gap: .55rem; margin: .4rem 0 1rem; color: var(--green); font-size: .85rem; font-weight: 750; }
.search-spinner { width: 1rem; height: 1rem; flex: 0 0 1rem; border: 2px solid #d8e4d9; border-top-color: var(--green); border-radius: 50%; animation: search-spin .8s linear infinite; }
@keyframes search-spin { to { transform: rotate(360deg); } }
.manual-entry > summary { color: var(--green); font-size: .9rem; font-weight: 750; cursor: pointer; }
.manual-entry[open] > summary { margin-bottom: .7rem; }
.manual-group { min-width: 0; margin: .8rem 0; border: 1px solid var(--line); border-radius: 11px; padding: .85rem; }
.manual-group legend { padding: 0 .4rem; color: var(--green); font-weight: 750; }
.form-row { display: flex; align-items: end; flex-wrap: wrap; gap: .75rem; }
.form-row label { flex: 1 1 130px; }
.form-row button { flex: 0 0 auto; }
.component-list { display: grid; gap: .3rem; margin-top: .7rem; }
.component-list p { margin: 0; border-radius: 8px; padding: .5rem .7rem; background: #f3f7f1; font-size: .82rem; }
.workflow-strip { display: flex; align-items: center; flex-wrap: wrap; gap: .8rem; margin: 0 0 1rem; border: 1px solid #dbe7da; border-radius: 12px; padding: .8rem 1rem; background: #edf4e9; color: #658069; font-size: .84rem; }
.workflow-strip strong { color: var(--green); }
.flow-guidance { margin: 0 0 1rem; border-left: 4px solid #4c8c62; border-radius: 7px; padding: .8rem 1rem; background: #edf5ee; color: var(--green); font-size: .85rem; font-weight: 700; }
#current-list .card { display: flex; align-items: end; flex-wrap: wrap; gap: .55rem; }
#current-list .card h3, #current-list .card p, #current-list .card ul { flex: 0 0 100%; }
#current-list .card input { width: min(130px, 100%); }
#current-list .card select { width: min(150px, 100%); }
#current-list .card button { margin-top: 0; }
.current-nutrient-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(185px, 1fr)); gap: .2rem .7rem; margin: .3rem 0 .7rem; padding-left: 1.2rem; color: #4e6255; font-size: .79rem; }
.result-list { display: grid; gap: .35rem; margin-top: 1.1rem; }
.ai-panel { border-top: 3px solid #a6a3c8; }
#ai-form { margin-top: 1.2rem; }
#ai-form button { justify-self: start; }
#global-message:not(:empty) { position: fixed; z-index: 20; right: 1rem; bottom: 1rem; width: min(420px, calc(100% - 2rem)); margin: 0; border: 1px solid #c7dfcd; border-radius: 11px; padding: .85rem 1rem; background: #f4fbf3; color: var(--green-dark); box-shadow: 0 12px 32px #172b2050; font-size: .85rem; line-height: 1.5; }

@media (max-width: 1120px) {
  .app-layout { grid-template-columns: 210px minmax(0, 1fr); }
  .daily-columns { grid-template-columns: 1fr; grid-template-areas: "record" "aside" "summary"; }
  .daily-aside { display: grid; grid-template-columns: minmax(220px, .9fr) minmax(0, 1.1fr); gap: 1rem; }
  .source-status-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 850px) {
  .app-layout { display: block; }
  .sidebar { position: static; min-height: 0; padding: .5rem .8rem; }
  .sidebar-heading, .sidebar-note, .nav-label { display: none; }
  .sidebar nav { display: flex; gap: .3rem; margin: 0; overflow-x: auto; scrollbar-width: thin; }
  .sidebar nav a { flex: 0 0 auto; padding: .42rem .7rem; }
  .workspace { padding-top: 1.8rem; }
  .search-grid { grid-template-columns: 1fr; }
  .search-grid .panel { height: auto; }
}
@media (max-width: 680px) {
  .brand-caption { display: none; }
  .page-heading { margin-bottom: 1.1rem; }
  .page-number { display: none; }
  .date-panel { display: grid; align-items: stretch; }
  .date-control { display: grid; grid-template-columns: minmax(0, 1fr) auto; }
  .date-control label { width: auto; }
  .day-overview { text-align: left; }
  .daily-aside, .source-status-grid { grid-template-columns: 1fr; }
  .record-form { grid-template-columns: minmax(0, 1fr) minmax(85px, .6fr); }
  .record-form label:first-child { grid-column: 1 / -1; }
  .record-form button { width: 100%; }
}
@media (max-width: 480px) {
  .workspace { padding: 1.35rem .75rem 2.8rem; }
  .panel { padding: 1rem; border-radius: 13px; }
  .page-heading h1 { font-size: 1.8rem; }
  .date-control { grid-template-columns: 1fr; }
  .date-control button { width: 100%; }
  .form-row label, .form-row button, .search-form label, .search-form button { width: 100%; flex-basis: 100%; }
  .search-form { grid-template-columns: 1fr; }
  .search-form label:has(input[name="product_url"]) { grid-column: auto; }
  .record-form { grid-template-columns: 1fr 1fr; }
  .record-form label:first-child { grid-column: 1 / -1; }
  .record-row { grid-template-columns: minmax(0, 1fr) auto; }
  .record-row button { grid-column: 2; grid-row: 1 / 3; }
  #current-list .card input, #current-list .card select { width: 100%; }
  #current-list .card button { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
