/**
 * Styles for MicroPython-Stubs Playground
 */

/* CSS Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --header-height: 80px;
    --footer-height: 64px;
    --panel-tabbar-offset: 42px;
    --options-panel-width: min(360px, 92vw);
    --options-panel-handle-width: 18px;
    --mobile-sidebar-width: min(74vw, 280px);
    --mobile-sidebar-handle-width: 18px;
    --code-font-family: 'Monaspace Argon', 'SFMono-Regular', 'Consolas', 'Monaco', 'Courier New', monospace;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Dark theme (default) */
body.dark-theme {
    background-color: #1e1e1e;
    color: #d4d4d4;
}

body.dark-theme header {
    background-color: #2d2d30;
    border-bottom: 1px solid #3e3e42;
}

body.dark-theme footer {
    background-color: #2d2d30;
    border-top: 1px solid #3e3e42;
    color: #858585;
}

body.dark-theme button {
    background-color: #0e639c;
    color: #ffffff;
    border: 1px solid #0e639c;
}

body.dark-theme button:hover {
    background-color: #1177bb;
}

body.dark-theme a {
    color: #4daafc;
}

/* Light theme */
body.light-theme {
    background-color: #ffffff;
    color: #000000;
}

body.light-theme header {
    background-color: #f3f3f3;
    border-bottom: 1px solid #d4d4d4;
}

body.light-theme footer {
    background-color: #f3f3f3;
    border-top: 1px solid #d4d4d4;
    color: #616161;
}

body.light-theme button {
    background-color: #007acc;
    color: #ffffff;
    border: 1px solid #007acc;
}

body.light-theme button:hover {
    background-color: #005a9e;
}

body.light-theme a {
    color: #0066cc;
}

/* Header */
header {
    min-height: var(--header-height);
    padding: 10px 20px;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    flex-shrink: 0;
    flex-wrap: nowrap;
    gap: 8px;
}

.header-icon-wrap {
    grid-column: 1;
    justify-self: start;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

#headerIcon {
    width: 90px;
    height: 60px;
    object-fit: contain;
}

header h1 {
    grid-column: 2;
    font-size: 24px;
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-actions {
    grid-column: 3;
    justify-self: end;
    display: flex;
    align-items: center;
    gap: 6px;
}

.header-action-btn {
    min-height: 30px;
    padding: 6px 10px;
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.header-btn-icon {
    font-size: 13px;
    line-height: 1;
}

#themeToggle {
    background: transparent !important;
    border: none !important;
    color: inherit;
    padding: 0;
    min-height: 0;
    font-size: 22px;
    line-height: 1;
}

#themeToggle:hover {
    background: transparent !important;
    opacity: 0.8;
}

.controls {
    display: flex;
    gap: 10px;
    align-items: stretch;
    flex-wrap: nowrap;
    flex-direction: column;
}

#options-panel {
    position: fixed;
    top: calc(var(--header-height) + var(--panel-tabbar-offset));
    right: 0;
    bottom: var(--footer-height);
    width: var(--options-panel-width);
    transform: translateX(calc(var(--options-panel-width) - var(--options-panel-handle-width)));
    transition: transform 0.2s ease;
    z-index: 40;
    display: flex;
    flex-direction: column;
    border-left: 1px solid transparent;
    box-shadow: -4px 0 18px rgba(0, 0, 0, 0.18);
    overflow-y: auto;
    overflow-x: visible;
}

body.options-panel-open #options-panel {
    transform: translateX(0);
}

body.light-theme #options-panel {
    background-color: #f3f3f3;
    border: 1px solid #d4d4d4;
    border-right: none;
    border-radius: 6px 0 0 6px;
}

body.dark-theme #options-panel {
    background-color: #252526;
    border: 1px solid #3e3e42;
    border-right: none;
    border-radius: 6px 0 0 6px;
}

#options-panel-handle {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--options-panel-handle-width);
    cursor: ew-resize;
    background: rgba(0, 122, 204, 0.2);
    border-radius: 4px 0 0 4px;
}

#sidebar-resize-handle::after,
#options-panel-handle::after {
    position: absolute;
    left: 2px;
    top: 50%;
    transform: translateY(-50%) rotate(180deg);
    writing-mode: vertical-rl;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.08em;
    opacity: 0.95;
}

#sidebar-resize-handle::after {
    content: 'FILES';
}

#options-panel-handle::after {
    content: 'OPTIONS';
}

body.options-panel-open #options-panel-handle {
    background: rgba(0, 122, 204, 0.4);
}

.options-header {
    margin-left: var(--options-panel-handle-width);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    border-bottom: 1px solid rgba(127, 127, 127, 0.25);
    flex-shrink: 0;
}

.options-header h2 {
    font-size: inherit;
    font-weight: inherit;
    letter-spacing: inherit;
    text-transform: inherit;
    margin: 0;
}

