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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: #f5f5f5;
    color: #333;
    padding: 20px;
}

.container {
    max-width: 100%;
    margin: 0 auto;
}

.container > h1 {
    margin-bottom: 4px;
    font-size: 1.5rem;
    color: #222;
}

.subtitle {
    color: #666;
    font-size: 0.85rem;
    margin-bottom: 12px;
}

.help-section {
    background: white;
    border: 1px solid #ddd;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 0.82rem;
}

.help-section summary {
    padding: 8px 14px;
    cursor: pointer;
    font-weight: 600;
    color: #444;
    user-select: none;
}

.help-section summary:hover {
    color: #2563eb;
}

.help-body {
    padding: 4px 14px 14px;
    color: #555;
    line-height: 1.5;
}

.help-body h3 {
    font-size: 0.82rem;
    color: #333;
    margin: 10px 0 4px;
}

.help-body h3:first-child {
    margin-top: 0;
}

.help-body p {
    margin: 0 0 6px;
}

.help-body code {
    background: #f3f4f6;
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 0.78rem;
}

.upload-section {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.upload-btn {
    padding: 10px 20px;
    background: #2563eb;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
}

.upload-btn:hover {
    background: #1d4ed8;
}

.file-info {
    color: #666;
    font-size: 0.85rem;
}

.controls {
    margin-bottom: 16px;
}

.controls-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 12px;
}

.toggle-columns-btn {
    padding: 6px 14px;
    background: #6b7280;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
}

.toggle-columns-btn:hover {
    background: #4b5563;
}

.data-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.distinct-btn {
    padding: 6px 14px;
    background: #6b7280;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
}

.distinct-btn:hover {
    background: #4b5563;
}

.distinct-btn.active {
    background: #2563eb;
}

.distinct-btn.active:hover {
    background: #1d4ed8;
}

.export-btn {
    padding: 6px 14px;
    background: #059669;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
}

.export-btn:hover {
    background: #047857;
}

.excel-btn {
    background: #1d4ed8;
}

.excel-btn:hover {
    background: #1e40af;
}

.excel-options {
    background: white;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 10px 14px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 0.82rem;
}

.excel-options label {
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    white-space: nowrap;
}

.excel-options-actions {
    display: flex;
    gap: 8px;
    margin-left: auto;
}

.excel-download-btn {
    padding: 6px 14px !important;
    font-size: 0.8rem !important;
}

.excel-download-btn:disabled {
    background: #9ca3af !important;
    cursor: not-allowed;
}

.flatten-label {
    font-size: 0.8rem;
    color: #444;
    display: flex;
    align-items: center;
    gap: 4px;
}

.flatten-select {
    padding: 4px 6px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.78rem;
    background: white;
}

.count-col {
    background: #fefce8;
}

th.count-col {
    background: #fef9c3;
}

.result-count {
    font-size: 0.85rem;
    color: #555;
}

.column-details {
    background: white;
    border: 1px solid #ddd;
    border-radius: 6px;
    margin-bottom: 12px;
    font-size: 0.82rem;
}

.column-details summary {
    padding: 8px 14px;
    cursor: pointer;
    font-weight: 600;
    color: #444;
    user-select: none;
}

.column-details summary:hover {
    color: #2563eb;
}

.column-details .col-selector-toolbar {
    padding: 4px 12px 0;
}

.column-details .col-checkboxes {
    padding: 8px 12px 12px;
}

.col-selector-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.col-search-input {
    padding: 5px 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.8rem;
    width: 200px;
}

.col-search-input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.col-btn-group {
    display: inline-flex;
    gap: 4px;
    align-items: center;
}

.col-toolbar-btn {
    padding: 4px 10px;
    background: #e5e7eb;
    border: 1px solid #ccc;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 500;
    color: #333;
}

.col-toolbar-btn:hover:not(:disabled) {
    background: #d1d5db;
}

.col-toolbar-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.col-match-count {
    font-size: 0.75rem;
    color: #888;
}

.col-checkboxes {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 16px;
    max-height: 180px;
    overflow-y: auto;
}

