:root {
    --bg-color: #ffffff;
    --text-color: #333333;
    --primary-color: #2563eb;
    --secondary-color: #e5e7eb;
    --header-bg: #f8fafc;
    --textarea-bg: #ffffff;
    --success-status-bg: rgba(37, 99, 235, 0.5);
    --danger-status-bg:rgba(220, 38, 38, 0.5);
    --modal-overlay: rgba(0, 0, 0, 0.5);
    --modal-bg: #ffffff;
    --button-hover: #f3f4f6;
    --danger-color: #dc2626;
    --danger-hover: #ef4444;
    --code-markdown: rgba(37, 100, 235, 0.2);
    --transition: background-color 0.3s, color 0.3s;
    --input-element-transition: background-color 0.2s ease;
}

[data-theme="dark"] {
    --bg-color: #1a1a1a;
    --text-color: #e5e7eb;
    --primary-color: #60a5fa;
    --secondary-color: #374151;
    --header-bg: #111111;
    --textarea-bg: #242424;
    --success-status-bg: rgba(96, 165, 250, 0.5);
    --danger-status-bg:rgba(220, 38, 38, 0.5);
    --modal-bg: #242424;
    --button-hover: #374151;
    --danger-color: #dc2626;
    --danger-hover: #b91c1c;
    --code-markdown: rgba(96, 165, 250, 0.2);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    transition: var(--transition);
}

.container {
    max-width: 75%;
    margin: 0 auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    transition: var(--transition);
}

header {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem;
    background-color: var(--header-bg);
    border-radius: 12px;
    margin-bottom: 1rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    position: relative;
}

#header-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-color);
}

.header-top {
    display: flex;
    align-items: center;
}

.header-right {
    display: flex;
    justify-content: center;
    align-items: center;
    position: absolute;
    right: 1rem;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    color: var(--text-color);
    border-radius: 8px;
    transition: var(--input-element-transition);
    font-size: 1.5rem;
}

#theme-toggle span {
    font-size: 1.5rem;
    line-height: 1;
    display: block;
}

#theme-toggle:hover {
    background-color: var(--secondary-color);
}

[data-theme="light"] .moon {
    display: block;
}

[data-theme="light"] .sun {
    display: none;
}

[data-theme="dark"] .moon {
    display: none;
}

[data-theme="dark"] .sun {
    display: block;
}

main {
    flex: 1;
}

/* Custom Scrollbars */
/* Webkit browsers */
::-webkit-scrollbar {
    width: 10px;
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: transparent;
    border-radius: 8px;
    border: 2px solid var(--bg-color);
    min-height: 40px;
    transition: background 0.2s;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}
::-webkit-scrollbar-corner {
    background: transparent;
}

/* Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--secondary-color) transparent;
}

/* Scrollbars for specific scrollable containers */
#editor, #preview-pane {
    scrollbar-width: thin;
    scrollbar-color: var(--secondary-color) transparent;
}

#editor, #preview-pane {
    width: 100%;
    height: 100%;
    padding: 1.5rem;
    font-size: 1rem;
    line-height: 1.6;
    border: none;
    outline: none;
    resize: none;
    background-color: transparent;
    color: var(--text-color);
    transition: var(--transition);
    position: relative;
    z-index: 2;
    font-family: monospace;
}

#editor::placeholder {
    color: #9ca3af;
}

.editor-container, .preview-container {
    height: calc(100vh - 9rem);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    position: relative;
    z-index: 1;
    background-color: var(--textarea-bg);
    transition: var(--transition);
}

/* Split view wrapper */
.editor-preview-wrapper {
    display: flex;
    height: calc(100vh - 9rem);
    gap: 0;
    position: relative;
}

/* Split view styles */
.editor-preview-wrapper.split-view .editor-container {
    width: 50%;
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2), 2px 0 4px rgba(0, 0, 0, 0.1);
}

.editor-preview-wrapper.split-view .preview-container {
    width: 50%;
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2), -2px 0 4px rgba(0, 0, 0, 0.1);
}

.editor-preview-wrapper.preview-only .editor-container {
    display: none;
}

.editor-preview-wrapper.preview-only .preview-container {
    width: 100%;
}

