:root {
  --color-bg: #f4f6fa;
  --color-surface: #ffffff;
  --color-primary: #3b7ddd;
  --color-primary-dark: #2a5fb0;
  --color-text: #222833;
  --color-text-sub: #6b7280;
  --color-border: #e2e6ee;
  --color-safe: #2e9e5b;
  --color-caution: #d99a1b;
  --color-warning: #e07a1f;
  --color-over: #d8402f;
  --radius: 14px;
  --gap: 12px;
  font-size: 16px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--color-bg); color: var(--color-text); font-family: "Hiragino Sans", "Yu Gothic", "Noto Sans JP", system-ui, sans-serif; overscroll-behavior-y: contain; }
body { padding-bottom: 24px; }
h1, h2, h3 { margin: 0 0 8px; }
button { font-family: inherit; }
.hidden, [hidden] { display: none !important; }

#app-bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  background: var(--color-primary); color: #fff;
  padding: 12px 12px; min-height: 52px;
}
#app-bar .back-btn {
  background: transparent; border: none; color: #fff; font-size: 22px; padding: 4px 8px; cursor: pointer; border-radius: 8px;
}
#app-bar .back-btn:active { background: rgba(255,255,255,0.2); }
#app-bar h1 { font-size: 17px; flex: 1; }
#offline-badge { font-size: 11px; background: #d8402f; padding: 2px 8px; border-radius: 10px; }
#offline-badge.online { display: none; }

main { max-width: 560px; margin: 0 auto; padding: 12px; }

.card { background: var(--color-surface); border-radius: var(--radius); padding: 16px; margin-bottom: var(--gap); box-shadow: 0 1px 3px rgba(20,30,60,0.06); }
.card h2 { font-size: 15px; color: var(--color-text-sub); font-weight: 600; }

.dash-total { text-align: center; padding: 8px 0 4px; }
.dash-total .amount { font-size: 34px; font-weight: 700; color: var(--color-primary-dark); }
.dash-total .label { font-size: 13px; color: var(--color-text-sub); }
.dash-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; margin-top: 10px; }
.dash-grid .item .val { font-size: 16px; font-weight: 700; }
.dash-grid .item .lab { font-size: 11px; color: var(--color-text-sub); }

