/* CSS Variables & Reset */
:root {
    --bg-color: #ffffff;
    --text-color: #1e1e1e;
    --header-bg: #f3f3f3;
    --header-border: #e0e0e0;
    --header-text: #333333;
    --editor-bg: #ffffff;
    --editor-text: #24292f;
    --accent-color: #007acc;
    --selection-bg: #b3d4fc;
    --footer-bg: #f3f3f3;
    --footer-text: #666666;
    --menu-hover-bg: #e8e8e8;
    --dropdown-bg: #ffffff;
    --dropdown-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    --dropdown-border: #d0d0d0;

    --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Dark theme - applied via data attribute or OS preference */
[data-theme="dark"] {
    --bg-color: #1e1e1e;
    --text-color: #d4d4d4;
    --header-bg: #2d2d2d;
    --header-border: #3e3e3e;
    --header-text: #cccccc;
    --editor-bg: #1e1e1e;
    --editor-text: #d4d4d4;
    --accent-color: #4daafc;
    --selection-bg: #264f78;
    --footer-bg: #252526;
    --footer-text: #888888;
    --menu-hover-bg: #3e3e3e;
    --dropdown-bg: #252526;
    --dropdown-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    --dropdown-border: #454545;
}

/* OS preference fallback when no manual theme is set */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) {
        --bg-color: #1e1e1e;
        --text-color: #d4d4d4;
        --header-bg: #2d2d2d;
        --header-border: #3e3e3e;
        --header-text: #cccccc;
        --editor-bg: #1e1e1e;
        --editor-text: #d4d4d4;
        --accent-color: #4daafc;
        --selection-bg: #264f78;
        --footer-bg: #252526;
        --footer-text: #888888;
        --menu-hover-bg: #3e3e3e;
        --dropdown-bg: #252526;
        --dropdown-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
        --dropdown-border: #454545;
    }
}

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

body,
html {
    height: 100%;
    width: 100%;
    font-family: var(--font-ui);
    background-color: var(--bg-color);
    color: var(--text-color);
    overflow: hidden;
}

/* Layout */
.app-layout {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* App Bar */
.app-bar {
    display: flex;
    align-items: center;
    background-color: var(--header-bg);
    border-bottom: 1px solid var(--header-border);
    height: 48px;
    padding: 0 16px;
    user-select: none;
    flex-shrink: 0;
}

.logo-container {
    display: flex;
    align-items: center;
    margin-right: 24px;
    color: var(--header-text);
}

.app-logo {
    margin-right: 8px;
}

.app-name {
    font-weight: 600;
    font-size: 12px;
}

@media (min-width: 600px) {
    .app-name {
        font-size: 14px;
    }
}

/* Menubar */
.menubar {
    display: flex;
    align-items: center;
}

.menu-item-container {
    position: relative;
}

.menu-btn {
    background: none;
    border: none;
    color: var(--header-text);
    font-size: 14px;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-family: inherit;
}

.menu-btn:hover,
.menu-btn:focus {
    background-color: var(--menu-hover-bg);
    outline: none;
}

.menu-btn[aria-expanded="true"] {
    background-color: var(--menu-hover-bg);
}

/* Dropdown */
.dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 4px;
    background-color: var(--dropdown-bg);
    border: 1px solid var(--dropdown-border);
    border-radius: 6px;
    box-shadow: var(--dropdown-shadow);
    min-width: 200px;
    z-index: 1000;
    padding: 4px 0;
}

.dropdown-menu.show {
    display: block;
}

.dropdown-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 8px 16px;
    background: none;
    border: none;
    text-align: left;
    color: var(--text-color);
    font-size: 13px;
    cursor: pointer;
    font-family: inherit;
}

.dropdown-item:hover,
.dropdown-item:focus {
    background-color: var(--accent-color);
    color: #ffffff;
    outline: none;
}

.dropdown-item:hover .shortcut-hint,
.dropdown-item:focus .shortcut-hint {
    color: rgba(255, 255, 255, 0.8);
}

.shortcut-hint {
    color: var(--footer-text);
    font-size: 12px;
    margin-left: 16px;
    pointer-events: none;
}

.theme-check {
    color: var(--accent-color);
    font-size: 12px;
    margin-left: 16px;
    visibility: hidden;
}

.theme-check.active {
    visibility: visible;
}

