/* ===== Reset & Base ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #4f46e5;
    --primary-light: #818cf8;
    --primary-dark: #3730a3;
    --bg: #f0f2f5;
    --surface: #ffffff;
    --text: #1e293b;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 40px rgba(0,0,0,0.1);
    --radius: 12px;
    --radius-sm: 8px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* ===== Header ===== */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 56px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo {
    color: var(--primary);
}

.header h1 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
}

.supported-formats {
    font-size: 12px;
    color: var(--text-secondary);
}

/* ===== Upload Zone ===== */
.upload-zone {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    transition: background 0.2s ease;
}

.upload-zone.dragover {
    background: rgba(79, 70, 229, 0.05);
}

.upload-content {
    text-align: center;
    max-width: 480px;
}

.upload-icon {
    color: var(--primary-light);
    margin-bottom: 24px;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

.upload-title {
    font-size: 18px;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.upload-btn {
    display: inline-block;
    padding: 12px 32px;
    background: var(--primary);
    color: #fff;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    transition: all 0.2s;
    user-select: none;
}

.upload-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.upload-hint {
    margin-top: 20px;
    font-size: 13px;
    color: var(--text-secondary);
}

/* ===== Viewer Area ===== */
.viewer-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ===== Toolbar ===== */
.viewer-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    height: 48px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    gap: 12px;
}

.toolbar-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex: 1;
}

.file-icon {
    color: var(--primary);
    flex-shrink: 0;
}

.file-name {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-meta {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    flex-shrink: 0;
}

.toolbar-right {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

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

.tool-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 10px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.15s;
    user-select: none;
    white-space: nowrap;
}

.tool-btn:hover {
    background: var(--bg);
    color: var(--text);
}

.close-btn:hover {
    background: #fee2e2;
    color: #dc2626;
}

.upload-again {
    font-size: 13px;
    cursor: pointer;
}

.page-info {
    font-size: 12px;
    color: var(--text-secondary);
    min-width: 56px;
    text-align: center;
}

.zoom-level {
    font-size: 12px;
    color: var(--text-secondary);
    min-width: 44px;
    text-align: center;
}

/* ===== Viewer Content ===== */
.viewer-content {
    flex: 1;
    overflow: auto;
    display: flex;
    justify-content: center;
    background: #525659;
}

.viewer-content::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

.viewer-content::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.1);
}

.viewer-content::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 5px;
}

.viewer-content::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.3);
}

/* ===== Text / Code Viewer ===== */
.text-viewer {
    background: #fff;
    width: 100%;
    max-width: 960px;
    min-height: 100%;
    padding: 40px 48px;
    font-family: 'Fira Code', 'Courier New', Consolas, monospace;
    font-size: 14px;
    line-height: 1.8;
    color: #333;
    white-space: pre-wrap;
    word-break: break-all;
}

.code-viewer {
    background: #282c34;
    width: 100%;
    max-width: 960px;
    min-height: 100%;
    padding: 32px 40px;
    font-family: 'Fira Code', 'Courier New', Consolas, monospace;
    font-size: 14px;
    line-height: 1.8;
    overflow-x: auto;
}

.code-viewer pre {
    margin: 0;
    background: transparent !important;
}

.code-viewer code {
    font-family: inherit !important;
    font-size: 14px !important;
}

/* ===== PDF Viewer ===== */
.pdf-viewer {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 20px 0;
    width: 100%;
}

.pdf-canvas-wrapper {
    box-shadow: 0 2px 12px rgba(0,0,0,0.3);
    background: #fff;
}

.pdf-canvas-wrapper canvas {
    display: block;
}

/* ===== PPTX Slides Container ===== */
.pptx-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 0;
    width: 100%;
    overflow-x: auto;
}

/* ===== Docx Viewer ===== */
.office-viewer {
    background: #fff;
    width: 100%;
    max-width: 960px;
    min-height: 100%;
    padding: 40px 48px;
    overflow: auto;
}

