/* Arcana Rich Notes — Full-featured note-taking interface */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
    --bg: #1a1b26; --surface: #24283b; --text: #c0caf5;
    --text-dim: #565f89; --accent: #7aa2f7; --border: #414868;
    --success: #9ece6a; --error: #f7768e; --warn: #e0af68;
    --purple: #bb9af7; --cyan: #7dcfcf; --orange: #ff9e64;
    --editor-bg: #1a1b26; --preview-bg: #1e2030;
}
html, body { height: 100%; overflow: hidden; }
body { background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }

/* === App Bar === */
.app-bar { display: flex; align-items: center; gap: 12px; padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 100; min-height: 48px; }
.app-bar .brand { font-size: 18px; font-weight: 700; color: var(--accent); text-decoration: none; }
.app-bar .nav-link { font-size: 14px; color: var(--text-dim); text-decoration: none; padding: 4px 10px; border-radius: 6px; transition: all 0.15s; }
.app-bar .nav-link:hover { color: var(--text); background: rgba(122,162,247,0.08); }
.app-bar .nav-link.active { color: var(--accent); background: rgba(122,162,247,0.12); }
.spacer { flex: 1; }
.theme-toggle { background: none; border: 1px solid var(--border); color: var(--text-dim); width: 36px; height: 36px; border-radius: 6px; cursor: pointer; font-size: 16px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; transition: border-color 0.15s, color 0.15s; }
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }

/* === Main Layout === */
.notes-layout { display: flex; height: calc(100vh - 48px); overflow: hidden; }

/* === Sidebar === */
.sidebar { width: 280px; min-width: 280px; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; }
.sidebar-header { padding: 12px; display: flex; gap: 8px; border-bottom: 1px solid var(--border); }
.sidebar-header .btn-new { flex: 1; background: var(--accent); color: #fff; border: none; padding: 8px 12px; border-radius: 6px; font-size: 13px; font-weight: 600; cursor: pointer; transition: opacity 0.15s; }
.sidebar-header .btn-new:hover { opacity: 0.9; }
.sidebar-search { padding: 8px 12px; border-bottom: 1px solid var(--border); }
.sidebar-search input { width: 100%; background: var(--bg); border: 1px solid var(--border); color: var(--text); padding: 6px 10px; border-radius: 6px; font-size: 13px; outline: none; }
.sidebar-search input:focus { border-color: var(--accent); }
.note-list { flex: 1; overflow-y: auto; }
.note-list::-webkit-scrollbar { width: 4px; }
.note-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.note-item { padding: 10px 12px; cursor: pointer; border-bottom: 1px solid rgba(65,72,104,0.2); transition: background 0.1s; }
.note-item:hover { background: rgba(122,162,247,0.06); }
.note-item.active { background: rgba(122,162,247,0.12); border-left: 3px solid var(--accent); }
.note-item-title { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: 2px; }
.note-item-snippet { font-size: 12px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-item-date { font-size: 11px; color: var(--text-dim); margin-top: 4px; opacity: 0.7; }
.sidebar-empty { padding: 24px 16px; text-align: center; color: var(--text-dim); font-size: 13px; }

/* === Editor Area === */
.editor-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.editor-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--text-dim); font-size: 14px; text-align: center; }
.editor-empty p { max-width: 280px; }

/* Title bar */
.title-bar { padding: 12px 16px 8px; border-bottom: 1px solid var(--border); background: var(--surface); }
.title-bar input { width: 100%; background: transparent; border: none; color: var(--text); font-size: 20px; font-weight: 700; outline: none; }
.title-bar input::placeholder { color: var(--text-dim); }

