:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --error-color: #ef4444;
    --warning-color: #f59e0b;
    --suggestion-bg: #eff6ff;

    /* Light Theme */
    --bg-color: #f8fafc;
    --text-color: #1e293b;
    --border-color: #e2e8f0;
    --card-bg: #ffffff;
    --header-bg: #f1f5f9;
    --input-bg: #ffffff;
    --input-border: #cbd5e1;
    --highlight-error-bg: rgba(239, 68, 68, 0.2);
    --highlight-warning-bg: rgba(245, 158, 11, 0.2);
    --highlight-active-bg: rgba(37, 99, 235, 0.2);
    --context-bg: #f1f5f9;
    --context-text-color: #475569;
}

[data-theme='dark'] {
    --bg-color: #1a202c;
    --text-color: #e2e8f0;
    --border-color: #2d3748;
    --card-bg: #2d3748;
    --header-bg: #2d3748;
    --input-bg: #2d3748;
    --input-border: #4a5568;
    --highlight-error-bg: rgba(239, 68, 68, 0.3);
    --highlight-warning-bg: rgba(245, 158, 11, 0.3);
    --highlight-active-bg: rgba(66, 153, 225, 0.3);
    --context-bg: #4a5568;
    --context-text-color: #e2e8f0;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    height: 100vh;
    display: flex;
    flex-direction: column;
    transition: background-color 0.3s, color 0.3s; /* Smooth theme transition */
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 1rem;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

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

/* Theme Switcher Styles */
.theme-switch-wrapper {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.theme-switch-wrapper label {
    font-size: 0.9rem;
    color: var(--text-color);
}

#theme-toggle {
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--input-bg);
    color: var(--text-color);
    cursor: pointer;
    appearance: none; /* Remove default select arrow */
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%236B7280'%3E%3Cpath fill-rule='evenodd' d='M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z' clip-rule='evenodd'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    background-size: 1.25em;
    padding-right: 2rem;
}

#theme-toggle:focus {
    outline: none;
    border-color: var(--primary-color);
}

main {
    display: flex;
    gap: 1.5rem;
    flex: 1;
    overflow: hidden; /* Prevent scrolling on main container */
}

/* Editor Section */
.editor-section {
    flex: 1; /* Changed from flex: 2 to flex: 1 */
    display: flex;
    flex-direction: column;
    background: var(--card-bg); /* Use var */
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    overflow: hidden;
}

.toolbar {
    padding: 0.75rem;
    background: var(--header-bg); /* Use var */
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 1rem;
}

select {
    padding: 0.5rem;
    border: 1px solid var(--input-border); /* Use var */
    border-radius: 4px;
    background: var(--input-bg); /* Use var */
    color: var(--text-color); /* Use var */
}

button {
    padding: 0.5rem 1rem;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
    transition: background-color 0.2s;
}

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

button:disabled {
    background-color: #94a3b8;
    cursor: not-allowed;
}

#status-msg {
    font-size: 0.9rem;
    color: var(--text-color); /* Use var */
    margin-left: auto;
}

.textarea-container {
    position: relative;
    flex: 1;
    overflow: hidden;
}

/* Textarea and Overlay styling */
textarea, #highlights-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: 1.5rem;
    font-family: inherit;
    font-size: 1rem;
    line-height: 1.6;
    border: none;
    resize: none;
    background: transparent;
    white-space: pre-wrap;
    overflow-y: auto;
    word-wrap: break-word;
    color: var(--text-color); /* Ensure textarea text color adapts */
}

textarea:focus {
    outline: none;
}

#highlights-overlay {
    z-index: 1;
    color: transparent; /* Text is transparent, only backgrounds/underlines show */
    pointer-events: none;
}

/* Sidebar (Optional/Hidden for inline mode, but kept for fallback or logs) */
.sidebar {
    display: none; /* We are going inline! */
}

/* Tooltip / Popover */
.suggestion-tooltip {
    position: absolute;
    background: var(--card-bg); /* Use var */
    border: 1px solid var(--border-color); /* Use var */
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    border-radius: 6px;
    padding: 1rem;
    z-index: 100;
    width: 300px;
    display: none; /* Hidden by default */
    border-left: 4px solid var(--warning-color);
    animation: fadeIn 0.1s ease-out;
}

.suggestion-tooltip.error {
    border-left-color: var(--error-color);
}

.tooltip-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-color); /* Use var */
    font-weight: 600;
}

.tooltip-msg {
    font-size: 0.95rem;
    margin-bottom: 0.75rem;
    color: var(--text-color); /* Use var */
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Adjusted Replacements for Tooltip */
.replacements {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.replacement-chip {
    background: var(--suggestion-bg);
    color: var(--primary-color);
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
    font-size: 0.85rem;
    cursor: pointer;
    border: 1px solid #bfdbfe;
    transition: all 0.2s;
}

.replacement-chip:hover {
    background: #dbeafe;
    border-color: #93c5fd;
}

/* Highlight styles in overlay */
.highlight-error {
    background-color: var(--highlight-error-bg); /* Use var */
    border-bottom: 2px solid var(--error-color);
}

.highlight-warning {
    background-color: var(--highlight-warning-bg); /* Use var */
    border-bottom: 2px solid var(--warning-color);
}

.highlight-active {
    background-color: var(--highlight-active-bg); /* Use var */
}

.error-text {
    background-color: var(--highlight-error-bg); /* Use highlight background for context error */
    color: var(--text-color); /* Keep text readable */
    padding: 0 2px;
    border-radius: 2px;
}

@media (max-width: 768px) {
    main {
        flex-direction: column;
    }
    /* Removed .sidebar reference as it's display: none; */
}
