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

:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --success: #10b981;
    --error: #ef4444;
    --text: #1f2937;
    --text-light: #6b7280;
    --text-lighter: #9ca3af;
    --bg: #f9fafb;
    --bg-card: #ffffff;
    --border: #e5e7eb;
    --border-hover: #d1d5db;
    --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);
    line-height: 1.6;
    min-height: 100vh;
}

.container {
    max-width: 1040px;
    margin: 0 auto;
    padding: 40px 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 32px;
}

.header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

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

.logo h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text);
}

.btn-logout {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    color: var(--text-light);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-logout:hover {
    background: #fef2f2;
    border-color: var(--error);
    color: var(--error);
}

.subtitle {
    color: var(--text-light);
    font-size: 14px;
}

/* Main */
.main {
    flex: 1;
}

/* Mode Tabs */
.mode-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    margin-bottom: 20px;
    padding: 4px;
    background: #eef2f7;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.mode-tab {
    min-height: 40px;
    padding: 8px 12px;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    color: var(--text-light);
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.mode-tab.active {
    color: var(--text);
    background: var(--bg-card);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

.mode-panel {
    display: none;
}

.mode-panel.active {
    display: block;
}

/* Upload Zone */
.upload-zone {
    background: var(--bg-card);
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 48px 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--primary);
    background: #f0f0ff;
}

.upload-icon {
    color: var(--text-lighter);
    margin-bottom: 16px;
}

.upload-zone:hover .upload-icon {
    color: var(--primary);
}

.upload-text {
    font-size: 16px;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 8px;
}

.upload-hint {
    font-size: 13px;
    color: var(--text-light);
}

/* File Info */
.file-info {
    margin-bottom: 20px;
}

.file-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

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

.file-meta {
    flex: 1;
    min-width: 0;
}

.file-name {
    display: block;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-size {
    font-size: 13px;
    color: var(--text-light);
}

.btn-remove {
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-light);
    transition: all 0.2s;
}

.btn-remove:hover {
    background: #fef2f2;
    border-color: var(--error);
    color: var(--error);
}

/* Settings */
.settings {
    margin-bottom: 20px;
}

.setting-row {
    display: flex;
    align-items: center;
    gap: 16px;
}

.setting-row label {
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
}

.setting-row select {
    flex: 1;
    padding: 12px 16px;
    font-size: 14px;
    font-family: inherit;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text);
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 40px;
}

.setting-row input {
    flex: 1;
    min-width: 0;
    padding: 12px 16px;
    font-size: 14px;
    font-family: inherit;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text);
}

.setting-row select:focus,
.setting-row input:focus {
    outline: none;
    border-color: var(--primary);
}

/* Paste Panel */
.paste-preview-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}

.paste-panel {
    min-width: 0;
}

.paste-header,
.preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.paste-header label,
.preview-header span:first-child {
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
}

.paste-header span,
.preview-header span:last-child {
    font-size: 12px;
    color: var(--text-light);
}

#markdownInput {
    width: 100%;
    min-height: 280px;
    resize: vertical;
    padding: 16px;
    font-size: 14px;
    line-height: 1.6;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', monospace;
    color: var(--text);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

#markdownInput:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
}

.preview-panel {
    min-width: 0;
}

.markdown-preview {
    min-height: 280px;
    max-height: 520px;
    overflow: auto;
    padding: 16px;
    font-size: 14px;
    line-height: 1.7;
    color: var(--text);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.markdown-preview.empty {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-lighter);
    text-align: center;
}

.markdown-preview.preview-error {
    color: var(--error);
    background: #fef2f2;
    border-color: #fecaca;
}

.markdown-preview > *:first-child {
    margin-top: 0;
}

.markdown-preview > *:last-child {
    margin-bottom: 0;
}

.markdown-preview h1,
.markdown-preview h2,
.markdown-preview h3,
.markdown-preview h4,
.markdown-preview h5,
.markdown-preview h6 {
    margin: 18px 0 10px;
    line-height: 1.35;
    color: var(--text);
}

.markdown-preview h1 {
    font-size: 24px;
}

.markdown-preview h2 {
    font-size: 20px;
}

.markdown-preview h3 {
    font-size: 17px;
}