body.dark-theme .options-header,
body.dark-theme .file-tree__header { color: #bbb; }

body.light-theme .options-header,
body.light-theme .file-tree__header { color: #555; }

#options-panel .controls {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    margin-left: var(--options-panel-handle-width);
    padding: 10px 12px 14px;
    gap: 8px;
    overflow: visible;
}

#options-panel .board-selector,
#options-panel .typecheck-selector,
#options-panel .typeshed-toggle,
#options-panel .python-version-selector,
#options-panel .verbose-toggle,
#options-panel .generated-config-viewer,
#options-panel .sample-selector {
    flex: 1 1 100%;
    display: grid;
    grid-template-columns: 60px 1fr;
    align-items: center;
    gap: 8px;
}

#options-panel .sample-selector {
    grid-template-columns: 1fr auto;
}

#options-panel .board-selector label,
#options-panel .typecheck-selector label,
#options-panel .typeshed-toggle label,
#options-panel .python-version-selector label,
#options-panel .verbose-toggle label,
#options-panel .generated-config-viewer label {
    text-align: right;
}

#options-panel .extra-stubs-section {
    flex: 1 1 100%;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
}

#options-panel .extra-stubs-section > label {
    font-size: 13px;
    font-weight: 500;
    text-align: left;
}

#options-panel .extra-stubs-controls {
    display: grid;
    gap: 6px;
}

#options-panel .extra-stubs-controls input {
    width: 100%;
    padding: 4px 8px;
    font-size: 12px;
    border-radius: 4px;
}

body.dark-theme #options-panel .extra-stubs-controls input {
    background-color: #3c3c3c;
    color: #d4d4d4;
    border: 1px solid #3e3e42;
}

body.light-theme #options-panel .extra-stubs-controls input {
    background-color: #ffffff;
    color: #000000;
    border: 1px solid #d4d4d4;
}

#options-panel .extra-stubs-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

#options-panel .extra-stubs-buttons button {
    min-width: 0;
    padding: 6px 8px;
    font-size: 12px;
}

#options-panel .extra-stubs-status {
    min-height: 16px;
    font-size: 11px;
    line-height: 1.3;
    word-break: break-word;
}

body.dark-theme #options-panel .extra-stubs-status {
    color: #b6b6b6;
}

body.light-theme #options-panel .extra-stubs-status {
    color: #555;
}

#options-panel .extra-stubs-status[data-state='error'] {
    color: #d14343;
}

#options-panel .extra-stubs-status[data-state='success'] {
    color: #0b8f7a;
}

#options-panel .sample-selector select,
#options-panel .board-selector select,
#options-panel .typecheck-selector select,
#options-panel .python-version-selector select {
    width: 100%;
    max-width: none;
}

#options-panel .generated-config-viewer button {
    width: 100%;
    min-width: 0;
    min-height: 0;
    padding: 4px 8px;
    font-size: 13px;
    font-weight: 500;
    text-align: left;
}

body.dark-theme #options-panel .generated-config-viewer button {
    background-color: #3c3c3c;
    color: #d4d4d4;
    border: 1px solid #3e3e42;
}

body.dark-theme #options-panel .generated-config-viewer button:hover {
    background-color: #4a4a4a;
}

body.light-theme #options-panel .generated-config-viewer button {
    background-color: #ffffff;
    color: #000000;
    border: 1px solid #d4d4d4;
}

body.light-theme #options-panel .generated-config-viewer button:hover {
    background-color: #f3f3f3;
}

#options-panel .generated-config-viewer button:focus {
    outline: 2px solid #007acc;
    outline-offset: 2px;
}

#options-panel .toggle-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

#options-panel .toggle-row input[type="checkbox"] {
    margin: 0;
}

#options-panel .typeshed-switch-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

#options-panel .switch-side-label {
    font-size: 12px;
    font-weight: 600;
}

#options-panel .switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

#options-panel .switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

#options-panel .switch-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background-color: #8a8a8a;
    transition: background-color 0.2s ease;
    border-radius: 999px;
}

#options-panel .switch-slider::before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    top: 3px;
    background-color: #fff;
    transition: transform 0.2s ease;
    border-radius: 50%;
    transform: translateX(20px);
}

#options-panel .switch input:checked + .switch-slider {
    background-color: #0d9488;
}

#options-panel .switch input:checked + .switch-slider::before {
    transform: translateX(0);
}

#options-panel .switch input:focus-visible + .switch-slider {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

#options-panel .share-wrapper {
    display: inline-block;
    flex: 0 0 auto;
}

#options-panel #helpBtn {
    flex: 0 0 auto;
}

#options-panel .share-wrapper #shareBtn,
#options-panel #helpBtn,
#options-panel #loadSampleBtn,
#options-panel .report-issue-wrapper #reportIssueBtn {
    min-width: 96px;
}

#options-panel #helpBtn {
    align-self: flex-start;
    width: auto;
}

.sample-selector {
    display: flex;
    gap: 4px;
    align-items: center;
    min-width: 0;
}