.editor-preview-wrapper:not(.split-view):not(.preview-only) .editor-container {
    width: 100%;
}

.editor-preview-wrapper:not(.split-view):not(.preview-only) .preview-container {
    display: none;
}

/* Resize handle */
.resize-handle {
    width: 6px;
    background-color: var(--secondary-color);
    cursor: ew-resize;
    position: relative;
    user-select: none;
    touch-action: none; /* Prevent default touch behaviors */
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 11;
}

.resize-handle:hover {
    background-color: var(--primary-color);
}

.resize-handle-line {
    width: 4px;
    height: 40px;
    background-color: var(--text-color);
    opacity: 0.3;
    border-radius: 2px;
    transition: opacity 0.2s ease;
}

.resize-handle:hover .resize-handle-line {
    opacity: 0.6;
    width: 6px;
}

/* Ensure proper flex behavior in split view */
.editor-preview-wrapper.split-view .editor-container,
.editor-preview-wrapper.split-view .preview-container {
    flex-shrink: 0;
    min-width: 200px;
    max-width: calc(100% - 200px - 8px);
}

.toast-container {
    position: fixed;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    padding: 0.5rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 2000;
}

.toast {
    color: #ffffff;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
    max-width: 300px;
    box-sizing: border-box;
    word-wrap: break-word;
    font-size: 0.875rem;
    text-align: center;
}

.toast.show {
    opacity: 1;
}

.toast.success {
    background-color: var(--success-status-bg);
}

.toast.error {
    background-color: var(--danger-status-bg);
}

.notepad-controls {
    position: absolute;
    left: 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.select-wrapper, .notepad-controls-wrapper {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 1rem, auto;
}

#notepad-selector {
    padding: 0.5rem;
    border-radius: 6px;
    border: 1px solid var(--secondary-color);
    background-color: var(--textarea-bg);
    color: var(--text-color);
    font-size: 0.875rem;
    min-width: 5rem;
    max-width: 8rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.icon-button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    color: var(--text-color);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--input-element-transition);
}

.icon-button:hover {
    background-color: var(--button-hover);
}

#preview-markdown.active svg, #search-open.active svg {
    stroke: var(--primary-color);
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--modal-overlay);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.visible {
    display: flex;
}

.modal-content {
    background-color: var(--modal-bg);
    padding: 2rem;
    border-radius: 12px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.modal-content h2 {
    margin-bottom: 1rem;
    color: var(--text-color);
}

.modal-input {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--secondary-color);
    border-radius: 6px;
    background-color: var(--textarea-bg);
    color: var(--text-color);
    font-size: 1rem;
}

.modal-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 1rem;
}

.modal-buttons button {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
    transition: var(--input-element-transition);
}

#rename-cancel, #download-cancel, #settings-cancel {
    background-color: var(--secondary-color);
    color: var(--text-color);
}

#rename-confirm, #download-txt, #download-md, #settings-save {
    background-color: var(--primary-color);
    color: white;
}

.modal-message {
    color: var(--text-color);
    margin-bottom: 1.5rem;
    line-height: 1.5;
}

.modal-buttons button.danger {
    background-color: var(--danger-color);
    color: white;
}

.modal-buttons button.danger:hover {
    background-color: var(--danger-hover);
}

#delete-notepad {
    color: var(--danger-color);
}

#delete-notepad:hover {
    background-color: rgba(220, 38, 38, 0.1);
}

#pin-modal {
    background-color: var(--bg-color);
}

#pin-modal .modal-content {
    text-align: center;
    padding: 3rem 2rem;
}

.pin-header {
    color: var(--text-color);
    font-size: 1.2rem;
    margin-bottom: 1rem;
    font-weight: 700;
    text-shadow: none;
}

.pin-header h2 {
    color: var(--text-color);
    opacity: 0.8;
    font-size: 1.25rem;
    font-weight: 500;
    margin-top: 1rem;
}

.pin-container {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    margin: 2rem 0;
}

.pin-digit {
    width: 35px;
    height: 45px;
    text-align: center;
    font-size: 1.25rem;
    border: 2px solid var(--secondary-color);
    border-radius: 8px;
    background-color: var(--textarea-bg);
    color: var(--text-color);
    transition: all 0.2s ease;
    flex: none;
    max-width: 30px;
    padding: 0;
}

