/* ============================================================
   MONK NOTES — Style Sheet
   © AI-MONK.COM
   ============================================================ */

*, *::before, *::after {
  box-sizing: border-box; margin: 0; padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg:           #0d0d0d;
  --surface:      #161616;
  --surface-2:    #1f1f1f;
  --surface-3:    #272727;
  --border:       #282828;
  --border-2:     #383838;
  --text:         #e8e8e8;
  --text-2:       #909090;
  --text-3:       #525252;
  --accent:       #c9a84c;
  --accent-dim:   rgba(201,168,76,.12);
  --accent-hover: rgba(201,168,76,.20);
  --danger:       #c95b5b;
  --danger-dim:   rgba(201,91,91,.12);
  --success:      #5bc97a;
  --sidebar-w:    280px;
  --toolbar-h:    46px;
  --mob-hdr-h:    52px;
}

html, body {
  height: 100%; background: var(--bg); color: var(--text);
  font-family: -apple-system,'SF Pro Text','Inter','Segoe UI',system-ui,sans-serif;
  font-size: 16px; line-height: 1.6; overflow: hidden; overscroll-behavior: none;
}

::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 2px; }

.hidden { display: none !important; }

/* ── LOGIN ─────────────────────────────────────────────────── */
.login-screen {
  position: fixed; inset: 0; background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 24px; z-index: 200;
}
.login-container {
  display: flex; flex-direction: column; align-items: center;
  gap: 18px; animation: fadeUp .6s ease both;
}
.login-logo svg { width: 88px; height: 88px; filter: drop-shadow(0 0 24px rgba(201,168,76,.25)); }
.login-title { font-size: 2rem; font-weight: 300; letter-spacing: .18em; }
.login-subtitle { font-size: .85rem; color: var(--text-3); letter-spacing: .08em; margin-top: -10px; }
.login-copyright { font-size: .72rem; color: var(--text-3); letter-spacing: .12em; margin-top: 16px; }

/* ── APP SHELL ─────────────────────────────────────────────── */
.app { display: flex; height: 100dvh; height: 100vh; overflow: hidden; }