.markdown-preview p,
.markdown-preview ul,
.markdown-preview ol,
.markdown-preview blockquote,
.markdown-preview pre,
.markdown-preview table {
    margin: 0 0 14px;
}

.markdown-preview ul,
.markdown-preview ol {
    padding-left: 22px;
}

.markdown-preview blockquote {
    padding: 10px 14px;
    color: var(--text-light);
    background: #f8fafc;
    border-left: 3px solid var(--border-hover);
    border-radius: 0 6px 6px 0;
}

.markdown-preview code {
    padding: 2px 5px;
    font-size: 13px;
    background: #f3f4f6;
    border-radius: 4px;
}

.markdown-preview pre {
    overflow: auto;
    padding: 12px;
    background: #111827;
    border-radius: 6px;
}

.markdown-preview pre code {
    padding: 0;
    color: #f9fafb;
    background: transparent;
}

.markdown-preview table {
    width: 100%;
    border-collapse: collapse;
    display: block;
    overflow-x: auto;
}

.markdown-preview th,
.markdown-preview td {
    padding: 8px 10px;
    border: 1px solid var(--border);
    text-align: left;
}

.markdown-preview th {
    background: #f8fafc;
    font-weight: 600;
}

.markdown-preview a {
    color: var(--primary);
    text-decoration: none;
}

.markdown-preview a:hover {
    text-decoration: underline;
}

.markdown-preview img {
    max-width: 100%;
    height: auto;
    border-radius: 6px;
}

.markdown-preview .math {
    overflow-x: auto;
}

.markdown-preview .math.display {
    display: block;
    margin: 16px 0;
    text-align: center;
}

.markdown-preview math {
    font-family: 'Times New Roman', Times, serif;
    font-size: 1.05em;
}

.markdown-preview math[display="block"] {
    display: block;
    max-width: 100%;
    margin: 16px auto;
    overflow-x: auto;
    text-align: center;
}

/* Buttons */
.btn-convert {
    width: 100%;
    padding: 14px 24px;
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--text-lighter);
    color: white;
    cursor: not-allowed;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-convert:disabled {
    background: var(--text-lighter);
    cursor: not-allowed;
}

.btn-convert:not(:disabled) {
    background: var(--primary);
    cursor: pointer;
}

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

.btn-text,
.btn-loading {
    display: flex;
    align-items: center;
    gap: 8px;
}

.spinner {
    animation: spin 1s linear infinite;
}

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

/* Result Panel */
.result-panel {
    margin-top: 24px;
    padding: 32px;
    background: var(--bg-card);
    border: 1px solid var(--success);
    border-radius: var(--radius);
    text-align: center;
}

.result-icon {
    color: var(--success);
    margin-bottom: 12px;
}

.result-success h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 4px;
}

.result-success p {
    color: var(--text-light);
    font-size: 14px;
    margin-bottom: 20px;
}

.btn-download {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--primary);
    color: white;
    cursor: pointer;
    transition: all 0.2s;
}

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

.btn-new {
    display: block;
    margin: 16px auto 0;
    padding: 8px 16px;
    font-size: 13px;
    font-family: inherit;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: transparent;
    color: var(--text-light);
    cursor: pointer;
    transition: all 0.2s;
}

.btn-new:hover {
    border-color: var(--border-hover);
    color: var(--text);
}

/* Error Panel */
.error-panel {
    margin-top: 16px;
    padding: 14px 16px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    gap: 10px;
}

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

.error-panel span {
    font-size: 14px;
    color: var(--error);
}

/* Footer */
.footer {
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-light);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-lighter);
}

.status.healthy .status-dot {
    background: var(--success);
}

.status.error .status-dot {
    background: var(--error);
}

.powered {
    font-size: 12px;
    color: var(--text-lighter);
}

.powered a {
    color: var(--primary);
    text-decoration: none;
}

.powered a:hover {
    text-decoration: underline;
}

/* Responsive */
@media (max-width: 760px) {
    .paste-preview-layout {
        grid-template-columns: 1fr;
    }

    .markdown-preview {
        max-height: none;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 24px 16px;
    }

    .upload-zone {
        padding: 32px 16px;
    }

    .setting-row {
        flex-direction: column;
        align-items: stretch;
    }

    .setting-row label {
        margin-bottom: 6px;
    }

    .footer {
        flex-direction: column;
        gap: 12px;
    }
}
