/* ===== ペット日記 : スタイル ===== */

/* ライト（初期設定）。右上の 🌙 / ☀️ ボタンで切り替えます */
:root, :root[data-theme="light"] {
  --bg: #f4efe4;          /* やさしいクリーム色の背景 */
  --panel: #ffffff;       /* カードは白で、背景とはっきり分ける */
  --panel-2: #f7f2ea;
  --text: #2b2420;        /* 文字は濃く、読みやすく */
  --muted: #6b6158;       /* 補助テキストもしっかり読める濃さ */
  --line: #ddd0bd;        /* 枠線をはっきりさせる */
  --accent: #b96f24;      /* 白地でも読める濃いオレンジ */
  --accent-soft: #fbeeda;
  --danger: #b8402a;
  --shadow: 0 2px 10px rgba(90, 66, 45, .10);
  --radius: 14px;
}

:root[data-theme="dark"] {
  --bg: #16130f;          /* 本体の背景はぐっと暗く */
  --panel: #2b2622;       /* パネルは明るめにして境目をはっきり */
  --panel-2: #363029;
  --text: #f5efe7;        /* 文字はしっかり明るく */
  --muted: #bdb0a2;
  --line: #4a423b;        /* 枠線を見えるように */
  --accent: #f0ac67;
  --accent-soft: #4a3a26;
  --danger: #f08a70;
  --shadow: 0 2px 12px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.75;
  padding-bottom: 60px;
}

h1, h2, h3 { line-height: 1.4; }

/* ---------- トップバー ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand-icon { font-size: 24px; }
.brand h1 { font-size: 21px; margin: 0; letter-spacing: .04em; }
.dog-switch { display: flex; gap: 6px; align-items: center; }

/* 家族との同期の状態 */
.sync-badge {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--accent-soft);
  color: var(--accent);
  white-space: nowrap;
  cursor: pointer;
}
.sync-badge.is-error {
  background: transparent;
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 45%, transparent);
}

/* だれが書いたか */
.author-badge {
  font-size: 12px;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}

