:root {
  --bg: #f4f6f2;
  --surface: #ffffff;
  --text: #22301f;
  --text-muted: #6b7568;
  --accent: #2f6b4f;
  --accent-light: #dcefe2;
  --warn: #b45309;
  --warn-bg: #fef3e2;
  --danger: #b3261e;
  --danger-bg: #fdecea;
  --border: #e2e6dd;
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141812;
    --surface: #1e241b;
    --text: #e9efe4;
    --text-muted: #9aa596;
    --accent: #6fcf9a;
    --accent-light: #223a2c;
    --warn: #f2b872;
    --warn-bg: #3a2c15;
    --danger: #f2a19c;
    --danger-bg: #3a1f1d;
    --border: #2b3327;
  }
}
:root[data-theme="dark"] {
  --bg: #141812;
  --surface: #1e241b;
  --text: #e9efe4;
  --text-muted: #9aa596;
  --accent: #6fcf9a;
  --accent-light: #223a2c;
  --warn: #f2b872;
  --warn-bg: #3a2c15;
  --danger: #f2a19c;
  --danger-bg: #3a1f1d;
  --border: #2b3327;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Sans", "Noto Sans JP", "Yu Gothic", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  background: var(--accent);
  color: #fff;
  padding: 14px 16px;
  font-weight: 700;
  font-size: 17px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.app-body {
  flex: 1;
  display: flex;
  min-height: 0;
}

.side-nav {
  display: none;
}

.view-container {
  flex: 1;
  padding: 12px 14px 90px;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 30;
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 0 6px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 11px;
}
.nav-item.active { color: var(--accent); font-weight: 700; }
.nav-icon { font-size: 20px; }

@media (min-width: 860px) {
  .side-nav {
    display: block;
    width: 220px;
    padding: 20px 12px;
    border-right: 1px solid var(--border);
  }
  .side-links { display: flex; flex-direction: column; gap: 4px; }
  .side-link {
    padding: 10px 12px;
    border-radius: 10px;
    text-decoration: none;
    color: var(--text);
    font-size: 14px;
  }
  .side-link.active, .side-link:hover { background: var(--accent-light); color: var(--accent); }
  .bottom-nav { position: static; border-top: none; padding-bottom: 0; }
  .view-container { padding-bottom: 40px; }
}

h1, h2, h3 { margin: 0 0 8px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; color: var(--text-muted); }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
}

.card-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.section-title { font-size: 20px; font-weight: 800; margin: 4px 0 12px; }

.est-note {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.notice-warn {
  background: var(--warn-bg);
  color: var(--warn);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 10px;
}

.notice-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 10px;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

.stat-box { text-align: center; padding: 10px; background: var(--accent-light); border-radius: 10px; }
.stat-value { font-size: 20px; font-weight: 800; color: var(--accent); }
.stat-label { font-size: 11px; color: var(--text-muted); }

label { display: block; font-size: 13px; color: var(--text-muted); margin: 10px 0 4px; }

input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
}
textarea { resize: vertical; min-height: 60px; }

.form-row { display: flex; gap: 10px; }
.form-row > * { flex: 1; }

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 4px; }
.chip {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
}
.chip.selected { background: var(--accent); border-color: var(--accent); color: #fff; }

.btn {
  display: inline-block;
  padding: 12px 18px;
  border-radius: 12px;
  border: none;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
}
.btn-primary { background: var(--accent); color: #fff; width: 100%; }
.btn-secondary { background: var(--accent-light); color: var(--accent); }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-block { width: 100%; margin-top: 10px; }
.btn-sm { padding: 6px 10px; font-size: 12px; border-radius: 8px; }
.btn-row { display: flex; gap: 8px; margin-top: 10px; }
.btn-row > .btn { flex: 1; }

.stepper { display: flex; align-items: center; gap: 10px; }
.stepper-btn {
  width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); font-size: 18px; font-weight: 700; color: var(--accent);
}
.stepper-value { min-width: 56px; text-align: center; font-size: 17px; font-weight: 700; }
.stepper-value-input {
  width: 64px; text-align: center; font-size: 17px; font-weight: 700; padding: 8px 2px;
  border-radius: 10px; border: 1px solid var(--border);
}

.quick-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.quick-btn {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 14px 4px; border-radius: 12px; background: var(--surface);
  border: 1px solid var(--border); text-decoration: none; color: var(--text); font-size: 12px;
}
.quick-btn .icon { font-size: 22px; }

.list-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: none; }
.list-item-main { flex: 1; }
.list-item-title { font-weight: 700; font-size: 14px; }
.list-item-sub { font-size: 12px; color: var(--text-muted); }

.tab-row { display: flex; gap: 6px; margin-bottom: 12px; overflow-x: auto; }
.tab-btn {
  padding: 8px 14px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); font-size: 13px; white-space: nowrap; color: var(--text);
}
.tab-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.chart-svg { display: block; width: 100%; }
.chart-grid { stroke: var(--border); stroke-width: 1; }
.chart-line { stroke-width: 2.5; }
.chart-axis-label { font-size: 9px; fill: var(--text-muted); }
.chart-empty { font-size: 12px; fill: var(--text-muted); }
.chart-legend { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 6px; font-size: 11px; color: var(--text-muted); }
.chart-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }

.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: all 0.2s; z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-undo { display: flex; align-items: center; gap: 12px; padding: 10px 12px 10px 18px; pointer-events: auto; }
.toast-undo .undo-btn { background: none; border: none; color: var(--accent-light); font-weight: 700; font-size: 13px; padding: 4px 8px; }

.dialog-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center; z-index: 200; padding: 20px;
}
.dialog-box { background: var(--surface); border-radius: var(--radius); padding: 18px; max-width: 340px; width: 100%; }
.dialog-actions { display: flex; gap: 10px; margin-top: 14px; }
.dialog-actions > .btn { flex: 1; }

.loading, .error-box { padding: 30px 10px; text-align: center; color: var(--text-muted); }

.photo-preview { max-width: 100%; border-radius: 10px; margin-top: 8px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; margin-left: 6px; }
.badge-ai { background: var(--warn-bg); color: var(--warn); }
.badge-confirmed { background: var(--accent-light); color: var(--accent); }

.big-btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 4px; }
.big-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  padding: 22px 10px; border-radius: 18px; background: var(--accent); color: #fff;
  text-decoration: none; font-size: 15px; font-weight: 700; border: none; min-height: 96px;
}
.big-btn .icon { font-size: 30px; }
.big-btn.secondary { background: var(--accent-light); color: var(--accent); }

.choice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px; margin: 8px 0; }
.choice-btn {
  padding: 16px 8px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface);
  font-size: 14px; font-weight: 700; color: var(--text); text-align: center;
}
.choice-btn.selected { background: var(--accent); border-color: var(--accent); color: #fff; }

details.detail-toggle { margin-top: 10px; }
details.detail-toggle > summary {
  cursor: pointer; font-size: 13px; color: var(--accent); font-weight: 700; list-style: none;
  padding: 8px 0;
}
details.detail-toggle > summary::-webkit-details-marker { display: none; }
details.detail-toggle > summary::before { content: '▸ '; }
details.detail-toggle[open] > summary::before { content: '▾ '; }
details.detail-toggle .detail-body { padding-top: 6px; }

.timeline-item { display: flex; justify-content: space-between; padding: 6px 0; font-size: 13px; border-bottom: 1px solid var(--border); }
.timeline-item:last-child { border-bottom: none; }
.timeline-time { color: var(--text-muted); margin-right: 8px; }
