/* EMU Editor - Functional CSS (Layout & Structure) */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    height: 100vh;
    overflow: hidden;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* App Toolbar (top) */
#app-toolbar {
    border-bottom: 1px solid var(--border-color);
    padding: 8px 12px;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 12px;
    align-items: center;
    min-height: 76px; /* Accommodate 60px logo + padding */
}

.toolbar-section {
    display: flex;btn-toggle-syntax
    gap: 8px;
    align-items: center;
}

.toolbar-left {
    justify-content: flex-start;
}

.toolbar-center {
    justify-content: center;
}

.toolbar-right {
    justify-content: flex-end;
}

.app-logo-large {
    height: 60px;
    width: auto;
    object-fit: contain;
}

.logo-link {
    display: inline-block;
    position: relative;
    text-decoration: none;
    transition: opacity 0.2s;
}

.logo-link:hover {
    opacity: 0.8;
}

/* Custom tooltip for logo */
.logo-link::after {
    content: attr(title);
    position: absolute;
    bottom: -35px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--logo-color);
    color: black;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 1000;
}

.logo-link:hover::after {
    opacity: 1;
}

/* Editor Toolbar (WYSIWYG) */
#editor-toolbar {
    border-bottom: 1px solid var(--border-color);
    padding: 8px 12px;
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

/* Dropdown menu for Save button */
.btn-with-dropdown {
    position: relative;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 4px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    min-width: 200px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s;
    z-index: 1000;
}

.btn-with-dropdown:hover .dropdown-menu,
.btn-with-dropdown.forced-open .dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/*#btn-toggle-syntax{display: none;}*/
#btn-toggle-view  {width: 105px; }

.dropdown-item {
    padding: 10px 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-primary);
    transition: background 0.15s;
}

.dropdown-item:hover,
.dropdown-item.kb-focus {
    background: var(--bg-primary);
}

.dropdown-item:first-child {
    border-radius: 4px 4px 0 0;
}

.dropdown-item:last-child {
    border-radius: 0 0 4px 4px;
}

.dropdown-item i {
    width: 16px;
    text-align: center;
}

.dropdown-item .shortcut {
    margin-left: auto;
    font-size: 0.85em;
    color: var(--text-muted);
}

.dropdown-separator {
    height: 1px;
    margin: 4px 0;
    background: var(--border-color);
}

/* Right-aligned dropdown (opens to the left) */
.dropdown-menu-right {
    left: auto;
    right: 0;
}

/* Label row inside dropdown (non-interactive) */
.dropdown-label {
    padding: 6px 16px 2px;
    font-size: 0.75em;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    cursor: default;
}

/* Select element inside dropdown */
.dropdown-item-select {
    padding: 4px 16px 8px;
    cursor: default;
    display: flex;
    align-items: center;
    gap: 8px;
}

.dropdown-item-select:hover {
    background: transparent;
}

.dropdown-item-select label {
    display: inline-block;
    width: 32px;
    font-size: 0.8em;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.dropdown-item-select select {
    flex: 1;
    min-width: 0;
    padding: 4px 8px;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 3px;
    font-size: 0.9em;
    cursor: pointer;
}

.dropdown-item-select select:focus {
    outline: 1px solid var(--accent-color);
}

/* Checkbox toggle inside dropdown */
.dropdown-item-toggle {
    padding: 6px 16px;
    cursor: pointer;
}

.dropdown-item-toggle:hover {
    background: var(--bg-hover);
}

.dropdown-item-toggle .toggle-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9em;
    cursor: pointer;
    color: var(--text-primary);
}

.dropdown-item-toggle input[type="checkbox"] {
    accent-color: var(--accent-color);
    cursor: pointer;
}

/* Code Toolbar */
#code-toolbar {
    border-bottom: 1px solid var(--border-color);
    padding: 8px 12px;
    background: var(--bg-secondary);
    display: flex;
    align-items: center;
    gap: 12px;
}

#code-toolbar label {
    font-size: 13px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