.sample-selector select {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.board-selector {
    display: flex;
    gap: 4px;
    align-items: center;
}

.board-selector label,
.typecheck-selector label,
.typeshed-toggle label,
.python-version-selector label,
.verbose-toggle label,
.generated-config-viewer label {
    font-size: 13px;
    font-weight: 500;
}

.typecheck-selector {
    display: flex;
    gap: 4px;
    align-items: center;
}

.typeshed-toggle,
.python-version-selector,
.verbose-toggle {
    display: flex;
    gap: 4px;
    align-items: center;
}

.loading-indicator {
    font-size: 14px;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

select {
    padding: 4px 8px;
    font-size: 13px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
    min-width: auto;
}

body.dark-theme select {
    background-color: #3c3c3c;
    color: #d4d4d4;
    border: 1px solid #3e3e42;
}

body.dark-theme select:hover {
    background-color: #4a4a4a;
}

body.light-theme select {
    background-color: #ffffff;
    color: #000000;
    border: 1px solid #d4d4d4;
}

body.light-theme select:hover {
    background-color: #f3f3f3;
}

select:focus {
    outline: 2px solid #007acc;
    outline-offset: 2px;
}

button {
    padding: 8px 16px;
    font-size: 14px;
    cursor: pointer;
    border-radius: 4px;
    transition: background-color 0.2s ease;
    font-weight: 500;
    min-height: 34px;
    line-height: 1;
}

button:active {
    transform: translateY(1px);
}

button:focus {
    outline: 2px solid #007acc;
    outline-offset: 2px;
}

/* Main content area */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0 30px 20px 30px;
}

/* Workspace: sidebar + editor side-by-side */
#workspace {
    flex: 1;
    display: flex;
    flex-direction: row;
    overflow: hidden;
    gap: 0;
}

/* File tree sidebar */
#file-tree-panel {
    width: 220px;
    min-width: 100px;
    max-width: 600px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 4px 0 0 4px;
    border-right: none;
}

body.dark-theme #file-tree-panel {
    background-color: #252526;
    border: 1px solid #3e3e42;
}

body.light-theme #file-tree-panel {
    background-color: #f3f3f3;
    border: 1px solid #d4d4d4;
}

/* Resize handle */
#sidebar-resize-handle {
    width: 4px;
    cursor: col-resize;
    flex-shrink: 0;
    background: transparent;
    transition: background 0.15s;
}

#sidebar-resize-handle:hover,
#sidebar-resize-handle.dragging {
    background: #007acc;
}

/* Editor column */
#editor-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

#editor-container {
    flex: 1;
    border-radius: 0 4px 4px 0;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* Per-tab editor panes — only the active one is shown. */
.editor-pane {
    display: none;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}
.editor-pane--active {
    display: flex;
    flex-direction: column;
}
.editor-pane > .cm-editor {
    flex: 1;
    min-height: 0;
}

/* Tab bar */
.tab-bar {
    display: flex;
    flex-direction: row;
    overflow-x: auto;
    flex-shrink: 0;
    scrollbar-width: thin;
}

body.dark-theme .tab-bar {
    background-color: #2d2d2d;
    border-bottom: 1px solid #3e3e42;
}

body.light-theme .tab-bar {
    background-color: #ececec;
    border-bottom: 1px solid #d4d4d4;
}

.tab-bar__tab {
    display: flex;
    align-items: center;
    padding: 4px 8px;
    cursor: pointer;
    white-space: nowrap;
    font-size: 13px;
    gap: 4px;
    border-right: 1px solid transparent;
}

body.dark-theme .tab-bar__tab {
    color: #9d9d9d;
    border-right-color: #3e3e42;
}

body.light-theme .tab-bar__tab {
    color: #444;
    border-right-color: #d4d4d4;
}

.tab-bar__tab--active {
    border-top: 2px solid #007acc;
}

body.dark-theme .tab-bar__tab--active {
    background-color: #1e1e1e;
    color: #d4d4d4;
}

body.light-theme .tab-bar__tab--active {
    background-color: #ffffff;
    color: #000;
}

.tab-bar__label {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tab-bar__close {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    padding: 0 2px;
    font-size: 14px;
    line-height: 1;
    opacity: 0.5;
    border-radius: 2px;
}

.tab-bar__close:hover { opacity: 1; background: rgba(128,128,128,0.2); }

.tab-bar__tab--placeholder {
    cursor: default;
    opacity: 0.8;
}

/* File tree component */
.file-tree {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    user-select: none;
}

.file-tree__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    flex-shrink: 0;
    border-bottom: 1px solid rgba(127, 127, 127, 0.25);
}

.file-tree__title { flex: 1; }

.file-tree__list {
    flex: 1;
    overflow-y: auto;
    list-style: none;
    padding: 0;
    margin: 0;
    font-size: 13px;
}

.file-tree__list ul {
    list-style: none;
    padding: 0;
    margin: 0;
    padding-left: 28px;
}

.file-tree__row {
    display: flex;
    align-items: center;
    padding: 2px 6px;
    cursor: pointer;
    border-radius: 3px;
    gap: 4px;
}

