/* ===========================
   CSS Variables & Reset
   =========================== */
:root {
    --bg-dark: #0f172a;
    --bg-surface: #1e293b;
    --bg-surface-light: #253347;
    --bg-editor: #131c2e;
    --accent: #60a5fa;
    --accent-bright: #3b82f6;
    --accent-hover: #93bbfd;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-dim: #64748b;
    --border: rgba(255, 255, 255, 0.08);
    --border-light: rgba(255, 255, 255, 0.12);
    --radius: 8px;
    --radius-lg: 12px;
    --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'SF Mono', 'Consolas', 'Monaco', monospace;
    --header-height: 52px;
    --panel-header-height: 36px;
    --status-height: 28px;
    --gradient-header: linear-gradient(135deg, #1e3a5f 0%, #2563eb 50%, #7c3aed 100%);
}

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

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font-ui);
    background: var(--bg-dark);
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
}

/* ===========================
   Scrollbar
   =========================== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.2);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(148, 163, 184, 0.35);
}

::-webkit-scrollbar-corner {
    background: transparent;
}

/* ===========================
   Top Bar
   =========================== */
.top-bar {
    background: var(--gradient-header);
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    position: relative;
    z-index: 100;
}

.top-bar::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(96, 165, 250, 0.3), transparent);
}

.top-bar-left {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.app-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    letter-spacing: -0.01em;
}

.app-title svg {
    opacity: 0.9;
}

/* Toolbar */
.toolbar {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.toolbar::-webkit-scrollbar {
    display: none;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 2px;
}

.toolbar-separator {
    width: 1px;
    height: 20px;
    background: rgba(255, 255, 255, 0.15);
    margin: 0 6px;
    flex-shrink: 0;
}

.tool-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 30px;
    min-width: 30px;
    padding: 0 6px;
    border: none;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    cursor: pointer;
    font-family: var(--font-ui);
    font-size: 12px;
    font-weight: 500;
    transition: all 0.15s ease;
    flex-shrink: 0;
    white-space: nowrap;
}

.tool-btn:hover {
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
}

.tool-btn:active {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(0.96);
}

.tool-btn.active {
    background: rgba(255, 255, 255, 0.22);
    color: #fff;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.15);
}

.tool-label {
    font-weight: 700;
    font-size: 13px;
}

.btn-text {
    font-size: 11px;
    font-weight: 500;
}

/* ===========================
   Main Content
   =========================== */
.main-content {
    flex: 1;
    display: flex;
    overflow: hidden;
    min-height: 0;
}