/* ---------- タブ ---------- */
.tabs {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  overflow-x: auto;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: var(--topbar-h, 66px);   /* 実際のヘッダー高さを app.js が入れます */
  z-index: 19;
}
.tab {
  flex: 0 0 auto;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  padding: 10px 18px;
  font-size: 17px;
  font-weight: 600;
  line-height: 1.4;
  border-radius: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.tab:hover { background: var(--panel-2); border-color: var(--line); }
.tab.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}
:root[data-theme="dark"] .tab.is-active { color: #241c14; }

main { max-width: 780px; margin: 0 auto; padding: 16px; }
.view { display: none; }
.view.is-active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

/* ---------- 汎用パーツ ---------- */
button {
  font: inherit;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  padding: 8px 14px;
  cursor: pointer;
  transition: filter .12s, background .12s;
}
button:hover { filter: brightness(.97); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
button.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); background: transparent; }
button.ghost { background: transparent; }
.icon-btn {
  width: 34px; height: 34px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 17px; line-height: 1; border-radius: 10px;
}
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }
.hint { color: var(--muted); font-size: 13px; }
small { color: var(--muted); font-weight: 400; }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 10px;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent);
  outline-offset: 1px;
}
textarea { resize: vertical; line-height: 1.8; }
input[type="file"] { padding: 6px; background: var(--panel-2); }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.panel h3 { margin: 0 0 12px; font-size: 15px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid label, label.block { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.form-grid label input, .form-grid label select, label.block textarea, label.block input {
  color: var(--text); font-size: 15px;
}
.span2 { grid-column: 1 / -1; }
.unit-wrap { position: relative; display: block; }
.unit-wrap input { padding-right: 34px; }
.unit { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 13px; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }

/* ---------- わんこカード ---------- */
.dog-card {
  display: flex; align-items: center; gap: 14px;
  background: linear-gradient(135deg, var(--accent-soft), var(--panel));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
}
.dog-card .avatar {
  width: 62px; height: 62px; border-radius: 50%;
  object-fit: cover; background: var(--panel-2);
  display: flex; align-items: center; justify-content: center;
  font-size: 30px; flex: 0 0 auto; border: 2px solid var(--panel);
}
.dog-card .dog-name { font-size: 18px; font-weight: 700; }
.dog-card .dog-meta { color: var(--muted); font-size: 13px; }

/* ---------- ツールバー ---------- */
.toolbar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input[type="search"] { flex: 1 1 180px; }
.toolbar select { flex: 0 0 auto; width: auto; }
.toolbar button { flex: 0 0 auto; }

/* ---------- 日記カード ---------- */
.entry-list { display: flex; flex-direction: column; gap: 12px; }
.entry {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.entry:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.entry-top { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.entry-date { font-weight: 700; color: var(--accent); font-size: 14px; }
.entry-emoji { font-size: 15px; }
.entry-title { font-weight: 700; font-size: 16px; margin: 2px 0 4px; }
.entry-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.entry-body.clamp { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.entry-facts { display: flex; gap: 10px; flex-wrap: wrap; color: var(--muted); font-size: 13px; margin-top: 8px; }
.entry-photos { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.entry-photos img { width: 86px; height: 86px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.tag {
  font-size: 12px; padding: 2px 9px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
}

.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.empty .big { font-size: 44px; display: block; margin-bottom: 8px; }

/* ---------- チップ ---------- */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: var(--panel-2);
  border-radius: 999px; padding: 5px 12px; font-size: 13px; cursor: pointer;
}
.chip[aria-pressed="true"] {
  background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 700;
}
fieldset { border: none; padding: 0; margin: 0 0 14px; }
legend { font-size: 13px; color: var(--muted); padding: 0 0 6px; }

/* ---------- カレンダー ---------- */
.cal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.cal-head h2 { font-size: 17px; margin: 0; flex: 1; text-align: center; }
.cal-weekdays, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-weekdays { font-size: 12px; color: var(--muted); text-align: center; margin-bottom: 4px; }
.cal-weekdays .sun { color: #d06b5c; }
.cal-weekdays .sat { color: #5c86d0; }
.cal-cell {
  position: relative;
  overflow: hidden;
  aspect-ratio: 1 / 1;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; cursor: pointer; font-size: 13px; padding: 2px;
}
/* その日の写真を1枚だけ背景に表示 */
.cal-cell .cal-photo {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  z-index: 0;
}
.cal-cell .num, .cal-cell .dot { position: relative; z-index: 1; }
.cal-cell.has-photo .num {
  color: #fff; font-weight: 700;
  background: rgba(0, 0, 0, .45);
  min-width: 22px; border-radius: 8px; text-align: center;
  padding: 0 4px;
}
.cal-cell.has-photo .dot { text-shadow: 0 1px 3px rgba(0, 0, 0, .8); }
.cal-cell.blank { border: none; background: transparent; cursor: default; }
.cal-cell.today { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.cal-cell.has-entry { background: var(--accent-soft); font-weight: 700; }
.cal-cell .dot { font-size: 11px; line-height: 1; }
.cal-cell:hover:not(.blank) { border-color: var(--accent); }

/* ---------- アルバム ---------- */
.album-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
}
.album-item {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--panel-2);
  cursor: pointer;
}
.album-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.album-item .cap {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: linear-gradient(transparent, rgba(0, 0, 0, .65));
  color: #fff; font-size: 11px; padding: 14px 6px 5px;
  display: flex; justify-content: space-between; gap: 4px;
}
.album-item .cap .src { opacity: .85; }
.album-month { margin: 18px 0 8px; font-size: 14px; color: var(--muted); font-weight: 700; }
.album-month:first-child { margin-top: 0; }

.photo-caption {
  color: #fff; text-align: center; margin: 10px 0 0;
  font-size: 13px; text-shadow: 0 1px 3px rgba(0, 0, 0, .6);
}
.photo-actions { display: flex; justify-content: center; margin-top: 8px; }
.photo-actions button { background: rgba(0, 0, 0, .45); border-color: rgba(255, 255, 255, .3); color: #ffb4a2; }

/* ---------- できたこと（タイムライン） ---------- */
.timeline { position: relative; padding-left: 22px; }
.timeline::before {
  content: ''; position: absolute; left: 6px; top: 6px; bottom: 6px;
  width: 2px; background: var(--line); border-radius: 2px;
}
.ms {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.ms::before {
  content: ''; position: absolute; left: -20px; top: 18px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--panel);
}
.ms:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.ms-top { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.ms-date { color: var(--accent); font-weight: 700; font-size: 14px; }
.ms-age { color: var(--muted); font-size: 12px; }
.ms-title { font-weight: 700; font-size: 16px; margin: 3px 0; }
.ms-note { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; }
.ms-photo { margin-top: 10px; }
.ms-photo img { max-width: 180px; border-radius: 10px; border: 1px solid var(--line); display: block; }

/* ---------- 統計 ---------- */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; box-shadow: var(--shadow);
}
.stat-card .num { font-size: 24px; font-weight: 700; color: var(--accent); }
.stat-card .lbl { font-size: 12px; color: var(--muted); }

.chart svg { width: 100%; height: auto; display: block; }
.chart .no-data { color: var(--muted); font-size: 13px; text-align: center; padding: 20px 0; }

.mood-bars { display: flex; flex-direction: column; gap: 8px; }
.mood-row { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.mood-row .name { width: 76px; flex: 0 0 auto; }
.mood-row .bar { flex: 1; height: 12px; background: var(--panel-2); border-radius: 999px; overflow: hidden; }
.mood-row .bar > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.mood-row .val { width: 44px; text-align: right; color: var(--muted); flex: 0 0 auto; }

.tag-cloud { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- ダイアログ ---------- */
dialog {
  border: none; border-radius: 16px; padding: 0;
  background: var(--panel); color: var(--text);
  width: min(640px, 94vw); max-height: 92vh;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .25);
}
dialog::backdrop { background: rgba(30, 22, 16, .55); backdrop-filter: blur(2px); }
#entryForm { display: flex; flex-direction: column; max-height: 92vh; }
.dialog-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.dialog-head h2 { font-size: 16px; margin: 0; }
.dialog-body { padding: 16px; overflow-y: auto; }
.dialog-foot {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px; border-top: 1px solid var(--line); background: var(--panel-2);
}

.photo-preview { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.photo-preview figure { position: relative; margin: 0; }
.photo-preview img { width: 92px; height: 92px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.photo-preview .rm {
  position: absolute; top: -6px; right: -6px; width: 22px; height: 22px;
  border-radius: 50%; background: var(--danger); color: #fff; border: none;
  font-size: 12px; line-height: 1; cursor: pointer; padding: 0;
}

.photo-dialog { background: transparent; box-shadow: none; width: auto; }
.photo-dialog img { max-width: 92vw; max-height: 88vh; border-radius: 12px; display: block; }
.close-float { position: absolute; top: 6px; right: 6px; background: rgba(0, 0, 0, .55); color: #fff; border: none; }

/* ---------- トースト ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: #3a2f28; color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: .22s; z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
