/* === リセット & 基本 === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --danger: #dc2626;
    --success: #16a34a;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-500: #6b7280;
    --gray-700: #374151;
    --gray-900: #111827;
    --radius: 8px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", sans-serif;
    background: var(--gray-50);
    color: var(--gray-900);
    font-size: 16px;
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
}

/* === トップバー === */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--primary);
    color: #fff;
    padding: 6px 12px;
    position: sticky;
    top: 0;
    z-index: 100;
    font-size: 13px;
}

.top-bar-user {
    opacity: 0.9;
}

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 4px;
}

.top-bar-right a, .top-bar-link {
    color: #fff;
    text-decoration: none;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 13px;
    white-space: nowrap;
}

.top-bar-right a:hover {
    background: rgba(255,255,255,0.2);
}

/* === ボトムナビ === */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #fff;
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 8px 0 env(safe-area-inset-bottom, 8px);
    box-shadow: 0 -2px 8px rgba(0,0,0,0.12);
    z-index: 100;
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    color: var(--gray-500);
    font-size: 13px;
    padding: 6px 12px;
    border-radius: 8px;
    transition: color 0.15s;
    min-width: 60px;
}

.bottom-nav-item.active {
    color: var(--primary);
}

.bottom-nav-item:hover {
    color: var(--primary);
}

.bottom-nav-icon {
    font-size: 28px;
    line-height: 1;
}

.bottom-nav-label {
    font-weight: 600;
    margin-top: 4px;
    white-space: nowrap;
}

/* === カメラページ === */
.camera-page {
    padding-bottom: 20px;
}

.camera-area {
    margin-bottom: 16px;
}

.camera-capture-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    border: 2px dashed var(--primary);
    border-radius: var(--radius);
    cursor: pointer;
    text-align: center;
    color: var(--primary);
    background: #eff6ff;
    transition: background 0.15s;
}

.camera-capture-label:hover {
    background: #dbeafe;
}

.camera-capture-icon {
    font-size: 48px;
    margin-bottom: 8px;
}

.camera-capture-text {
    font-size: 16px;
    font-weight: 600;
}

.camera-preview {
    margin-top: 12px;
}

.camera-preview img {
    max-width: 100%;
    border-radius: var(--radius);
    max-height: 240px;
    object-fit: contain;
}

.nav-dropdown {
    position: relative;
}

.dropdown-content {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    background: #fff;
    border-radius: var(--radius);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    min-width: 140px;
    overflow: hidden;
    z-index: 200;
}

.dropdown-content a {
    color: var(--gray-700) !important;
    display: block;
    padding: 10px 14px !important;
    font-size: 14px !important;
}

.dropdown-content a:hover {
    background: var(--gray-100) !important;
}

.nav-dropdown:hover .dropdown-content,
.nav-dropdown:focus-within .dropdown-content {
    display: block;
}

/* === コンテナ === */
.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 16px;
    padding-bottom: 80px;
}

/* === 見出し === */
h1 {
    font-size: 20px;
    margin-bottom: 16px;
    color: var(--gray-900);
}

/* === フラッシュメッセージ === */
.flash {
    padding: 10px 14px;
    border-radius: var(--radius);
    margin-bottom: 12px;
    font-size: 14px;
}

