*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body { font-family: system-ui, sans-serif; font-size: 14px; background: #f5f5f5; color: #222; }

/* Login */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { background: #fff; border: 1px solid #ddd; border-radius: 6px; padding: 2rem; width: 320px; }
.login-card h1 { font-size: 1.2rem; margin-bottom: 1.5rem; text-align: center; color: #333; }
.field { margin-bottom: 1rem; }
.field label { display: block; margin-bottom: .3rem; font-weight: 500; }
.field input { width: 100%; padding: .5rem .75rem; border: 1px solid #ccc; border-radius: 4px; font-size: 14px; }
.login-card button[type="submit"] { width: 100%; padding: .6rem; background: #1a73e8; color: #fff; border: none; border-radius: 4px; cursor: pointer; font-size: 14px; }
.login-card button[type="submit"]:hover { background: #1558b0; }

/* Topbar */
.topbar { background: #1a73e8; color: #fff; display: flex; align-items: center; justify-content: space-between; padding: .6rem 1.5rem; }
.topbar .logo { font-weight: 600; }
.topbar nav { display: flex; align-items: center; gap: 1rem; }
.topbar a { color: #fff; text-decoration: none; }
.topbar a:hover { text-decoration: underline; }

/* Layout */
.container { max-width: 1200px; margin: 1.5rem auto; padding: 0 1rem; }

/* Toolbar */
.toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.toolbar h2 { font-size: 1.1rem; }
.filters { display: flex; gap: .5rem; align-items: center; }
.filters select, .filters input { padding: .4rem .6rem; border: 1px solid #ccc; border-radius: 4px; font-size: 13px; }

/* Buttons */
button, .btn-primary, .btn-secondary, .btn-approve, .btn-reject, .btn-text {
  cursor: pointer; border-radius: 4px; font-size: 13px; padding: .4rem .8rem; border: 1px solid transparent;
}
.btn-primary { background: #1a73e8; color: #fff; }
.btn-primary:hover { background: #1558b0; }
.btn-secondary { background: #fff; color: #444; border-color: #ccc; }
.btn-secondary:hover { background: #f0f0f0; }
.btn-approve { background: #34a853; color: #fff; font-size: 15px; padding: .6rem 1.5rem; }
.btn-approve:hover { background: #2d8f46; }
.btn-reject { background: #ea4335; color: #fff; font-size: 15px; padding: .6rem 1.5rem; }
.btn-reject:hover { background: #c5221f; }
.btn-text { background: none; border: none; color: inherit; padding: 0; }
.btn-sm { padding: .25rem .6rem; font-size: 12px; }

/* Table */
.data-table { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid #e0e0e0; border-radius: 6px; overflow: hidden; }
.data-table th { background: #f8f8f8; font-weight: 600; text-align: left; padding: .6rem .75rem; border-bottom: 1px solid #e0e0e0; }
.data-table td { padding: .55rem .75rem; border-bottom: 1px solid #f0f0f0; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #fafafa; }

/* Badges */
.badge { display: inline-block; padding: .2em .55em; border-radius: 3px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .02em; }
.badge-pending_review { background: #fff3cd; color: #856404; }
.badge-succeeded { background: #d4edda; color: #155724; }
.badge-approved { background: #d4edda; color: #155724; }
.badge-failed { background: #f8d7da; color: #721c24; }
.badge-rejected { background: #f8d7da; color: #721c24; }
.badge-queued { background: #d1ecf1; color: #0c5460; }
.badge-processing { background: #e2d9f3; color: #4a3f6b; }
.badge-review { background: #fff3cd; color: #856404; }
.badge-imap { background: #e8f4fd; color: #0860a8; }
.badge-folder { background: #e8f0fe; color: #1a56a0; }
.badge-local_file { background: #f3e8ff; color: #6b21a8; }
.badge-info { background: #d1ecf1; color: #0c5460; }
.badge-warning { background: #fff3cd; color: #856404; }
.badge-error { background: #f8d7da; color: #721c24; }

/* Review layout */
.review-layout { display: flex; flex-direction: column; gap: 1.5rem; }
.review-layout section { background: #fff; border: 1px solid #e0e0e0; border-radius: 6px; padding: 1rem 1.25rem; }
.review-layout h3 { font-size: .95rem; font-weight: 600; margin-bottom: .75rem; color: #333; }
.meta-grid { display: grid; grid-template-columns: 140px 1fr; gap: .35rem 1rem; font-size: 13px; }
.meta-key { color: #666; font-weight: 500; }
.review-actions { display: flex; gap: 1rem; justify-content: flex-end; }
.run-card { border: 1px solid #e0e0e0; border-radius: 4px; padding: .6rem .75rem; margin-bottom: .5rem; display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-start; }
pre.usage { background: #f8f8f8; padding: .5rem; border-radius: 4px; font-size: 11px; overflow-x: auto; width: 100%; }
ul#flags-list { padding-left: 1.25rem; }
ul#flags-list li { color: #c0392b; font-size: 13px; margin-bottom: .2rem; }

/* Pagination */
.pagination { display: flex; gap: .35rem; margin-top: 1rem; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal.hidden { display: none; }
.modal-card { background: #fff; border-radius: 6px; padding: 1.5rem; width: 400px; max-width: 95vw; }
.modal-card h3 { margin-bottom: 1rem; }
.modal-card label { display: block; margin-bottom: .4rem; font-weight: 500; }
.modal-card textarea { width: 100%; padding: .5rem; border: 1px solid #ccc; border-radius: 4px; font-size: 13px; resize: vertical; }
.modal-buttons { display: flex; gap: .75rem; justify-content: flex-end; margin-top: 1rem; }

/* Stats bar */
.stats-bar { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1.25rem; align-items: center; }
.stat-card { display: flex; flex-direction: column; align-items: center; padding: .5rem .9rem; border-radius: 6px; border: 1px solid transparent; cursor: pointer; min-width: 80px; transition: opacity .15s; }
.stat-card:hover { opacity: .85; }
.stat-count { font-size: 1.4rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; margin-top: .15rem; }
.stat-pending   { background: #fff3cd; color: #856404; border-color: #ffc107; }
.stat-queued    { background: #d1ecf1; color: #0c5460; border-color: #17a2b8; }
.stat-processing { background: #e2d9f3; color: #4a3f6b; border-color: #7b5ea7; }
.stat-succeeded  { background: #d4edda; color: #155724; border-color: #28a745; }
.stat-approved   { background: #d4edda; color: #155724; border-color: #28a745; }
.stat-rejected   { background: #f8d7da; color: #721c24; border-color: #dc3545; }
.stat-failed     { background: #f8d7da; color: #721c24; border-color: #dc3545; }
.stat-24h        { background: #e8f4fd; color: #0860a8; border-color: #78b7e5; cursor: default; }
.stat-total { margin-left: auto; font-size: 12px; color: #888; }

/* Pipeline flow */
.flow-diagram-section { background: #fff; border: 1px solid #e0e0e0; border-radius: 6px; padding: 1rem 1.25rem; margin-bottom: 1.5rem; }
.flow-diagram-section h2 { font-size: 1.05rem; margin-bottom: .9rem; color: #333; }
.flow-diagram { display: flex; flex-direction: column; align-items: center; gap: .35rem; }
.flow-row { display: grid; gap: .75rem; width: 100%; justify-content: center; }
.flow-row--sources { grid-template-columns: repeat(3, minmax(110px, 150px)); }
.flow-row--single { grid-template-columns: minmax(130px, 170px); }
.flow-row--outcomes { grid-template-columns: repeat(2, minmax(130px, 170px)); }
.flow-node { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 64px; padding: .55rem .75rem; border: 1px solid transparent; border-radius: 6px; }
.flow-count { font-size: 1.45rem; font-weight: 700; line-height: 1; }
.flow-label { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; margin-top: .2rem; text-align: center; }
.flow-arrow { color: #888; font-size: 1.15rem; line-height: 1; }
.flow-node--source { background: #e8f4fd; color: #0860a8; border-color: #78b7e5; }
.flow-node--queued { background: #d1ecf1; color: #0c5460; border-color: #17a2b8; }
.flow-node--processing { background: #e2d9f3; color: #4a3f6b; border-color: #7b5ea7; }
.flow-node--failed { background: #f8d7da; color: #721c24; border-color: #dc3545; }
.flow-node--pending { background: #fff3cd; color: #856404; border-color: #ffc107; }
.flow-node--succeeded { background: #d4edda; color: #155724; border-color: #28a745; }

@media (max-width: 560px) {
  .flow-row--sources,
  .flow-row--outcomes {
    grid-template-columns: 1fr;
  }
}

/* Review sections */
.review-layout section { background: #fff; border: 1px solid #e0e0e0; border-radius: 6px; padding: 1rem 1.25rem; }
.review-layout h3 { font-size: .95rem; font-weight: 600; margin-bottom: .75rem; color: #333; }

/* Extracted fields */
.fields-grid { display: grid; grid-template-columns: 160px 1fr; gap: .35rem 1rem; font-size: 13px; margin-bottom: .75rem; }
.validation-grid { display: grid; grid-template-columns: 160px 1fr; gap: .35rem 1rem; font-size: 13px; border-top: 1px solid #f0f0f0; padding-top: .75rem; }
.val-ok   { color: #28a745; font-weight: 600; }
.val-fail { color: #dc3545; font-weight: 600; }
.val-warn { color: #ffc107; font-weight: 600; }
.na { color: #aaa; font-style: italic; }

/* Downloads */
.downloads-row { display: flex; flex-wrap: wrap; gap: .5rem; }
.btn-download { text-decoration: none; display: inline-block; }

/* Requeue */
.requeue-actions { display: flex; justify-content: flex-end; }
.btn-requeue { border-color: #6c757d; color: #495057; }
.btn-requeue:hover { background: #e9ecef; }

/* Upload */
.upload-card { background: #fff; border: 1px solid #e0e0e0; border-radius: 6px; padding: 1rem 1.25rem; margin-bottom: 1.5rem; }
.upload-card h3 { font-size: .95rem; font-weight: 600; margin-bottom: .75rem; color: #333; }
.drop-zone { border: 2px dashed #ccc; border-radius: 6px; padding: 1.75rem 1rem; text-align: center; cursor: pointer; transition: border-color .15s, background .15s; }
.drop-zone:hover, .drop-zone.dragover { border-color: #1a73e8; background: #f0f5ff; }
.drop-zone input[type="file"] { display: none; }
.drop-zone-text { color: #555; margin-bottom: .3rem; font-size: 14px; }
.drop-zone-hint { font-size: 12px; color: #999; }
.upload-selected { margin-top: .75rem; display: flex; align-items: center; gap: .75rem; }
.upload-selected .file-info { font-size: 13px; color: #444; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-result { margin-top: .75rem; padding: .5rem .75rem; border-radius: 4px; font-size: 13px; }
.upload-result a { color: inherit; font-weight: 600; }
.upload-result.success { background: #d4edda; color: #155724; }
.upload-result.error { background: #f8d7da; color: #721c24; }
.badge-web_upload { background: #fef3c7; color: #92400e; }

/* Misc */
.error-msg { color: #c0392b; font-size: 13px; margin-top: .4rem; }
.hidden { display: none !important; }
