:root {
    --cm-fg: #1a1a1a;
    --cm-bg: #ffffff;
    --cm-caret: rgba(255, 80, 0, 0.7);
    --cm-selection-bg: #d7e6ff;
    --cm-gutter-bg: #f4f4f4;
    --cm-gutter-fg: #999999;
    /* Reserved for Phase 2 RL sync */
    --cm-sync-highlight-bg: #fff3b0;
}

html, body {
    margin: 0;
    height: 100%;
    overflow: hidden;          /* the document itself never scrolls */
    overscroll-behavior: none; /* no rubber-band / scroll-chaining to the page */
}

.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden; /* pin the shell to the viewport; panels scroll internally */
    background: #666666;
    font-family: ui-sans-serif, system-ui, sans-serif;
}

.app-header {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #e6e6e6;
    font-weight: 700;
    padding: 8px 16px;
}

.app-header .app-label {
    color: #ffffff;
    font-size: 16px;
    margin-right: 6px;
}

.app-header .header-item {
    color: #f0f0f0;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 260px;
}

.app-header .dirty {
    color: #ffd27a;
}

.app-header .header-key {
    color: #bdbdbd;
}

.app-header .notice {
    color: #ffd27a;
    font-size: 13px;
    margin-left: auto;
}

/* Pinned to the right corner; when a notice is showing, the notice takes
   the free space and the count sits just after it. */
.app-header .word-count {
    margin-left: auto;
}

.app-header .notice + .word-count {
    margin-left: 10px;
}

/* File menu */
.menu {
    position: relative;
}

.toolbar-button.open {
    background: #ffffff;
}

.menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 10;
}

.menu-list {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    z-index: 11;
    min-width: 170px;
    display: flex;
    flex-direction: column;
    padding: 4px 0;
    background: #ffffff;
    border: 1px solid #999;
    border-radius: 4px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

.menu-item {
    font: inherit;
    font-size: 13px;
    font-weight: 500;
    color: #1a1a1a;
    text-align: left;
    background: none;
    border: 0;
    padding: 6px 14px;
    cursor: pointer;
}

/* Label on the left, keyboard shortcut (if any) on the right */
.menu-item {
    display: flex;
    justify-content: space-between;
    gap: 24px;
}

.menu-shortcut {
    color: #888;
}

/* Recent menu: about twice as wide as the File menu, one line per file */
.recent-list {
    width: 357px;
}

.recent-list .menu-item {
    gap: 12px;
    white-space: nowrap;
}

.recent-name,
.recent-folder {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* The folder gives way before the file name does */
.recent-folder {
    flex-shrink: 10;
}

/* Recent menu: shown when no file has been opened yet */
.menu-empty {
    font-size: 13px;
    color: #888;
    padding: 6px 14px;
}

.menu-item:hover {
    background: #e3ebfb;
}

/* File-name window (New, Save As) */
.dialog-backdrop {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.35);
}

.dialog {
    min-width: 320px;
    padding: 16px 18px;
    background: #ffffff;
    color: #1a1a1a;
    border-radius: 6px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
    font-weight: 400;
}

.dialog h2 {
    margin: 0 0 12px;
    font-size: 15px;
}

.dialog label {
    display: block;
    font-size: 12px;
    color: #555;
    margin-bottom: 4px;
}

.dialog input {
    width: 100%;
    box-sizing: border-box;
    padding: 6px 8px;
    font-size: 14px;
    border: 1px solid #bbb;
    border-radius: 4px;
}

.dialog-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 14px;
}

.toolbar-button.primary {
    background: #2f6fde;
    border-color: #2a5fc0;
    color: #ffffff;
}

.toolbar-button.primary:hover {
    background: #3b7bea;
}

.toolbar-button:disabled {
    opacity: 0.5;
    cursor: default;
}

.toolbar {
    display: flex;
    gap: 8px;
}

.toolbar-button {
    font: inherit;
    font-weight: 600;
    font-size: 13px;
    color: #1a1a1a;
    background: #e6e6e6;
    border: 1px solid #999;
    border-radius: 4px;
    padding: 5px 12px;
    cursor: pointer;
}

.toolbar-button:hover {
    background: #ffffff;
}

.toolbar-button:active {
    background: #cfcfcf;
}

.panels {
    display: flex;
    gap: 0; /* the .divider elements provide the spacing */
    padding: 0 16px 16px;
    flex: 1;
    min-height: 0;
}

.panel {
    background: #ffffff;
    border-radius: 4px;
    overflow: auto;
    overscroll-behavior: contain; /* keep scroll inside the panel at its edges */
    min-height: 0;
}

.editor-panel {
    flex: none;
    padding: 0;
    overflow: hidden; /* CodeMirror manages its own scrolling */
}

.editor-panel codemirror-editor {
    display: block;
    height: 100%;
}

.rendered-panel,
.toc-panel {
    padding: 16px 24px;
    font-size: 14px;
}

.rendered-panel {
    flex: 1; /* takes whatever the editor and TOC leave */
    min-width: 0;
}

/* Draggable divider between panels; a thin line appears on hover/drag. */
.divider {
    flex: none;
    width: 16px;
    cursor: col-resize;
    position: relative;
}

.divider::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 7px;
    width: 2px;
    border-radius: 1px;
    background: transparent;
    transition: background 0.15s;
}

.divider:hover::after,
.divider.active::after {
    background: rgba(255, 255, 255, 0.6);
}

/* While dragging, keep the resize cursor everywhere and don't select text. */
.app.dragging {
    cursor: col-resize;
    user-select: none;
}
