/* ========== Reset & Base ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Helvetica Neue', Arial, 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', Meiryo, sans-serif; font-size: 14px; color: #2c3e50; background: #f0f2f5; }
a { color: #3498db; text-decoration: none; }
a:hover { text-decoration: underline; }
input, select, textarea, button { font-family: inherit; font-size: 14px; }

/* ========== Layout ========== */
.app-layout { display: flex; height: 100vh; overflow: hidden; }

/* ========== Sidebar ========== */
.sidebar { width: 200px; min-width: 200px; background: #1a2f4b; color: #c8d8e8; display: flex; flex-direction: column; overflow-y: auto; }
.sidebar-header { padding: 1.5rem 1rem 1rem; border-bottom: 1px solid #2d4a6e; }
.sidebar-logo { font-size: 1rem; font-weight: 700; color: #fff; }
.sidebar-sub { font-size: 0.7rem; color: #7a9bbf; margin-top: 2px; }
.sidebar-nav { flex: 1; padding: 0.5rem 0; }
.nav-item { display: flex; align-items: center; gap: 0.5rem; padding: 0.7rem 1rem; color: #a8c0d8; transition: background 0.15s, color 0.15s; border-left: 3px solid transparent; font-size: 0.875rem; }
.nav-item:hover { background: #243e5e; color: #fff; text-decoration: none; }
.nav-item.active { background: #243e5e; color: #fff; border-left-color: #3498db; }
.nav-icon { font-size: 1rem; }
.sidebar-footer { padding: 1rem; border-top: 1px solid #2d4a6e; }
.sidebar-user { display: flex; align-items: center; gap: 0.4rem; font-size: 0.8rem; color: #a8c0d8; margin-bottom: 0.5rem; }
.btn-logout { width: 100%; background: transparent; border: 1px solid #3d5c7e; color: #a8c0d8; padding: 0.35rem 0; border-radius: 4px; cursor: pointer; font-size: 0.8rem; transition: background 0.15s; }
.btn-logout:hover { background: #243e5e; color: #fff; }

/* ========== Main area ========== */
.main-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.main-header { display: flex; align-items: center; justify-content: space-between; padding: 0.75rem 1.5rem; background: #fff; border-bottom: 1px solid #e2e8f0; min-height: 56px; flex-shrink: 0; }
.page-title { font-size: 1.1rem; font-weight: 700; color: #1a2f4b; }
.header-actions { display: flex; gap: 0.5rem; align-items: center; }
.main-content { flex: 1; overflow-y: auto; padding: 1.25rem 1.5rem; }

/* ========== Buttons ========== */
.btn { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.45rem 1rem; border-radius: 6px; border: none; cursor: pointer; font-size: 0.85rem; font-weight: 500; transition: background 0.15s, opacity 0.15s; white-space: nowrap; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: #3498db; color: #fff; }
.btn-primary:hover:not(:disabled) { background: #2980b9; }
.btn-secondary { background: #7f8c8d; color: #fff; }
.btn-secondary:hover:not(:disabled) { background: #6c7a7d; }
.btn-outline { background: #fff; color: #3498db; border: 1px solid #3498db; }
.btn-outline:hover:not(:disabled) { background: #ebf5fb; }
.btn-danger { background: #e74c3c; color: #fff; }
.btn-danger:hover:not(:disabled) { background: #c0392b; }
.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.78rem; }
.btn-lg { padding: 0.65rem 1.5rem; font-size: 0.95rem; }
.btn-block { width: 100%; justify-content: center; }

/* ========== Forms ========== */
.form-group { display: flex; flex-direction: column; gap: 0.3rem; }
.form-group label { font-size: 0.8rem; font-weight: 600; color: #4a5568; }
.form-group input, .form-group select, .form-group textarea {
  padding: 0.5rem 0.7rem; border: 1px solid #cbd5e0; border-radius: 6px; background: #fff;
  transition: border-color 0.15s; width: 100%;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none; border-color: #3498db; box-shadow: 0 0 0 3px rgba(52,152,219,0.1);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-section { margin-bottom: 1.5rem; }
.section-title { font-size: 0.85rem; font-weight: 700; color: #1a2f4b; margin-bottom: 0.75rem; padding-bottom: 0.4rem; border-bottom: 2px solid #e2e8f0; }
.form-actions { display: flex; gap: 0.75rem; margin-top: 1.5rem; align-items: center; }
.form-hint { font-size: 0.75rem; color: #718096; }
.required { color: #e74c3c; }

/* ========== Alerts ========== */
.alert { padding: 0.75rem 1rem; border-radius: 6px; margin-bottom: 1rem; font-size: 0.875rem; }
.alert-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.alert-error { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
.alert-warn { background: #fff3cd; color: #856404; border: 1px solid #ffeeba; }
.alert-info { background: #d1ecf1; color: #0c5460; border: 1px solid #bee5eb; }

/* ========== Badges ========== */
.badge { display: inline-block; padding: 0.2em 0.6em; border-radius: 9999px; font-size: 0.72rem; font-weight: 600; white-space: nowrap; }
.badge-type { background: #ebf5fb; color: #1a5276; }
.badge-ocr-done { background: #d4efdf; color: #1e8449; }
.badge-ok { background: #d5f5e3; color: #1e8449; }
.badge-warn { background: #fef9e7; color: #9a7d0a; }
.badge-error { background: #fadbd8; color: #922b21; }
.badge-running { background: #d7dbdd; color: #626567; }
.badge-neutral { background: #f0f0f0; color: #666; }

/* ========== Cards ========== */
.card { background: #fff; border-radius: 8px; border: 1px solid #e2e8f0; padding: 1.5rem; margin-bottom: 1.25rem; }
.card-title { font-size: 1rem; font-weight: 700; color: #1a2f4b; margin-bottom: 1rem; padding-bottom: 0.5rem; border-bottom: 1px solid #e2e8f0; }

/* ========== Filter panel ========== */
.filter-panel { background: #fff; border: 1px solid #e2e8f0; border-radius: 8px; margin-bottom: 1rem; overflow: hidden; }
.filter-panel-header { padding: 0.75rem 1rem; cursor: pointer; display: flex; justify-content: space-between; align-items: center; font-weight: 600; font-size: 0.875rem; color: #4a5568; user-select: none; }
.filter-panel-header:hover { background: #f7fafc; }
.filter-panel-body { padding: 1rem; border-top: 1px solid #e2e8f0; }
.filter-panel-body.collapsed { display: none; }
.filter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0.75rem; margin-bottom: 0.75rem; }
.filter-actions { display: flex; gap: 0.5rem; }

/* ========== Table ========== */
.table-wrap { overflow-x: auto; background: #fff; border-radius: 8px; border: 1px solid #e2e8f0; }
.doc-table { width: 100%; border-collapse: collapse; }
.doc-table th { background: #f7fafc; padding: 0.7rem 0.8rem; text-align: left; font-size: 0.78rem; font-weight: 700; color: #4a5568; border-bottom: 2px solid #e2e8f0; white-space: nowrap; }
.doc-table td { padding: 0.65rem 0.8rem; border-bottom: 1px solid #f0f4f8; vertical-align: middle; }
.doc-row { cursor: pointer; transition: background 0.1s; }
.doc-row:hover { background: #f0f7ff; }
.filename-cell { display: flex; align-items: center; gap: 0.4rem; max-width: 220px; }
.filename { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.partner-cell { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.amount-cell { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.date-cell { white-space: nowrap; color: #718096; font-size: 0.82rem; }
.file-icon { font-size: 1rem; }
.list-meta { padding: 0.5rem 0; color: #718096; font-size: 0.82rem; }

/* ========== Pagination ========== */
.pagination { display: flex; gap: 0.4rem; margin-top: 1rem; justify-content: center; }
.page-btn { padding: 0.35rem 0.7rem; border: 1px solid #cbd5e0; border-radius: 4px; background: #fff; color: #4a5568; font-size: 0.82rem; transition: background 0.1s; }
.page-btn:hover { background: #f0f7ff; text-decoration: none; }
.page-btn.active { background: #3498db; color: #fff; border-color: #3498db; }

/* ========== Empty state ========== */
.empty-state { text-align: center; padding: 3rem 1rem; color: #718096; }
.empty-icon { font-size: 3rem; margin-bottom: 0.75rem; }

/* ========== Detail layout ========== */
.detail-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; align-items: start; }
.file-viewer { background: #fff; border: 1px solid #e2e8f0; border-radius: 8px; overflow: hidden; position: sticky; top: 1rem; }
.pdf-viewer { width: 100%; height: 70vh; border: none; display: block; }
.image-viewer { width: 100%; height: auto; max-height: 70vh; object-fit: contain; display: block; background: #f7fafc; }
.no-file { padding: 3rem; text-align: center; color: #718096; font-size: 0.875rem; }
.file-actions { padding: 0.75rem; display: flex; gap: 0.5rem; border-top: 1px solid #e2e8f0; background: #f7fafc; }
.detail-form-area { background: #fff; border: 1px solid #e2e8f0; border-radius: 8px; overflow: hidden; }

/* ========== Tabs ========== */
.tab-bar { display: flex; border-bottom: 2px solid #e2e8f0; background: #f7fafc; }
.tab-btn { padding: 0.7rem 1rem; border: none; background: transparent; cursor: pointer; font-size: 0.85rem; color: #718096; border-bottom: 2px solid transparent; margin-bottom: -2px; transition: color 0.15s; }
.tab-btn.active { color: #3498db; border-bottom-color: #3498db; font-weight: 600; }
.tab-btn:hover { color: #3498db; }
.tab-content { padding: 1.25rem; }

/* ========== History ========== */
.history-list { display: flex; flex-direction: column; gap: 0.75rem; }
.history-item { background: #f7fafc; border: 1px solid #e2e8f0; border-radius: 6px; padding: 0.75rem; }
.history-header { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.3rem; flex-wrap: wrap; }
.history-date { font-size: 0.78rem; color: #718096; }
.history-user { font-size: 0.78rem; color: #718096; }
.history-summary { font-size: 0.85rem; color: #2c3e50; }
.history-change { font-size: 0.8rem; margin-top: 0.3rem; color: #4a5568; }
.history-field { font-weight: 600; }
.old-val { color: #e74c3c; text-decoration: line-through; }
.new-val { color: #27ae60; }
.history-reason { font-size: 0.78rem; color: #718096; margin-top: 0.2rem; }
.empty-note { color: #718096; font-size: 0.875rem; padding: 1rem 0; }

/* ========== Doc meta ========== */
.doc-meta { display: flex; gap: 1rem; flex-wrap: wrap; font-size: 0.75rem; color: #718096; margin-top: 1rem; padding-top: 0.75rem; border-top: 1px solid #e2e8f0; }

/* ========== Modal ========== */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 1000; display: flex; align-items: center; justify-content: center; }
.modal { background: #fff; border-radius: 10px; padding: 1.75rem; max-width: 440px; width: 90%; box-shadow: 0 20px 60px rgba(0,0,0,0.2); }
.modal h3 { margin-bottom: 0.75rem; color: #1a2f4b; }
.modal p { color: #718096; margin-bottom: 1rem; font-size: 0.875rem; }
.modal-actions { display: flex; gap: 0.75rem; margin-top: 1rem; }

/* ========== OCR ========== */
.ocr-banner { display: flex; gap: 1rem; padding: 1rem; background: #eaf6ff; border-bottom: 1px solid #bee3f8; align-items: flex-start; }
.ocr-banner-icon { font-size: 1.75rem; }
.ocr-banner strong { font-size: 0.9rem; color: #1a2f4b; }
.ocr-banner p { font-size: 0.82rem; color: #2c5f8a; margin-top: 0.2rem; }
.ocr-banner small { font-size: 0.72rem; color: #718096; }
.ocr-val { font-size: 0.72rem; color: #2980b9; font-style: italic; }
.ocr-rawtext { margin-top: 1rem; }
.ocr-rawtext summary { cursor: pointer; font-size: 0.82rem; color: #718096; padding: 0.3rem 0; }
.ocr-rawtext pre { background: #f7fafc; border: 1px solid #e2e8f0; border-radius: 4px; padding: 0.75rem; font-size: 0.72rem; overflow-x: auto; max-height: 200px; overflow-y: auto; margin-top: 0.5rem; white-space: pre-wrap; word-break: break-all; }

/* ========== Upload / Dropzone ========== */
.upload-card { max-width: 700px; }
.dropzone { border: 2px dashed #cbd5e0; border-radius: 8px; margin-bottom: 1.5rem; transition: border-color 0.2s; }
.dropzone.drag-over { border-color: #3498db; background: #ebf5fb; }
.dropzone-inner { padding: 2.5rem 1rem; text-align: center; cursor: pointer; }
.dropzone-inner:hover { background: #f7fafc; }
.dropzone-icon { font-size: 2.5rem; margin-bottom: 0.75rem; }
.dropzone-text { font-size: 0.9rem; color: #4a5568; margin-bottom: 0.25rem; }
.dropzone-sub { font-size: 0.78rem; color: #718096; }
.dropzone-preview { padding: 1rem 1.25rem; display: flex; align-items: center; gap: 0.75rem; }
.preview-icon { font-size: 1.5rem; }
.preview-name { flex: 1; font-size: 0.875rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-size { font-size: 0.78rem; color: #718096; white-space: nowrap; }
.preview-clear { background: none; border: none; font-size: 1.1rem; cursor: pointer; color: #718096; padding: 0.2rem; }
.preview-clear:hover { color: #e74c3c; }
.upload-options { margin-bottom: 1.5rem; }
.ocr-option { margin-top: 0.75rem; }
.checkbox-label { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; }
.checkbox-label input[type=checkbox] { width: auto; }

/* ========== Login ========== */
.login-body { background: #1a2f4b; display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-container { width: 100%; max-width: 380px; padding: 1rem; }
.login-card { background: #fff; border-radius: 12px; padding: 2.5rem 2rem; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.login-logo { text-align: center; margin-bottom: 1.75rem; }
.login-logo-icon { font-size: 2.5rem; }
.login-logo h1 { font-size: 1.4rem; color: #1a2f4b; margin: 0.5rem 0 0.2rem; }
.login-logo p { font-size: 0.8rem; color: #718096; }
.login-form { display: flex; flex-direction: column; gap: 1rem; }

/* ========== Simple search bar ========== */
.search-bar-simple { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.search-bar-simple input { flex: 1; padding: 0.5rem 0.75rem; border: 1px solid #cbd5e0; border-radius: 6px; }

/* ========== Simple table ========== */
.simple-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.simple-table th { background: #f7fafc; padding: 0.5rem 0.75rem; text-align: left; font-size: 0.78rem; color: #4a5568; border-bottom: 2px solid #e2e8f0; }
.simple-table td { padding: 0.5rem 0.75rem; border-bottom: 1px solid #f0f4f8; }

/* ========== Settings ========== */
.settings-card { max-width: 640px; }

/* ========== Responsive ========== */
@media (max-width: 900px) {
  .sidebar { width: 56px; min-width: 56px; }
  .sidebar-logo, .sidebar-sub, .nav-item span:not(.nav-icon), .sidebar-user span:not(.user-icon), .sidebar-footer .btn-logout { display: none; }
  .nav-item { justify-content: center; padding: 0.7rem; }
  .detail-layout { grid-template-columns: 1fr; }
  .pdf-viewer, .image-viewer { height: 40vh; }
  .file-viewer { position: static; }
  .form-row { grid-template-columns: 1fr; }
  .filter-grid { grid-template-columns: 1fr; }
}
