/* ============================================================
   カロリー収支ノート — デザイントークン
   コンセプト: 「収支帳簿（ledger）」としてのカロリー管理。
   摂取(amber/橙)と消費(teal/青緑)を対の色で表し、
   中央から左右に伸びる帳簿バーで日々の収支を可視化する。
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,600;9..144,700&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;700&display=swap');

:root {
  --bg:        #EFECE2;
  --bg-alt:    #E5E1D2;
  --card:      #FBFAF5;
  --ink:       #22291F;
  --ink-soft:  #5B6355;
  --line:      #D9D4C2;
  --accent-in:   #C97A3D; /* 摂取（食事）: 温かいオーカー */
  --accent-in-soft: #F1D9BE;
  --accent-out:  #2E6F6B; /* 消費（運動・基礎代謝）: 深いティール */
  --accent-out-soft: #CFE3E0;
  --danger:    #B5482E;
  --radius:    10px;
  --shadow:    0 1px 2px rgba(34,41,31,0.06), 0 8px 24px -12px rgba(34,41,31,0.18);
  --font-display: "Fraunces", serif;
  --font-body: "Inter", -apple-system, "Hiragino Sans", "Yu Gothic", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
}

a { color: inherit; }

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 600;
  margin: 0 0 .4em;
  letter-spacing: -.01em;
}

.app-shell {
  max-width: 880px;
  margin: 0 auto;
  padding: 0 20px 80px;
}

/* --- ヘッダー / ナビ ------------------------------------------------ */
.app-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 28px 0 18px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 24px;
}
.app-header .brand {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
}
.app-header .brand small {
  display: block;
  font-family: var(--font-body);
  font-weight: 400;
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-top: 2px;
}
.app-nav { display: flex; align-items: center; gap: 18px; font-size: 13.5px; }
.app-nav a { text-decoration: none; color: var(--ink-soft); }
.app-nav a:hover { color: var(--ink); }
.app-nav .user-pill {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-soft);
}

/* --- 日付ナビゲーション ------------------------------------------- */
.date-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 22px;
}
.date-nav button {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  width: 34px; height: 34px;
  cursor: pointer;
  font-size: 15px;
  color: var(--ink);
}
.date-nav input[type="date"] {
  font-family: var(--font-mono);
  font-size: 14px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
}
.date-nav .today-label {
  font-size: 12.5px;
  color: var(--ink-soft);
}

/* --- 収支帳簿バー（シグネチャー要素） ------------------------------ */
.ledger {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 24px 18px;
  margin-bottom: 26px;
}
.ledger-heading {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 14px;
}
.ledger-heading h2 { font-size: 17px; }
.ledger-balance {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink-soft);
}
.ledger-balance strong { font-size: 16px; color: var(--ink); }
.ledger-balance.over strong { color: var(--accent-in); }
.ledger-balance.under strong { color: var(--accent-out); }

.ledger-bar-row {
  position: relative;
  height: 40px;
  background: var(--bg-alt);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
}
.ledger-bar-row .center-line {
  position: absolute;
  left: 50%; top: 0; bottom: 0;
  width: 1px;
  background: var(--line);
  z-index: 2;
}
.ledger-half { position: relative; width: 50%; height: 100%; display: flex; }
.ledger-half.left { justify-content: flex-end; }
.ledger-fill {
  height: 100%;
  transition: width .4s ease;
}
.ledger-fill.in  { background: var(--accent-in); }
.ledger-fill.out { background: var(--accent-out); }

.ledger-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
  font-size: 12.5px;
}
.ledger-labels .label-in  { color: var(--accent-in); }
.ledger-labels .label-out { color: var(--accent-out); }
.ledger-labels .figure { font-family: var(--font-mono); font-weight: 700; font-size: 15px; }

.ledger-breakdown {
  display: flex;
  justify-content: space-between;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
  font-size: 12px;
  color: var(--ink-soft);
}
.ledger-breakdown .bmr-edit {
  cursor: pointer;
  text-decoration: underline dotted;
}