/* ── SIDEBAR ───────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  transition: transform .28s cubic-bezier(.4,0,.2,1); z-index: 50;
}

.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px; height: 58px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.app-logo { display: flex; align-items: center; gap: 9px; font-size: 1rem; font-weight: 400; letter-spacing: .14em; color: var(--accent); }
.app-logo svg { width: 26px; height: 26px; }

.btn-icon-sm {
  width: 34px; height: 34px; border-radius: 7px; border: 1px solid var(--border);
  background: transparent; color: var(--text-2); cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: all .15s;
}
.btn-icon-sm svg { width: 16px; height: 16px; }
.btn-icon-sm:hover { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

/* Search */
.search-wrap {
  position: relative; padding: 10px 12px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.search-icon { position: absolute; left: 22px; top: 50%; transform: translateY(-50%); width: 14px; height: 14px; color: var(--text-3); pointer-events: none; }
.search-wrap input {
  width: 100%; background: var(--surface-2); border: 1px solid var(--border); border-radius: 7px;
  padding: 7px 10px 7px 30px; color: var(--text); font-size: .83rem; outline: none; transition: border-color .15s;
}
.search-wrap input::placeholder { color: var(--text-3); }
.search-wrap input:focus { border-color: var(--accent); }

/* Nav sections */
.sidebar-nav { padding: 6px 8px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.nav-item {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 8px;
  border: none; background: transparent; color: var(--text-2); font-size: .84rem;
  border-radius: 7px; cursor: pointer; transition: all .12s; text-align: left;
}
.nav-item svg { width: 15px; height: 15px; flex-shrink: 0; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-dim); color: var(--accent); }
.nav-count {
  margin-left: auto; font-size: .7rem; background: var(--surface-3);
  padding: 1px 6px; border-radius: 8px; color: var(--text-3); min-width: 18px; text-align: center;
}
.nav-item.active .nav-count { background: var(--accent-hover); color: var(--accent); }

/* Notebooks section */
.nb-section { border-bottom: 1px solid var(--border); flex-shrink: 0; }
.nb-section-header {
  display: flex; align-items: center; padding: 8px 14px 6px;
  font-size: .72rem; text-transform: uppercase; letter-spacing: .1em; color: var(--text-3);
}
.btn-add {
  margin-left: auto; width: 20px; height: 20px; border: none; background: transparent;
  color: var(--text-3); cursor: pointer; display: flex; align-items: center; justify-content: center;
  border-radius: 4px; transition: all .12s;
}
.btn-add svg { width: 12px; height: 12px; }
.btn-add:hover { background: var(--surface-2); color: var(--accent); }

.notebooks-list { padding: 2px 8px 8px; }
.nb-item {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 7px;
  cursor: pointer; font-size: .84rem; color: var(--text-2); transition: all .12s; border: none; background: transparent; width: 100%; text-align: left;
}
.nb-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.nb-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nb-count { font-size: .7rem; color: var(--text-3); flex-shrink: 0; }
.nb-item:hover { background: var(--surface-2); color: var(--text); }
.nb-item.active { background: var(--accent-dim); color: var(--accent); }
.nb-edit-btn {
  width: 18px; height: 18px; border: none; background: transparent; color: var(--text-3);
  cursor: pointer; display: none; align-items: center; justify-content: center; border-radius: 3px;
  font-size: .7rem; flex-shrink: 0;
}
.nb-item:hover .nb-edit-btn { display: flex; }
.nb-item:hover .nb-count { display: none; }

/* Sort bar */
.sort-bar {
  display: flex; align-items: center; gap: 6px; padding: 6px 12px; border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sort-bar svg { width: 13px; height: 13px; color: var(--text-3); flex-shrink: 0; }
.sort-bar select {
  flex: 1; background: transparent; border: none; color: var(--text-3); font-size: .78rem;
  outline: none; cursor: pointer; appearance: none; -webkit-appearance: none;
}
.sort-bar select option { background: var(--surface-2); color: var(--text); }

/* Notes list */
.notes-list { flex: 1; overflow-y: auto; padding: 4px 0; }
.note-item {
  padding: 10px 16px; cursor: pointer; border-left: 2px solid transparent; transition: all .12s;
}
.note-item:hover { background: var(--surface-2); }
.note-item.active { background: var(--accent-dim); border-left-color: var(--accent); }
.note-item-title {
  font-size: .86rem; font-weight: 500; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 3px;
  display: flex; align-items: center; gap: 5px;
}
.note-item.active .note-item-title { color: var(--accent); }
.note-fav-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); flex-shrink: 0; }
.note-item-meta { display: flex; align-items: center; gap: 6px; }
.note-item-preview { font-size: .74rem; color: var(--text-3); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.note-item-time { font-size: .7rem; color: var(--text-3); white-space: nowrap; flex-shrink: 0; }
.notes-empty { padding: 28px 16px; text-align: center; font-size: .85rem; color: var(--text-3); }

/* Sidebar footer */
.sidebar-footer {
  border-top: 1px solid var(--border); padding: 10px 14px;
  display: flex; align-items: center; gap: 8px; flex-shrink: 0;
}
.user-info { flex: 1; display: flex; align-items: center; }
.user-avatar { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; }
.user-avatar-ph {
  width: 30px; height: 30px; border-radius: 50%; background: var(--accent-dim); color: var(--accent);
  display: flex; align-items: center; justify-content: center; font-size: .83rem; font-weight: 600;
}
.btn-signout {
  width: 30px; height: 30px; border: none; background: transparent; color: var(--text-3);
  cursor: pointer; border-radius: 6px; display: flex; align-items: center; justify-content: center; transition: all .15s;
}
.btn-signout svg { width: 15px; height: 15px; }
.btn-signout:hover { background: var(--danger-dim); color: var(--danger); }

/* ── MAIN ──────────────────────────────────────────────────── */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

.mobile-header {
  display: none; align-items: center; justify-content: space-between;
  padding: 0 12px; height: var(--mob-hdr-h);
  background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.mobile-title { font-size: .95rem; letter-spacing: .14em; color: var(--accent); }
.btn-icon {
  width: 40px; height: 40px; border: none; background: transparent; color: var(--text-2);
  cursor: pointer; display: flex; align-items: center; justify-content: center; border-radius: 8px;
}
.btn-icon svg { width: 20px; height: 20px; }
.btn-icon:hover { background: var(--surface-2); }

/* Empty state */
.empty-state {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 14px; color: var(--text-3); font-size: .9rem;
}
.empty-state svg { width: 80px; height: 80px; }

.btn-primary {
  padding: 10px 28px; background: var(--accent); color: #0d0d0d;
  border: none; border-radius: 8px; font-size: .875rem; font-weight: 700; cursor: pointer;
  letter-spacing: .04em; transition: opacity .15s, transform .15s;
}
.btn-primary:hover { opacity: .88; transform: translateY(-1px); }

/* ── EDITOR ────────────────────────────────────────────────── */
.editor-container {
  flex: 1; display: flex; flex-direction: column; overflow: hidden;
  position: relative; animation: fadeUp .22s ease both;
}

.editor-header { padding: 14px 24px 0; border-bottom: 1px solid var(--border); flex-shrink: 0; }

/* Meta bar (fav + notebook + dates) */
.note-meta-bar {
  display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap;
}
.fav-btn {
  width: 28px; height: 28px; border: none; background: transparent; cursor: pointer;
  display: flex; align-items: center; justify-content: center; border-radius: 6px;
  color: var(--text-3); transition: all .15s; flex-shrink: 0; padding: 0;
}
.fav-btn svg { width: 16px; height: 16px; }
.fav-btn:hover { color: var(--accent); }
.fav-btn.active { color: var(--accent); }
.fav-btn.active svg { fill: var(--accent); }

.notebook-select {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text-2); font-size: .78rem; padding: 4px 8px; outline: none; cursor: pointer;
  transition: border-color .15s; max-width: 160px;
}
.notebook-select:focus { border-color: var(--accent); }
.notebook-select option { background: var(--surface-2); }

.note-dates {
  margin-left: auto; font-size: .72rem; color: var(--text-3);
  display: flex; gap: 12px; flex-wrap: wrap; justify-content: flex-end;
}
.note-dates span { white-space: nowrap; }

.note-title-input {
  display: block; width: 100%; background: transparent; border: none; outline: none;
  font-size: 1.6rem; font-weight: 600; color: var(--text); padding: 0 0 12px;
  letter-spacing: -.01em;
}
.note-title-input::placeholder { color: var(--text-3); }

/* ── TOOLBAR ───────────────────────────────────────────────── */
.toolbar {
  display: flex; align-items: center; gap: 1px; padding: 0 10px;
  height: var(--toolbar-h); border-bottom: 1px solid var(--border);
  background: var(--surface); overflow-x: auto; flex-shrink: 0; scrollbar-width: none;
}
.toolbar::-webkit-scrollbar { display: none; }
.toolbar-group { display: flex; align-items: center; gap: 1px; }
.toolbar-sep { width: 1px; height: 18px; background: var(--border-2); margin: 0 5px; flex-shrink: 0; }
.toolbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-shrink: 0; padding-left: 8px; }