.col-checkboxes label {
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    white-space: nowrap;
}

.col-checkboxes label.col-hidden {
    display: none;
}

.filter-set-controls {
    padding: 8px 12px 12px;
}

.filter-set-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.filter-set-row:last-child {
    margin-bottom: 0;
}

.filter-set-select {
    padding: 5px 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.78rem;
    background: white;
    min-width: 200px;
    flex: 1;
    max-width: 400px;
}

.filter-set-select:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.search-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.filter-label {
    font-size: 0.7rem;
    color: #555;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 160px;
}

.filter-input-row {
    display: flex;
    align-items: center;
    gap: 4px;
}

.blank-select {
    padding: 4px 2px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.75rem;
    background: white;
    cursor: pointer;
}

.blank-select:focus {
    outline: none;
    border-color: #2563eb;
}

.filter-input {
    width: 120px;
    padding: 4px 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.8rem;
}

.filter-input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.filter-input.regex-error {
    border-color: #dc2626;
    box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.15);
}

.regex-toggle {
    display: flex;
    align-items: center;
    gap: 2px;
    font-size: 0.65rem;
    color: #888;
    cursor: pointer;
    user-select: none;
}

.regex-toggle input {
    cursor: pointer;
}

.regex-presets {
    padding: 4px 2px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.72rem;
    background: white;
    cursor: pointer;
    max-width: 120px;
}

.regex-presets:focus {
    outline: none;
    border-color: #2563eb;
}

.table-wrapper {
    overflow-x: auto;
    background: white;
    border-radius: 6px;
    border: 1px solid #ddd;
    max-height: 70vh;
    overflow-y: auto;
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.8rem;
}

thead {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #f8f9fa;
}

th {
    background: #f8f9fa;
    border-bottom: 2px solid #dee2e6;
    padding: 8px 10px;
    text-align: left;
    font-weight: 600;
    white-space: nowrap;
    font-size: 0.75rem;
    color: #444;
}

td {
    padding: 6px 10px;
    border-bottom: 1px solid #eee;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.78rem;
}

td:hover {
    white-space: normal;
    word-break: break-all;
}

tr:hover td {
    background: #f0f7ff;
}

tr.row-selected td {
    background: #dbeafe;
}

tr.row-selected:hover td {
    background: #bfdbfe;
}

.select-col {
    width: 30px;
    text-align: center;
    padding: 4px !important;
}

th.select-col {
    background: #f8f9fa;
}

.filter-label-row {
    display: flex;
    align-items: center;
    gap: 4px;
}

.stats-btn {
    background: none;
    border: 1px solid #ccc;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.65rem;
    padding: 1px 4px;
    color: #666;
    line-height: 1;
    flex-shrink: 0;
}

.stats-btn:hover {
    background: #e0e7ff;
    border-color: #2563eb;
    color: #2563eb;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal {
    background: white;
    border-radius: 10px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    width: 720px;
    max-width: 90vw;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #eee;
}

.modal-header h2 {
    font-size: 1rem;
    color: #222;
    word-break: break-all;
}

.modal-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.save-pdf-btn {
    padding: 5px 14px;
    background: #2563eb;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 500;
}

.save-pdf-btn:hover {
    background: #1d4ed8;
}

.save-pdf-btn:disabled {
    background: #9ca3af;
    cursor: not-allowed;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #999;
    padding: 0 4px;
    line-height: 1;
}

.modal-close:hover {
    color: #333;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    font-size: 0.82rem;
}

.stats-section {
    margin-bottom: 20px;
}

.stats-section h3 {
    font-size: 0.85rem;
    color: #2563eb;
    margin-bottom: 8px;
    border-bottom: 1px solid #e5e7eb;
    padding-bottom: 4px;
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 24px;
}

.stats-grid dt {
    color: #666;
    font-size: 0.78rem;
}

.stats-grid dd {
    font-weight: 600;
    font-size: 0.78rem;
    text-align: right;
}

.stats-bar-list {
    list-style: none;
}

