/* CSS Root Variables for mathematically perfect grid scaling */
:root {
    --editor-font-size: 14px;
    --editor-line-height: 21px; /* Always precisely 1.5x font size */
    --editor-font-family: 'Courier New', Courier, monospace;
    --editor-tab-size: 4;
}

/* UI Reset and Base Settings */
* { 
    box-sizing: border-box; 
    margin: 0; 
    padding: 0; 
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; 
    font-size: 12px; 
}
body, html { 
    height: 100%; 
    display: flex; 
    flex-direction: column; 
    background-color: #f0f0f0; 
    overflow: hidden; 
}
.divider { 
    height: 1px; 
    background-color: #a0a0a0; 
    margin: 3px 0; 
}
.vert-divider { 
    width: 1px; 
    background-color: #a0a0a0; 
    height: 16px; 
    margin: 0 4px; 
    display: inline-block; 
    vertical-align: middle; 
}

/* Distraction Free Mode Override */
body.distraction-free #menubar,
body.distraction-free #toolbar,
body.distraction-free #tabbar,
body.distraction-free #statusbar {
    display: none !important;
}

/* Distraction Free Exit Hint */
#df-exit-hint {
    display: none;
    position: fixed;
    top: 15px;
    right: 25px;
    background: rgba(0,0,0,0.6);
    color: #fff;
    padding: 8px 16px;
    border-radius: 6px;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 12px;
    z-index: 9999;
    cursor: default;
    user-select: none;
    transition: background 0.2s;
}
#df-exit-hint:hover { background: rgba(0,0,0,0.8); }
body.distraction-free #df-exit-hint { display: block; }

/* Menu Bar */
#menubar { 
    background-color: #ffffff; 
    display: flex; 
    border-bottom: 1px solid #ccc; 
    user-select: none; 
    flex-wrap: wrap; 
    z-index: 2000; 
    flex-shrink: 0; 
}
.menu-root { 
    position: relative; 
    padding: 4px 8px; 
    cursor: default; 
}
.menu-root:hover { 
    background-color: #e5f3ff; 
}
.dropdown { 
    display: none; 
    position: absolute; 
    top: 100%; 
    left: 0; 
    background-color: #f2f2f2; 
    border: 1px solid #ccc; 
    box-shadow: 2px 2px 5px rgba(0,0,0,0.2); 
    min-width: 280px; 
    z-index: 1000; 
}
.menu-root.open .dropdown { 
    display: block; 
}
.menu-item { 
    padding: 4px 16px 4px 24px; 
    position: relative; 
    display: flex; 
    justify-content: space-between; 
    color: #000; 
    cursor: default; 
}
.menu-item:hover > .submenu { 
    display: block; 
}
.menu-item:hover { 
    background-color: #91c9f7; 
}
.hotkey { 
    color: #666; 
    margin-left: 20px; 
    white-space: nowrap; 
}
.submenu { 
    display: none; 
    position: absolute; 
    top: 0; 
    left: 100%; 
    background-color: #f2f2f2; 
    border: 1px solid #ccc; 
    min-width: 200px; 
    box-shadow: 2px 2px 5px rgba(0,0,0,0.2); 
}
.has-submenu::after { 
    content: "▶"; 
    font-size: 8px; 
    position: absolute; 
    right: 8px; 
    top: 8px; 
    color: #666; 
}
.check-icon {
    position: absolute;
    left: 6px;
    font-weight: bold;
    color: #000;
}

/* Toolbar */
#toolbar { 
    background-color: #f0f0f0; 
    padding: 4px; 
    display: flex; 
    align-items: center; 
    flex-wrap: wrap; 
    border-bottom: 1px solid #d4d4d4; 
    flex-shrink: 0; 
}
.tool-btn { 
    width: 22px; 
    height: 22px; 
    margin: 0 1px; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    cursor: default; 
    border: 1px solid transparent; 
    border-radius: 2px; 
    transition: background-color 0.2s;
}
.tool-btn:hover { 
    border-color: #a0a0a0; 
    background-color: #e5f3ff; 
}
.tool-icon { 
    font-size: 14px; 
}
.tool-btn img { 
    width: 16px; 
    height: 16px; 
    pointer-events: none; 
}

