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

:root {
    --bg: #f8f9fa;
    --surface: #ffffff;
    --border: #dee2e6;
    --text: #212529;
    --text-muted: #6c757d;
    --primary: #0d6efd;
    --primary-hover: #0b5ed7;
    --success: #198754;
    --danger: #dc3545;
    --warning: #ffc107;
    --radius: 8px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

/* Two-column layout */
.layout {
    display: flex;
    gap: 1.5rem;
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem 1rem;
    min-height: 100vh;
}

.left-panel {
    flex: 0 0 480px;
}

.right-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    max-height: calc(100vh - 4rem);
    position: sticky;
    top: 2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.5rem;
}

.top-bar .subtitle {
    margin-bottom: 0;
}

.user-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.8125rem;
    color: var(--text-muted);
}

.btn-logout {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.25rem 0.625rem;
    font-size: 0.75rem;
    cursor: pointer;
    color: var(--text-muted);
}

.btn-logout:hover {
    border-color: var(--danger);
    color: var(--danger);
}

h1 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

h2 {
    font-size: 1.125rem;
    font-weight: 600;
}

.subtitle {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

/* Drop zone */
.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 2rem 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background-color 0.2s;
}

.drop-zone:hover,
.drop-zone.dragover {
    border-color: var(--primary);
    background: rgba(13, 110, 253, 0.04);
}

.drop-zone-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.drop-zone-text {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.drop-zone-text strong {
    color: var(--primary);
}

.file-input {
    display: none;
}

.file-list {
    margin-top: 0.75rem;
}

.file-list:empty {
    display: none;
}

.file-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: rgba(13, 110, 253, 0.04);
    border-radius: var(--radius);
    margin-bottom: 0.375rem;
}

.file-item .name {
    font-weight: 500;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.875rem;
}

.file-item .size {
    color: var(--text-muted);
    font-size: 0.8125rem;
}

.file-item .remove {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 1.125rem;
    padding: 0 0.25rem;
}

/* Settings */
.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.form-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.025em;
    color: var(--text-muted);
}

.form-group select {
    width: 100%;
    padding: 0.375rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    font-size: 0.875rem;
    color: var(--text);
    appearance: auto;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.5rem;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.15s;
    width: 100%;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.processing-banner {
    background: rgba(13, 110, 253, 0.08);
    border: 1px solid rgba(13, 110, 253, 0.25);
    color: var(--primary);
    padding: 0.625rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.processing-banner.hidden {
    display: none;
}

.processing-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid var(--primary);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.error-banner {
    display: none;
    background: rgba(220, 53, 69, 0.1);
    border: 1px solid rgba(220, 53, 69, 0.3);
    color: var(--danger);
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.875rem;
}

.error-banner.active {
    display: block;
}

/* Right panel - Document list */
.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    flex-shrink: 0;
}

.panel-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.btn-delete {
    background: none;
    border: 1px solid var(--danger);
    color: var(--danger);
    border-radius: var(--radius);
    padding: 0.25rem 0.625rem;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.btn-delete:hover:not(:disabled) {
    background: var(--danger);
    color: white;
}

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

.sort-controls {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.sort-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.2rem 0.5rem;
    font-size: 0.75rem;
    cursor: pointer;
    color: var(--text-muted);
}

.sort-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.search-box {
    margin-bottom: 0.75rem;
    flex-shrink: 0;
}

.search-box input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
    background: var(--surface);
    color: var(--text);
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(13, 110, 253, 0.15);
}

.history-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    padding-right: 0.25rem;
}

.history-empty {
    color: var(--text-muted);
    text-align: center;
    padding: 3rem 1rem;
    font-size: 0.875rem;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.history-empty.hidden {
    display: none;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    transition: border-color 0.15s;
    flex-shrink: 0;
}

.history-item:hover {
    border-color: #b0b0b0;
    background: #ececec;
}

.history-item .checkbox {
    flex-shrink: 0;
}

.history-item .checkbox input {
    width: 15px;
    height: 15px;
    cursor: pointer;
}

.history-item .doc-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
}

.history-item .doc-info {
    flex: 1;
    min-width: 0;
}

.history-item.done .doc-info {
    cursor: pointer;
}

.history-item .doc-name {
    font-weight: 500;
    font-size: 0.8125rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-item .doc-meta {
    font-size: 0.6875rem;
    color: var(--text-muted);
}

.history-item .doc-details {
    display: none;
    gap: 0.25rem;
    margin-top: 0.25rem;
    flex-wrap: wrap;
}

.history-item .doc-details.open {
    display: flex;
}

.detail-tag {
    font-size: 0.625rem;
    padding: 0.1rem 0.375rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-muted);
    white-space: nowrap;
}

.detail-tag.ai-tag {
    background: rgba(139, 92, 246, 0.08);
    border-color: rgba(139, 92, 246, 0.3);
    color: #7c3aed;
}

.detail-tag.aws-tag {
    background: rgba(255, 153, 0, 0.08);
    border-color: rgba(255, 153, 0, 0.3);
    color: #c27200;
}

.history-item .doc-status {
    flex-shrink: 0;
}

.history-item .doc-actions {
    display: flex;
    gap: 0.25rem;
    flex-shrink: 0;
}

.action-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    cursor: pointer;
    color: var(--text);
    transition: all 0.15s;
    white-space: nowrap;
}

.action-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

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

.status-badge {
    padding: 0.125rem 0.375rem;
    border-radius: 999px;
    font-size: 0.6875rem;
    font-weight: 500;
}

.status-badge.processing {
    background: rgba(13, 110, 253, 0.1);
    color: var(--primary);
}

.status-badge.done {
    background: rgba(25, 135, 84, 0.1);
    color: var(--success);
}

.status-badge.failed {
    background: rgba(220, 53, 69, 0.1);
    color: var(--danger);
}

.status-badge.interrupted {
    background: rgba(255, 193, 7, 0.15);
    color: #997404;
}

.progress-inline {
    display: inline-block;
    width: 50px;
    height: 3px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
    vertical-align: middle;
    margin-left: 0.375rem;
}

.progress-inline-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 2px;
    transition: width 0.3s;
}

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

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--surface);
    border-radius: var(--radius);
    width: 90vw;
    height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

.modal-title {
    font-weight: 600;
    font-size: 1rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0 0.25rem;
}

.modal-close:hover {
    color: var(--text);
}

.modal-body {
    flex: 1;
    overflow: hidden;
}

.preview-frame {
    width: 100%;
    height: 100%;
    border: none;
}

@media (max-width: 900px) {
    .layout {
        flex-direction: column;
    }
    .left-panel {
        flex: none;
    }
    .right-panel {
        max-height: 50vh;
        position: static;
    }
    .settings-grid {
        grid-template-columns: 1fr 1fr;
    }
    .modal {
        width: 100vw;
        height: 100vh;
        border-radius: 0;
    }
}