.pin-digit:disabled,
.pin-digit.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    border-color: var(--secondary-color) !important;
    background-color: var(--textarea-bg) !important;
    color: var(--text-color) !important;
    box-shadow: none !important;
}

.pin-digit.disabled:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: none;
}

.pin-digit:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px var(--primary-color);
    outline: none;
}

.pin-digit.filled {
    border-color: var(--primary-color);
    background-color: var(--primary-color);
    color: white;
}

.error-message {
    color: var(--danger-color);
    margin-top: 1rem;
    font-size: 0.875rem;
    min-height: 1.25rem;
}

.modal-buttons button.primary {
    background-color: var(--primary-color);
    color: white;
    padding: 0.75rem 2rem;
    font-size: 1rem;
    margin-top: 1rem;
    min-width: 120px;
    border-radius: 8px;
    transition: var(--input-element-transition);
}

.modal-buttons button.primary:hover {
    background-color: var(--primary-color);
    opacity: 0.9;
}

#pin-modal .modal-buttons {
    display: flex;
    justify-content: center;
    margin-top: 2rem;
}

#pin-modal .modal-buttons button.primary {
    background-color: var(--primary-color);
    color: white;
    padding: 0.75rem 2rem;
    font-size: 1rem;
    min-width: 120px;
    border-radius: 8px;
    transition: var(--input-element-transition);
}

#pin-modal .modal-buttons button.primary:hover {
    background-color: var(--primary-color);
    opacity: 0.9;
    transform: translateY(-1px);
}

#pin-modal .modal-buttons button.primary:active {
    transform: translateY(0);
}

.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background-color: var(--bg-color);
    position: relative;
}

#login-content {
    text-align: center;
    padding: 2rem;
    border-radius: 12px;
    max-width: 400px;
    width: 90%;
}

/* Theme toggle for login page */
.login-container #theme-toggle {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    color: var(--text-color);
    border-radius: 8px;
    transition: var(--input-element-transition);
}

.login-container #theme-toggle:hover {
    background-color: var(--secondary-color);
}

/* Remote cursor styling */
.remote-cursor {
    position: absolute;
    pointer-events: none;
    z-index: 3;
    width: 2px;
    height: 1.6em;
    background-color: currentColor;
    will-change: transform;
    transform-origin: left top;
    transition: transform 0.1s ease;
    opacity: 0.8;
    display: block;
    top: 0;
    left: 0;
}

.remote-cursor::before {
    content: '';
    position: absolute;
    top: -6px;
    left: -4px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: currentColor;
    opacity: 0.9;
}

/* Remove the old label styles */
.remote-cursor-label {
    display: none;
} 

.tooltip {
    position: absolute;
    background-color: var(--secondary-color);
    color: var(--text-color);
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 12px;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.3s;
    z-index: 1000; /* Ensure it's above other elements */
}

.tooltip.show {
    visibility: visible;
    opacity: 1;
}

/* Search styles */
/* Scoped Search Styles */
#search-modal.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.35);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}
#search-modal.hidden {
    display: none;
}
.search-modal-content {
    background: var(--header-bg);
    padding: 20px;
    min-width: 30%;
    max-width: 50%;
    border-radius: 8px;
    box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.3);
}
#search-modal input {
    width: 100%;
    padding: 8px;
    margin-bottom: 10px;
    border: 1px solid var(--primary-color);
    border-radius: 4px;
    background-color: var(--textarea-bg);
    color: var(--text-color);
    font-family: monospace;
    font-size: 1rem;
}
#search-results {
    list-style-type: none;
    padding: 0;
    margin: 0;
    max-height: 30rem;
    overflow-y: auto;
    font-family: monospace;
    font-size: 1rem;
}
#search-results li {
    list-style-type: none;
    padding: 5px;
    cursor: pointer;
    border-bottom: 0.1px solid var(--secondary-color);
    transition: var(--input-element-transition);
}
#search-results li:last-child {
    border-bottom: none;
}
#search-results li:hover,
#search-results .selected {
    background-color: var(--button-hover);
    border-radius: 6px;
    padding: 4px 8px; /* Adds spacing to make the rounded corners more visible */
}
#search-results mark {
    background: var(--primary-color);
    font-weight: bold;
}

