/* 家計簿アプリ共通スタイル(Tailwind CSS 導入までの暫定) */
:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --border: #e5e7eb;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --income: #15803d;
    --income-bg: #dcfce7;
    --expense: #b91c1c;
    --expense-bg: #fee2e2;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0, 0, 0, .08);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
    line-height: 1.5;
}

a { color: var(--primary); }

.app-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.app-header-inner {
    max-width: 960px;
    margin: 0 auto;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.app-title {
    margin: 0;
    font-size: 1.25rem;
}
.app-title a { color: inherit; text-decoration: none; }

main {
    max-width: 960px;
    margin: 0 auto;
    padding: 20px 16px 48px;
}
main.narrow { max-width: 520px; }

h2.section-title {
    font-size: 1rem;
    margin: 28px 0 10px;
    color: var(--muted);
}

/* ボタン */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font-size: .9rem;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
}
.btn:hover { background: #f9fafb; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--expense); border-color: #fca5a5; }
.btn-danger:hover { background: var(--expense-bg); }
.btn-sm { padding: 4px 10px; font-size: .8rem; }

/* メッセージ */
.flash {
    padding: 10px 14px;
    margin: 0 0 16px;
    border-radius: 8px;
    background: var(--income-bg);
    color: var(--income);
}

/* 月の切り替え */
.month-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 16px;
}
.month-nav .current {
    font-size: 1.25rem;
    font-weight: bold;
    min-width: 9em;
    text-align: center;
}
.month-nav .today-link { font-size: .85rem; }

/* 集計カード */
.summaries {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
}
.summary-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px 18px;
}
.summary-card h3 {
    margin: 0 0 12px;
    font-size: .95rem;
    color: var(--muted);
}
.summary-balance {
    font-size: 1.75rem;
    font-weight: bold;
    font-variant-numeric: tabular-nums;
    margin-bottom: 4px;
}
.summary-balance-label { font-size: .8rem; color: var(--muted); }
.summary-rows {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 12px;
}
.summary-item {
    border-radius: 8px;
    padding: 8px 10px;
}
.summary-item .label { font-size: .8rem; }
.summary-item .value { font-weight: bold; font-variant-numeric: tabular-nums; }
.summary-item.income { background: var(--income-bg); color: var(--income); }
.summary-item.expense { background: var(--expense-bg); color: var(--expense); }
.rate-bar {
    height: 6px;
    background: var(--income-bg);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 12px;
}
.rate-bar span { display: block; height: 100%; background: var(--expense); }
.rate-text { font-size: .75rem; color: var(--muted); margin-top: 4px; }

.positive { color: var(--income); }
.negative { color: var(--expense); }

/* 一覧 */
.list-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow-x: auto;
}
table.budget-table { width: 100%; border-collapse: collapse; }
.budget-table th, .budget-table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    white-space: nowrap;
}
.budget-table th { font-size: .8rem; color: var(--muted); font-weight: normal; background: #f9fafb; }
.budget-table tr:last-child td { border-bottom: none; }
.budget-table .amount { text-align: right; font-variant-numeric: tabular-nums; font-weight: bold; }
.budget-table .actions { text-align: right; }
.budget-table .actions form { display: inline; margin: 0; }

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: bold;
}
.badge.income { background: var(--income-bg); color: var(--income); }
.badge.expense { background: var(--expense-bg); color: var(--expense); }

.empty {
    padding: 32px 16px;
    text-align: center;
    color: var(--muted);
}

/* フォーム */
.form-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}
.field { margin-bottom: 18px; }
.field > label, .field > .field-label {
    display: block;
    font-weight: bold;
    font-size: .9rem;
    margin-bottom: 6px;
}
.field input[type="date"],
.field input[type="number"],
.field select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 1rem;
    background: #fff;
    color: var(--text);
}
.field input:focus, .field select:focus {
    outline: 2px solid #bfdbfe;
    border-color: var(--primary);
}
.field.has-error input, .field.has-error select { border-color: var(--expense); }
.error { color: var(--expense); font-size: .85rem; margin: 6px 0 0; }

.amount-input { position: relative; }
.amount-input input { padding-right: 2.5em !important; text-align: right; }
.amount-input .unit {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
}

/* 区分の切り替え(ラジオボタン) */
.type-toggle {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.type-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.type-toggle label {
    display: block;
    text-align: center;
    padding: 10px;
    border: 2px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    color: var(--muted);
}
.type-toggle input:focus-visible + label { outline: 2px solid #bfdbfe; }
.type-toggle input.income:checked + label { border-color: var(--income); background: var(--income-bg); color: var(--income); }
.type-toggle input.expense:checked + label { border-color: var(--expense); background: var(--expense-bg); color: var(--expense); }

.form-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 8px;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

@media (max-width: 600px) {
    .budget-table th.col-type, .budget-table td.col-type { display: none; }
    .summary-balance { font-size: 1.5rem; }
}