#code-toolbar select {
    padding: 4px 8px;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 3px;
    font-size: 13px;
    cursor: pointer;
}

#code-toolbar select optgroup {
    font-style: normal;
    font-weight: bold;
    color: var(--text-muted);
    background: var(--bg-secondary);
}

#code-toolbar select option {
    font-weight: normal;
    color: var(--text-primary);
    background: var(--bg-primary);
}

#btn-refresh-languages,
#btn-save-language {
    padding: 4px 8px;
    font-size: 13px;
}

/* Main Container */
#main-container {
    flex: 1;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    position: relative;
}

/* Find/Replace Bar */
#find-bar {
    position: absolute;
    top: 8px;
    right: 16px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px 12px;
    border-radius: 6px;
    min-width: 380px;
    max-width: 500px;
}

.find-bar-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

#find-bar input[type="text"] {
    flex: 1;
    padding: 5px 8px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    font-size: 13px;
    font-family: inherit;
    outline: none;
    min-width: 180px;
}

.find-bar-btn {
    padding: 4px 8px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    background: var(--button-bg);
    color: var(--text-primary);
    transition: background 0.15s;
}

.find-bar-btn:hover {
    background: var(--button-hover);
}

.find-match-count {
    font-size: 12px;
    min-width: 60px;
    text-align: center;
    white-space: nowrap;
}

/* Markdown Cheat Sheet Sidebar */
.md-cheatsheet {
    position: fixed;
    top: var(--cheatsheet-top, 0);
    right: 0;
    bottom: 0;
    width: 280px;
    z-index: 200;
    transform: translateX(100%);
    transition: transform 0.2s ease;
    display: flex;
    flex-direction: column;
}

.md-cheatsheet.open {
    transform: translateX(0);
}

.md-cheatsheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    font-weight: 600;
    font-size: 13px;
    flex-shrink: 0;
}

.md-cheatsheet-body {
    flex: 1;
    overflow-y: auto;
    padding: 4px 12px 16px;
}

.md-cheatsheet-body details {
    margin-bottom: 2px;
}

.md-cheatsheet-body summary {
    cursor: pointer;
    padding: 6px 0;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    user-select: none;
}

.md-cs-items {
    padding: 4px 0 8px 4px;
}

.md-cs-row {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 3px 0;
    font-size: 12px;
    line-height: 1.5;
}

.md-cs-row code {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 11px;
    padding: 1px 5px;
    border-radius: 3px;
    white-space: nowrap;
    flex-shrink: 0;
}

.md-cs-row span {
    font-size: 11px;
}

/* Drop Overlay */
#drop-overlay {
    position: fixed;
    inset: 0;
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
}

#drop-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.drop-overlay-message {
    font-size: 20px;
    font-weight: 600;
    padding: 24px 40px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.drop-overlay-message i {
    font-size: 28px;
}

.toolbar-spacer {
    flex: 1;
}

.toolbar-divider {
    width: 1px;
    height: 24px;
    margin: 0 4px;
}

/* Width control slider */
.width-control {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    cursor: pointer;
}

.width-control input[type="range"] {
    width: 120px;
    cursor: pointer;
}

.width-control span {
    min-width: 45px;
    font-variant-numeric: tabular-nums;
}

/* Claude transcript toggle */
.transcript-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background 0.2s;
    user-select: none;
}

.transcript-toggle:hover {
    background: var(--button-hover);
}

.transcript-toggle input[type="checkbox"] {
    cursor: pointer;
    width: 16px;
    height: 16px;
}

.transcript-toggle span {
    font-weight: 500;
    color: var(--text-primary);
}

.transcript-toggle input[type="text"] {
    width: 80px;
    padding: 2px 6px;
    border: 1px solid var(--border-color);
    border-radius: 3px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 12px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}

.transcript-toggle input[type="text"]:focus {
    border-color: var(--accent-main);
}

.transcript-toggle input[type="text"]::placeholder {
    color: var(--text-tertiary);
    opacity: 0.6;
}

button {
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.2s;
    font-weight: 500;
}

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