.panel {
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

.editor-panel {
    flex: 1;
    background: var(--bg-editor);
    border-right: 1px solid var(--border);
}

.preview-panel {
    flex: 1;
    background: var(--bg-surface);
}

/* Panel Headers */
.panel-header {
    height: var(--panel-header-height);
    display: flex;
    align-items: center;
    padding: 0 14px;
    background: rgba(0, 0, 0, 0.15);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.panel-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    display: flex;
    align-items: center;
    gap: 6px;
}

.panel-label svg {
    opacity: 0.6;
}

/* Resize Handle */
.resize-handle {
    width: 5px;
    cursor: col-resize;
    background: var(--border);
    position: relative;
    flex-shrink: 0;
    transition: background 0.15s ease;
    z-index: 10;
}

.resize-handle:hover,
.resize-handle.active {
    background: var(--accent);
}

.resize-grip {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 3px;
    height: 30px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
}

.resize-grip::before,
.resize-grip::after {
    content: '';
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: var(--text-dim);
}

/* ===========================
   Editor
   =========================== */
.editor-wrapper {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
}

.line-numbers {
    width: 48px;
    padding: 12px 8px 12px 4px;
    text-align: right;
    font-family: var(--font-mono);
    font-size: 12.5px;
    line-height: 1.65;
    color: var(--text-dim);
    background: rgba(0, 0, 0, 0.12);
    border-right: 1px solid var(--border);
    overflow: hidden;
    user-select: none;
    flex-shrink: 0;
}

.line-numbers .line-num {
    display: block;
    height: calc(12.5px * 1.65);
    opacity: 0.6;
}

.editor-textarea {
    flex: 1;
    width: 100%;
    padding: 12px 16px;
    border: none;
    outline: none;
    resize: none;
    background: transparent;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 12.5px;
    line-height: 1.65;
    tab-size: 4;
    -moz-tab-size: 4;
    overflow-y: auto;
    overflow-x: auto;
    white-space: pre;
}

.editor-textarea::placeholder {
    color: var(--text-dim);
    opacity: 0.5;
}

.editor-textarea::selection {
    background: rgba(96, 165, 250, 0.3);
}

/* ===========================
   Preview
   =========================== */
.preview-content {
    flex: 1;
    padding: 24px 32px;
    overflow-y: auto;
    overflow-x: hidden;
}

/* ===========================
   Markdown Body Styles
   =========================== */
.markdown-body {
    color: var(--text-primary);
    font-family: var(--font-ui);
    font-size: 15px;
    line-height: 1.7;
    word-wrap: break-word;
}

.markdown-body > *:first-child {
    margin-top: 0 !important;
}

.markdown-body > *:last-child {
    margin-bottom: 0 !important;
}

/* Headings */
.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
    font-weight: 600;
    line-height: 1.3;
    margin-top: 1.5em;
    margin-bottom: 0.6em;
    color: var(--text-primary);
}

.markdown-body h1 {
    font-size: 2em;
    padding-bottom: 0.3em;
    border-bottom: 2px solid var(--border-light);
}

.markdown-body h2 {
    font-size: 1.5em;
    padding-bottom: 0.25em;
    border-bottom: 1px solid var(--border);
}

.markdown-body h3 { font-size: 1.25em; }
.markdown-body h4 { font-size: 1.1em; }
.markdown-body h5 { font-size: 1em; color: var(--text-secondary); }
.markdown-body h6 { font-size: 0.9em; color: var(--text-dim); }

/* Paragraph */
.markdown-body p {
    margin-bottom: 1em;
}

/* Links */
.markdown-body a {
    color: var(--accent);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.15s ease;
}

.markdown-body a:hover {
    color: var(--accent-hover);
    border-bottom-color: var(--accent-hover);
}

/* Bold, Italic, Strikethrough */
.markdown-body strong {
    font-weight: 600;
    color: #fff;
}

.markdown-body em {
    font-style: italic;
    color: var(--text-primary);
}

.markdown-body del {
    color: var(--text-dim);
    text-decoration: line-through;
}

/* Inline Code */
.markdown-body code {
    font-family: var(--font-mono);
    font-size: 0.88em;
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(96, 165, 250, 0.1);
    color: #93c5fd;
    border: 1px solid rgba(96, 165, 250, 0.15);
}

/* Code Blocks */
.markdown-body pre {
    margin: 1em 0;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
    background: #0d1117;
}

.markdown-body pre code {
    display: block;
    padding: 16px 20px;
    overflow-x: auto;
    font-size: 13px;
    line-height: 1.55;
    background: none;
    border: none;
    color: var(--text-primary);
    border-radius: 0;
}

.markdown-body .code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.04);
    border-bottom: 1px solid var(--border);
    font-family: var(--font-ui);
    font-size: 11px;
    color: var(--text-dim);
    text-transform: lowercase;
}