body.dark-theme .file-tree__row:hover { background: #2a2d2e; }
body.light-theme .file-tree__row:hover { background: #e5ebf0; }

.file-tree__file--active .file-tree__row {
    font-weight: 600;
}

body.dark-theme .file-tree__file--active .file-tree__row { background: #37373d; color: #d4d4d4; }
body.light-theme .file-tree__file--active .file-tree__row { background: #cce5ff; color: #000; }

.file-tree__arrow,
.file-tree__icon {
    font-size: 12px;
    width: 14px;
    flex-shrink: 0;
    color: #888;
    line-height: 1;
    text-align: center;
}

.file-tree__icon-img {
    display: block;
    width: 14px;
    height: 14px;
}

.file-tree__name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-tree__actions {
    display: none;
    gap: 2px;
    align-items: center;
}

.file-tree__row:hover .file-tree__actions,
.file-tree__row:focus .file-tree__actions {
    display: flex;
}

.file-tree__icon-btn {
    background: none;
    border: none;
    padding: 1px 4px;
    font-size: 12px;
    cursor: pointer;
    border-radius: 2px;
    line-height: 1;
    color: inherit;
    opacity: 0.7;
}

.file-tree__icon-btn:hover { opacity: 1; background: rgba(128,128,128,0.2); }
.file-tree__icon-btn--danger:hover { color: #f44; }

/* Inline input for new-file / rename */
.file-tree__inline-input {
    display: block;
    width: calc(100% - 8px);
    margin: 2px 4px;
    padding: 2px 4px;
    font-size: 12px;
    font-family: inherit;
    border: 1px solid #888;
    border-radius: 3px;
    background: var(--bg-color-edit, #fff);
    color: inherit;
    outline: none;
}
.file-tree__inline-input:focus { border-color: #4fc3f7; }

/* Inline confirm for delete */
.file-tree__inline-confirm {
    display: flex;
    align-items: center;
    gap: 4px;
    margin: 2px 4px;
    font-size: 12px;
}

/* Clear All footer button */
.file-tree__footer {
    flex-shrink: 0;
    padding: 4px 8px;
    border-top: 1px solid rgba(128, 128, 128, 0.2);
}

.file-tree__footer-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-bottom: 6px;
}

.file-tree__footer-btn {
    background: none;
    border: 1px solid rgba(128, 128, 128, 0.3);
    padding: 2px 6px;
    font-size: 11px;
    cursor: pointer;
    border-radius: 3px;
    color: inherit;
    opacity: 0.7;
    min-height: 0;
    width: 100%;
    text-align: center;
}

.file-tree__footer-btn.import-label {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 500;
    line-height: 1.2;
    padding: 2px 6px;
    min-height: 0;
}

.file-tree__footer-btn:hover {
    opacity: 1;
}

.file-tree__clear-all-btn {
    background: none;
    border: 1px solid rgba(128, 128, 128, 0.3);
    padding: 2px 6px;
    font-size: 11px;
    cursor: pointer;
    border-radius: 3px;
    color: inherit;
    opacity: 0.55;
    width: 100%;
    text-align: center;
}

.file-tree__clear-all-btn:hover {
    opacity: 1;
    border-color: #f44;
    color: #f44;
}

/* Import label styled like a button */
.import-label {
    padding: 8px 16px;
    font-size: 14px;
    cursor: pointer;
    border-radius: 4px;
    transition: background-color 0.2s ease;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    line-height: 1;
}

body.dark-theme .import-label {
    background-color: #3c3c3c;
    color: #d4d4d4;
    border: 1px solid #3e3e42;
}

body.light-theme .import-label {
    background-color: #007acc;
    color: #ffffff;
    border: 1px solid #007acc;
}

.import-label:hover { opacity: 0.85; }

/* Footer action style override for moved Import control */
.file-tree__footer .import-label.file-tree__footer-btn,
body.dark-theme .file-tree__footer .import-label.file-tree__footer-btn,
body.light-theme .file-tree__footer .import-label.file-tree__footer-btn {
    background: none;
    color: inherit;
    border: 1px solid rgba(128, 128, 128, 0.3);
}

.file-tree__footer .import-label.file-tree__footer-btn:hover {
    opacity: 1;
}

/* CodeMirror specific overrides */
.cm-editor {
    height: 100%;
    font-family: var(--code-font-family);
    font-weight: 200;
    font-variation-settings: "TXTH" 1;
}

.cm-scroller,
.cm-gutters {
    overflow: auto;
    font-family: var(--code-font-family);
    font-weight: 400;
    font-variation-settings: "TXTH" 1;
}

.cm-line {
    padding: 0 4px;
}

/* Diagnostics status bar */
#diagnostics-status {
    padding: 4px 12px;
    font-size: 12px;
    font-family: var(--code-font-family);
    font-weight: 400;
    font-variation-settings: "TXTH" 1;
    flex-shrink: 0;
    opacity: 0.8;
}

#diagnostics-status .status-main,
#diagnostics-status .status-meta-sep,
#diagnostics-status .status-meta {
    display: inline;
}

#diagnostics-status .count-error { color: #f44; }
#diagnostics-status .count-warning { color: #b8860b; }
#diagnostics-status .count-info { color: #4af; }

@media (max-width: 700px) {
    #diagnostics-status .status-main,
    #diagnostics-status .status-meta {
        display: block;
    }

    #diagnostics-status .status-meta-sep {
        display: none;
    }

    #diagnostics-status .status-meta {
        margin-top: 2px;
    }
}

/* Footer */
footer {
    min-height: var(--footer-height);
    padding: 10px 30px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    flex-shrink: 0;
}

.footer-links {
    text-align: center;
}

footer a {
    text-decoration: none;
    margin-left: 5px;
}

.github-stars {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

footer a:hover {
    text-decoration: underline;
}

/* Keyboard shortcuts help panel */
#keyboard-help {
    font-size: 12px;
    padding: 8px 16px;
    border-bottom: 1px solid #d4d4d4;
    overflow-y: auto;
    max-height: 200px;
}

#keyboard-help table {
    width: 100%;
    border-collapse: collapse;
}

