*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

  :root {
    --primary: #2563EB;
    --primary-light: #EFF6FF;
    --danger: #EF4444;
    --success: #22C55E;
    --text: #1F2937;
    --muted: #6B7280;
    --border: #E5E7EB;
    --bg: #F9FAFB;
    --card: #FFFFFF;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
  }

  body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 15px;
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
  }

  /* ヘッダー */
  .app-header {
    background: var(--primary);
    color: white;
    padding: 12px 16px;
    position: sticky;
    top: 0;
    z-index: 100;
  }
  .app-header h1 { font-size: 18px; font-weight: 700; }

  /* タブナビ */
  .tab-nav {
    display: flex;
    background: white;
    border-bottom: 2px solid var(--border);
    position: sticky;
    top: 48px;
    z-index: 99;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tab-nav::-webkit-scrollbar { display: none; }
  .tab-btn {
    flex: 1;
    min-width: 56px;
    padding: 10px 4px;
    font-size: 13px;
    font-weight: 500;
    color: var(--muted);
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    white-space: nowrap;
  }
  .tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
  }

  /* メイン */
  .app-main {
    padding: 16px;
    max-width: 640px;
    margin: 0 auto;
  }
  .tab-content { display: none; }
  .tab-content.active { display: block; }

  /* カード */
  .card {
    background: var(--card);
    border-radius: 12px;
    padding: 16px;
    box-shadow: var(--shadow);
    margin-bottom: 12px;
  }

  /* フォーム */
  .form-row { margin-bottom: 12px; }
  .form-row label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 4px;
  }
  input[type="text"],
  input[type="number"],
  input[type="date"],
  select {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 15px;
    color: var(--text);
    background: white;
    -webkit-appearance: none;
    appearance: none;
    outline: none;
  }
  input:focus, select:focus { border-color: var(--primary); }

  /* 内訳セクション */
  .items-section {
    background: var(--bg);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
  }
  .items-section h3 { font-size: 14px; font-weight: 600; margin-bottom: 10px; }

  /* 合計 */
  .form-total {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    font-size: 18px;
    font-weight: 700;
    border-top: 2px solid var(--border);
    margin-bottom: 16px;
  }

  /* ボタン */
  .btn-primary {
    width: 100%;
    padding: 14px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
  }
  .btn-primary:active { opacity: 0.85; }
  .btn-secondary {
    padding: 10px 16px;
    background: none;
    color: var(--primary);
    border: 1.5px solid var(--primary);
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
  }
  .btn-add {
    width: 100%;
    padding: 10px;
    background: none;
    color: var(--primary);
    border: 1.5px dashed var(--primary);
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 8px;
  }

  /* フィルター行 */
  .filter-row { display: flex; gap: 8px; margin-bottom: 16px; }
  .filter-row select { flex: 1; }

  /* 履歴 */
  .history-session {
    background: var(--card);
    border-radius: 12px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
    overflow: hidden;
  }
  .history-session-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--primary-light);
    border-bottom: 1px solid var(--border);
  }
  .session-date { font-weight: 700; font-size: 15px; }
  .session-store { color: var(--muted); font-size: 13px; }
  .session-total { font-weight: 700; color: var(--primary); }
  .history-item {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    gap: 8px;
  }
  .history-item:last-child { border-bottom: none; }
  .history-item-amount { margin-left: auto; font-weight: 700; }
  .history-item-actions { display: flex; gap: 4px; }
  .edit-btn, .delete-btn { background: none; border: none; cursor: pointer; font-size: 16px; padding: 4px; }
  .delete-btn { color: var(--danger); }
  .edit-btn { color: var(--primary); }

  /* カテゴリバッジ */
  .badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    color: white;
    white-space: nowrap;
  }
  .badge-内食費  { background: #FF6384; }
  .badge-主食費  { background: #36A2EB; }
  .badge-中食費  { background: #FFCE56; color: #333; }
  .badge-外食費  { background: #4BC0C0; }
  .badge-嗜好品費 { background: #9966FF; }

  /* 集計 */
  .summary-total {
    background: var(--card);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
  }
  .summary-label { color: var(--muted); font-size: 14px; margin-bottom: 4px; }
  .summary-amount { font-size: 28px; font-weight: 700; color: var(--primary); }
  .summary-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow);
    margin-bottom: 12px;
  }
  .summary-table th, .summary-table td {
    padding: 12px;
    text-align: right;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
  }
  .summary-table th { text-align: left; background: var(--bg); font-weight: 600; font-size: 13px; }
  .summary-table td:first-child { text-align: left; }
  .summary-table tr:last-child td { border-bottom: none; }
  .total-row { font-weight: 700; background: var(--primary-light); }

  /* 週別 */
  .week-card {
    background: var(--card);
    border-radius: 12px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
    overflow: hidden;
  }
  .week-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
  }
  .week-label { font-weight: 700; }
  .week-range { color: var(--muted); font-size: 12px; }
  .week-total { font-weight: 700; color: var(--primary); }

  /* グラフ */
  .chart-wrap { max-width: 280px; margin: 0 auto 20px; }
  .chart-legend { margin-top: 8px; }
  .legend-item {
    display: flex;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
    gap: 8px;
  }
  .legend-item:last-child { border-bottom: none; }
  .legend-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
  .legend-name { flex: 1; }
  .legend-amount { font-weight: 600; }
  .legend-pct { color: var(--muted); font-size: 13px; }

  /* 推移テーブル */
  .trend-wrap { overflow-x: auto; }
  .trend-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow);
    font-size: 12px;
  }
  .trend-table th, .trend-table td {
    padding: 10px 8px;
    text-align: right;
    border-bottom: 1px solid var(--border);
  }
  .trend-table th { background: var(--bg); font-weight: 600; color: var(--muted); white-space: nowrap; }
  .trend-table td:first-child, .trend-table th:first-child { text-align: left; }
  .trend-table tr:last-child td { border-bottom: none; }
  .col-total { font-weight: 700; color: var(--primary); }

  /* CSV行 */
  .csv-row { margin-top: 16px; text-align: right; }

  /* トースト */
  .toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: white;
    padding: 12px 20px;
    border-radius: 24px;
    font-size: 14px;
    z-index: 300;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  }
  .toast.success { background: var(--success); }
  .toast.error   { background: var(--danger); }

  /* 空状態 */
  .empty { text-align: center; padding: 40px 16px; color: var(--muted); font-size: 14px; }

  /* ユーティリティ */
  .hidden { display: none !important; }

  /* レスポンシブ */
  @media (min-width: 600px) {
    .app-header h1 { font-size: 20px; }
    .tab-btn { font-size: 14px; padding: 12px 8px; }
  }

/* 内訳行 */
.item-row { margin-bottom: 10px; }
.item-row-main { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.item-cat { flex: 1.5; }
.item-amt { flex: 1; }
.item-del { background: none; border: none; color: var(--danger); font-size: 18px; cursor: pointer; padding: 4px; flex-shrink: 0; }
.item-note { width: 100%; }