.tool-btn {
  min-width: 30px; height: 30px; border-radius: 6px; border: none; background: transparent;
  color: var(--text-2); cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: .78rem; font-weight: 600; padding: 0 6px; transition: background .12s, color .12s;
  flex-shrink: 0; white-space: nowrap; gap: 2px;
}
.tool-btn svg { width: 14px; height: 14px; }
.tool-btn:hover { background: var(--surface-2); color: var(--text); }
.tool-btn.active { background: var(--accent-dim); color: var(--accent); }
.tool-btn.recording { background: rgba(201,91,91,.15); color: var(--danger); animation: pulse-rec 1.4s ease infinite; }
.danger-btn:hover { background: var(--danger-dim) !important; color: var(--danger) !important; }

.save-indicator { font-size: .73rem; white-space: nowrap; min-width: 50px; text-align: right; }
.save-indicator .saving { color: var(--text-3); }
.save-indicator .saved  { color: var(--success); }
.save-indicator .err    { color: var(--danger); }

/* ── NOTE EDITOR ───────────────────────────────────────────── */
.note-editor {
  flex: 1; padding: 20px 24px; overflow-y: auto; outline: none;
  font-size: 1rem; line-height: 1.85; color: var(--text);
  word-break: break-word; caret-color: var(--accent);
}
.note-editor:empty::before { content: attr(data-placeholder); color: var(--text-3); pointer-events: none; }