.stats-bar-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
    font-size: 0.78rem;
}

.stats-bar-label {
    min-width: 140px;
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex-shrink: 0;
}

.stats-bar-track {
    flex: 1;
    height: 14px;
    background: #f0f0f0;
    border-radius: 3px;
    overflow: hidden;
    min-width: 60px;
}

.stats-bar-fill {
    height: 100%;
    background: #2563eb;
    border-radius: 3px;
    min-width: 1px;
}

.stats-bar-count {
    min-width: 60px;
    text-align: right;
    color: #666;
    font-size: 0.72rem;
    flex-shrink: 0;
    white-space: nowrap;
}

.stats-overview-row {
    display: flex;
    align-items: center;
    gap: 24px;
}

.chart-wrapper-inline {
    flex-shrink: 0;
}

.chart-wrapper {
    margin-top: 10px;
    position: relative;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 0.82rem;
    color: #555;
}

.page-info {
    font-weight: 500;
}

.page-controls {
    display: flex;
    align-items: center;
    gap: 4px;
}

.page-btn {
    padding: 4px 10px;
    background: #e5e7eb;
    border: 1px solid #ccc;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    line-height: 1;
}

.page-btn:hover:not(:disabled) {
    background: #d1d5db;
}

.page-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.page-size-label {
    font-size: 0.8rem;
    color: #444;
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: 8px;
}

.page-size-select {
    padding: 4px 6px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.78rem;
    background: white;
}

.export-name-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: #555;
    white-space: nowrap;
}

.export-name-presets {
    padding: 4px 6px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.75rem;
    background: white;
    cursor: pointer;
}

.export-name-presets:focus {
    outline: none;
    border-color: #2563eb;
}

.export-name-input {
    flex: 1;
    max-width: 350px;
    padding: 5px 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
    font-size: 0.78rem;
}

.export-name-input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.export-name-preview {
    font-size: 0.72rem;
    font-style: italic;
    color: #888;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stats-generated-date {
    font-size: 0.75rem;
    font-style: italic;
    color: #888;
    margin-bottom: 12px;
}

.sort-arrow {
    font-size: 0.7rem;
    margin-left: 2px;
    color: #2563eb;
}

.sort-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #2563eb;
    color: white;
    font-size: 0.55rem;
    font-weight: 700;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    margin-left: 3px;
    vertical-align: middle;
    line-height: 1;
}

th:hover {
    color: #2563eb;
}

.hidden {
    display: none !important;
}

.loading {
    text-align: center;
    padding: 40px;
    color: #888;
    font-size: 0.9rem;
}

