/* --- Cài đặt chung & Font --- */
body {
    font-family: 'Segoe UI', Roboto, sans-serif;
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #e0eafc, #cfdef3);
    color: #333;
    transition: background-color 0.3s ease, color 0.3s ease;
    font-size: 14px;
    box-sizing: border-box;
    overflow: hidden;
}
*, *::before, *::after {
    box-sizing: inherit;
}

/* --- Khung Notepad --- */
.notepad-container {
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
    background: #ffffff;
    width: 90%;
    max-width: 1200px;
    height: 90vh;
    border-radius: 12px;
    overflow: hidden;
    transition: background-color 0.3s ease;
}

/* --- Thanh Tabs --- */
.tabs-container {
    display: flex;
    flex-wrap: nowrap;
    align-items: stretch;
    background: #f5f7fa;
    padding: 8px;
    border-bottom: 2px solid #e0e0e0;
    overflow-x: auto;
    flex-shrink: 0;
    min-height: 40px;
    box-shadow: inset 0 -2px 5px rgba(0, 0, 0, 0.05);
}
.tab {
    padding: 10px 15px;
    margin-right: 5px;
    cursor: pointer;
    background: #e8ecef;
    border-radius: 8px 8px 0 0;
    position: relative;
    display: flex;
    align-items: center;
    max-width: 150px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 0;
    font-size: 13px;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.tab.active {
    background: #ffffff;
    font-weight: bold;
    margin-bottom: -2px;
    z-index: 1;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}
.tab:hover {
    background: #ddd;
    transform: translateY(-2px);
}
.tab.active:hover {
    background: #ffffff;
}
.tab-close-btn {
    margin-left: 8px;
    border: none;
    background: none;
    font-weight: bold;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 3px;
    line-height: 1;
    font-size: 12px;
    color: #666;
}
.tab-close-btn:hover {
    background: #ffbdbd;
    color: #c00;
}
#newTabBtn {
    padding: 0;
    margin-right: 8px;
    border: none;
    background: #007bff;
    color: white;
    cursor: pointer;
    border-radius: 50%;
    font-size: 16px;
    font-weight: bold;
    line-height: 1;
    align-self: center;
    width: 30px;
    height: 30px;
    transition: all 0.3s ease;
}
#newTabBtn:hover {
    background: #0056b3;
    transform: scale(1.1);
}
.tab .unsaved-indicator {
    color: red;
    font-weight: bold;
    margin-right: 4px;
    display: none;
}

/* --- Thanh điều khiển --- */
.controls {
    padding: 12px;
    background: #f8f9fa;
    border-bottom: 2px solid #e9ecef;
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    flex-shrink: 0;
}
.controls button {
    padding: 8px 12px;
    border: none;
    background: #ffffff;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.3s ease;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
.controls button:hover {
    background: #f1f3f5;
    transform: translateY(-1px);
}
.controls button:active {
    background: #e9ecef;
}
.controls input[type="text"]#filenameInput {
    padding: 5px 8px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 13px;
    min-width: 150px;
    flex-grow: 1;
}
.controls input[type="text"]#searchInput {
    padding: 5px 8px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 13px;
    width: 120px;
}

/* --- Vùng soạn thảo --- */
.editor-sessions {
    flex-grow: 1;
    position: relative;
    overflow: hidden;
    background: #fff;
}
.editor-instance {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
}
.editor-instance.active {
    display: block;
}

/* --- CodeMirror --- */
.CodeMirror {
    height: 100% !important;
    width: 100% !important;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 14px;
    border: none;
}

/* --- Highlight --- */
.cm-highlight {
    background-color: rgba(255, 255, 0, 0.6);
}
.cm-s-material-darker .cm-highlight {
    background-color: rgba(255, 236, 61, 0.7);
    color: #333 !important;
}
.cm-search-match {
    background-color: rgba(0, 255, 0, 0.4);
}
.cm-s-material-darker .cm-search-match {
    background-color: rgba(0, 255, 0, 0.5);
    color: #000 !important;
}

