/* Reset and base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
    background: #f5f7fa;
    color: #1a1a2e;
    line-height: 1.6;
}

.hidden {
    display: none !important;
}

/* Header */
.app-header {
    background: #1a1a2e;
    color: #fff;
    padding: 1rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.app-header h1 {
    font-size: 1.25rem;
    font-weight: 600;
}

.app-title-link {
    color: inherit;
    text-decoration: none;
}

.app-title-link:hover {
    opacity: 0.85;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

#user-display {
    font-size: 0.9rem;
    opacity: 0.9;
}

/* Container */
.container {
    max-width: 960px;
    margin: 2rem auto;
    padding: 0 1.5rem;
}

/* Buttons */
.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
}

.btn:hover {
    opacity: 0.9;
}

.btn:focus-visible {
    outline: 2px solid #4a6cf7;
    outline-offset: 2px;
}

.btn-primary {
    background: #4a6cf7;
    color: #fff;
}

.btn-secondary {
    background: #e2e8f0;
    color: #1a1a2e;
}

.btn-download {
    background: #10b981;
    color: #fff;
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
}

/* Message area */
.message-area {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}

.message-area.success {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #6ee7b7;
}

.message-area.error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
}

/* Upload section */
.upload-section {
    margin-bottom: 2rem;
}

.upload-section h2,
.files-header h2 {
    font-size: 1.1rem;
    margin-bottom: 0.75rem;
}

.drop-zone {
    border: 2px dashed #cbd5e1;
    border-radius: 8px;
    padding: 2.5rem 1rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    background: #fff;
}

.drop-zone:hover,
.drop-zone.active {
    border-color: #4a6cf7;
    background: #eef2ff;
}

.drop-zone-text {
    color: #64748b;
    font-size: 0.95rem;
}

.file-input {
    display: none;
}

/* Progress */
.upload-progress {
    margin-top: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.progress-bar-container {
    flex: 1;
    height: 8px;
    background: #e2e8f0;
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: #4a6cf7;
    border-radius: 4px;
    transition: width 0.2s;
}

.progress-text {
    font-size: 0.8rem;
    color: #64748b;
    min-width: 3rem;
    text-align: right;
}

/* Files section */
.files-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.file-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.file-table th,
.file-table td {
    padding: 0.65rem 0.75rem;
    text-align: left;
    font-size: 0.875rem;
}

.file-table thead {
    background: #f1f5f9;
}

.file-table th {
    font-weight: 600;
    color: #475569;
}

.file-table tbody tr {
    border-top: 1px solid #e2e8f0;
}

.file-table tbody tr:hover {
    background: #f8fafc;
}

/* Status badges */
.status-badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: capitalize;
}

.status-uploaded {
    background: #dbeafe;
    color: #1e40af;
}

.status-processing {
    background: #fef3c7;
    color: #92400e;
}

.status-completed {
    background: #d1fae5;
    color: #065f46;
}

.status-error {
    background: #fee2e2;
    color: #991b1b;
}

.status-detail {
    display: block;
    font-size: 0.75rem;
    color: #64748b;
    margin-top: 0.15rem;
}

.no-files {
    text-align: center;
    color: #94a3b8;
    padding: 2rem 0;
    font-size: 0.9rem;
}

/* Refresh spinner */
.refresh-spinner {
    display: none;
    width: 14px;
    height: 14px;
    border: 2px solid #94a3b8;
    border-top-color: #1a1a2e;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    vertical-align: middle;
    margin-right: 0.35rem;
}

.refreshing .refresh-spinner {
    display: inline-block;
}

.refreshing {
    opacity: 0.7;
    cursor: wait;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Responsive */
@media (max-width: 640px) {
    .app-header {
        flex-direction: column;
        gap: 0.5rem;
        text-align: center;
    }

    .file-table th:nth-child(2),
    .file-table td:nth-child(2),
    .file-table th:nth-child(3),
    .file-table td:nth-child(3) {
        display: none;
    }

    .container {
        padding: 0 1rem;
    }
}

/* -----------------------------------------------------------------------
   Preview Panel
   ----------------------------------------------------------------------- */
.preview-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.preview-dialog {
    background: #fff;
    border-radius: 8px;
    width: 90%;
    max-width: 900px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
}

.preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #e2e8f0;
}