.settings-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 1rem;
    /* margin-bottom: 1.5rem; */
}

.settings-label {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}
.settings-label input {
    margin-top: 0.5rem;
}

#settings-modal input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 40px;
    height: 20px;
    background-color: #ccc;
    border-radius: 10px;
    position: relative;
    cursor: pointer;
    transition: background-color 0.3s;
}
#settings-modal input[type="checkbox"]:after {
    content: "";
    position: absolute;
    left: 2px;
    top: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background-color: white;
    transition: transform 0.3s;
}
#settings-modal input[type="checkbox"]:checked {
    background-color: var(--primary-color);
}
#settings-modal input[type="checkbox"]:checked:after {
    transform: translateX(20px);
}

#settings-modal input[type="radio"] {
    appearance: none;
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border: 2px solid var(--secondary-color);
    border-radius: 50%;
    background-color: var(--textarea-bg);
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
}

#settings-modal input[type="radio"]:checked {
    border-color: var(--primary-color);
    background-color: var(--primary-color);
}

#settings-modal input[type="radio"]:checked::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: white;
}

@media(max-width: 1400px) {
    #header-title {
        font-size: 1.2rem;
    }
}
@media (max-width: 1300px) {
    .container {
        max-width: 95%;
        padding: 0.3rem;
    }

    header {
        flex-direction: column;
        gap: 0.5rem;
        padding: 0, auto;
        margin: 0, auto;
    }

    .header-title {
        justify-content: center;
    }

    .header-right {
        position: absolute;
        float: right;
        padding: 0;
        margin: 0;
    }
    
    .notepad-controls {
        position: static;
        width: 100%;
        align-items: center;
        justify-content: center;
    }
    
    #theme-toggle {
        position: static;
    }

    .editor-container, .preview-container {
        max-height: 83vh;
    }

    .notepad-controls-wrapper {
        gap: 2rem;
    }
}


/* MOBILE */
@media (max-width: 585px) {
    .container {
        max-width: 100%;
        padding: 0, auto;
        margin: 0, auto;
    }

    .pin-container {
        gap: 0.5rem;
    }

    .pin-digit {
        width: 32px;
        height: 40px;
        font-size: 1.125rem;
        max-width: 28px;
    }

    .header-top {
        flex-direction: column;
    }

    .header-right {
        position: static;
        gap: 2rem;
    }

    #header-title {
        margin-bottom: 0.25rem;
    }

    .notepad-controls {
        flex-direction: column;
        margin: 0, auto;
        padding: 0, auto;
        margin-bottom: 0;
        row-gap: 0.1rem;
    }

    #notepad-selector {
        margin: 0, auto;
        padding: 0, auto;
        width: auto;
        max-width: 15rem;
    }
    
    .select-wrapper {
        width: 100%;
        justify-content: center;
        margin: 0, auto;
        padding: 0, auto;
    }

    .editor-container, .preview-container {
        max-height: 71vh;
        margin: 0, auto;
        padding: 0, auto;
    }
    
    .editor-preview-wrapper {
        height: 71vh;
        flex-direction: column; /* Stack vertically on mobile */
    }
    
    /* Mobile split view layout */
    .editor-preview-wrapper.split-view {
        flex-direction: column;
    }
    
    .editor-preview-wrapper.split-view .editor-container,
    .editor-preview-wrapper.split-view .preview-container {
        width: 100% !important;
        min-width: unset;
        max-width: unset;
        height: calc(50% - 10px); /* Split height equally, accounting for handle */
        border-radius: 12px; /* Restore border radius on mobile */
    }
    
    .editor-preview-wrapper.split-view .resize-handle {
        width: 100%;
        height: 8px;
        cursor: row-resize;
    }
    
    .editor-preview-wrapper.split-view .resize-handle-line {
        width: 40px;
        height: 2px;
    }
    
    .editor-preview-wrapper.split-view .resize-handle:hover .resize-handle-line {
        opacity: 0.6;
        height: 4px;
    }
    
    #editor {
        padding: 0.3rem;
    }
}

@media (max-width: 375px) {
    .editor-container, .preview-container {
        max-height: 65vh;
    }
}