/* Table header drag */
th[draggable="true"] { cursor: grab; }
th[draggable="true"]:active { cursor: grabbing; }
th.col-dragging { opacity: 0.4; }
th.col-drag-over-left { border-left: 3px solid #2563eb; }
th.col-drag-over-right { border-right: 3px solid #2563eb; }

/* Column Order panel */
.col-order-list { padding: 8px 12px 12px; max-height: 300px; overflow-y: auto; }
.col-order-item {
    display: flex; align-items: center; gap: 8px;
    padding: 4px 8px; margin-bottom: 2px;
    background: #f8f9fa; border: 1px solid #e5e7eb;
    border-radius: 4px; font-size: 0.8rem;
    cursor: grab; user-select: none;
}
.col-order-item:active { cursor: grabbing; }
.col-order-dragging { opacity: 0.4; }
.col-order-handle { color: #999; font-size: 0.75rem; flex-shrink: 0; }
.col-order-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col-order-drag-over-top { border-top: 2px solid #2563eb; }
.col-order-drag-over-bottom { border-bottom: 2px solid #2563eb; }

/* Upload limit */
.upload-limit-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    font-size: 0.9em;
    color: #64748b;
}
.upload-limit-row select {
    padding: 4px 8px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.9em;
    background: #fff;
}
.clear-btn {
    padding: 4px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.9em;
    background: #fff;
    cursor: pointer;
    color: #64748b;
}
.clear-btn:hover {
    background: #f1f5f9;
    color: #334155;
}

/* Dropzone */
.dropzone {
    border: 2px dashed #cbd5e1;
    border-radius: 10px;
    padding: 32px 20px;
    text-align: center;
    cursor: pointer;
    margin-bottom: 16px;
    transition: border-color 0.2s, background 0.2s;
    background: #fafbfc;
}

.dropzone:hover {
    border-color: #2563eb;
    background: #eff6ff;
}

.dropzone.drag-over {
    border-color: #2563eb;
    background: #dbeafe;
    border-style: solid;
}

.dropzone-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    pointer-events: none;
}

.dropzone-icon {
    font-size: 2rem;
    line-height: 1;
}

.dropzone-text {
    font-size: 0.95rem;
    font-weight: 600;
    color: #444;
}

.dropzone-hint {
    font-size: 0.78rem;
    color: #888;
}

/* Body-level drag overlay */
body.file-dragging .dropzone {
    border-color: #2563eb;
    background: #dbeafe;
    border-style: solid;
}

/* Inline filter row in thead */
.inline-filter-row td {
    background: #f8f9fa;
    border-bottom: 2px solid #dee2e6;
    padding: 3px 4px;
    vertical-align: top;
}

.inline-filter-cell {
    display: flex;
    align-items: center;
    gap: 2px;
}

.inline-filter-input {
    width: 100%;
    min-width: 50px;
    padding: 3px 6px;
    border: 1px solid #ccc;
    border-radius: 3px;
    font-size: 0.75rem;
}

.inline-filter-input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.inline-filter-input.regex-error {
    border-color: #dc2626;
    box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.15);
}

.inline-filter-menu-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.85rem;
    color: #999;
    padding: 0 2px;
    line-height: 1;
    flex-shrink: 0;
}

.inline-filter-menu-btn:hover {
    color: #2563eb;
}

/* Context menu (per-column popup) */
.col-context-menu {
    position: absolute;
    z-index: 50;
    background: white;
    border: 1px solid #ddd;
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    padding: 8px 10px;
    font-size: 0.78rem;
    min-width: 180px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.col-context-menu label {
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
}

.col-context-menu select {
    padding: 3px 4px;
    border: 1px solid #ccc;
    border-radius: 3px;
    font-size: 0.75rem;
    background: white;
    width: 100%;
}

.col-context-menu .ctx-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.col-context-menu .ctx-label {
    font-size: 0.72rem;
    color: #666;
    min-width: 50px;
}

.col-context-menu .ctx-report-btn {
    padding: 4px 10px;
    background: #2563eb;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 500;
    width: 100%;
    margin-top: 2px;
}

.col-context-menu .ctx-report-btn:hover {
    background: #1d4ed8;
}

/* Column resize handle */
th {
    position: relative;
}

.col-resize-handle {
    position: absolute;
    right: 0;
    top: 0;
    width: 5px;
    height: 100%;
    cursor: col-resize;
    z-index: 2;
}

.col-resize-handle:hover,
.col-resize-handle.resizing {
    background: rgba(37, 99, 235, 0.3);
}

/* table-layout: fixed when resizing — allow wider than viewport for horizontal scroll */
table.fixed-layout {
    table-layout: fixed;
    width: max-content;
    min-width: 100%;
}

/* PDF Report button */
.pdf-report-btn {
    background: #7c3aed;
}

.pdf-report-btn:hover {
    background: #6d28d9;
}

/* PDF Options modal */
.pdf-options-modal {
    width: 480px;
}

.pdf-col-count {
    font-size: 0.85rem;
    color: #555;
    margin-bottom: 12px;
}

.pdf-option-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    margin-bottom: 6px;
}

.pdf-option-hint {
    font-size: 0.78rem;
    color: #888;
    margin-bottom: 16px;
    line-height: 1.4;
}

.pdf-options-actions {
    display: flex;
    gap: 8px;
}

.pdf-options-actions .upload-btn {
    padding: 8px 18px;
    font-size: 0.85rem;
}