/* Tab Bar */
#tabbar { 
    background-color: #f0f0f0; 
    display: flex; 
    padding-top: 4px; 
    border-bottom: 1px solid #a0a0a0; 
    overflow-x: auto; 
    flex-shrink: 0; 
    min-height: 29px; 
}
.tab { 
    background-color: #e4e4e4; 
    border: 1px solid #a0a0a0; 
    border-bottom: none; 
    padding: 4px 10px; 
    margin-left: 2px; 
    border-top-left-radius: 4px; 
    border-top-right-radius: 4px; 
    cursor: default; 
    display: flex; 
    align-items: center; 
    gap: 5px; 
    user-select: none; 
}
.tab.active { 
    background-color: #ffffff; 
    border-top: 3px solid #ff8c00; 
    margin-bottom: -1px; 
    padding-bottom: 5px; 
    z-index: 10; 
}

.floppy-icon { 
    width: 14px; 
    height: 14px; 
    pointer-events: none;
}

.tab-close { 
    width: 12px; 
    height: 12px; 
    margin-left: 8px; 
    border-radius: 2px; 
    background-image: url('https://proxy.duckduckgo.com/iu/?u=https://i.imgur.com/grlZsSQ.png');
    background-size: cover;
    display: none;
}
.tab.active .tab-close {
    display: inline-block;
}
.tab.active .tab-close:hover { 
    background-image: url('https://proxy.duckduckgo.com/iu/?u=https://i.imgur.com/unlJwjz.png');
}

/* Editor Layout */
#editor-container { 
    display: flex; 
    flex-grow: 1; 
    background-color: #ffffff; 
    position: relative; 
    overflow: hidden; 
    min-height: 0; 
}
#line-numbers { 
    background-color: #e4e4e4; 
    color: #888; 
    padding: 5px 5px 400px 5px; 
    text-align: right; 
    border-right: 1px solid #c0c0c0; 
    font-family: var(--editor-font-family) !important; 
    font-size: var(--editor-font-size); 
    line-height: var(--editor-line-height); 
    min-width: 45px; 
    user-select: none; 
    overflow: hidden; 
    z-index: 5; 
    display: block; 
}

#code-wrapper { 
    position: relative; 
    flex-grow: 1; 
    overflow: hidden; 
    background-color: #ffffff;
}

/* THE FORTRESS OF SYNC - ABSOLUTELY PERFECT ALIGNMENT */
#editor, 
#highlighting, 
#highlighting-content, 
#highlighting-content *,
#wrap-measurer,
#wrap-measurer * { 
    font-family: var(--editor-font-family) !important; 
    font-size: var(--editor-font-size) !important; 
    line-height: var(--editor-line-height) !important; 
    tab-size: var(--editor-tab-size) !important; 
    -moz-tab-size: var(--editor-tab-size) !important; 
    -o-tab-size: var(--editor-tab-size) !important; 
    letter-spacing: 0px !important;
    word-spacing: 0px !important;
    font-weight: 400 !important; 
    font-style: normal !important; 
    box-sizing: border-box !important;
    text-decoration: none !important;
    text-transform: none !important;
    direction: ltr !important;
    text-align: left !important;
    vertical-align: top !important; 
    font-kerning: none !important;
    font-variant-ligatures: none !important;
}

#editor, #highlighting { 
    position: absolute !important; 
    top: 0 !important; 
    left: 0 !important; 
    width: 100% !important; 
    height: 100% !important; 
    margin: 0 !important; 
    padding: 5px 5px 400px 5px !important; 
    white-space: pre !important; 
    word-wrap: normal !important; 
    overflow-wrap: normal !important; 
    border: none !important; 
    outline: none !important; 
    background: transparent !important;
    overflow-anchor: none !important;
}