.preview-title {
    font-weight: 600;
    font-size: 0.95rem;
    color: #1a1a2e;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.preview-close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    color: #64748b;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}

.preview-close-btn:hover {
    background: #f1f5f9;
    color: #1a1a2e;
}

/* Tab bar */
.preview-tab-bar {
    display: flex;
    gap: 0;
    border-bottom: 1px solid #e2e8f0;
    padding: 0 1rem;
}

.preview-tab {
    padding: 0.5rem 1rem;
    border: none;
    background: none;
    font-size: 0.85rem;
    font-weight: 500;
    color: #64748b;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color 0.2s, border-color 0.2s;
}

.preview-tab:hover {
    color: #1a1a2e;
}

.preview-tab.active {
    color: #4a6cf7;
    border-bottom-color: #4a6cf7;
}

/* Loading spinner */
.preview-spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.preview-spinner-dot {
    width: 24px;
    height: 24px;
    border: 3px solid #e2e8f0;
    border-top-color: #4a6cf7;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

/* Error area */
.preview-error {
    padding: 0.75rem 1rem;
    margin: 0.5rem 1rem;
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
    border-radius: 6px;
    font-size: 0.85rem;
}

/* Content area */
.preview-content-wrap {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

.preview-line-numbers {
    padding: 0.75rem 0.5rem;
    background: #f1f5f9;
    color: #94a3b8;
    text-align: right;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 0.8rem;
    line-height: 1.5;
    user-select: none;
    overflow: hidden;
    min-width: 3.5rem;
    border-right: 1px solid #e2e8f0;
    margin: 0;
}

.preview-content {
    flex: 1;
    padding: 0.75rem 1rem;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 0.8rem;
    line-height: 1.5;
    overflow: auto;
    white-space: pre;
    margin: 0;
    color: #1a1a2e;
}

/* Pagination bar */
.preview-pagination {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-top: 1px solid #e2e8f0;
    background: #f8fafc;
    flex-wrap: wrap;
}

.preview-page-info {
    font-size: 0.85rem;
    color: #475569;
    white-space: nowrap;
}

.preview-page-input,
.preview-goto-input {
    width: 5rem;
    padding: 0.3rem 0.5rem;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    font-size: 0.8rem;
    text-align: center;
}

.preview-page-input:focus,
.preview-goto-input:focus {
    outline: 2px solid #4a6cf7;
    outline-offset: 1px;
}

.preview-pagesize-label {
    font-size: 0.8rem;
    color: #64748b;
    margin-left: 0.5rem;
    white-space: nowrap;
}

.preview-pagesize-select {
    padding: 0.3rem 0.4rem;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    font-size: 0.8rem;
    background: #fff;
}

.preview-pagesize-select:focus {
    outline: 2px solid #4a6cf7;
    outline-offset: 1px;
}

/* Action buttons */
.actions-wrap {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.actions-row {
    display: flex;
    gap: 0.3rem;
}

.actions-row .btn {
    flex: 1;
    text-align: center;
    white-space: nowrap;
}

.btn-preview {
    background: #4a6cf7;
    color: #fff;
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
}

.btn-diff {
    background: #8b5cf6;
    color: #fff;
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
}

.btn-download-original {
    background: #0ea5e9;
    color: #fff;
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
}

/* Responsive */
@media (max-width: 640px) {
    .preview-dialog {
        width: 98%;
        max-height: 95vh;
    }
}

/* -----------------------------------------------------------------------
   Diff View
   ----------------------------------------------------------------------- */
.diff-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.diff-dialog {
    background: #fff;
    border-radius: 8px;
    width: 95%;
    max-width: 1400px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
}

.diff-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #e2e8f0;
}

.diff-title {
    font-weight: 600;
    font-size: 0.95rem;
    color: #1a1a2e;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.diff-close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    color: #64748b;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}

.diff-close-btn:hover {
    background: #f1f5f9;
    color: #1a1a2e;
}

/* Loading spinner */
.diff-spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.diff-spinner-dot {
    width: 24px;
    height: 24px;
    border: 3px solid #e2e8f0;
    border-top-color: #8b5cf6;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

/* Error area */
.diff-error {
    padding: 0.75rem 1rem;
    margin: 0.5rem 1rem;
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
    border-radius: 6px;
    font-size: 0.85rem;
}

/* Side-by-side panels */
.diff-panels {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

.diff-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

.diff-panel + .diff-panel {
    border-left: 2px solid #e2e8f0;
}

.diff-panel-header {
    padding: 0.4rem 0.75rem;
    background: #f1f5f9;
    font-weight: 600;
    font-size: 0.8rem;
    color: #475569;
    border-bottom: 1px solid #e2e8f0;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.diff-content-wrap {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

.diff-line-numbers {
    padding: 0.75rem 0.5rem;
    background: #f1f5f9;
    color: #94a3b8;
    text-align: right;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 0.8rem;
    line-height: 1.5;
    user-select: none;
    overflow: hidden;
    min-width: 3.5rem;
    border-right: 1px solid #e2e8f0;
    margin: 0;
}

.diff-content {
    flex: 1;
    padding: 0.75rem 1rem;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 0.8rem;
    line-height: 1.5;
    overflow: auto;
    white-space: pre;
    margin: 0;
    color: #1a1a2e;
}

/* Diff line divs inside pre elements */
.diff-content > div,
.diff-line-numbers > div {
    display: block;
    min-height: 1.5em;
    line-height: 1.5;
}

.diff-line-numbers > div {
    padding: 0;
}

/* Diff highlight classes */
.diff-changed-left {
    background: rgba(239, 68, 68, 0.1);
}

.diff-changed-right {
    background: rgba(34, 197, 94, 0.1);
}

/* Responsive: stack panels vertically at 640px */
@media (max-width: 640px) {
    .diff-dialog {
        width: 98%;
        max-height: 95vh;
    }

    .diff-panels {
        flex-direction: column;
    }

    .diff-panel + .diff-panel {
        border-left: none;
        border-top: 2px solid #e2e8f0;
    }
}

/* Diff pagination bar */
.diff-pagination {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-top: 1px solid #e2e8f0;
    background: #f8fafc;
    flex-wrap: wrap;
}

.diff-page-info {
    font-size: 0.85rem;
    color: #475569;
    white-space: nowrap;
}

.diff-page-input,
.diff-goto-input {
    width: 5rem;
    padding: 0.3rem 0.5rem;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    font-size: 0.8rem;
    text-align: center;
}

.diff-page-input:focus,
.diff-goto-input:focus {
    outline: 2px solid #4a6cf7;
    outline-offset: 1px;
}

.diff-pagesize-label {
    font-size: 0.8rem;
    color: #64748b;
    margin-left: 0.5rem;
    white-space: nowrap;
}

.diff-pagesize-select {
    padding: 0.3rem 0.4rem;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    font-size: 0.8rem;
    background: #fff;
}

.diff-pagesize-select:focus {
    outline: 2px solid #4a6cf7;
    outline-offset: 1px;
}