/* Status Indicator in Header */
.status-bar-header {
    margin-left: auto;
    font-size: 12px;
    color: var(--footer-text);
    font-variant-numeric: tabular-nums;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    font-family: inherit;
}

.status-bar-header:hover {
    background-color: var(--menu-hover-bg);
}

/* Editor Area */
.editor-container {
    flex: 1;
    position: relative;
    overflow: hidden;
}

#text-editor {
    width: 100%;
    height: 100%;
    border: none;
    resize: none;
    outline: none;
    background-color: var(--editor-bg);
    color: var(--editor-text);
    font-family: var(--font-mono);
    font-size: 15px;
    padding: 24px;
    line-height: 1.6;
}

#text-editor::selection {
    background-color: var(--selection-bg);
}

/* Footer */
.app-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 28px;
    padding: 0 16px;
    background-color: var(--footer-bg);
    border-top: 1px solid var(--header-border);
    font-size: 11px;
    color: var(--footer-text);
    flex-shrink: 0;
}

.footer-stats {
    font-variant-numeric: tabular-nums;
}

.app-footer a {
    color: var(--accent-color);
    text-decoration: none;
    transition: opacity 0.15s ease;
}

.app-footer a:hover {
    text-decoration: underline;
    opacity: 0.8;
}

/* Rename Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.modal-overlay[hidden] {
    display: none;
}

.modal {
    background-color: var(--dropdown-bg);
    border: 1px solid var(--dropdown-border);
    border-radius: 8px;
    box-shadow: var(--dropdown-shadow);
    width: 90%;
    max-width: 360px;
    padding: 20px;
}

.modal-header {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 16px;
}

.modal-body {
    margin-bottom: 20px;
}

.modal-body label {
    display: block;
    font-size: 12px;
    color: var(--footer-text);
    margin-bottom: 6px;
}

.modal-input {
    width: 100%;
    padding: 10px 12px;
    font-size: 14px;
    font-family: inherit;
    border: 1px solid var(--dropdown-border);
    border-radius: 6px;
    background-color: var(--editor-bg);
    color: var(--text-color);
    -webkit-text-fill-color: var(--text-color);
    outline: none;
}

.modal-input:focus {
    border-color: var(--accent-color);
}

.modal-input::selection {
    background-color: var(--selection-bg);
    color: var(--text-color);
    -webkit-text-fill-color: var(--text-color);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.modal-btn {
    padding: 8px 16px;
    font-size: 13px;
    font-family: inherit;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

.modal-btn-cancel {
    background-color: var(--menu-hover-bg);
    color: var(--text-color);
}

.modal-btn-cancel:hover {
    opacity: 0.8;
}

.modal-btn-save {
    background-color: var(--accent-color);
    color: #ffffff;
}

.modal-btn-save:hover:not(:disabled) {
    opacity: 0.9;
}

.modal-btn-save:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Mobile & Improvements */
@media (max-width: 600px) {
    .app-bar {
        padding: 0 12px;
    }

    #text-editor {
        padding: 16px;
        font-size: 16px;
    }
}

/* ========================================
   PRINT STYLES - Only print text content
   ======================================== */
@media print {

    /* Force hide ALL UI elements */
    header,
    footer,
    nav,
    .app-bar,
    .app-footer,
    .menubar,
    .logo-container,
    .status-bar-header,
    .menu-item-container,
    .dropdown-menu,
    .menu-btn {
        display: none !important;
        visibility: hidden !important;
        height: 0 !important;
        width: 0 !important;
        overflow: hidden !important;
    }

    /* Reset page layout */
    *,
    *::before,
    *::after {
        background: white !important;
        color: black !important;
        box-shadow: none !important;
        text-shadow: none !important;
    }

    html,
    body {
        height: auto !important;
        width: 100% !important;
        overflow: visible !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .app-layout {
        display: block !important;
        height: auto !important;
    }

    .editor-container {
        display: block !important;
        height: auto !important;
        overflow: visible !important;
        position: static !important;
    }

    /* Style textarea for clean print output */
    #text-editor {
        display: block !important;
        width: 100% !important;
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        border: none !important;
        padding: 0 !important;
        margin: 0 !important;
        font-family: "Courier New", Courier, monospace !important;
        font-size: 12pt !important;
        line-height: 1.4 !important;
        white-space: pre-wrap !important;
        word-wrap: break-word !important;
        overflow: visible !important;
        resize: none !important;
    }

    /* Hide scrollbars */
    ::-webkit-scrollbar {
        display: none !important;
    }
}