#keyboard-help th {
    text-align: left;
    padding: 2px 8px;
    font-weight: 600;
    border-bottom: 1px solid #d4d4d4;
}

#keyboard-help td {
    padding: 2px 8px;
}

#keyboard-help kbd {
    display: inline-block;
    padding: 1px 5px;
    font-family: var(--code-font-family);
    font-size: 11px;
    border-radius: 3px;
    border: 1px solid #999;
    background: #f7f7f7;
    color: #333;
    box-shadow: 0 1px 0 #bbb;
}

body.dark-theme #keyboard-help {
    border-bottom-color: #3e3e42;
}

body.dark-theme #keyboard-help th {
    border-bottom-color: #3e3e42;
}

body.dark-theme #keyboard-help kbd {
    background: #3c3c3c;
    color: #d4d4d4;
    border-color: #555;
    box-shadow: 0 1px 0 #222;
}

/* Lint panel (F8 / Shift-F8 diagnostic navigation) */
.cm-panel.cm-panel-lint {
    background-color: #f5f5f5;
    border-top: 1px solid #d4d4d4;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    font-size: 13px;
    max-height: 150px;
    overflow-y: auto;
}

.cm-panel.cm-panel-lint ul {
    padding: 0;
    margin: 0;
}

.cm-panel.cm-panel-lint [name="close"] {
    color: #616161;
}

body.dark-theme .cm-panel.cm-panel-lint {
    background-color: #252526;
    border-top: 1px solid #3e3e42;
    color: #d4d4d4;
}

body.dark-theme .cm-panel.cm-panel-lint [name="close"] {
    color: #858585;
}

/* Lint diagnostic tooltip (shown on gutter marker click) */
.cm-tooltip.cm-tooltip-lint {
    background-color: #ffffff;
    color: #1e1e1e;
    border: 1px solid #cccccc;
    border-radius: 4px;
    padding: 4px 8px;
    max-width: 500px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    font-size: 13px;
    line-height: 1.5;
}

body.dark-theme .cm-tooltip.cm-tooltip-lint {
    background-color: #2d2d2d;
    color: #e0e0e0;
    border: 1px solid #555555;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6);
}

/* LSP Hover Tooltips */
.cm-tooltip.cm-tooltip-hover {
    background-color: #ffffff;
    color: #1e1e1e;
    border: 1px solid #aaaaaa;
    border-radius: 4px;
    padding: 0;
    max-width: 700px;
    /* Constrain total height so the box never overflows the viewport,
       whether the tooltip is placed below (default) or above the cursor.
       The inner .cm-lsp-hover uses max-height:100% to fill this budget. */
    max-height: min(440px, 50vh);
    overflow: hidden;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    font-size: 13px;
    line-height: 1.5;
    z-index: 1000;
    /* Flex column so the fixed-height signature stays at the top and the
       scrollable body fills the remaining space */
    display: flex;
    flex-direction: column;
}

body.dark-theme .cm-tooltip.cm-tooltip-hover {
    background-color: #1e1e2e;
    color: #cdd6f4;
    border: 1px solid #585b70;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.55);
}

/* Python signature / declaration line (first line of Pyright hover) */
.cm-hover-signature {
    font-family: var(--code-font-family);
    font-weight: 400;
    font-variation-settings: "TXTH" 1;
    font-size: 11px;
    background-color: #eef0f3;
    color: #1e1e1e;
    padding: 4px 10px;
    border-radius: 3px 3px 0 0;  /* top corners only — sits flush above the body */
    border-left: 3px solid #0550ae;
    overflow-x: auto;
    /* Don't shrink when body content is tall */
    flex: 0 0 auto;
}

body.dark-theme .cm-hover-signature {
    background-color: #11111b;
    color: #cdd6f4;
    border-left-color: #89b4fa;
}

/* code inside signature inherits — no pill styling */
.cm-hover-signature code {
    display: block;
    background: none;
    color: inherit;
    padding: 0;
    border: none;
    font-size: inherit;
    font-family: inherit;
    line-height: 1.45;
    white-space: pre;
    text-decoration: none;
    box-shadow: none;
}

/* Resizable hover content area — fills the height budget set on the outer
   .cm-tooltip.cm-tooltip-hover so the box never overflows the viewport. */
.cm-lsp-hover {
    padding: 8px 12px;
    min-width: 220px;
    max-width: 700px;
    min-height: 40px;
    /* Fill whatever height the outer tooltip allows (min/50vh cap above) */
    flex: 1 1 auto;
    overflow: auto;
    resize: both;
    box-sizing: border-box;
}

/* Headers inside hover popup */
.cm-lsp-hover h1,
.cm-lsp-hover h2,
.cm-lsp-hover h3,
.cm-lsp-hover h4 {
    margin: 8px 0 4px;
    font-size: 13px;
    font-weight: 700;
    border-bottom: 1px solid #dddddd;
    padding-bottom: 2px;
    color: #0f0f0f;
}