.flash.success { background: #dcfce7; color: #166534; }
.flash.error { background: #fef2f2; color: #991b1b; }

/* === フォーム === */
.form-group {
    margin-bottom: 14px;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 4px;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 16px;
    background: #fff;
    -webkit-appearance: none;
    appearance: none;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%236b7280' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.input-with-unit {
    display: flex;
    align-items: center;
    gap: 6px;
}

.input-with-unit input { flex: 1; }
.unit { font-size: 14px; color: var(--gray-500); white-space: nowrap; }

/* === ラジオボタン === */
.radio-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color 0.15s;
}

.radio-label:has(input:checked) {
    border-color: var(--primary);
    background: #eff6ff;
}

.radio-label input[type="radio"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

.radio-text {
    font-size: 15px;
}

/* === カメラ入力 === */
.file-input {
    display: none;
}

.camera-label {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 20px;
    border: 2px dashed var(--gray-300);
    border-radius: var(--radius);
    cursor: pointer;
    text-align: center;
    color: var(--gray-500);
    transition: border-color 0.15s, background 0.15s;
}

.camera-label:hover {
    border-color: var(--primary);
    background: #eff6ff;
}

.camera-icon { font-size: 24px; }

/* === OCRステータス === */
.ocr-status {
    margin-top: 8px;
    padding: 8px 12px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
}

.ocr-status.loading {
    background: #eff6ff;
    color: var(--primary);
    animation: pulse 1.5s infinite;
}

.ocr-status.success {
    background: #dcfce7;
    color: #166534;
}

.ocr-status.error {
    background: #fef2f2;
    color: #991b1b;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.image-preview {
    margin-top: 8px;
}

.image-preview img {
    max-width: 100%;
    border-radius: var(--radius);
    max-height: 200px;
    object-fit: contain;
}

/* === ボタン === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--gray-200); color: var(--gray-700); }
.btn-secondary:hover { background: var(--gray-300); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-block { width: 100%; }

.btn-small {
    padding: 5px 12px;
    font-size: 13px;
}

.button-row {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.button-row .btn { flex: 1; }

/* === ログイン === */
.login-container {
    max-width: 360px;
    margin: 60px auto;
    padding: 24px;
    background: #fff;
    border-radius: var(--radius);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.login-container h1 {
    text-align: center;
    margin-bottom: 24px;
}

/* === フィルター === */
.filter-section {
    margin-bottom: 16px;
    background: #fff;
    border-radius: var(--radius);
    padding: 12px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.filter-section summary {
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    color: var(--gray-700);
}

.filter-form {
    margin-top: 12px;
}

.filter-row {
    display: flex;
    gap: 8px;
}

.filter-row .form-group { flex: 1; }

.result-count {
    font-size: 13px;
    color: var(--gray-500);
    margin-bottom: 8px;
}

.summary-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #fff;
    padding: 10px 14px;
    border-radius: var(--radius);
    margin-bottom: 10px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
    font-size: 14px;
    color: var(--gray-700);
}

.summary-total {
    font-size: 18px;
    font-weight: 700;
    color: var(--gray-900);
}

/* === レシートカード === */
.receipt-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.receipt-card {
    background: #fff;
    border-radius: var(--radius);
    padding: 12px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

.receipt-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.receipt-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.receipt-date {
    font-size: 13px;
    color: var(--gray-500);
    font-weight: 600;
}

.receipt-user {
    font-size: 12px;
    color: #fff;
    background: var(--gray-500);
    padding: 1px 8px;
    border-radius: 10px;
    font-weight: 500;
}

.receipt-company {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 600;
}

.tag-株式会社Repair { background: #dbeafe; color: #1e40af; }
.tag-合同会社MIBA { background: #fce7f3; color: #9d174d; }
.tag-個人 { background: #f3f4f6; color: #374151; }

.receipt-body {
    display: flex;
    gap: 10px;
}

.receipt-thumb {
    flex-shrink: 0;
    width: 60px;
    height: 60px;
    border-radius: 6px;
    overflow: hidden;
}

.receipt-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.receipt-info { flex: 1; min-width: 0; }

.receipt-store {
    font-weight: 600;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.receipt-amount {
    font-size: 18px;
    font-weight: 700;
    color: var(--gray-900);
}

.receipt-meta {
    font-size: 12px;
    color: var(--gray-500);
    display: flex;
    gap: 8px;
}

.receipt-memo {
    font-size: 12px;
    color: var(--gray-500);
    margin-top: 2px;
}

.receipt-actions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
    justify-content: flex-end;
}

.inline-form { display: inline; }

/* === マスタ管理 === */
.add-form, .add-section {
    margin-bottom: 16px;
    background: #fff;
    padding: 12px;
    border-radius: var(--radius);
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.add-section summary {
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
}

.form-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.flex-input { flex: 1; }

.master-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.master-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #fff;
    padding: 10px 14px;
    border-radius: var(--radius);
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.master-name {
    font-weight: 600;
    font-size: 15px;
}

.user-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.user-meta {
    font-size: 12px;
    color: var(--gray-500);
}

/* === チェックボックス・インボイス === */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color 0.15s;
}

.checkbox-label:has(input:checked) {
    border-color: var(--primary);
    background: #eff6ff;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

.checkbox-text {
    font-size: 15px;
    font-weight: 500;
}

.field-hint {
    display: block;
    font-size: 12px;
    color: var(--gray-500);
    margin-top: 2px;
}

.invoice-badge {
    background: #fef3c7;
    color: #92400e;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
}

/* === その他 === */
.info-box {
    margin-top: 24px;
    padding: 16px;
    background: #eff6ff;
    border-radius: var(--radius);
    font-size: 14px;
}

.info-box h3 {
    font-size: 15px;
    margin-bottom: 6px;
}

.info-box p {
    color: var(--gray-700);
    margin-top: 4px;
}

.empty-message {
    text-align: center;
    color: var(--gray-500);
    padding: 40px 0;
}

/* === 画像フルビューモーダル === */
.image-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.9);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.image-modal img {
    max-width: 95%;
    max-height: 95%;
    object-fit: contain;
    touch-action: pinch-zoom;
}

.image-modal-close {
    position: absolute;
    top: 12px;
    right: 16px;
    color: #fff;
    font-size: 36px;
    cursor: pointer;
    z-index: 1001;
    line-height: 1;
}

/* === 下書きバッジ・ナビバッジ === */
.nav-badge {
    background: #ef4444;
    color: #fff;
    font-size: 10px;
    padding: 1px 5px;
    border-radius: 8px;
    margin-left: 2px;
    font-weight: 700;
}

/* === 下書きカード === */
.draft-card {
    background: #fff;
    border-radius: var(--radius);
    padding: 12px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
    border-left: 4px solid #f59e0b;
}

.draft-card .receipt-actions {
    gap: 6px;
}

.btn-success {
    background: var(--success);
    color: #fff;
}

.btn-success:hover {
    background: #15803d;
}

/* === バッチプレビューグリッド === */
.batch-preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 8px;
    margin-top: 12px;
}

.batch-preview-grid img {
    width: 100%;
    height: 80px;
    object-fit: cover;
    border-radius: 6px;
}

.batch-progress {
    margin-top: 12px;
    padding: 10px 14px;
    background: #eff6ff;
    border-radius: var(--radius);
    font-size: 14px;
}

/* === レスポンシブ（デスクトップ） === */
@media (min-width: 768px) {
    .radio-group {
        flex-direction: row;
    }

    .radio-label {
        flex: 1;
    }
}
