:root {
    --font-family: 'Inter', system-ui, Avenir, Helvetica, Arial, sans-serif;
    --line-height: 1.5;
    --font-weight: 400;

    /* Light Theme Vars */
    --color-bg-body: #f8f9fa;
    --color-text-body: #212529;
    --color-primary: #d32f2f;
    --color-primary-hover: #b71c1c;
    --color-surface: #ffffff;
    --color-border: #dee2e6;
    --color-input-bg: #ffffff;
    --color-panel-header: #f8f9fa;

    --color-log-bg: #e9ecef;
    --color-log-text: #212529;

    --header-height: 60px;
}

[data-theme="dark"] {
    --color-bg-body: #121214;
    --color-text-body: #e1e1e6;
    --color-primary: #ff5555;
    --color-primary-hover: #ff6e6e;
    --color-surface: #1e1e22;
    --color-border: #323238;
    --color-input-bg: #121214;
    --color-panel-header: #1e1e22;

    --color-log-bg: #09090a;
    --color-log-text: #c4c4cc;
}

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background-color: var(--color-bg-body);
    font-family: var(--font-family);
    color: var(--color-text-body);
    transition: background-color 0.2s, color 0.2s;
}

#app {
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

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

.logo {
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--color-primary);
}

.header-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

/* Main Layout */
.app-content {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 1rem;
    padding: 1rem;
    flex: 1;
    overflow: hidden;
}

.panel {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    /* Important: prevents column expansion */
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.panel h3 {
    margin-top: 0;
    border-bottom: 1px solid var(--color-border);
    padding-bottom: 0.5rem;
    font-size: 1rem;
    color: var(--color-primary);
}

textarea {
    width: 100%;
    flex: 1;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    padding: 0.75rem;
    resize: none;
    font-family: inherit;
    box-sizing: border-box;
    background-color: var(--color-input-bg);
    color: var(--color-text-body);
    font-size: 0.95rem;
    line-height: 1.5;
}

textarea:focus {
    outline: none;
    border-color: var(--color-primary);
}

/* Dropzone */
.dropzone {
    border: 2px dashed var(--color-border);
    border-radius: 4px;
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    margin-bottom: 1rem;
    transition: border-color 0.2s;
    background: var(--color-bg-body);
}

.dropzone.compact {
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
}

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

.result-editor {
    flex: 1;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    padding: 0.75rem;
    overflow-y: auto;
    overflow-x: hidden;
    outline: none;
    background-color: var(--color-input-bg);
    white-space: normal;
    word-break: break-word;
    overflow-wrap: break-word;
}

.result-editor h1,
.result-editor h2,
.result-editor h3 {
    color: var(--color-primary);
}

/* Buttons */
button {
    cursor: pointer;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text-body);
    font-size: 0.9rem;
    transition: all 0.2s;
}

button:hover {
    background: var(--color-bg-body);
}

button.icon-btn {
    padding: 0.25rem 0.5rem;
}

.primary-btn {
    background: var(--color-primary);
    color: white;
    border: none;
    font-weight: 600;
}

.primary-btn:hover {
    background: var(--color-primary-hover);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

* {
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

/* Theme Toggle */
.theme-toggle {
    font-size: 1.2rem;
    padding: 4px 10px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Compact Actions */
.compact-actions {
    display: grid;
    grid-template-columns: 80px 1fr;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 0.5rem;
}

.compact-actions input {
    height: 32px;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    padding: 0 0.5rem;
    background: var(--color-input-bg);
    color: var(--color-text-body);
}

/* Structure Rows */
.structure-row {
    display: flex;
    align-items: center;
    margin-bottom: 0.25rem;
    padding: 0.25rem;
    background: var(--color-bg-body);
    border-radius: 4px;
    gap: 0.5rem;
    border: 1px solid transparent;
}

.structure-row:hover {
    border-color: var(--color-border);
}

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

.row-controls select {
    padding: 2px;
    font-size: 0.8rem;
    background: var(--color-surface);
    color: var(--color-text-body);
    border: 1px solid var(--color-border);
}

.row-content {
    flex: 1;
    outline: none;
    font-weight: 500;
}

[data-level="1"] .row-content {
    font-size: 1.1rem;
    font-weight: 700;
}

[data-level="2"] .row-content {
    padding-left: 1rem;
}

[data-level="3"] .row-content {
    padding-left: 2rem;
    font-size: 0.9rem;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
}

.modal.open {
    display: flex;
}

.modal-overlay {
    position: absolute;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
}

.modal-content {
    background: var(--color-surface);
    width: 700px;
    max-width: 95vw;
    border-radius: 8px;
    z-index: 1001;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
}

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

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    font-size: 0.9rem;
}

.form-group textarea {
    min-height: 100px;
    resize: vertical;
}

/* Footer / Logs */
.app-footer {
    height: 160px;
    background: var(--color-log-bg);
    color: var(--color-log-text);
    border-top: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
}

.log-header {
    background: var(--color-surface);
    padding: 0.4rem 1rem;
    font-size: 0.75rem;
    font-weight: 700;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--color-border);
}

.app-log {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 1rem;
    font-family: monospace;
    font-size: 0.85rem;
}

.log-entry {
    margin-bottom: 0.2rem;
}

.log-time {
    opacity: 0.6;
    margin-right: 0.5rem;
}

.hidden {
    display: none;
}