body.dark-theme .cm-lsp-hover h1,
body.dark-theme .cm-lsp-hover h2,
body.dark-theme .cm-lsp-hover h3,
body.dark-theme .cm-lsp-hover h4 {
    color: #cdd6f4;
    border-bottom-color: #45475a;
}

.cm-lsp-hover strong {
    color: #0550ae;
    font-weight: 700;
}

body.dark-theme .cm-lsp-hover strong {
    color: #89b4fa;
}

.cm-lsp-hover em {
    font-style: italic;
    color: #444;
}

body.dark-theme .cm-lsp-hover em {
    color: #a6adc8;
}

.cm-lsp-hover hr {
    border: none;
    border-top: 1px solid #dddddd;
    margin: 6px 0;
}

body.dark-theme .cm-lsp-hover hr {
    border-top-color: #45475a;
}

.cm-lsp-hover pre {
    background-color: #f0f0f0;
    color: #1e1e1e;
    padding: 8px 10px;
    border-radius: 4px;
    overflow-x: auto;
    margin: 6px 0;
    font-family: var(--code-font-family);
    font-weight: 400;
    font-variation-settings: "TXTH" 1;
    font-size: 11px;
    border: 1px solid #d0d0d0;
    white-space: pre;
}

body.dark-theme .cm-lsp-hover pre {
    background-color: #11111b;
    color: #cdd6f4;
    border: 1px solid #313244;
}

.cm-lsp-hover code {
    font-family: var(--code-font-family);
    font-weight: 400;
    font-variation-settings: "TXTH" 1;
    font-size: 11px;
    background-color: #eef0f3;
    color: #0550ae;
    padding: 1px 4px;
    border-radius: 3px;
    border: 1px solid #d0d7de;
}

body.dark-theme .cm-lsp-hover code {
    background-color: #181825;
    color: #89b4fa;
    border-color: #313244;
}

/* RST role references (e.g. :func:`name`) */
.cm-lsp-hover .cm-hover-rst-ref {
    color: #6f42c1;
    background-color: #f0eafb;
    border-color: #d8c4f0;
}

body.dark-theme .cm-lsp-hover .cm-hover-rst-ref {
    color: #cba6f7;
    background-color: #1e1e2e;
    border-color: #45475a;
}

/* Inline code inside pre shouldn't get the inline-code pill style */
.cm-lsp-hover pre code {
    background: none;
    color: inherit;
    padding: 0;
    border: none;
    font-size: inherit;
}

.cm-lsp-hover p {
    margin: 5px 0;
}

.cm-lsp-hover ul,
.cm-lsp-hover ol {
    margin: 4px 0 4px 18px;
    padding: 0;
}

.cm-lsp-hover li {
    margin: 2px 0;
}

/* RST field list (:param:, :returns:, etc.) */
.cm-hover-fields {
    margin: 6px 0;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 2px 8px;
    align-items: baseline;
}

.cm-hover-field-name {
    font-family: var(--code-font-family);
    font-weight: 400;
    font-variation-settings: "TXTH" 1;
    font-size: 10px;
    background-color: #e8f0fe;
    color: #0550ae;
    padding: 1px 5px;
    border-radius: 3px;
    border: 1px solid #c4d4f8;
    white-space: nowrap;
}

body.dark-theme .cm-hover-field-name {
    background-color: #1e2030;
    color: #89b4fa;
    border-color: #313244;
}

.cm-hover-fields dd {
    margin: 0;
    color: #333;
}

body.dark-theme .cm-hover-fields dd {
    color: #bac2de;
}

