* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    color: #222;
    background: #f4f4f4;
}

/* ---- Setup / admin / account pages ---- */
.setup-page { display: flex; justify-content: center; padding: 40px 16px; }
.setup-box {
    background: #fff; padding: 24px 32px; border-radius: 6px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.15); width: 100%; max-width: 380px;
}
.setup-box.wide { max-width: 640px; }
.setup-box label { display: block; margin: 12px 0 4px; font-size: 14px; }
.setup-box input[type=text], .setup-box input[type=password] {
    width: 100%; padding: 8px; font-size: 16px; border: 1px solid #ccc; border-radius: 4px;
}
.setup-box button { margin-top: 16px; padding: 10px 16px; font-size: 15px; cursor: pointer; }
.error { color: #b00020; margin: 8px 0; }
.success { color: #147a14; margin: 8px 0; }
.user-table-wrap { overflow-x: auto; margin-top: 12px; }
.user-table { width: 100%; border-collapse: collapse; }
.user-table th, .user-table td { border-bottom: 1px solid #eee; padding: 6px 8px; text-align: left; font-size: 14px; }
.user-table td { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 480px) {
    .setup-page { padding: 24px 12px; }
    .setup-box { padding: 20px 18px; }
}

/* ---- App layout ---- */
#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; height: var(--app-height, 100dvh); }

#topbar {
    display: flex; align-items: center; background: #2b3a4a; color: #fff;
    padding: 0 8px; height: 48px; flex-shrink: 0;
}
#drawerToggle {
    display: none; background: none; border: none; color: #fff; font-size: 20px; cursor: pointer; padding: 8px;
}
#topbarLogo { width: 24px; height: 24px; margin-right: 12px; flex-shrink: 0; }
#projectTabs { flex: 1; overflow-x: auto; overflow-y: hidden; white-space: nowrap; }
#projectList { list-style: none; display: flex; margin: 0; padding: 0; }
#projectList li {
    padding: 8px 14px; margin-right: 4px; background: #3d5166; border-radius: 4px 4px 0 0;
    cursor: pointer; display: flex; align-items: center; gap: 6px; user-select: none;
}
#projectList li.active { background: #f4f4f4; color: #222; }
#projectList li .proj-name { max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
#projectList li .proj-del { opacity: 0.6; font-weight: bold; }
#projectList li .proj-del:hover { opacity: 1; }
#addProject {
    flex-shrink: 0; margin-left: 6px; background: #3d5166; color: #fff; border: none;
    width: 32px; height: 32px; border-radius: 4px; font-size: 18px; cursor: pointer;
}
.topbar-user { display: flex; align-items: center; gap: 12px; margin-left: 16px; font-size: 13px; flex-shrink: 0; }
.topbar-user a { color: #cfe0f0; text-decoration: none; border-left: 1px solid rgba(255, 255, 255, 0.3); padding-left: 12px; }
.topbar-user a:hover { text-decoration: underline; }

#main { flex: 1; display: flex; overflow: hidden; }

#sidebar {
    width: 220px; flex-shrink: 0; background: #fff; border-right: 1px solid #ddd;
    display: flex; flex-direction: column; overflow: hidden;
}
.sidebar-panel { display: none; flex-direction: column; overflow: hidden; flex: 1; min-height: 0; }
#sidebarNotes { display: flex; }
.sidebar-head {
    display: flex; align-items: center; justify-content: flex-end; gap: 6px;
    padding: 8px 12px; border-bottom: 1px solid #eee; font-size: 13px; color: #666;
}
.sidebar-title { flex: 1; font-size: 13px; font-weight: bold; color: #333; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-head button {
    width: 24px; height: 24px; border: none; background: #eee; border-radius: 4px; cursor: pointer; flex-shrink: 0;
}
#noteList, #drawerProjectList { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
#noteList li, .proj-row-head, .drawer-notes li {
    padding: 10px 12px; border-bottom: 1px solid #f0f0f0; cursor: pointer;
    display: flex; justify-content: space-between; align-items: center; gap: 6px;
}
#noteList li.active, .proj-row-head.active, .drawer-notes li.active { background: #e8f0fa; }
#noteList li .note-title, .proj-row-head .proj-name, .drawer-notes li .note-title {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;
}
#noteList li .note-del, .proj-row-head .proj-del, .drawer-notes li .note-del { opacity: 0.5; font-weight: bold; }
#noteList li .note-del:hover, .proj-row-head .proj-del:hover, .drawer-notes li .note-del:hover { opacity: 1; }