/* --- Thanh trạng thái --- */
#statusBar {
    padding: 8px 15px;
    background: #f8f9fa;
    border-top: 2px solid #e9ecef;
    font-size: 13px;
    color: #6c757d;
    flex-shrink: 0;
    display: flex;
    gap: 10px;
    align-items: center;
}
#statusBar span {
    margin-right: 10px;
}
.unsaved-star {
    color: red;
    font-weight: bold;
    margin-left: 5px;
    display: none;
}

/* --- Dark Mode --- */
body.dark-mode {
    background: linear-gradient(135deg, #1e1e1e, #2a2a2a);
}
.notepad-container.dark-mode {
    background: #1a1a1a;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}
.tabs-container.dark-mode {
    background: #2c2c2e;
    border-bottom: 2px solid #404040;
}
.tab.dark-mode {
    background: #3a3a3c;
    color: #ccc;
}
.tab.dark-mode.active {
    background: #1e1e1e;
    color: #fff;
}
.tab.dark-mode:hover {
    background: #4a4a4c;
}
.tab.dark-mode.active:hover {
    background: #1e1e1e;
}
.tab-close-btn.dark-mode {
    color: #888;
}
.tab-close-btn.dark-mode:hover {
    background: #553333;
    color: #ff8f8f;
}
#newTabBtn.dark-mode {
    background: #1e90ff;
}
#newTabBtn.dark-mode:hover {
    background: #187bcd;
}
.controls.dark-mode {
    background: #252526;
    border-bottom: 2px solid #404040;
}
.controls.dark-mode button {
    background: #3a3a3c;
    color: #e0e0e0;
}
.controls.dark-mode button:hover {
    background: #4a4a4c;
}
.controls.dark-mode button:active {
    background: #555;
}
.controls.dark-mode input[type="text"]#filenameInput,
.controls.dark-mode input[type="text"]#searchInput {
    background: #333;
    border-color: #555;
    color: #e0e0e0;
}
.editor-sessions.dark-mode {
    background: #1e1e1e;
}
.dark-mode .CodeMirror {
    background: #1e1e1e !important;
}
.dark-mode .CodeMirror .CodeMirror-gutters {
    background: #252526 !important;
    border-right: 1px solid #444;
    color: #858585;
}
.dark-mode .CodeMirror .CodeMirror-cursor {
    border-left-color: #e0e0e0 !important;
}
.dark-mode .CodeMirror .CodeMirror-selected {
    background: #264f78 !important;
}
#statusBar.dark-mode {
    background: #2c2c2e;
    color: #adb5bd;
    border-top: 2px solid #404040;
}
.unsaved-star.dark-mode {
    color: #ff8f8f;
}
.tab .unsaved-indicator.dark-mode {
    color: #ff8f8f;
}

/* Scrollbar dark mode */
.dark-mode ::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}
.dark-mode ::-webkit-scrollbar-track {
    background: #252526;
    border-radius: 5px;
}
.dark-mode ::-webkit-scrollbar-thumb {
    background: #555;
    border-radius: 5px;
}
.dark-mode ::-webkit-scrollbar-thumb:hover {
    background: #666;
}
.dark-mode ::-webkit-scrollbar-corner {
    background: #1e1e1e;
}
@supports (scrollbar-color: auto) {
    .dark-mode {
        scrollbar-color: #555 #252526;
    }
}

/* --- Toast --- */
.copy-notification {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(33, 37, 41, 0.95);
    color: #eee;
    padding: 12px 25px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 1050;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s ease, visibility 0s linear 0.4s;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    white-space: nowrap;
}
.copy-notification.show {
    opacity: 1;
    visibility: visible;
    transition: opacity 0.4s ease, visibility 0s linear 0s;
}
body:not(.dark-mode) .copy-notification {
    background: rgba(255, 255, 255, 0.95);
    color: #212529;
}