/* Toolbar */
.toolbar { display: flex; align-items: center; gap: 2px; padding: 4px 12px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.toolbar .sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.toolbar button { background: none; border: none; color: var(--text-dim); padding: 4px 7px; border-radius: 4px; cursor: pointer; font-size: 13px; font-weight: 600; transition: all 0.1s; min-width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; }
.toolbar button:hover { background: rgba(122,162,247,0.12); color: var(--text); }
.toolbar button.active { background: rgba(122,162,247,0.2); color: var(--accent); }
.toolbar button[title] { font-family: inherit; }
.tb-italic { font-style: italic; }
.tb-strike { text-decoration: line-through; }
.tb-code { font-family: "SF Mono", "Fira Code", monospace; font-size: 12px; }

/* Editor + Preview split */
.editor-split { display: flex; flex: 1; overflow: hidden; }
.editor-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.editor-pane textarea { flex: 1; width: 100%; background: var(--editor-bg); color: var(--text); border: none; padding: 16px; font-family: "SF Mono", "Fira Code", "Cascadia Code", monospace; font-size: 14px; line-height: 1.6; resize: none; outline: none; tab-size: 4; }
.editor-pane textarea::placeholder { color: var(--text-dim); }

.preview-pane { flex: 1; overflow-y: auto; padding: 16px 24px; background: var(--preview-bg); border-left: 1px solid var(--border); min-width: 0; }
.preview-pane.hidden { display: none; }

/* Preview markdown styles */
.preview-pane h1 { font-size: 24px; font-weight: 700; margin: 0 0 12px; color: var(--accent); border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.preview-pane h2 { font-size: 20px; font-weight: 600; margin: 20px 0 8px; color: var(--accent); }
.preview-pane h3 { font-size: 16px; font-weight: 600; margin: 16px 0 6px; color: var(--accent); }
.preview-pane p { margin: 0 0 12px; line-height: 1.7; }
.preview-pane strong { font-weight: 700; }
.preview-pane em { font-style: italic; }
.preview-pane del { text-decoration: line-through; color: var(--text-dim); }
.preview-pane a { color: var(--accent); text-decoration: underline; }
.preview-pane code { background: var(--bg); padding: 2px 6px; border-radius: 3px; font-family: "SF Mono", "Fira Code", monospace; font-size: 13px; }
.preview-pane pre { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 12px 16px; overflow-x: auto; margin: 0 0 12px; }
.preview-pane pre code { background: none; padding: 0; }
.preview-pane ul, .preview-pane ol { margin: 0 0 12px; padding-left: 24px; }
.preview-pane li { margin: 4px 0; line-height: 1.6; }
.preview-pane blockquote { border-left: 3px solid var(--accent); padding: 8px 16px; margin: 0 0 12px; color: var(--text-dim); background: rgba(122,162,247,0.04); border-radius: 0 6px 6px 0; }
.preview-pane hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.preview-pane table { border-collapse: collapse; margin: 0 0 12px; width: 100%; }
.preview-pane th, .preview-pane td { border: 1px solid var(--border); padding: 6px 10px; font-size: 13px; }
.preview-pane th { background: var(--bg); font-weight: 600; }
.preview-pane img { max-width: 100%; border-radius: 6px; margin: 8px 0; }
.preview-pane input[type="checkbox"] { margin-right: 6px; }

/* Status bar */
.status-bar { display: flex; align-items: center; gap: 12px; padding: 6px 16px; background: var(--surface); border-top: 1px solid var(--border); font-size: 12px; color: var(--text-dim); flex-wrap: wrap; }
.status-bar .save-status { display: flex; align-items: center; gap: 4px; }
.status-bar .save-status.saving { color: var(--warn); }
.status-bar .save-status.saved { color: var(--success); }
.status-bar .save-status.error { color: var(--error); }
.status-sep { width: 1px; height: 12px; background: var(--border); }

/* Tags bar */
.tags-bar { display: flex; align-items: center; gap: 6px; padding: 8px 16px; border-top: 1px solid var(--border); background: var(--surface); flex-wrap: wrap; }
.tags-bar .label { font-size: 12px; color: var(--text-dim); font-weight: 600; }
.tag-badge { display: inline-flex; align-items: center; gap: 3px; padding: 2px 8px; border-radius: 10px; font-size: 11px; background: rgba(122,162,247,0.12); color: var(--accent); cursor: default; }
.tag-badge .tag-remove { cursor: pointer; opacity: 0.6; font-size: 14px; line-height: 1; }
.tag-badge .tag-remove:hover { opacity: 1; }
.tag-add-input { background: var(--bg); border: 1px solid var(--border); color: var(--text); padding: 2px 8px; border-radius: 10px; font-size: 11px; outline: none; width: 100px; }
.tag-add-input:focus { border-color: var(--accent); }

/* Attachments bar */
.attachments-bar { display: flex; align-items: center; gap: 6px; padding: 6px 16px; border-top: 1px solid var(--border); background: var(--surface); flex-wrap: wrap; }
.attachments-bar .label { font-size: 12px; color: var(--text-dim); font-weight: 600; }
.attachment-chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 6px; font-size: 11px; background: rgba(158,206,106,0.12); color: var(--success); cursor: pointer; }
.attachment-chip:hover { background: rgba(158,206,106,0.2); }
.attachment-chip .att-remove { font-size: 14px; line-height: 1; opacity: 0.6; }
.attachment-chip .att-remove:hover { opacity: 1; }

/* === History Modal === */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 300; align-items: center; justify-content: center; }
.modal-overlay.visible { display: flex; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 24px; width: 90%; max-width: 560px; max-height: 80vh; overflow-y: auto; }
.modal h3 { font-size: 16px; font-weight: 600; margin-bottom: 16px; color: var(--accent); }
.modal-close { background: none; border: 1px solid var(--border); color: var(--text-dim); padding: 6px 16px; border-radius: 6px; cursor: pointer; margin-top: 12px; font-size: 13px; }
.modal-close:hover { border-color: var(--accent); color: var(--text); }
.version-item { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-bottom: 1px solid rgba(65,72,104,0.3); cursor: pointer; transition: background 0.1s; border-radius: 6px; margin-bottom: 4px; }
.version-item:hover { background: rgba(122,162,247,0.08); }
.version-item .v-info { flex: 1; }
.version-item .v-num { font-size: 13px; font-weight: 600; color: var(--accent); }
.version-item .v-time { font-size: 12px; color: var(--text-dim); }
.version-item .v-size { font-size: 12px; color: var(--text-dim); }