/* --- カード共通 ----------------------------------------------------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
  margin-bottom: 20px;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.card-head h2 { font-size: 16px; display: flex; align-items: center; gap: 8px; }
.tag {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
}
.tag.in  { background: var(--accent-in); }
.tag.out { background: var(--accent-out); }

/* --- フォーム -------------------------------------------------------- */
.inline-form {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr auto;
  gap: 8px;
  align-items: end;
  margin-bottom: 16px;
}
.inline-form.exercise-form { grid-template-columns: 2fr 1fr auto; }
.field { display: flex; flex-direction: column; gap: 4px; position: relative; }
.field label { font-size: 11.5px; color: var(--ink-soft); }
.field input, .field select {
  font-family: var(--font-body);
  font-size: 14px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  width: 100%;
}
.field input:focus, .field select:focus, button:focus-visible {
  outline: 2px solid var(--accent-out);
  outline-offset: 1px;
}

button, .btn {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 13.5px;
  padding: 9px 16px;
  border-radius: 7px;
  border: 1px solid transparent;
  cursor: pointer;
}
.btn-primary { background: var(--ink); color: var(--card); }
.btn-primary:hover { background: #384231; }
.btn-outline { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-outline:hover { background: var(--bg-alt); }
.btn-danger-ghost { background: transparent; border: none; color: var(--danger); font-size: 12px; padding: 4px 6px; }
.btn-danger-ghost:hover { text-decoration: underline; }
.btn-sm { padding: 6px 10px; font-size: 12.5px; }
button:disabled { opacity: .5; cursor: not-allowed; }

/* --- オートコンプリート ---------------------------------------------- */
.autocomplete-list {
  position: absolute;
  top: 100%; left: 0; right: 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 7px;
  box-shadow: var(--shadow);
  max-height: 220px;
  overflow-y: auto;
  z-index: 20;
  margin-top: 4px;
  display: none;
}
.autocomplete-list.open { display: block; }
.autocomplete-list .opt {
  padding: 8px 10px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
}
.autocomplete-list .opt:hover { background: var(--bg-alt); }
.autocomplete-list .opt .meta { color: var(--ink-soft); font-family: var(--font-mono); font-size: 11.5px; }

/* --- ログ一覧テーブル -------------------------------------------------- */
table.log-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.log-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ink-soft);
  font-weight: 600;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
}
table.log-table td {
  padding: 8px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
table.log-table tr:last-child td { border-bottom: none; }
table.log-table .kcal-cell { font-family: var(--font-mono); font-weight: 600; text-align: right; white-space: nowrap; }
table.log-table input.edit-amount, table.log-table input.edit-minutes {
  width: 64px;
  font-family: var(--font-mono);
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
}
.empty-row td { color: var(--ink-soft); text-align: center; padding: 18px 0; font-size: 13px; }
.meal-badge {
  font-size: 10.5px;
  color: var(--ink-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
}

/* --- 認証ページ --------------------------------------------------- */
.auth-wrap {
  max-width: 400px;
  margin: 60px auto;
  padding: 0 20px;
}
.auth-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
}
.auth-card h1 { font-size: 24px; margin-bottom: 4px; }
.auth-card .sub { color: var(--ink-soft); font-size: 13px; margin-bottom: 22px; }
.auth-card .field { margin-bottom: 14px; }
.auth-card .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.auth-card button[type="submit"] { width: 100%; margin-top: 6px; padding: 11px; }
.auth-card .switch { text-align: center; margin-top: 18px; font-size: 13px; color: var(--ink-soft); }
.alert {
  font-size: 13px;
  padding: 10px 12px;
  border-radius: 7px;
  margin-bottom: 14px;
  display: none;
}
.alert.error { background: #F7E3DB; color: var(--danger); display: block; }
.alert.ok { background: var(--accent-out-soft); color: var(--accent-out); display: block; }

/* --- プロフィールページ --------------------------------------------- */
.profile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* --- レスポンシブ ---------------------------------------------------- */
@media (max-width: 640px) {
  .inline-form, .inline-form.exercise-form { grid-template-columns: 1fr 1fr; }
  .inline-form button, .inline-form.exercise-form button { grid-column: 1 / -1; }
  .profile-grid { grid-template-columns: 1fr; }
  .app-header { flex-direction: column; align-items: flex-start; gap: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