.cm-hover-admonition {
    margin: 8px 0;
    border: 1px solid #d9c77a;
    border-left: 4px solid #a16207;
    border-radius: 6px;
    background: linear-gradient(180deg, #fffbea 0%, #fffdf5 100%);
    overflow: hidden;
}

body.dark-theme .cm-hover-admonition {
    border-color: #5b4a1a;
    border-left-color: #eab308;
    background: linear-gradient(180deg, #221b0b 0%, #181412 100%);
}

.cm-hover-admonition-title {
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 700;
    color: #7c4a03;
    background-color: rgba(245, 158, 11, 0.14);
    border-bottom: 1px solid rgba(161, 98, 7, 0.18);
}

body.dark-theme .cm-hover-admonition-title {
    color: #fcd34d;
    background-color: rgba(234, 179, 8, 0.12);
    border-bottom-color: rgba(234, 179, 8, 0.18);
}

.cm-hover-admonition-body {
    padding: 6px 10px;
}

.cm-hover-admonition-body > :first-child {
    margin-top: 0;
}

.cm-hover-admonition-body > :last-child {
    margin-bottom: 0;
}

.cm-hover-admonition-attention {
    border-left-color: #b45309;
}

body.dark-theme .cm-hover-admonition-attention {
    border-left-color: #f59e0b;
}

.cm-lsp-hover a {
    color: #0550ae;
    text-decoration: underline;
    text-underline-offset: 2px;
}

body.dark-theme .cm-lsp-hover a {
    color: #89b4fa;
}

.cm-lsp-hover a:hover {
    color: #0366d6;
    text-decoration: underline;
}

body.dark-theme .cm-lsp-hover a:hover {
    color: #b4d0ff;
}

/* RST grid table inside hover tooltip */
.cm-hover-table {
    border-collapse: collapse;
    font-size: 11px;
    margin: 6px 0;
    min-width: 100%;
}

.cm-hover-table th,
.cm-hover-table td {
    border: 1px solid #d0d7de;
    padding: 3px 8px;
    text-align: left;
    white-space: nowrap;
}

.cm-hover-table thead th {
    background-color: #eef0f3;
    font-weight: 600;
    color: #0550ae;
}

.cm-hover-table tbody tr:nth-child(even) td {
    background-color: #f6f8fa;
}

body.dark-theme .cm-hover-table th,
body.dark-theme .cm-hover-table td {
    border-color: #313244;
}

body.dark-theme .cm-hover-table thead th {
    background-color: #181825;
    color: #89b4fa;
}

body.dark-theme .cm-hover-table tbody tr:nth-child(even) td {
    background-color: #13131e;
}

/* RST substitution references e.g. |see_cpython_module| */
.cm-hover-cpython-ref {
    font-size: 10px;
    font-weight: 600;
    color: #0550ae;
    background-color: #e8f0fe;
    padding: 1px 5px;
    border-radius: 3px;
    border: 1px solid #c4d4f8;
}

body.dark-theme .cm-hover-cpython-ref {
    color: #89b4fa;
    background-color: #1e2030;
    border-color: #313244;
}

/* Scrollbar styling for hover tooltips */
.cm-lsp-hover::-webkit-scrollbar {
    width: 7px;
    height: 7px;
}

.cm-lsp-hover::-webkit-scrollbar-track {
    background: transparent;
}

.cm-lsp-hover::-webkit-scrollbar-thumb {
    background: rgba(128, 128, 128, 0.4);
    border-radius: 4px;
}

.cm-lsp-hover::-webkit-scrollbar-thumb:hover {
    background: rgba(128, 128, 128, 0.65);
}

/* Responsive design */
@media (max-width: 768px) {
    :root {
        --header-height: 92px;
        --options-panel-width: min(94vw, 360px);
    }

    header {
        min-height: var(--header-height);
        gap: 8px;
        padding: 8px 12px;
        align-items: center;
    }

    header h1 {
        font-size: 22px;
        text-align: center;
    }

    .header-action-btn {
        min-height: 28px;
        padding: 5px 8px;
        font-size: 12px;
    }

    /* .header-icon-wrap {
        width: 60px;
        height: 60px;
        border-radius: 14px;
    } */

    #options-panel .sample-selector {
        grid-template-columns: 1fr auto;
    }

    main {
        padding: 0 10px 10px 10px;
    }

    footer {
        padding: 10px 15px;
        font-size: 12px;
    }

    button {
        font-size: 13px;
        padding: 6px 12px;
    }
}

@media (max-width: 480px) {
    header h1 {
        font-size: 18px;
    }

    button {
        width: auto;
    }
}

@media (max-width: 900px) {
    main {
        padding: 0;
    }

    body:not(.mobile-sidebar-open) #editor-column {
        margin-left: var(--mobile-sidebar-handle-width);
    }

    body:not(.mobile-sidebar-open) #diagnostics-status {
        padding-left: calc(12px + var(--mobile-sidebar-handle-width) + 6px);
    }
}

@media (max-width: 900px) and (orientation: portrait) {
    :root {
        --header-height: 90px;
        --footer-height: 0px;
        --panel-tabbar-offset: 40px;
        --options-panel-width: min(92vw, 360px);
    }

    #helpBtn,
    footer {
        display: none;
    }

    #workspace {
        position: relative;
    }

    main {
        padding-bottom: 0;
    }

    #editor-column {
        margin-left: 0;
        margin-right: var(--options-panel-handle-width);
    }

    #file-tree-panel {
        position: absolute;
        left: 0;
        top: var(--panel-tabbar-offset);
        bottom: 0;
        width: var(--mobile-sidebar-width);
        min-width: var(--mobile-sidebar-width);
        max-width: var(--mobile-sidebar-width);
        border-radius: 0 6px 6px 0;
        transform: translateX(calc(-1 * var(--mobile-sidebar-width)));
        transition: transform 0.2s ease;
        z-index: 60;
        box-shadow: 2px 0 16px rgba(0, 0, 0, 0.2);
    }

    body.mobile-sidebar-open #file-tree-panel {
        transform: translateX(0);
    }

    #sidebar-resize-handle {
        position: absolute;
        left: 0;
        top: var(--panel-tabbar-offset);
        bottom: 0;
        width: var(--mobile-sidebar-handle-width);
        background: rgba(0, 122, 204, 0.88);
        border-radius: 0 4px 4px 0;
        cursor: ew-resize;
        z-index: 61;
    }

    body.mobile-sidebar-open #sidebar-resize-handle {
        left: calc(var(--mobile-sidebar-width) - var(--mobile-sidebar-handle-width));
        background: rgba(0, 122, 204, 1);
    }

    body.mobile-sidebar-open #editor-column {
        margin-left: 0;
    }

    #editor-container {
        border-radius: 4px;
    }

    #options-panel {
        top: calc(var(--header-height) + var(--panel-tabbar-offset));
        bottom: 10px;
    }
}