/* === Confirm Delete Modal === */
.modal .delete-warning { color: var(--error); font-size: 14px; margin-bottom: 16px; }
.modal .btn-row { display: flex; gap: 8px; justify-content: flex-end; }
.modal .btn-cancel { background: none; border: 1px solid var(--border); color: var(--text-dim); padding: 8px 16px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.modal .btn-cancel:hover { border-color: var(--accent); color: var(--text); }
.modal .btn-delete { background: var(--error); color: #fff; border: none; padding: 8px 16px; border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 600; }
.modal .btn-delete:hover { opacity: 0.9; }

/* === Mobile sidebar toggle === */
.sidebar-toggle { display: none; background: none; border: 1px solid var(--border); color: var(--text-dim); padding: 6px 10px; border-radius: 6px; font-size: 14px; cursor: pointer; }
.sidebar-toggle:hover { border-color: var(--accent); color: var(--accent); }

/* === Light Theme === */
[data-theme="light"] {
    --bg: #f8f9fa; --surface: #ffffff; --text: #1a1b26;
    --text-dim: #6c757d; --accent: #4f46e5; --border: #dee2e6;
    --success: #198754; --error: #dc3545; --warn: #ffc107;
    --purple: #7c3aed; --cyan: #0d9488; --orange: #ea580c;
    --editor-bg: #f8f9fa; --preview-bg: #f0f1f3;
}

/* === Responsive === */
@media (max-width: 768px) {
    .sidebar { position: fixed; left: -300px; top: 48px; bottom: 0; z-index: 200; transition: left 0.25s ease; width: 280px; }
    .sidebar.open { left: 0; }
    .sidebar-backdrop { display: none; position: fixed; inset: 0; top: 48px; background: rgba(0,0,0,0.4); z-index: 199; }
    .sidebar-backdrop.visible { display: block; }
    .sidebar-toggle { display: flex; }
    .editor-split { flex-direction: column; }
    .preview-pane { border-left: none; border-top: 1px solid var(--border); }
    .toolbar { gap: 1px; padding: 4px 8px; }
    .toolbar button { padding: 4px 5px; min-width: 26px; height: 26px; font-size: 12px; }
}

@media (max-width: 480px) {
    .title-bar input { font-size: 16px; }
    .editor-pane textarea { font-size: 13px; padding: 12px; }
    .preview-pane { padding: 12px; }
}

/* Touch devices */
@media (hover: none) and (pointer: coarse) {
    .toolbar button { min-width: 36px; min-height: 36px; }
    .note-item { padding: 12px; min-height: 44px; }
    .sidebar-header .btn-new { min-height: 44px; }
}