button.is-active {
    background: var(--button-active);
    color: var(--button-active-text);
}

button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Editor Container */
#editor-container {
    width: 60%;  /* Initial width - JavaScript will adjust */
    max-width: 100%;
    height: 100%;
    overflow: auto;
    padding: 40px;
    position: relative;
}

/* Toolbar filename display */
.toolbar-filename {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    opacity: 0.8;
    padding: 0 8px;
}

/* EMU Editor Structure */
.emu {
    max-width: 100%;
    outline: none;
    min-height: 100%;
}

.emu > * {
    margin-bottom: 0.75em;
}

.emu h1 {
    font-size: 2em;
    font-weight: bold;
}

.emu h2 {
    font-size: 1.5em;
    font-weight: bold;
}

.emu h3 {
    font-size: 1.25em;
    font-weight: bold;
}

.emu p {
    line-height: 1.6;
}

.emu strong {
    font-weight: bold;
}

.emu em {
    font-style: italic;
}

.emu code {
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.9em;
}

.emu pre {
    padding: 16px;
    border-radius: 6px;
    overflow-x: auto;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.9em;
}

.emu pre code {
    background: transparent;
    padding: 0;
    color: inherit;
}

.emu ul,
.emu ol {
    padding-left: 2em;
}

.emu li {
    margin-bottom: 0.25em;
}

.emu blockquote {
    border-left: 3px solid var(--accent-color);
    padding-left: 1em;
    font-style: italic;
}

.emu a {
    text-decoration: underline;
}

.emu hr {
    border: none;
    border-top: 2px solid var(--border-color);
    margin: 2em 0;
}

/* Placeholder */
.emu p.is-editor-empty:first-child::before {
    content: attr(data-placeholder);
    float: left;
    height: 0;
    pointer-events: none;
}

/* Status bar */
#status-bar {
    padding: 4px 12px;
    font-size: 12px;
    display: flex;
    justify-content: space-between;
}

/* Code view container */
#code-container {
    width: 60%;  /* Initial width - JavaScript will adjust based on screen size */
    max-width: 100%;
    height: 100%;
    display: flex;
    overflow: hidden;
    position: relative;
}

#code-line-numbers {
    padding: 40px 0;
    padding-bottom: calc(40px + 1.5em);  /* match pre padding-bottom so scroll heights align */
    text-align: right;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 14px;
    user-select: none;
    min-width: 60px;
    flex-shrink: 0;
    overflow-y: scroll;
    overflow-x: hidden;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    scrollbar-width: none;  /* Firefox */
    -ms-overflow-style: none;  /* IE and Edge */
}

#code-line-numbers::-webkit-scrollbar {
    display: none;  /* Chrome, Safari, Opera */
}

#code-line-numbers > div {
    line-height: 1.5;
    padding-right: 12px;
}

/* Code editor wrapper - overlay context */
#code-editor-wrapper {
    position: relative;
    overflow: hidden;
    flex: 1;
}

/* Code editor and highlight overlay - positioned within wrapper */
#code-editor,
#code-highlight {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    padding: 40px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre;
    word-wrap: normal;
    overflow-wrap: normal;
    tab-size: 4;
}

#code-editor {
    border: none;
    resize: none;
    outline: none;
    overflow-y: auto;
    overflow-x: auto;
    background: transparent;
    z-index: 2;
    color: transparent;
    caret-color: var(--text-primary);
    -webkit-text-fill-color: transparent;
}

#code-highlight {
    pointer-events: none;
    overflow-y: scroll;  /* match textarea scrollbar gutter so widths stay identical */
    overflow-x: auto;
    z-index: 1;
    background: transparent !important;
    margin: 0;
}

#code-highlight code {
    display: block;
    padding: 0 !important;
    padding-bottom: 1.5em !important;  /* one line extra so scroll heights match textarea */
    margin: 0 !important;
    background: transparent !important;
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
    white-space: inherit;
    word-wrap: inherit;
    tab-size: inherit;
    color: inherit;
}