.progress-bar { height: 10px; background: #eef1f6; border-radius: 6px; overflow: hidden; margin: 8px 0; }
.progress-bar > div { height: 100%; border-radius: 6px; background: var(--color-primary); transition: width .3s; }
.status-safe { color: var(--color-safe); }
.status-caution { color: var(--color-caution); }
.status-warning { color: var(--color-warning); }
.status-over { color: var(--color-over); }
.progress-bar.status-safe > div { background: var(--color-safe); }
.progress-bar.status-caution > div { background: var(--color-caution); }
.progress-bar.status-warning > div { background: var(--color-warning); }
.progress-bar.status-over > div { background: var(--color-over); }

.menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.menu-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius);
  padding: 16px 8px; font-size: 13px; font-weight: 600; color: var(--color-text); cursor: pointer;
  min-height: 84px; box-shadow: 0 1px 2px rgba(20,30,60,0.05);
}
.menu-btn .icon { font-size: 26px; }
.menu-btn:active { background: #eef3fb; }
.menu-btn.primary { background: var(--color-primary); color: #fff; }
.menu-btn.primary:active { background: var(--color-primary-dark); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: none; border-radius: 10px; padding: 13px 18px; font-size: 15px; font-weight: 600; cursor: pointer; width: 100%; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:active { background: var(--color-primary-dark); }
.btn-secondary { background: #eef1f6; color: var(--color-text); }
.btn-danger { background: #fdeceb; color: var(--color-over); }
.btn-outline { background: transparent; border: 1px solid var(--color-border); color: var(--color-text); }
.btn-row { display: flex; gap: 8px; margin-top: 10px; }
.btn-row .btn { width: auto; flex: 1; }
.btn[disabled] { opacity: .5; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--color-text-sub); margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 12px; border: 1px solid var(--color-border); border-radius: 10px; font-size: 16px; background: #fff; color: var(--color-text);
}
.radio-group { display: flex; gap: 8px; flex-wrap: wrap; }
.radio-chip { flex: 1; min-width: 90px; text-align: center; padding: 12px 6px; border: 2px solid var(--color-border); border-radius: 10px; font-size: 14px; cursor: pointer; }
.radio-chip input { display: none; }
.radio-chip.checked { border-color: var(--color-primary); background: #eaf2fd; color: var(--color-primary-dark); font-weight: 700; }

table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data-table th, table.data-table td { border-bottom: 1px solid var(--color-border); padding: 8px 4px; text-align: right; }
table.data-table th:nth-child(1), table.data-table td:nth-child(1),
table.data-table th:nth-child(2), table.data-table td:nth-child(2) { text-align: left; }
.table-wrap { overflow-x: auto; }

.list-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--color-border); gap: 8px; }
.list-row:last-child { border-bottom: none; }
.list-row .main { flex: 1; min-width: 0; }
.list-row .main .title { font-weight: 600; font-size: 14px; }
.list-row .main .sub { font-size: 12px; color: var(--color-text-sub); }
.list-row .amount { font-weight: 700; white-space: nowrap; }
.list-row .actions { display: flex; gap: 4px; }
.icon-btn { background: #eef1f6; border: none; border-radius: 8px; padding: 6px 10px; font-size: 14px; }

.multi-row-table input, .multi-row-table select { padding: 8px; font-size: 14px; }

.chart-box { position: relative; height: 240px; margin: 10px 0; }

.tag { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 8px; background: #eef1f6; color: var(--color-text-sub); }
.tag.warn { background: #fff2df; color: var(--color-warning); }
.tag.ok { background: #e6f6ed; color: var(--color-safe); }

.modal-overlay { position: fixed; inset: 0; background: rgba(10,15,30,0.5); display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
.modal-overlay.center { align-items: center; padding: 16px; }
.modal-sheet { background: #fff; border-radius: 18px 18px 0 0; width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto; padding: 18px; }
.modal-overlay.center .modal-sheet { border-radius: 16px; }
.modal-sheet h3 { font-size: 17px; }

.notice { padding: 10px 12px; border-radius: 10px; font-size: 13px; margin-bottom: 12px; }
.notice.info { background: #eaf2fd; color: var(--color-primary-dark); }
.notice.warn { background: #fff2df; color: #8a5a00; }
.notice.error { background: #fdeceb; color: var(--color-over); }
.notice.success { background: #e6f6ed; color: var(--color-safe); }

.section-tabs { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.section-tabs button { flex: 1; padding: 10px 4px; border-radius: 10px; border: 1px solid var(--color-border); background: #fff; font-size: 13px; }
.section-tabs button.active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

#toast-area { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; width: calc(100% - 32px); max-width: 520px; }
.toast { background: #222833; color: #fff; padding: 12px 16px; border-radius: 10px; font-size: 13px; box-shadow: 0 4px 14px rgba(0,0,0,0.2); }
.toast.error { background: var(--color-over); }
.toast.success { background: var(--color-safe); }

#loading-overlay { position: fixed; inset: 0; background: rgba(255,255,255,0.85); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; z-index: 200; }
.spinner { width: 36px; height: 36px; border: 4px solid #dbe4f5; border-top-color: var(--color-primary); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.receipt-preview { width: 100%; max-height: 260px; object-fit: contain; border-radius: 10px; background: #eee; margin-bottom: 10px; }
.confidence-row { display: flex; justify-content: space-between; font-size: 12px; color: var(--color-text-sub); padding: 2px 0; }

.empty-state { text-align: center; padding: 32px 12px; color: var(--color-text-sub); font-size: 14px; }

@media (min-width: 600px) {
  .menu-grid { grid-template-columns: repeat(3, 1fr); }
}
