/* かんたん家計簿 スタイル — CDN・外部フォント不使用。すべてローカル完結。 */

/* hidden 属性は display 指定(flex/grid等)より優先して必ず非表示にする */
[hidden] { display: none !important; }

:root {
    --bg: #eef1f8;
    --bg-grad: radial-gradient(1200px 600px at 80% -10%, #e8e3ff 0%, transparent 60%),
        radial-gradient(900px 500px at -10% 0%, #dcefff 0%, transparent 55%), #eef1f8;
    --surface: #ffffff;
    --text: #111827;
    --muted: #6b7280;
    --faint: #9ca3af;
    --border: #e9ecf3;
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --income: #059669;
    --income-soft: #10b981;
    --expense: #e11d48;
    --balance: #0284c7;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow-sm: 0 1px 2px rgba(17, 24, 39, 0.04), 0 1px 3px rgba(17, 24, 39, 0.06);
    --shadow: 0 6px 24px rgba(31, 41, 51, 0.07), 0 2px 6px rgba(31, 41, 51, 0.04);
    --shadow-lg: 0 16px 40px rgba(31, 41, 51, 0.12);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI",
        "Segoe UI", Meiryo, sans-serif;
    background: var(--bg-grad);
    background-attachment: fixed;
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

.container {
    width: min(1080px, 92vw);
    margin: 0 auto;
}

/* ヘッダー */
.app-header {
    background: linear-gradient(120deg, #4f46e5 0%, #6d28d9 55%, #7c3aed 100%);
    color: #fff;
    box-shadow: 0 8px 30px rgba(79, 70, 229, 0.28);
}
.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    padding: 20px 0;
}
.brand {
    margin: 0;
    font-size: 1.45rem;
    font-weight: 700;
    letter-spacing: 0.01em;
}
.month-picker {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.88rem;
    color: rgba(255, 255, 255, 0.92);
}
.month-picker input {
    border: none;
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    font-size: 0.95rem;
    background: rgba(255, 255, 255, 0.95);
    color: var(--text);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.06);
}
.header-tools {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
/* ヘッダーは濃色背景のため CSV ボタンは白枠で視認性を確保 */
.btn--csv {
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.55);
    background: rgba(255, 255, 255, 0.12);
    text-decoration: none;
    white-space: nowrap;
}
.btn--csv:hover { background: rgba(255, 255, 255, 0.22); }
/* ヘッダーのユーザー情報＋ログアウト */
.user-box {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #fff;
    font-size: 0.88rem;
}
.user-box__name {
    font-weight: 700;
    white-space: nowrap;
}
.user-box__name::before { content: "👤 "; }
.btn--logout {
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.55);
    background: rgba(255, 255, 255, 0.12);
    white-space: nowrap;
}
.btn--logout:hover { background: rgba(255, 255, 255, 0.22); }

/* 認証画面 */
.auth {
    display: flex;
    justify-content: center;
    padding: 48px 16px;
}
.auth__card {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 32px 28px;
}
.auth__title {
    margin: 0 0 4px;
    font-size: 1.4rem;
    font-weight: 800;
}
.auth__lead {
    margin: 0 0 20px;
    color: var(--muted);
    font-size: 0.88rem;
}
.btn--block { width: 100%; justify-content: center; }
.auth__switch {
    margin: 18px 0 0;
    font-size: 0.85rem;
    color: var(--muted);
    text-align: center;
}
.auth__switch a { color: var(--primary); font-weight: 600; text-decoration: none; }
.auth__switch a:hover { text-decoration: underline; }
/* ダッシュボード */
.dashboard { margin-top: 26px; }
.cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}
.card {
    position: relative;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow: hidden;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.card::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 5px;
    background: var(--border);
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.card--income::before { background: linear-gradient(var(--income-soft), var(--income)); }
.card--expense::before { background: linear-gradient(#fb7185, var(--expense)); }
.card--balance::before { background: linear-gradient(#38bdf8, var(--balance)); }
.card__label {
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}
.card__value {
    font-size: 1.7rem;
    font-weight: 800;
    letter-spacing: -0.01em;
    font-variant-numeric: tabular-nums;
}
.card__diff {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}
.card__diff--good { color: var(--income); }
.card__diff--bad { color: var(--expense); }

/* パネル共通 */
.panel {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 22px;
    box-shadow: var(--shadow);
    margin-top: 20px;
    border: 1px solid rgba(233, 236, 243, 0.7);
}
.panel__title {
    margin: 0 0 18px;
    font-size: 1.05rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* 円グラフ（ドーナツ）＋凡例 — 自前 SVG/JS が描画 */
.chart { min-height: 60px; }
.chart:has(.donut-wrap) {
    display: grid;
    grid-template-columns: 160px 1fr;
    gap: 28px;
    align-items: center;
}
.donut-wrap { display: flex; justify-content: center; }
.donut { width: 160px; height: 160px; }
.donut__seg {
    transition: stroke-dashoffset 0.6s ease, stroke-dasharray 0.6s ease;
}
.donut__seg:hover { opacity: 0.82; cursor: default; }
.donut__total-label { fill: var(--faint); font-size: 11px; font-weight: 600; }
.donut__total-val { fill: var(--text); font-size: 15px; font-weight: 800; }

.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.legend__item {
    display: grid;
    grid-template-columns: 14px 1fr auto auto;
    align-items: center;
    gap: 10px;
    padding: 7px 6px;
    border-radius: 8px;
    font-size: 0.88rem;
    transition: background 0.15s ease;
}
.legend__item:hover { background: #f6f7fb; }
.legend__dot { width: 12px; height: 12px; border-radius: 4px; }
.legend__name { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.legend__pct { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 48px; text-align: right; }
.legend__val { font-weight: 600; font-variant-numeric: tabular-nums; min-width: 78px; text-align: right; }
.chart .empty { color: var(--muted); font-size: 0.9rem; }

/* 2カラムレイアウト */
.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1.35fr;
    gap: 20px;
    align-items: start;
}

/* フォーム */
.form__row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 15px; }
.form__row label { font-size: 0.82rem; color: var(--muted); font-weight: 600; }
.form input[type="text"],
.form input[type="number"],
.form input[type="date"],
.form input[type="password"] {
    padding: 11px 13px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    width: 100%;
    background: #fbfcfe;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

/* パスワード欄＋表示/非表示トグル */
.pw-field { position: relative; display: flex; align-items: center; }
.pw-field input[type="password"],
.pw-field input[type="text"] { padding-right: 60px; }
.pw-toggle {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    line-height: 0;
}
.pw-toggle:hover { background: rgba(79, 70, 229, 0.10); color: var(--primary); }
.pw-toggle__icon { width: 20px; height: 20px; }
/* 既定（非表示）は「目」を表示、表示中は「目＋スラッシュ」を表示 */
.pw-toggle__icon--hide { display: none; }
.pw-toggle[aria-pressed="true"] .pw-toggle__icon--show { display: none; }
.pw-toggle[aria-pressed="true"] .pw-toggle__icon--hide { display: inline; }
.form input:focus {
    outline: none;
    background: #fff;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.14);
}
.seg { display: flex; gap: 10px; }
.seg__item {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.9rem;
    background: #fbfcfe;
    transition: all 0.15s ease;
}
.seg__item:hover { border-color: #c7cbe0; }
.seg__item:has(input:checked) {
    border-color: var(--primary);
    background: rgba(79, 70, 229, 0.08);
    color: var(--primary-dark);
    font-weight: 700;
}
.seg__item input { accent-color: var(--primary); }
.form__actions { display: flex; gap: 10px; margin-top: 4px; }

.btn {
    border: none;
    border-radius: var(--radius-sm);
    padding: 11px 18px;
    font-size: 0.95rem;
    cursor: pointer;
    font-weight: 700;
    transition: all 0.15s ease;
}
.btn--primary {
    background: linear-gradient(120deg, var(--primary), #6d28d9);
    color: #fff;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.28);
}
.btn--primary:hover { filter: brightness(1.05); box-shadow: 0 6px 18px rgba(79, 70, 229, 0.36); transform: translateY(-1px); }
.btn--primary:active { transform: translateY(0); }
.btn--ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn--ghost:hover { background: #f6f7fb; }
.btn--mini {
    padding: 5px 11px;
    font-size: 0.78rem;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
}
.btn--mini:hover { border-color: var(--primary); color: var(--primary); background: rgba(79, 70, 229, 0.06); }
/* ヘッダーの「設定」ボタンも CSV/ログアウトと同じ白枠で揃える */
.btn--account {
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.55);
    background: rgba(255, 255, 255, 0.12);
    white-space: nowrap;
}
.btn--account:hover { background: rgba(255, 255, 255, 0.22); }
/* 危険操作（アカウント削除）用の赤ボタン */
.btn--danger {
    background: linear-gradient(120deg, #f43f5e, var(--expense));
    color: #fff;
    box-shadow: 0 4px 12px rgba(225, 29, 72, 0.26);
}
.btn--danger:hover { filter: brightness(1.05); box-shadow: 0 6px 18px rgba(225, 29, 72, 0.34); transform: translateY(-1px); }
.btn--danger:active { transform: translateY(0); }

/* 成功メッセージ（エラーの緑版） */
.success {
    color: var(--income);
    font-size: 0.85rem;
    margin-bottom: 12px;
    padding: 10px 12px;
    background: rgba(5, 150, 105, 0.08);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(5, 150, 105, 0.2);
}
.success:empty { display: none; }

/* モーダル（アカウント設定） */
.modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 6vh 16px;
    overflow-y: auto;
}
.modal__overlay {
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, 0.5);
    backdrop-filter: blur(2px);
}
.modal__dialog {
    position: relative;
    width: 100%;
    max-width: 440px;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 24px 26px 26px;
}
.modal__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}
.modal__title { margin: 0; font-size: 1.2rem; font-weight: 800; }
.modal__close {
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
}
.modal__close:hover { background: #f0f1f6; color: var(--text); }
.modal__section { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--border); }
.modal__subtitle { margin: 0 0 14px; font-size: 0.98rem; font-weight: 700; }
.modal__note { margin: 0 0 14px; font-size: 0.84rem; color: var(--muted); line-height: 1.7; }
.modal__section--danger .modal__subtitle { color: var(--expense); }

.errors {
    color: var(--expense);
    font-size: 0.85rem;
    margin-bottom: 12px;
    padding: 10px 12px;
    background: rgba(225, 29, 72, 0.07);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(225, 29, 72, 0.18);
}
.errors:empty { display: none; }

/* テーブル */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
    padding: 11px 8px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}
.table th {
    color: var(--faint);
    font-weight: 700;
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.table tbody tr { transition: background 0.12s ease; }
.table tbody tr:hover { background: #f8f9fd; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.tag {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 700;
    margin-right: 7px;
    vertical-align: 1px;
}
.tag--income { background: rgba(5, 150, 105, 0.12); color: #047857; }
.tag--expense { background: rgba(225, 29, 72, 0.12); color: #be123c; }
.amount--income { color: var(--income); font-weight: 700; }
.amount--expense { color: var(--expense); font-weight: 700; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.empty { text-align: center; color: var(--muted); padding: 24px; }

/* フッター */
.app-footer {
    margin: 40px 0 28px;
    color: var(--faint);
    font-size: 0.8rem;
    text-align: center;
}
.app-footer__nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px 20px;
}
.app-footer__nav a {
    color: var(--muted);
    text-decoration: none;
}
.app-footer__nav a:hover { color: var(--primary); text-decoration: underline; }

/* ブランド見出しのリンク（静的ページ用） */
.brand__link { color: inherit; text-decoration: none; }

/* 法務・静的ページ */
.legal { max-width: 760px; margin-top: 28px; }
.legal__title { font-size: 1.5rem; margin: 0 0 18px; }
.legal__content { color: var(--text); line-height: 1.85; font-size: 0.95rem; }
.legal__content h2 {
    font-size: 1.05rem;
    margin: 26px 0 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}
.legal__content ul { padding-left: 1.3em; margin: 8px 0; }
.legal__content li { margin: 4px 0; }
.legal__content a { color: var(--primary); }
.legal__dl { margin: 8px 0; }
.legal__dl dt { font-weight: 600; color: var(--muted); font-size: 0.85rem; margin-top: 14px; }
.legal__dl dd { margin: 2px 0 0; }
.legal__meta { margin-top: 26px; color: var(--muted); font-size: 0.85rem; }
.legal__back { margin: 30px 0 0; }
.legal__back a { color: var(--primary); text-decoration: none; }
.legal__back a:hover { text-decoration: underline; }

/* レスポンシブ */
@media (max-width: 760px) {
    .cards { grid-template-columns: 1fr; }
    .grid-2 { grid-template-columns: 1fr; }
    .chart:has(.donut-wrap) { grid-template-columns: 1fr; justify-items: center; gap: 18px; }
    .legend { width: 100%; max-width: 360px; }
}
