/* receipt_ocr - スマホ最適化CSS */
:root {
    --primary: #2d8659;
    --primary-light: #3da86f;
    --primary-dark: #1e5c3d;
    --bg: #f5f5f5;
    --card: #ffffff;
    --text: #333333;
    --text-sub: #888888;
    --border: #e0e0e0;
    --danger: #d32f2f;
    --nav-height: 60px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Hiragino Sans', sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    height: 100dvh;
    width: 100vw;
}

/* スクリーン切り替え */
.screen { display: none; position: absolute; inset: 0; overflow-y: auto; padding-bottom: calc(var(--nav-height) + var(--safe-bottom)); }
.screen.active { display: flex; flex-direction: column; }
#login-screen { padding-bottom: 0; }
#camera-screen { padding-bottom: 0; }

/* ===== ログイン画面 ===== */
.login-container {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    padding: 2rem; gap: 1rem;
}
.login-icon { font-size: 4rem; }
.login-container h1 { font-size: 1.5rem; color: var(--primary); }
.login-container p { color: var(--text-sub); }
.login-container input {
    width: 100%; max-width: 300px; padding: 12px 16px;
    border: 2px solid var(--border); border-radius: 12px;
    font-size: 1rem; text-align: center; outline: none;
}
.login-container input:focus { border-color: var(--primary); }
.error-msg { color: var(--danger); font-size: 0.85rem; min-height: 1.2em; }

/* ===== ボタン共通 ===== */
.btn-primary {
    background: var(--primary); color: #fff; border: none;
    padding: 12px 24px; border-radius: 12px; font-size: 1rem;
    cursor: pointer; font-weight: 600; width: 100%; max-width: 300px;
}
.btn-primary:active { background: var(--primary-dark); }
.btn-secondary {
    background: var(--card); color: var(--text); border: 2px solid var(--border);
    padding: 12px 24px; border-radius: 12px; font-size: 1rem;
    cursor: pointer; width: 100%; max-width: 300px;
}
.btn-large { padding: 16px 24px; font-size: 1.1rem; }
.btn-danger {
    background: var(--danger); color: #fff; border: none;
    padding: 10px 20px; border-radius: 10px; font-size: 0.9rem; cursor: pointer;
}
.btn-back {
    background: none; border: none; color: var(--primary);
    font-size: 1rem; cursor: pointer; padding: 8px;
}
.btn-close {
    background: none; border: none; font-size: 1.3rem;
    cursor: pointer; padding: 4px 8px; color: var(--text-sub);
}