/* Syntax Highlighting */
.markdown-body .syn-keyword { color: #c084fc; font-weight: 500; }
.markdown-body .syn-string { color: #86efac; }
.markdown-body .syn-comment { color: #64748b; font-style: italic; }
.markdown-body .syn-number { color: #fbbf24; }
.markdown-body .syn-function { color: #67e8f9; }
.markdown-body .syn-type { color: #f0abfc; }
.markdown-body .syn-operator { color: #f87171; }
.markdown-body .syn-builtin { color: #60a5fa; }
.markdown-body .syn-tag { color: #f87171; }
.markdown-body .syn-attr { color: #fbbf24; }
.markdown-body .syn-value { color: #86efac; }

/* Blockquote */
.markdown-body blockquote {
    margin: 1em 0;
    padding: 12px 20px;
    border-left: 4px solid var(--accent);
    background: rgba(96, 165, 250, 0.06);
    border-radius: 0 var(--radius) var(--radius) 0;
    color: var(--text-secondary);
}

.markdown-body blockquote p:last-child {
    margin-bottom: 0;
}

.markdown-body blockquote blockquote {
    margin: 0.5em 0;
}

/* Lists */
.markdown-body ul,
.markdown-body ol {
    margin: 0.5em 0 1em 0;
    padding-left: 1.8em;
}

.markdown-body li {
    margin: 0.3em 0;
    line-height: 1.65;
}

.markdown-body li > ul,
.markdown-body li > ol {
    margin: 0.2em 0 0.2em 0;
}

.markdown-body ul {
    list-style-type: disc;
}

.markdown-body ul ul {
    list-style-type: circle;
}

.markdown-body ul ul ul {
    list-style-type: square;
}

.markdown-body ol {
    list-style-type: decimal;
}

/* Horizontal Rule */
.markdown-body hr {
    border: none;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--border-light), transparent);
    margin: 2em 0;
}

/* Tables */
.markdown-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 1em 0;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
}

.markdown-body thead {
    background: rgba(255, 255, 255, 0.05);
}

.markdown-body th {
    font-weight: 600;
    text-align: left;
    padding: 10px 14px;
    border-bottom: 2px solid var(--border-light);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
}

.markdown-body td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
}

.markdown-body tr:last-child td {
    border-bottom: none;
}

.markdown-body tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

/* Images */
.markdown-body img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    margin: 1em 0;
    display: block;
}

/* ===========================
   Status Bar
   =========================== */
.status-bar {
    height: var(--status-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 14px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
    font-size: 11px;
    color: var(--text-dim);
    flex-shrink: 0;
}

.status-left,
.status-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-item {
    white-space: nowrap;
}

.status-separator {
    color: rgba(255, 255, 255, 0.1);
    user-select: none;
}

/* ===========================
   Toast Notification
   =========================== */
.toast {
    position: fixed;
    bottom: 48px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--accent-bright);
    color: #fff;
    padding: 8px 20px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    pointer-events: none;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 1000;
    box-shadow: 0 8px 24px rgba(59, 130, 246, 0.35);
}

.toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ===========================
   View Modes
   =========================== */
.main-content.editor-only .preview-panel,
.main-content.editor-only .resize-handle {
    display: none;
}

.main-content.editor-only .editor-panel {
    flex: 1;
    border-right: none;
}

.main-content.preview-only .editor-panel,
.main-content.preview-only .resize-handle {
    display: none;
}

.main-content.preview-only .preview-panel {
    flex: 1;
}

/* ===========================
   Responsive
   =========================== */
@media (max-width: 900px) {
    .btn-text {
        display: none;
    }

    .toolbar-separator:nth-child(n+8) {
        display: none;
    }

    .preview-content {
        padding: 16px 20px;
    }
}

@media (max-width: 650px) {
    .top-bar {
        padding: 0 8px;
        gap: 8px;
    }

    .app-title {
        font-size: 13px;
    }

    .toolbar-separator {
        margin: 0 3px;
    }

    .tool-btn {
        height: 28px;
        min-width: 28px;
        padding: 0 5px;
    }

    .line-numbers {
        width: 36px;
        font-size: 11px;
    }

    .editor-textarea {
        font-size: 12px;
        padding: 10px 12px;
    }
}