@media (max-width: 900px) and (orientation: landscape) {
    :root {
        --panel-tabbar-offset: 40px;
        --mobile-sidebar-width: min(56vw, 340px);
    }

    #workspace {
        position: relative;
    }

    main {
        padding-bottom: 0;
    }

    #editor-column {
        margin-left: 0;
        transition: margin-left 0.2s ease;
    }

    #file-tree-panel {
        position: absolute;
        left: 0;
        top: var(--panel-tabbar-offset);
        bottom: 0;
        width: var(--mobile-sidebar-width);
        min-width: var(--mobile-sidebar-width);
        max-width: var(--mobile-sidebar-width);
        border-radius: 0 6px 6px 0;
        transform: translateX(calc(-1 * var(--mobile-sidebar-width)));
        transition: transform 0.2s ease;
        z-index: 60;
        box-shadow: 2px 0 16px rgba(0, 0, 0, 0.2);
    }

    body.mobile-sidebar-open #file-tree-panel {
        transform: translateX(0);
    }

    #sidebar-resize-handle {
        position: absolute;
        left: 0;
        top: var(--panel-tabbar-offset);
        bottom: 0;
        width: var(--mobile-sidebar-handle-width);
        background: rgba(0, 122, 204, 0.88);
        border-radius: 0 4px 4px 0;
        cursor: ew-resize;
        z-index: 61;
    }

    body.mobile-sidebar-open #sidebar-resize-handle {
        left: calc(var(--mobile-sidebar-width) - var(--mobile-sidebar-handle-width));
        background: rgba(0, 122, 204, 1);
    }

    body.mobile-sidebar-open #editor-column {
        margin-left: var(--mobile-sidebar-width);
    }

    #editor-container {
        border-radius: 4px;
    }
}

/* Loading state (optional) */
.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    font-size: 18px;
}

/* Share dropdown */
.share-wrapper {
    position: relative;
    display: inline-block;
}

.share-dropdown,
.report-issue-dropdown {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1000;
    width: min(90vw, 460px);
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
    flex-direction: column;
    gap: 10px;
}

.share-dropdown[hidden],
.report-issue-dropdown[hidden] {
    display: none;
}

.share-dropdown:not([hidden]),
.report-issue-dropdown:not([hidden]) {
    display: flex;
}

body.light-theme .share-dropdown,
body.light-theme .report-issue-dropdown {
    background-color: #ffffff;
    border: 1px solid #d4d4d4;
}

body.dark-theme .share-dropdown,
body.dark-theme .report-issue-dropdown {
    background-color: #2d2d30;
    border: 1px solid #3e3e42;
}

.share-title {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

.share-desc {
    font-size: 12px;
    opacity: 0.7;
    margin-bottom: 6px;
}

.share-warning,
.report-issue-warning {
    font-size: 12px;
    margin: 0 0 8px 0;
    padding: 8px 10px;
    border-radius: 4px;
    border: 1px solid;
    font-weight: 600;
}

.share-warning {
    line-height: 1.35;
}

.report-issue-warning {
    line-height: 1.4;
}

body.light-theme .share-warning,
body.light-theme .report-issue-warning {
    color: #8a4b00;
    background-color: #fff5e6;
    border-color: #f2c07a;
}

body.dark-theme .share-warning,
body.dark-theme .report-issue-warning {
    color: #ffd9a6;
    background-color: #4b2f00;
    border-color: #9a6400;
}

.share-option {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 10px;
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
    text-align: left;
    transition: background-color 0.15s;
}

body.light-theme .share-option {
    background-color: #f5f5f5;
    color: #333;
    border: 1px solid #e0e0e0;
}

body.light-theme .share-option:hover {
    background-color: #e8e8e8;
}

body.dark-theme .share-option {
    background-color: #3c3c3c;
    color: #d4d4d4;
    border: 1px solid #4a4a4a;
}

body.dark-theme .share-option:hover {
    background-color: #4a4a4a;
}

.share-option .share-icon {
    flex-shrink: 0;
    font-size: 14px;
}

.share-copied {
    color: #22c55e !important;
    font-weight: 600;
}

/* Scope selector row (Current file / All files) */
.share-scope-row {
    display: flex;
    gap: 12px;
    margin-bottom: 8px;
}

.share-scope-option {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    cursor: pointer;
    user-select: none;
}

/* Report Issue dropdown */
.report-issue-wrapper {
    display: inline-block;
    flex: 0 0 auto;
    position: relative;
}

.report-issue-backdrop {
    position: fixed;
    inset: 0;
    z-index: 999;
    background: rgba(0, 0, 0, 0.45);
    pointer-events: auto;
}

.report-issue-backdrop[hidden] {
    display: none;
}

body.dark-theme .report-issue-backdrop {
    background: rgba(0, 0, 0, 0.6);
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Print styles */
@media print {
    header, footer, .controls {
        display: none;
    }

    main {
        padding: 0;
    }

    body {
        height: auto;
    }

    .cm-editor {
        border: none;
        box-shadow: none;
    }
}