/* ===== カメラ画面 ===== */
#camera-screen { background: #000; }
#camera-video {
    width: 100%; height: 100%; object-fit: cover;
}
.camera-overlay {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    pointer-events: none;
}
.camera-guide {
    width: 80%; max-width: 320px; aspect-ratio: 3/5;
    border: 2px dashed rgba(255,255,255,0.4); border-radius: 12px;
}
.camera-controls {
    position: absolute; left: 0; right: 0;
    bottom: calc(var(--nav-height) + var(--safe-bottom));
    display: flex; align-items: center; justify-content: space-around;
    padding: 20px 16px;
    background: linear-gradient(transparent, rgba(0,0,0,0.6));
    z-index: 10;
}
.btn-capture {
    width: 72px; height: 72px; border-radius: 50%;
    background: #fff; border: 4px solid rgba(255,255,255,0.5);
    cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.capture-inner {
    width: 58px; height: 58px; border-radius: 50%; background: #fff;
    transition: background 0.1s;
}
.btn-capture:active .capture-inner { background: #ccc; }
.btn-icon {
    font-size: 1.5rem; background: none; border: none;
    color: #fff; cursor: pointer; padding: 8px;
    display: flex; align-items: center; justify-content: center;
}

/* ===== 分析画面 ===== */
.analyze-header {
    display: flex; align-items: center; gap: 8px;
    padding: 12px 16px; background: var(--card);
    border-bottom: 1px solid var(--border);
}
.analyze-header h2 { font-size: 1.1rem; }
.analyze-body {
    flex: 1; overflow-y: auto;
    padding: 16px; padding-bottom: calc(16px + var(--nav-height) + var(--safe-bottom));
    display: flex; flex-direction: column; gap: 16px; align-items: center;
}
.preview-container {
    width: 100%; max-width: 400px; border-radius: 12px; overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.preview-container img { width: 100%; display: block; }
#analyze-actions { width: 100%; display: flex; justify-content: center; }

/* 分析中 */
.spinner {
    width: 40px; height: 40px; border: 4px solid var(--border);
    border-top-color: var(--primary); border-radius: 50%;
    animation: spin 0.8s linear infinite; margin: 0 auto 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }
#analyzing-indicator { text-align: center; padding: 24px; }
#analyzing-indicator p { color: var(--text-sub); }

/* 結果カード */
.result-card {
    background: var(--card); border-radius: 16px; overflow: hidden;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08); width: 100%; max-width: 400px;
}
.result-header {
    padding: 16px; background: var(--primary); color: #fff;
    display: flex; justify-content: space-between; align-items: center;
}
.result-header h3 { font-size: 1.1rem; }
.result-date { font-size: 0.85rem; opacity: 0.9; }
.items-table { width: 100%; border-collapse: collapse; }
.items-table th {
    background: #f8f8f8; padding: 8px 12px; font-size: 0.8rem;
    color: var(--text-sub); text-align: left; font-weight: 500;
}
.items-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.items-table td:nth-child(2), .items-table td:nth-child(4) { text-align: center; }
.items-table td:nth-child(3) { text-align: right; font-weight: 600; }
.result-footer { padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.result-total {
    display: flex; justify-content: space-between; font-size: 1.2rem;
    padding-bottom: 8px; border-bottom: 2px solid var(--primary);
}
.result-total strong { color: var(--primary); }
.result-tax, .result-payment {
    display: flex; justify-content: space-between; font-size: 0.85rem; color: var(--text-sub);
}
.result-cost {
    padding: 8px 16px; background: #f8f8f8; font-size: 0.75rem;
    color: var(--text-sub); text-align: center;
}
.result-actions {
    display: flex; gap: 12px; width: 100%; max-width: 400px;
}
.result-actions .btn-primary, .result-actions .btn-secondary { flex: 1; }
#result-container { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 16px; }

/* ===== 履歴画面 ===== */
.history-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px; background: var(--card);
    border-bottom: 1px solid var(--border);
}
.history-header h2 { font-size: 1.2rem; }
.month-filter {
    padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px;
    font-size: 0.85rem; background: var(--bg);
}
.history-list {
    flex: 1; overflow-y: auto;
    padding: 12px; padding-bottom: calc(12px + var(--nav-height) + var(--safe-bottom));
    display: flex; flex-direction: column; gap: 8px;
}
.history-item {
    background: var(--card); border-radius: 12px; padding: 14px 16px;
    display: flex; align-items: center; gap: 12px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06); cursor: pointer;
}
.history-item:active { background: #f0f0f0; }
.history-thumb {
    width: 48px; height: 48px; border-radius: 8px;
    object-fit: cover; background: var(--border); flex-shrink: 0;
}
.history-thumb-placeholder {
    width: 48px; height: 48px; border-radius: 8px;
    background: var(--border); flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.3rem;
}
.history-info { flex: 1; min-width: 0; }
.history-store { font-weight: 600; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-date { font-size: 0.8rem; color: var(--text-sub); }
.history-amount { font-weight: 700; color: var(--primary); font-size: 1rem; white-space: nowrap; }
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-sub); }

/* ===== 統計画面 ===== */
.stats-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px; background: var(--card);
    border-bottom: 1px solid var(--border);
}
.stats-header h2 { font-size: 1.2rem; }
.stats-body {
    flex: 1; overflow-y: auto;
    padding: 16px; padding-bottom: calc(16px + var(--nav-height) + var(--safe-bottom));
    display: flex; flex-direction: column; gap: 12px;
}
.stat-card {
    background: var(--card); border-radius: 16px; padding: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06); text-align: center;
}
.stat-label { font-size: 0.85rem; color: var(--text-sub); margin-bottom: 4px; }
.stat-value { font-size: 2rem; font-weight: 700; color: var(--primary); }
.stat-sub { font-size: 0.85rem; color: var(--text-sub); }
.api-card .stat-value { font-size: 1.3rem; color: var(--text-sub); }
.category-list { display: flex; flex-direction: column; gap: 8px; }
.category-item {
    background: var(--card); border-radius: 12px; padding: 12px 16px;
    display: flex; justify-content: space-between; align-items: center;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.category-name { font-size: 0.9rem; }
.category-amount { font-weight: 600; color: var(--primary); }
.category-bar {
    height: 4px; background: var(--primary); border-radius: 2px;
    margin-top: 6px; transition: width 0.3s;
}

/* ===== モーダル ===== */
.modal {
    position: fixed; inset: 0; background: rgba(0,0,0,0.5);
    display: flex; align-items: flex-end; justify-content: center; z-index: 100;
}
.modal.hidden { display: none; }
.modal-content {
    background: var(--card); border-radius: 20px 20px 0 0;
    width: 100%; max-width: 500px; max-height: 80vh; overflow-y: auto;
    padding: 20px; padding-bottom: calc(20px + var(--safe-bottom));
}
.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 16px;
}
.modal-header h3 { font-size: 1.1rem; }
.modal-actions { margin-top: 16px; display: flex; justify-content: center; }

/* ===== ナビゲーションバー ===== */
.nav-bar {
    position: fixed; bottom: 0; left: 0; right: 0;
    height: calc(var(--nav-height) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: var(--card); border-top: 1px solid var(--border);
    display: flex; justify-content: space-around; align-items: center;
    z-index: 50;
}
.nav-bar.hidden { display: none; }
.nav-item {
    background: none; border: none; display: flex; flex-direction: column;
    align-items: center; gap: 2px; padding: 6px 16px;
    font-size: 1.3rem; cursor: pointer; color: var(--text-sub);
}
.nav-item span { font-size: 0.7rem; }
.nav-item.active { color: var(--primary); }
.nav-item.active span { font-weight: 600; }

.hidden { display: none !important; }