#wrap-measurer {
    position: absolute !important;
    visibility: hidden !important;
    z-index: -100 !important;
    top: 0 !important; 
    left: 0 !important; 
    padding: 5px !important; 
    margin: 0 !important; 
    border: none !important;
}

/* MODIFIED: Z-Index 1 (Bottom). Scrollbars forced to stay visible so width is perfectly synced */
#editor { 
    overflow-y: scroll !important; 
    overflow-x: auto !important; 
    color: transparent !important; 
    caret-color: #000 !important; 
    z-index: 1 !important; 
    resize: none !important; 
}

/* MODIFIED: Z-Index 2 (Top). Shrunk by exactly 12px to protect the scrollbars from Chrome's bug */
#highlighting { 
    overflow: hidden !important; 
    z-index: 2 !important; 
    color: #000 !important; 
    pointer-events: none !important; 
    width: calc(100% - 12px) !important; /* Perfectly clears the vertical scrollbar */
    height: calc(100% - 12px) !important; /* Perfectly clears the horizontal scrollbar */
}

#highlighting-content { 
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
    background: transparent !important;
    white-space: inherit !important; 
}

/* RTL / LTR ENGINE - OVERRIDES DIRECTION AND ALIGNMENT CLEANLY */
#editor-container.is-rtl #editor, 
#editor-container.is-rtl #highlighting, 
#editor-container.is-rtl #highlighting-content, 
#editor-container.is-rtl #highlighting-content *,
body.is-rtl-measurer #wrap-measurer,
body.is-rtl-measurer #wrap-measurer div,
body.is-rtl-measurer #wrap-measurer * {
    direction: rtl !important;
    text-align: right !important;
}

/* WORD WRAP OVERRIDES - FORCES PRECISE MATHEMATICAL WRAPPING FOR TEXTAREA & SHADOWS */
.word-wrap #editor, 
.word-wrap #highlighting,
.word-wrap #highlighting-content,
.word-wrap #highlighting-content *,
.word-wrap #wrap-measurer,
.word-wrap #wrap-measurer div {
    white-space: pre-wrap !important;
    word-wrap: break-word !important;
    overflow-wrap: anywhere !important;
    word-break: break-all !important; 
}

#editor::-webkit-scrollbar { 
    width: 12px; 
    height: 12px; 
}
#editor::-webkit-scrollbar-thumb { 
    background: rgba(0,0,0,0.2); 
}

/* Solid background perfectly sitting behind the pristine syntax layer */
#editor::selection {
    background-color: #c9efd3; 
    color: transparent !important;
}
#editor::-moz-selection {
    background-color: #c9efd3; 
    color: transparent !important;
}

/* FORBIDS PRISM FROM STRETCHING TEXT WITH BOLD FONTS */
.token {
    font-weight: normal !important;
    font-style: normal !important;
}

code[class*="language-"], pre[class*="language-"] {
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
    background: transparent !important;
    text-shadow: none !important;
    box-shadow: none !important;
}

/* Status Bar */
#statusbar {
    background-color: #f0f0f0;
    border-top: 1px solid #ccc;
    display: flex;
    padding: 2px 10px;
    font-size: 11px;
    color: #333;
    user-select: none;
    flex-shrink: 0; 
}
.sb-section {
    border-left: 1px solid #ccc;
    padding: 0 10px;
    display: flex;
    align-items: center;
    min-width: 100px;
}
.sb-section:first-child {
    border-left: none;
    flex-grow: 1;
    padding-left: 0;
}

