:root {
    --bg-color: #0d1117;
    --panel-bg: #161b22;
    --border-color: #30363d;
    --text-primary: #c9d1d9;
    --text-secondary: #8b949e;
    --accent-color: #58a6ff;
    --accent-hover: #1f6feb;
    --danger-color: #da3633;
    --header-height: 60px;
    --font-mono: 'Fira Code', monospace;
    --font-sans: 'Inter', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-color);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Header */
.header {
    height: var(--header-height);
    background-color: var(--panel-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 20px;
}

.header-left h1 {
    font-size: 1.2rem;
    font-weight: 600;
}

.back-link {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    transition: color 0.2s;
}

.back-link:hover {
    color: var(--accent-color);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.action-btn {
    background-color: var(--accent-color);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background-color 0.2s;
    font-size: 0.9rem;
}

.action-btn:hover {
    background-color: var(--accent-hover);
}

.icon-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.icon-btn:hover {
    background-color: var(--border-color);
    color: var(--text-primary);
}

/* Dropdown */
.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-content {
    display: none;
    position: absolute;
    right: 0;
    /* Align to right */
    background-color: var(--panel-bg);
    min-width: 200px;
    box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    z-index: 1;
    margin-top: 5px;
}

.dropdown-content a {
    color: var(--text-primary);
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    font-size: 0.9rem;
}

.dropdown-content a:hover {
    background-color: var(--border-color);
}

.dropdown:hover .dropdown-content {
    display: block;
}

/* Main Editor Area */
.editor-container {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.panel {
    display: flex;
    flex-direction: column;
    min-width: 100px;
    /* Minimum width for panels */
}

.editor-panel {
    background-color: var(--bg-color);
    width: 50%;
    /* Default split */
}

.preview-panel {
    background-color: white;
    flex: 1;
    /* Takes remaining space */
}

.panel-header {
    height: 40px;
    background-color: var(--panel-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    user-select: none;
}

.panel-title {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.window-controls {
    display: flex;
    gap: 8px;
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.dot.red {
    background-color: #ff5f56;
}

.dot.yellow {
    background-color: #ffbd2e;
}

.dot.green {
    background-color: #27c93f;
}

/* Editor Container */
.textarea-wrapper {
    flex: 1;
    position: relative;
    overflow: hidden;
}

#editor {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    font-size: 14px;
    line-height: 1.6;
}

/* Ace Editor Overrides for Seamless Integration */
.ace_editor {
    background-color: var(--bg-color) !important;
    color: var(--text-primary) !important;
}

.ace_gutter {
    background-color: var(--panel-bg) !important;
    color: var(--text-secondary) !important;
    border-right: 1px solid var(--border-color);
}

.ace_gutter-active-line {
    background-color: rgba(255, 255, 255, 0.05) !important;
}

.ace_cursor {
    color: var(--accent-color) !important;
}

.ace_active-line {
    background-color: rgba(56, 139, 253, 0.1) !important;
}

/* Preview Iframe */
.iframe-wrapper {
    flex: 1;
    background-color: white;
    width: 100%;
    height: 100%;
}

iframe {
    width: 100%;
    height: 100%;
    border: none;
}

/* Panel Actions */
#refreshBtn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s;
}

#refreshBtn:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

/* Resizer */
.resizer {
    width: 5px;
    background-color: var(--panel-bg);
    cursor: col-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
    z-index: 10;
}

.resizer:hover,
.resizer.resizing {
    background-color: var(--accent-color);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal-content {
    background-color: var(--panel-bg);
    margin: 10% auto;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    width: 80%;
    max-width: 600px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

.close-modal {
    color: var(--text-secondary);
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
}

.close-modal:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
    max-height: 400px;
    overflow-y: auto;
}

.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
}

#historyList {
    list-style: none;
}

.history-item {
    padding: 12px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: background-color 0.2s;
    border-radius: 4px;
}

.history-item:hover {
    background-color: var(--border-color);
}

.history-item:last-child {
    border-bottom: none;
}

.history-time {
    font-size: 0.9rem;
    font-weight: 500;
}

.history-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.danger-btn {
    background-color: transparent;
    color: var(--danger-color);
    border: 1px solid var(--danger-color);
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.danger-btn:hover {
    background-color: var(--danger-color);
    color: white;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .editor-container {
        flex-direction: column;
    }

    .panel {
        width: 100% !important;
        /* Force full width on mobile */
        height: 50%;
        min-height: 200px;
    }

    .resizer {
        width: 100%;
        height: 5px;
        cursor: row-resize;
    }

    .header-right .action-btn span {
        display: none;
        /* Hide text on small screens, keep icon */
    }

    .header-right .action-btn svg {
        margin-right: 0;
    }

    .dropdown-content {
        right: -20px;
    }

    /* Hide Back text and Title on mobile to save space */
    .back-link {
        font-size: 0;
    }

    .back-link svg {
        margin-right: 0;
    }

    .header-left h1 {
        display: none;
        /* Hide title on very small screens */
    }

    .header {
        padding: 0 10px;
    }

    .header-left {
        gap: 10px;
    }

    .header-right {
        gap: 8px;
    }

    .icon-btn {
        padding: 6px;
    }
}

@media (min-width: 480px) and (max-width: 768px) {
    .header-left h1 {
        display: block;
        font-size: 1rem;
    }
}