.drawer-notes { list-style: none; margin: 0; padding: 0; background: #fafafa; }
.drawer-notes li { padding-left: 28px; border-bottom: none; border-top: 1px solid #f0f0f0; }
.drawer-notes li.drawer-add-note { color: #3d5166; font-weight: bold; }

#sidebarOverlay { display: none; }

#editor { flex: 1; display: flex; flex-direction: column; background: #fff; overflow: hidden; }
#editorHead { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid #eee; }
#noteTitle {
    flex: 1; font-size: 18px; font-family: Arial, Helvetica, sans-serif; border: none; outline: none; min-width: 0;
}
.editor-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.editor-brand { display: flex; align-items: center; gap: 6px; min-width: 0; }
.editor-buttons { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
#editorLogo { display: none; width: 18px; height: 18px; flex-shrink: 0; }
#historyBtn, #forceSaveBtn, #trashBtn {
    border: none; background: #eee; border-radius: 4px; width: 30px; height: 30px;
    font-size: 15px; cursor: pointer; flex-shrink: 0;
}
#historyBtn, #trashBtn { font-size: 20px; }
#saveStatus { font-size: 12px; color: #888; min-width: 90px; text-align: right; }
#noteBody {
    flex: 1; border: none; outline: none; resize: none; padding: 14px;
    font-family: "Courier New", Courier, monospace; font-size: 14px; line-height: 1.5;
}

/* ---- History modal ---- */
.modal { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4); align-items: center; justify-content: center; z-index: 100; }
.modal.open { display: flex; }
.modal-box { background: #fff; border-radius: 6px; padding: 20px; width: 92%; max-width: 960px; height: 90vh; max-height: 90vh; display: flex; flex-direction: column; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.modal-header h2 { margin: 0; }
.history-content { display: flex; gap: 16px; flex: 1; overflow: hidden; }
#historyList { list-style: none; margin: 0; padding: 0; width: 200px; overflow-y: auto; border-right: 1px solid #eee; }
#historyList li { padding: 8px; cursor: pointer; font-size: 13px; border-bottom: 1px solid #f5f5f5; }
#historyList li.active { background: #e8f0fa; }
#historyPreview { flex: 1; display: flex; flex-direction: column; }
#historyTitle { font-size: 16px; padding: 6px; margin-bottom: 8px; border: 1px solid #eee; font-family: Arial, sans-serif; }
#historyBody { flex: 1; padding: 8px; border: 1px solid #eee; font-family: "Courier New", monospace; font-size: 13px; resize: none; }
#historyTitle[readonly], #historyBody[readonly] { background: #f4f4f4; color: #444; cursor: default; }
#restoreBtn { margin-top: 8px; padding: 8px; cursor: pointer; }
.modal-close {
    border: none; background: #eee; border-radius: 4px; width: 28px; height: 28px;
    font-size: 18px; line-height: 1; cursor: pointer; flex-shrink: 0;
}

/* ---- Confirm / prompt modals ---- */
.modal-box-small { height: auto; max-height: 90vh; max-width: 420px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.modal-actions button, #promptOk, #confirmOk {
    padding: 8px 14px; cursor: pointer; border: none; border-radius: 4px; background: #eee;
}
.danger { background: #b00020 !important; color: #fff !important; }
#promptInput { width: 100%; padding: 8px; font-size: 14px; border: 1px solid #ccc; border-radius: 4px; margin-top: 4px; }
#promptError { min-height: 18px; }

/* ---- Trash modal ---- */
.trash-content { display: flex; flex-direction: column; gap: 20px; overflow-y: auto; flex: 1; }
.trash-section h3 { margin: 0 0 8px; font-size: 15px; }
.trash-list { list-style: none; margin: 0; padding: 0; }
.trash-list li {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 10px 8px; border-bottom: 1px solid #f0f0f0;
}
.trash-row-main { display: flex; flex-direction: column; min-width: 0; }
.trash-name { font-weight: bold; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trash-meta { font-size: 12px; color: #888; }
.trash-row-actions { display: flex; gap: 6px; flex-shrink: 0; }
.trash-row-actions button {
    padding: 6px 10px; font-size: 13px; cursor: pointer; border: none; border-radius: 4px; background: #eee;
}
.trash-empty { color: #888; font-size: 13px; display: none; }

/* ---- Mobile ---- */
@media (max-width: 768px) {
    #drawerToggle { display: block; }
    #projectTabs, #addProject, #topbarLogo { display: none; }
    #sidebar {
        position: fixed; top: 48px; left: 0; bottom: 0; z-index: 50;
        transform: translateX(-100%); transition: transform 0.2s ease; width: 80%; max-width: 300px;
        box-shadow: 2px 0 8px rgba(0,0,0,0.2);
    }
    #sidebar.open { transform: translateX(0); }
    #sidebarProjects { display: flex; }
    #sidebarNotes { display: none; }
    #sidebarOverlay.open {
        display: block; position: fixed; top: 48px; left: 0; right: 0; bottom: 0;
        background: rgba(0,0,0,0.3); z-index: 40;
    }
    .history-content { flex-direction: column; }
    #historyList { width: auto; max-height: 120px; border-right: none; border-bottom: 1px solid #eee; }

    #editorHead { flex-direction: column; align-items: stretch; gap: 6px; padding: 8px 10px; }
    #noteTitle { order: 2; }
    .editor-actions { order: 1; justify-content: space-between; }
    #saveStatus { min-width: 0; text-align: left; }
    #editorLogo { display: block; width: 26px; height: 26px; }
}