/* UNIVERSAL MODAL SYSTEM */
.modal {
    display: none;
    position: absolute;
    background-color: #f0f0f0;
    border: 1px solid #0078d7;
    box-shadow: 0 4px 15px rgba(0,0,0,0.4);
    z-index: 3000;
    min-width: 380px;
    border-radius: 6px; 
    overflow: hidden; 
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
.modal-header {
    background-color: #ffffff;
    padding: 6px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #d4d4d4;
    font-weight: bold;
    font-size: 13px;
    user-select: none;
}
.modal-header button {
    background: none;
    border: none;
    cursor: default;
    font-size: 14px;
    color: #333;
}
.modal-header button:hover { color: red; }
.modal-body {
    padding: 15px;
}
.input-row {
    display: flex;
    align-items: center;
    margin-bottom: 12px;
}
.input-row label {
    width: 90px;
    font-size: 12px;
}
.input-row input[type="text"], .input-row input[type="number"], .input-row select {
    flex-grow: 1;
    padding: 4px;
    border: 1px solid #8e8f8f;
    font-size: 12px;
}
.options {
    margin: 15px 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    border: 1px solid #d4d4d4;
    padding: 10px;
    background-color: #ffffff;
}
.actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 15px;
}
.actions button {
    padding: 4px 14px;
    cursor: default;
    border: 1px solid #a0a0a0;
    background-color: #e1e1e1;
    font-size: 12px;
    border-radius: 3px;
}
.actions button:hover {
    background-color: #e5f3ff;
    border-color: #0078d7;
}

/* Preferences Specific Modal Styles */
.pref-container { display: flex; height: 350px; }
.pref-sidebar { width: 120px; border-right: 1px solid #ccc; background-color: #f9f9f9; padding: 5px; }
.pref-sidebar-item { padding: 4px 8px; cursor: default; user-select: none; border-radius: 3px; }
.pref-sidebar-item.active { background-color: #e5f3ff; border: 1px solid #cce8ff; }
.pref-content { flex-grow: 1; padding: 15px; background-color: #ffffff; overflow-y: auto; }
.pref-group { margin-bottom: 15px; border: 1px solid #d4d4d4; padding: 10px; position: relative; border-radius: 4px; }
.pref-group-title { position: absolute; top: -8px; left: 10px; background: #fff; padding: 0 4px; color: #0078d7; font-size: 11px; }

/* VIBRANT NOTEPAD++ SYNTAX HIGHLIGHTING OVERRIDES */
.token.comment, .token.prolog, .token.doctype, .token.cdata { color: #008000 !important; } /* Green */
.token.punctuation { color: #0000FF !important; } /* Blue brackets/tags usually */
.token.namespace { opacity: .7 !important; }
.token.property, .token.tag, .token.boolean, .token.constant, .token.symbol, .token.deleted { color: #0000FF !important; } /* Pure Blue */
.token.selector, .token.attr-name, .token.char, .token.builtin, .token.inserted { color: #FF0000 !important; } /* Pure Red */
.token.string, .token.attr-value { color: #800080 !important; } /* Purple */
.token.operator, .token.entity, .token.url, .language-css .token.string, .style .token.string { color: #000000 !important; } /* Black */
.token.atrule, .token.keyword { color: #0000FF !important; } /* Blue */
.token.function, .token.class-name { color: #000000 !important; } /* Black */
.token.regex, .token.important, .token.variable, .token.number { color: #FF8000 !important; } /* Orange */
.language-html .token.punctuation { color: #0000FF !important; } 
.language-javascript .token.punctuation { color: #000000 !important; } 

/* Shortcut Mapper Grid */
.shortcut-table { width: 100%; border-collapse: collapse; text-align: left; font-size: 12px; }
.shortcut-table th, .shortcut-table td { padding: 4px 8px; border: 1px solid #ccc; }
.shortcut-table th { background: #e4e4e4; font-weight: bold; position: sticky; top: 0; }

/* Draggable Tab States */
.tab.dragging {
    opacity: 0.4;
}
.tab.drag-over {
    box-shadow: inset 0 0 0 2px #0078d7;
}