* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #f5f5f5;
    color: #333;
    line-height: 1.6;
}

header {
    background: #fff;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

header h1 { font-size: 1.4rem; }

#user-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
}

main { max-width: 1400px; margin: 2rem auto; padding: 0 1rem; }

.step {
    background: #fff;
    padding: 1.5rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.step h2 { margin-bottom: 1rem; font-size: 1.1rem; }

.hidden { display: none !important; }

.btn {
    padding: 0.5rem 1rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
    font-size: 0.9rem;
}

.btn:hover { background: #f0f0f0; }
.btn-primary { background: #4285f4; color: #fff; border-color: #4285f4; }
.btn-primary:hover { background: #3367d6; }
.btn-primary:disabled { background: #a0c4ff; cursor: not-allowed; }
.btn-sm { padding: 0.25rem 0.75rem; font-size: 0.85rem; }
.btn-large { padding: 0.75rem 2rem; font-size: 1.1rem; display: inline-block; text-decoration: none; color: #fff; }

select {
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    margin-left: 0.5rem;
    min-width: 250px;
}

#spreadsheet-select { min-width: 350px; }

#file-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
    max-height: 400px;
    overflow-y: auto;
}

.file-card {
    border: 2px solid #eee;
    border-radius: 6px;
    padding: 0.5rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s;
    font-size: 0.8rem;
    word-break: break-all;
}

.file-card.selected { border-color: #4285f4; background: #e8f0fe; }
.file-card img { max-width: 100%; max-height: 100px; border-radius: 4px; }

.stats-box {
    background: #e8f5e9;
    border: 1px solid #a5d6a7;
    border-radius: 6px;
    padding: 0.6rem 1rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.stats-note { color: #666; font-size: 0.8rem; }

.actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.actions label { display: flex; align-items: center; gap: 0.5rem; }
.actions input[type="text"] {
    padding: 0.4rem 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    min-width: 300px;
}

.export-options {
    background: #fafafa;
    border: 1px solid #eee;
    border-radius: 6px;
    padding: 1rem;
    margin-top: 1rem;
}
.export-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 0.6rem;
}
.export-row:last-child { margin-bottom: 0; }
.export-row label { display: flex; align-items: center; gap: 0.5rem; }
.export-row input[type="text"] {
    padding: 0.4rem 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    min-width: 250px;
}

.btn-delete {
    background: none;
    border: 1px solid #e57373;
    color: #e57373;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.85rem;
    padding: 2px 8px;
    line-height: 1.2;
}
.btn-delete:hover { background: #e57373; color: #fff; }

th:first-child, td:first-child { width: 35px; text-align: center; }

.file-card.ocr-done {
    opacity: 0.5;
    position: relative;
}
.file-card.ocr-done::after {
    content: "OCR済";
    position: absolute;
    top: 4px;
    right: 4px;
    background: #4caf50;
    color: #fff;
    font-size: 0.65rem;
    padding: 1px 5px;
    border-radius: 3px;
}

table {
    width: 100%;
    min-width: 800px;
    border-collapse: collapse;
    margin-bottom: 1rem;
    table-layout: fixed;
}

.table-scroll {
    overflow-x: auto;
    overflow-y: auto;
    max-height: calc(100vh - 250px);
}

th, td {
    text-align: left;
    padding: 0.6rem;
    border-bottom: 1px solid #eee;
    overflow: hidden;
}

th { background: #fafafa; font-weight: 600; }

/* 列幅: ×, ファイル名, 発生日, 勘定科目, 税区分, 金額, 税額, 備考, 決済口座 */
th:nth-child(2), td:nth-child(2) { width: 21%; }  /* ファイル名 */
th:nth-child(3), td:nth-child(3) { width: 10%; }  /* 発生日 */
th:nth-child(4), td:nth-child(4) { width: 10%; }  /* 勘定科目 */
th:nth-child(5), td:nth-child(5) { width: 11%; }  /* 税区分 */
th:nth-child(6), td:nth-child(6) { width: 9%; }   /* 金額 */
th:nth-child(7), td:nth-child(7) { width: 7%; }   /* 税額 */
th:nth-child(8), td:nth-child(8) { width: 15%; }  /* 備考 */
th:nth-child(9), td:nth-child(9) { width: 13%; }  /* 決済口座 */

td input, td select {
    width: 100%;
    box-sizing: border-box;
    padding: 0.3rem 0.4rem;
    border: 1px solid #ddd;
    border-radius: 3px;
}
td select[data-field="tax_class"] {
    font-size: 0.8rem;
    padding: 0.2rem 0.1rem;
}
td input.readonly-field {
    background: #f0f0f0;
    color: #666;
    cursor: not-allowed;
}

#loading {
    position: fixed;
    inset: 0;
    background: rgba(255,255,255,0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #ddd;
    border-top-color: #4285f4;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin { to { transform: rotate(360deg); } }

#loading-text {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

#progress-bar-container {
    width: 300px;
    height: 6px;
    background: #e0e0e0;
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 1rem;
}

#progress-bar {
    height: 100%;
    width: 0%;
    background: #4285f4;
    border-radius: 3px;
    transition: width 0.3s ease;
}

#progress-log {
    background: #fafafa;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 0.75rem 1rem;
    max-width: 450px;
    width: 90%;
    max-height: 200px;
    overflow-y: auto;
    font-size: 0.8rem;
    line-height: 1.6;
    color: #555;
    text-align: left;
}

#progress-log:empty { display: none; }

.log-entry { padding: 2px 0; }
.log-entry .log-icon { margin-right: 6px; }
.log-entry.done { color: #2e7d32; }
.log-entry.active { color: #1565c0; font-weight: 600; }

.welcome { padding: 2rem 1rem; max-width: 800px; margin: 0 auto; }
.welcome h2 { text-align: center; margin-bottom: 2rem; font-size: 1.3rem; color: #333; }

/* フィーチャーカード（上部の3カード） */
.features-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 2.5rem;
}
.feature-card {
    background: #fff;
    border-radius: 12px;
    padding: 1.2rem 1.5rem;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    flex: 1;
    max-width: 180px;
}
.feature-icon { font-size: 2rem; margin-bottom: 0.4rem; }
.feature-title { font-weight: 700; font-size: 0.95rem; margin-bottom: 0.2rem; }
.feature-desc { font-size: 0.8rem; color: #666; }
.feature-arrow { font-size: 1.4rem; color: #bbb; flex-shrink: 0; }

/* フェーズ */
.usage-phases { display: flex; flex-direction: column; gap: 1.5rem; margin-bottom: 2rem; }
.usage-phase {
    background: #fff;
    border-radius: 10px;
    padding: 1.2rem 1.5rem;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.phase-header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 1rem;
}
.phase-badge {
    display: inline-block;
    padding: 0.15rem 0.7rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: 0.02em;
}
.phase-prep { background: #34a853; }
.phase-action { background: #4285f4; }
.phase-check { background: #ea4335; }
.phase-title { font-weight: 600; font-size: 1rem; }

/* ステップカード */
.step-cards { display: flex; flex-direction: column; gap: 0.6rem; }
.step-card {
    display: flex;
    align-items: flex-start;
    gap: 0.8rem;
    padding: 0.6rem 0.5rem;
    border-radius: 6px;
    transition: background 0.15s;
}
.step-card:hover { background: #f8f9fa; }
.step-num {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #e8f0fe;
    color: #4285f4;
    font-weight: 700;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
}
.step-content { flex: 1; min-width: 0; }
.step-label { font-weight: 600; font-size: 0.9rem; margin-bottom: 0.1rem; }
.step-detail { font-size: 0.82rem; color: #555; line-height: 1.5; }

/* CTA */
.welcome-cta { text-align: center; }
.btn-cta { padding: 0.7rem 2rem; font-size: 1rem; border-radius: 6px; text-decoration: none; display: inline-block; }

@media (max-width: 600px) {
    .features-row { flex-direction: column; gap: 0.75rem; }
    .feature-arrow { transform: rotate(90deg); }
    .feature-card { max-width: none; }
}

#export-result a.btn-primary,
#export-result a.btn-primary:link,
#export-result a.btn-primary:visited,
#export-result a.btn-primary:hover,
#export-result a.btn-primary:active { color: #fff; font-weight: 600; }
#export-result a:not(.btn) { color: #4285f4; font-weight: 600; }

.file-name-text {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.8rem;
}

.btn-icon {
    background: none;
    border: 1px solid #ccc;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.75rem;
    padding: 0 4px;
    margin-right: 2px;
    vertical-align: middle;
}
.btn-icon:hover { background: #eee; }

/* スプリットレイアウト */
#split-container {
    display: flex;
    gap: 0;
    align-items: stretch;
}

#split-left {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

#split-divider {
    width: 6px;
    background: #e0e0e0;
    cursor: col-resize;
    flex-shrink: 0;
    display: none;
    position: relative;
}
#split-divider:hover,
#split-divider.dragging {
    background: #4285f4;
}
#split-divider.visible { display: block; }

#split-right {
    width: 0;
    display: none;
    flex-direction: column;
    background: #fafafa;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    overflow: hidden;
}
#split-right.active {
    display: flex;
    width: 350px;
}

.preview-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid #eee;
    font-size: 0.8rem;
    font-weight: 600;
    background: #fafafa;
    flex-shrink: 0;
}

.preview-panel-body {
    overflow: auto;
    padding: 0.5rem;
    flex: 1;
    max-height: calc(100vh - 250px);
}

.preview-panel-body img {
    width: 100%;
    display: block;
}

/* プレビューパネルアクション */
.preview-panel-actions {
    display: flex;
    gap: 4px;
    align-items: center;
}

/* プレビューモーダル */
.preview-modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
}

.preview-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.5);
}

.preview-modal-content {
    position: relative;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    max-width: 90vw;
    max-height: 90vh;
    width: 600px;
}

.preview-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 1rem;
    border-bottom: 1px solid #eee;
    font-size: 0.85rem;
    font-weight: 600;
    flex-shrink: 0;
}

.preview-modal-body {
    overflow: auto;
    padding: 0.5rem;
    flex: 1;
    min-height: 0;
}

.preview-modal-body img {
    width: 100%;
    display: block;
}

/* モード表示ボタン */
.btn-icon.active-mode {
    background: #e8f0fe;
    border-color: #4285f4;
    color: #4285f4;
}

.debug-panel {
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: #1e1e1e;
    color: #d4d4d4;
    border-radius: 4px;
    max-height: 300px;
    overflow: auto;
    font-size: 0.75rem;
}
.debug-panel strong { color: #569cd6; display: block; margin-top: 0.3rem; }
.debug-raw {
    white-space: pre-wrap;
    word-break: break-all;
    margin: 0.2rem 0 0.5rem;
    font-family: "SF Mono", Monaco, Consolas, monospace;
    font-size: 0.7rem;
    line-height: 1.4;
}