/* Old pptx styles kept for backwards compat */
.pptx-slide {
    width: 100%;
    max-width: 720px;
    aspect-ratio: 16/9;
    background: #fff;
    box-shadow: 0 2px 12px rgba(0,0,0,0.3);
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
    padding: 32px;
    overflow: auto;
}

/* ===== Excel Viewer ===== */
.excel-viewer {
    background: #fff;
    width: 100%;
    min-height: 100%;
    padding: 20px;
    overflow: auto;
}

.sheet-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.sheet-tab {
    padding: 6px 16px;
    background: #f1f5f9;
    border-radius: 6px 6px 0 0;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    transition: all 0.15s;
}

.sheet-tab.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.excel-table {
    border-collapse: collapse;
    width: 100%;
    font-size: 13px;
}

.excel-table th,
.excel-table td {
    border: 1px solid #e0e0e0;
    padding: 6px 10px;
    text-align: left;
    white-space: nowrap;
}

.excel-table th {
    background: #f8fafc;
    font-weight: 600;
    color: var(--text);
    position: sticky;
    top: 0;
    z-index: 1;
}

.excel-table tr:hover td {
    background: #f1f5f9;
}

/* ===== Markdown Viewer ===== */
.markdown-viewer {
    background: #fff;
    width: 100%;
    max-width: 800px;
    min-height: 100%;
    padding: 48px;
    line-height: 1.8;
    color: #333;
}

.markdown-viewer h1 { font-size: 2em; margin: 0.67em 0; border-bottom: 2px solid #eee; padding-bottom: .3em; }
.markdown-viewer h2 { font-size: 1.5em; margin: 0.83em 0; border-bottom: 1px solid #eee; padding-bottom: .3em; }
.markdown-viewer h3 { font-size: 1.17em; margin: 1em 0; }
.markdown-viewer p { margin: 0.8em 0; }
.markdown-viewer a { color: var(--primary); text-decoration: none; }
.markdown-viewer a:hover { text-decoration: underline; }
.markdown-viewer ul, .markdown-viewer ol { margin: 0.8em 0; padding-left: 2em; }
.markdown-viewer blockquote { margin: 1em 0; padding: 0.5em 1em; border-left: 4px solid var(--primary); background: #f8f9fa; color: var(--text-secondary); }
.markdown-viewer code { background: #f1f5f9; padding: 2px 6px; border-radius: 4px; font-size: 0.9em; font-family: monospace; }
.markdown-viewer pre { background: #282c34; color: #abb2bf; padding: 16px; border-radius: 8px; overflow-x: auto; margin: 1em 0; }
.markdown-viewer pre code { background: transparent; padding: 0; color: inherit; }
.markdown-viewer table { border-collapse: collapse; width: 100%; margin: 1em 0; }
.markdown-viewer th, .markdown-viewer td { border: 1px solid #ddd; padding: 8px 12px; }
.markdown-viewer img { max-width: 100%; border-radius: 8px; }

/* ===== Image Viewer ===== */
.image-viewer {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 20px;
}

.image-viewer img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 4px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.4);
}

/* ===== Audio / Video ===== */
.media-viewer {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 20px;
    padding: 40px;
}

.media-viewer audio,
.media-viewer video {
    max-width: 600px;
    width: 100%;
}

/* ===== CSV Viewer ===== */
.csv-viewer {
    background: #fff;
    width: 100%;
    min-height: 100%;
    padding: 20px;
    overflow: auto;
}

/* ===== JSON Viewer ===== */
.json-viewer {
    background: #282c34;
    width: 100%;
    max-width: 960px;
    min-height: 100%;
    padding: 32px 40px;
    overflow: auto;
}

/* ===== Unsupported / Error ===== */
.unsupported-viewer {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #cbd5e1;
    gap: 16px;
}

.unsupported-viewer svg {
    color: #64748b;
}

.unsupported-viewer p {
    font-size: 16px;
}

/* ===== Loading ===== */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #cbd5e1;
    gap: 16px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255,255,255,0.2);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .header h1 { font-size: 16px; }
    .supported-formats { display: none; }
    .toolbar-right { gap: 0; }
    .page-controls { margin-right: 4px; }
    .text-viewer, .office-viewer { padding: 20px; }
}