.note-editor h1 { font-size: 1.75rem; font-weight: 700; line-height: 1.25; margin: 22px 0 8px; }
.note-editor h2 { font-size: 1.3rem; font-weight: 600; margin: 18px 0 6px; }
.note-editor h3 { font-size: 1.05rem; font-weight: 600; margin: 14px 0 4px; color: var(--accent); }
.note-editor p  { margin-bottom: 6px; }
.note-editor ul, .note-editor ol { padding-left: 22px; margin-bottom: 8px; }
.note-editor li { margin-bottom: 3px; }
.note-editor blockquote { border-left: 3px solid var(--accent); padding: 4px 0 4px 16px; color: var(--text-2); font-style: italic; margin: 12px 0; }
.note-editor hr { border: none; border-top: 1px solid var(--border-2); margin: 18px 0; }
.note-editor code { font-family: 'SF Mono','Fira Code',ui-monospace,monospace; background: var(--surface-2); padding: 1px 6px; border-radius: 4px; font-size: .875em; color: var(--accent); }
.note-editor img.drawn-img { max-width: 100%; border-radius: 8px; margin: 10px 0; display: block; border: 1px solid var(--border); }

/* ── ATTACHMENTS PANEL ─────────────────────────────────────── */
.attachment-panel {
  border-top: 1px solid var(--border); background: var(--surface); flex-shrink: 0; max-height: 200px; overflow-y: auto;
}
.att-header {
  display: flex; align-items: center; gap: 8px; padding: 8px 16px;
  font-size: .78rem; color: var(--text-3); border-bottom: 1px solid var(--border); flex-shrink: 0; position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.att-header svg { width: 13px; height: 13px; flex-shrink: 0; }
.att-header span { font-size: .78rem; }
.btn-add-sm {
  margin-left: auto; padding: 3px 10px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 5px; color: var(--text-2); font-size: .75rem; cursor: pointer; transition: all .12s;
}
.btn-add-sm:hover { border-color: var(--accent); color: var(--accent); }

.att-list { padding: 6px 12px 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.att-item {
  display: flex; align-items: center; gap: 6px; padding: 5px 10px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px;
  font-size: .78rem; color: var(--text-2); max-width: 240px;
}
.att-icon { font-size: .9rem; flex-shrink: 0; }
.att-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att-size { font-size: .68rem; color: var(--text-3); flex-shrink: 0; }
.att-dl-btn, .att-del-btn {
  width: 20px; height: 20px; border: none; background: transparent; cursor: pointer;
  color: var(--text-3); display: flex; align-items: center; justify-content: center;
  border-radius: 4px; flex-shrink: 0; transition: all .12s; font-size: .75rem;
}
.att-dl-btn:hover  { color: var(--accent); }
.att-del-btn:hover { color: var(--danger); }
.att-uploading { opacity: .5; animation: pulse-rec 1s infinite; }

/* ── DRAWING OVERLAY ───────────────────────────────────────── */
.draw-overlay {
  position: absolute; inset: 0; background: rgba(10,10,10,.96);
  z-index: 20; display: flex; flex-direction: column;
}
.draw-overlay canvas { flex: 1; touch-action: none; cursor: crosshair; display: block; }
.draw-controls {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--border); flex-wrap: wrap; flex-shrink: 0;
}
.draw-tools { display: flex; gap: 4px; }
.draw-tool {
  width: 34px; height: 34px; border-radius: 7px; border: 1px solid var(--border);
  background: transparent; color: var(--text-2); cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: all .12s;
}
.draw-tool svg { width: 14px; height: 14px; }
.draw-tool.active, .draw-tool:hover { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
.draw-colors { display: flex; gap: 7px; align-items: center; }
.color-btn { width: 20px; height: 20px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; transition: transform .12s, border-color .12s; }
.color-btn.active { border-color: #fff; transform: scale(1.25); }
.color-btn:hover  { transform: scale(1.15); }
#brush-size { width: 80px; accent-color: var(--accent); cursor: pointer; }
.draw-actions { display: flex; gap: 6px; margin-left: auto; }

/* ── MODALS ────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.75);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px; backdrop-filter: blur(4px);
  animation: fadeIn .15s ease;
}
.modal-box {
  background: var(--surface); border: 1px solid var(--border-2);
  border-radius: 12px; width: 100%; max-width: 380px; padding: 20px;
  display: flex; flex-direction: column; gap: 12px;
  animation: fadeUp .2s ease both;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: .95rem; font-weight: 600; color: var(--text);
}
.modal-close {
  width: 28px; height: 28px; border: none; background: transparent;
  color: var(--text-3); cursor: pointer; font-size: 1rem; border-radius: 6px;
  display: flex; align-items: center; justify-content: center; transition: all .12s;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-input {
  width: 100%; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 7px; padding: 9px 12px; color: var(--text); font-size: .9rem; outline: none;
  transition: border-color .15s;
}
.modal-input:focus { border-color: var(--accent); }
.modal-input::placeholder { color: var(--text-3); }
.modal-label { font-size: .75rem; color: var(--text-3); margin-bottom: -6px; }

/* Notebook color swatches */
.color-swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch {
  width: 24px; height: 24px; border-radius: 50%; border: 2px solid transparent;
  cursor: pointer; transition: transform .12s, border-color .12s;
}
.swatch.active { border-color: #fff; transform: scale(1.2); }
.swatch:hover  { transform: scale(1.1); }

/* Share modal */
.share-tabs {
  display: flex; background: var(--surface-2); border-radius: 8px; padding: 3px; gap: 2px;
}
.share-tab {
  flex: 1; padding: 6px; border: none; background: transparent; color: var(--text-3);
  font-size: .82rem; border-radius: 6px; cursor: pointer; transition: all .12s;
}
.share-tab.active { background: var(--surface-3); color: var(--text); }

.share-result {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.share-result-label { font-size: .78rem; color: var(--text-3); }
.share-url-row { display: flex; gap: 6px; }
.share-url-row .modal-input { flex: 1; font-size: .78rem; }

/* ── BUTTONS ───────────────────────────────────────────────── */
.btn-gold-sm {
  padding: 6px 16px; background: var(--accent); color: #0d0d0d; border: none;
  border-radius: 6px; font-size: .8rem; font-weight: 700; cursor: pointer; transition: opacity .12s;
}
.btn-gold-sm:hover { opacity: .85; }
.btn-ghost-sm {
  padding: 6px 14px; background: transparent; color: var(--text-2);
  border: 1px solid var(--border); border-radius: 6px; font-size: .8rem; cursor: pointer; transition: all .12s;
}
.btn-ghost-sm:hover { background: var(--surface-2); color: var(--text); }

/* ── TOAST ─────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: calc(24px + env(safe-area-inset-bottom)); left: 50%;
  transform: translateX(-50%) translateY(60px); background: var(--surface-2); color: var(--text);
  padding: 9px 20px; border-radius: 20px; font-size: .86rem; border: 1px solid var(--border-2);
  transition: transform .28s cubic-bezier(.4,0,.2,1); z-index: 1000; white-space: nowrap; pointer-events: none;
}
.toast.show  { transform: translateX(-50%) translateY(0); }
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.ok    { border-color: var(--success); color: var(--success); }

/* Sidebar overlay */
.sidebar-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.65); z-index: 49; backdrop-filter: blur(2px); }

/* ── ANIMATIONS ────────────────────────────────────────────── */
@keyframes fadeUp  { from { opacity:0; transform:translateY(12px); } to { opacity:1; transform:translateY(0); } }
@keyframes fadeIn  { from { opacity:0; } to { opacity:1; } }
@keyframes pulse-rec { 0%,100%{opacity:1} 50%{opacity:.5} }

/* ── MOBILE ────────────────────────────────────────────────── */
@media (max-width: 740px) {
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100dvh; height: 100vh;
    transform: translateX(-100%); padding-top: env(safe-area-inset-top);
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-header {
    display: flex; padding-top: env(safe-area-inset-top);
    height: calc(var(--mob-hdr-h) + env(safe-area-inset-top));
  }
  .editor-header { padding: 12px 16px 0; }
  .note-title-input { font-size: 1.3rem; }
  .note-editor { padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
  .modal-box { max-width: 100%; }
}

@media (min-width: 741px) and (max-width: 1024px) { :root { --sidebar-w: 240px; } }
