/* ===== Obsidian-like theme (dark) ===== */
:root {
    --bg-primary: #1e1e1e;
    --bg-secondary: #262626;
    --bg-sidebar: #1a1a1a;
    --bg-hover: #2f2f2f;
    --bg-active: #3a3a3a;
    --border: #333;
    --text: #dcddde;
    --text-muted: #999;
    --text-faint: #666;
    --accent: #8b5cf6;
    --accent-hover: #a78bfa;
    --green: #4ade80;
    --red: #f87171;
    --font: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --mono: "JetBrains Mono", "Consolas", "Courier New", monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text);
    font-size: 14px;
    overflow: hidden;
}
.hidden { display: none !important; }

/* ===== Login screen ===== */
.auth-screen {
    position: fixed; inset: 0; z-index: 100;
    display: flex; align-items: center; justify-content: center;
    background: radial-gradient(circle at 50% 30%, #2a2440, #141414 70%);
}
.auth-card {
    width: 360px; padding: 40px 32px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 20px 60px rgba(0,0,0,.5);
    text-align: center;
}
.auth-logo { display: block; margin: 0 auto 8px; filter: drop-shadow(0 4px 14px rgba(139, 92, 246, .35)); }
.auth-card h1 { font-size: 22px; font-weight: 600; margin-bottom: 6px; }
.auth-sub { color: var(--text-muted); font-size: 13px; margin-bottom: 22px; }
.auth-card input {
    width: 100%; padding: 11px 14px; margin-bottom: 12px;
    background: var(--bg-primary); border: 1px solid var(--border);
    border-radius: 8px; color: var(--text); font-size: 14px;
}
.auth-card input:focus { outline: none; border-color: var(--accent); }
.auth-card button {
    width: 100%; padding: 11px; border: none; border-radius: 8px;
    background: var(--accent); color: #fff; font-size: 14px; font-weight: 600;
    cursor: pointer; transition: background .15s;
}
.auth-card button:hover { background: var(--accent-hover); }
.auth-error { color: var(--red); font-size: 13px; min-height: 18px; margin-top: 8px; }
.auth-note { color: var(--text-faint); font-size: 11px; margin-top: 18px; line-height: 1.5; }
/* Base (dark) language select — used inside Settings */
.lang-select {
    background: var(--bg-primary); color: var(--text);
    border: 1px solid var(--border); border-radius: 6px;
    padding: 5px 8px; font-size: 13px; cursor: pointer;
}
.lang-select:focus { outline: none; border-color: var(--accent); }
.lang-select option { background: var(--bg-secondary); color: var(--text); }

/* Login screen: a light selector that stands out against the dark card,
   placed a bit lower and separated by a divider. */
.lang-field {
    display: flex; flex-direction: column; align-items: center; gap: 9px;
    margin-top: 28px; padding-top: 20px;
    border-top: 1px solid var(--border);
    font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
    color: var(--text-faint);
}
.lang-field .lang-select {
    appearance: none; -webkit-appearance: none;
    min-width: 120px; text-align: center; text-align-last: center;
    background-color: var(--bg-primary); color: var(--text);
    border: 1px solid var(--border); border-radius: 7px;
    padding: 6px 26px 6px 12px; font-size: 12.5px; font-weight: 500;
    letter-spacing: 0; text-transform: none; cursor: pointer;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M2 4.5l4 4 4-4' fill='none' stroke='%23999' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/></svg>");
    background-repeat: no-repeat; background-position: right 9px center;
    transition: border-color .15s;
}
.lang-field .lang-select:hover { border-color: var(--text-faint); }
.lang-field .lang-select:focus { outline: none; border-color: var(--accent); }
.lang-field .lang-select option { background: var(--bg-secondary); color: var(--text); }

/* ===== Application shell ===== */
.app { display: flex; height: 100vh; }
.nav-toggle { font-size: 18px; line-height: 1; }
.app.nav-hidden .sidebar { display: none; }

/* --- Sidebar --- */
.sidebar {
    width: 280px; min-width: 200px; max-width: 480px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    resize: horizontal; overflow: hidden;
}
.sidebar-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 14px; border-bottom: 1px solid var(--border);
}
.vault-name { font-weight: 600; font-size: 13px; }
.sidebar-actions { display: flex; gap: 2px; }
.icon-btn {
    background: none; border: none; color: var(--text-muted);
    cursor: pointer; font-size: 15px; padding: 4px 7px; border-radius: 6px;
    transition: background .12s, color .12s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.search-box { padding: 10px 12px; }
.search-box input {
    width: 100%; padding: 7px 10px; font-size: 13px;
    background: var(--bg-primary); border: 1px solid var(--border);
    border-radius: 6px; color: var(--text);
}
.search-box input:focus { outline: none; border-color: var(--accent); }

.file-tree { flex: 1; overflow-y: auto; padding: 4px 6px; }
.tree-item { user-select: none; }
.tree-row {
    display: flex; align-items: center; gap: 6px;
    padding: 5px 8px; border-radius: 6px; cursor: pointer;
    font-size: 13px; color: var(--text); white-space: nowrap;
}
.tree-row:hover { background: var(--bg-hover); }
.tree-row.active { background: var(--bg-active); color: #fff; }
.tree-row.selected { box-shadow: inset 2px 0 0 var(--text-faint); }
.tree-row .twirl { width: 12px; color: var(--text-faint); font-size: 10px; }
.tree-row .ico { font-size: 13px; }
.tree-row .label { overflow: hidden; text-overflow: ellipsis; }
.tree-children { padding-left: 14px; }

.sidebar-footer { padding: 10px 12px; border-top: 1px solid var(--border); }
.sidebar-footer .icon-btn { width: 100%; text-align: left; font-size: 12px; }

/* --- Workspace --- */
.workspace { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.tabbar {
    display: flex; align-items: center; gap: 14px;
    padding: 8px 16px; border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
}
.active-title { flex: 1; font-weight: 500; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.view-toggle { display: flex; gap: 2px; background: var(--bg-primary); border-radius: 7px; padding: 2px; }
.toggle-btn {
    background: none; border: none; color: var(--text-muted);
    cursor: pointer; font-size: 12px; padding: 5px 10px; border-radius: 5px;
}
.toggle-btn:hover { color: var(--text); }
.toggle-btn.active { background: var(--bg-active); color: #fff; }
.save-status { font-size: 12px; color: var(--text-faint); min-width: 70px; text-align: right; }
.save-status.saved { color: var(--green); }
.save-status.saving { color: var(--text-muted); }

.editor-area { flex: 1; display: flex; min-height: 0; position: relative; }
.empty-state {
    position: absolute; inset: 0; display: flex; flex-direction: column;
    align-items: center; justify-content: center; color: var(--text-faint);
}
.empty-icon { font-size: 52px; margin-bottom: 14px; opacity: .6; }

.editor, .preview { flex: 1; height: 100%; overflow-y: auto; }
.editor {
    background: var(--bg-primary); color: var(--text); border: none;
    resize: none; padding: 28px 40px; font-family: var(--mono);
    font-size: 15px; line-height: 1.7;
}
.editor:focus { outline: none; }
.editor-area.split .editor { border-right: 1px solid var(--border); }

.preview { background: var(--bg-primary); padding: 28px 44px; }

/* ===== Vditor (instant rendering editor) ===== */
.cm-host { flex: 1; height: 100%; overflow: hidden; background: var(--bg-primary); }
.cm-host .vditor { border: none; border-radius: 0; }
.cm-host .vditor--dark { background: var(--bg-primary); }
.cm-host .vditor-toolbar { background: var(--bg-secondary); border-bottom: 1px solid var(--border); }
.cm-host .vditor-content { background: var(--bg-primary); }

/* ===== Markdown ===== */
.markdown-body { line-height: 1.7; font-size: 15px; max-width: none; }
.markdown-body h1, .markdown-body h2, .markdown-body h3 { margin: 1.2em 0 .5em; line-height: 1.3; }
.markdown-body h1 { font-size: 1.9em; border-bottom: 1px solid var(--border); padding-bottom: .25em; }
.markdown-body h2 { font-size: 1.5em; border-bottom: 1px solid var(--border); padding-bottom: .2em; }
.markdown-body h3 { font-size: 1.25em; }
.markdown-body p { margin: .7em 0; }
.markdown-body ul, .markdown-body ol { margin: .6em 0; padding-left: 1.6em; }
.markdown-body li { margin: .25em 0; }
.markdown-body a { color: var(--accent-hover); text-decoration: none; }
.markdown-body a:hover { text-decoration: underline; }
.markdown-body code {
    background: var(--bg-active); padding: .15em .4em; border-radius: 4px;
    font-family: var(--mono); font-size: .88em;
}
.markdown-body pre {
    background: #161616; padding: 14px 16px; border-radius: 8px;
    overflow-x: auto; border: 1px solid var(--border); margin: .8em 0;
}
.markdown-body pre code { background: none; padding: 0; }
.markdown-body blockquote {
    border-left: 3px solid var(--accent); padding-left: 14px;
    color: var(--text-muted); margin: .8em 0;
}
.markdown-body table { border-collapse: collapse; margin: .8em 0; }
.markdown-body th, .markdown-body td { border: 1px solid var(--border); padding: 6px 12px; }
.markdown-body img { max-width: 100%; border-radius: 8px; }
.markdown-body hr { border: none; border-top: 1px solid var(--border); margin: 1.2em 0; }

/* ===== Context menu ===== */
.context-menu {
    position: fixed; z-index: 200; min-width: 160px;
    background: var(--bg-secondary); border: 1px solid var(--border);
    border-radius: 8px; padding: 5px; box-shadow: 0 8px 30px rgba(0,0,0,.5);
}
.context-menu button {
    display: block; width: 100%; text-align: left; background: none;
    border: none; color: var(--text); padding: 8px 12px; border-radius: 5px;
    cursor: pointer; font-size: 13px;
}
.context-menu button:hover { background: var(--bg-hover); }
.context-menu button.danger:hover { background: rgba(248,113,113,.15); color: var(--red); }

/* ===== Drag-and-drop import overlay ===== */
.drop-overlay {
    position: fixed; inset: 0; z-index: 250;
    display: flex; align-items: center; justify-content: center;
    background: rgba(18, 14, 34, .80); pointer-events: none;
}
.drop-overlay .drop-box {
    border: 2.5px dashed var(--accent-hover); border-radius: 16px;
    padding: 44px 60px; text-align: center;
    background: rgba(139, 92, 246, .10);
    color: var(--text); font-size: 17px; font-weight: 500;
}
.drop-overlay .drop-ico { display: block; font-size: 46px; margin-bottom: 12px; }

/* ===== Settings modal ===== */
.modal {
    position: fixed; inset: 0; z-index: 150;
    display: flex; align-items: center; justify-content: center;
    background: rgba(0, 0, 0, .55);
}
.modal-card {
    width: 380px; max-width: 92vw; max-height: 88vh; overflow-y: auto;
    background: var(--bg-secondary); border: 1px solid var(--border);
    border-radius: 14px; padding: 22px 24px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.modal-head h2 { font-size: 18px; font-weight: 600; }
.modal-section { padding: 16px 0; border-top: 1px solid var(--border); }
.modal-section:first-of-type { border-top: none; }
.modal-section h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin-bottom: 12px; }
.modal-section input[type="password"],
.modal-section input[type="number"] {
    width: 100%; padding: 9px 12px; margin-bottom: 10px;
    background: var(--bg-primary); border: 1px solid var(--border);
    border-radius: 8px; color: var(--text); font-size: 14px;
}
.modal-section input:focus { outline: none; border-color: var(--accent); }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.field-row span { font-size: 14px; }
.field-row input[type="number"] { width: 90px; margin-bottom: 0; }
.field-row .lang-select { margin-bottom: 0; }
.primary-btn {
    width: 100%; padding: 10px; border: none; border-radius: 8px;
    background: var(--accent); color: #fff; font-size: 14px; font-weight: 600; cursor: pointer;
    transition: background .15s;
}
.primary-btn:hover { background: var(--accent-hover); }
.hint { font-size: 11.5px; color: var(--text-faint); margin-top: 8px; line-height: 1.5; }
.modal-msg { font-size: 13px; min-height: 18px; margin-top: 10px; color: var(--red); }
.modal-msg.ok { color: var(--green); }
.modal-msg.busy { color: var(--text-muted); }

/* ===== Scrollbars ===== */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #3a3a3a; border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #4a4a4a; }
::-webkit-scrollbar-track { background: transparent; }

/* ===== Responsive: sidebar overlays content on narrow screens ===== */
@media (max-width: 700px) {
    .sidebar {
        position: absolute; top: 0; bottom: 0; left: 0; z-index: 60;
        width: 82%; max-width: 320px; resize: none;
        box-shadow: 4px 0 24px rgba(0, 0, 0, .55);
    }
    .editor, .preview { padding: 20px 18px; }
    .tabbar { gap: 8px; padding: 8px 12px; }
    .view-toggle .toggle-btn { padding: 5px 8px; }
    .save-status { display: none; }
}
