
/* ===================== TOKENS ===================== */
[data-theme="dark"] {
  --bg:           #0f0f0f;
  --surface:      #1a1a1a;
  --surface2:     #222;
  --border:       #2a2a2a;
  --accent:       #c8f135;
  --accent-dim:   rgba(200,241,53,.12);
  --accent-text:  #0f0f0f;
  --text:         #e8e8e8;
  --muted:        #666;
  --danger:       #ff4d4d;
  --input-bg:     #222;
  --shadow:       rgba(0,0,0,.55);
  --editor-bg:    #0f0f0f;
}
[data-theme="light"] {
  --bg:           #f5f5f0;
  --surface:      #fff;
  --surface2:     #f0f0eb;
  --border:       #ddd;
  --accent:       #2d7a00;
  --accent-dim:   rgba(45,122,0,.1);
  --accent-text:  #fff;
  --text:         #1a1a1a;
  --muted:        #888;
  --danger:       #d93025;
  --input-bg:     #fafaf7;
  --shadow:       rgba(0,0,0,.1);
  --editor-bg:    #fafaf7;
}

/* ===================== RESET ===================== */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font-family: 'JetBrains Mono', monospace;
  display: flex; flex-direction: column; min-height: 100vh;
  transition: background .25s, color .25s;
}

/* ===================== TOPBAR ===================== */
.topbar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0 1.2rem; height: 52px;
  display: flex; align-items: center; gap: .7rem;
  position: sticky; top: 0; z-index: 100;
  transition: background .25s, border-color .25s;
}
.logo {
  font-family: 'JetBrains Mono', sans-serif; font-weight: 800;
  font-size: 1.1rem; color: var(--accent);
  letter-spacing: -.5px; text-decoration: none; white-space: nowrap;
}

/* ---- Título editável ---- */
.note-title-wrap {
  display: flex; align-items: center; gap: 4px;
  border-bottom: 1px solid var(--border);
  padding: 2px 6px 2px 4px; transition: border-color .2s;
}
.note-title-wrap:hover,
.note-title-wrap:focus-within { border-color: var(--accent); }
.note-title-input {
  background: transparent; border: none;
  color: var(--text); font-family: 'JetBrains Mono', monospace;
  font-size: .85rem; width: 190px; outline: none; cursor: default;
}
.note-title-input::placeholder { color: var(--muted); }
.rename-icon-btn {
  background: none; border: none; color: var(--muted);
  cursor: pointer; padding: 2px 5px; font-size: .72rem;
  border-radius: 3px; transition: color .15s; line-height: 1;
}
.rename-icon-btn:hover { color: var(--accent); }

/* ---- Botões ---- */
.btn-accent {
  background: var(--accent); color: var(--accent-text); border: none;
  font-family: 'JetBrains Mono', monospace; font-weight: 600;
  font-size: .78rem; padding: 6px 14px; border-radius: 4px;
  cursor: pointer; transition: opacity .15s; white-space: nowrap;
  text-decoration: none; display: inline-flex; align-items: center; gap: 5px;
}
.btn-accent:hover { opacity: .85; color: var(--accent-text); }

.btn-ghost {
  background: transparent; color: var(--muted); border: 1px solid var(--border);
  font-family: 'JetBrains Mono', monospace; font-size: .78rem;
  padding: 5px 10px; border-radius: 4px; cursor: pointer;
  transition: all .15s; white-space: nowrap; text-decoration: none;
  display: inline-flex; align-items: center; gap: 5px;
}
.btn-ghost:hover { color: var(--text); border-color: var(--muted); }
.btn-danger { color: var(--danger) !important; border-color: var(--danger) !important; }

/* ---- Theme toggle ---- */
.theme-toggle {
  display: flex; background: var(--surface2); border: 1px solid var(--border);
  border-radius: 20px; padding: 3px; gap: 2px;
}
.theme-btn {
  background: none; border: none; border-radius: 16px;
  width: 28px; height: 24px; display: flex; align-items: center;
  justify-content: center; font-size: .8rem; cursor: pointer;
  color: var(--muted); transition: all .2s;
}
.theme-btn.active { background: var(--accent); color: var(--accent-text); }

.save-status { font-size: .72rem; color: var(--muted); white-space: nowrap; }
.save-status.saved  { color: var(--accent); }
.save-status.saving { color: #f0a030; }
.save-status.error  { color: var(--danger); }

/* ===================== LAYOUT ===================== */
.main-layout {
  display: flex; flex: 1; overflow: hidden; height: calc(100vh - 52px);
}

/* ===================== SIDEBAR ===================== */
.sidebar {
  width: 260px; min-width: 260px;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
  transition: width .28s cubic-bezier(.4,0,.2,1),
              min-width .28s cubic-bezier(.4,0,.2,1),
              background .25s, border-color .25s;
}
.sidebar.collapsed {
  width: 0 !important;
  min-width: 0 !important;
  border-right: none;
}
.sidebar.collapsed > * { opacity: 0; pointer-events: none; }

/* Botão de toggle flutuante na borda do editor */
.sidebar-toggle {
  position: absolute;
  left: 0; top: 50%;
  transform: translateY(-50%);
  z-index: 50;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: none;
  color: var(--muted);
  cursor: pointer;
  width: 18px; height: 48px;
  display: flex; align-items: center; justify-content: center;
  font-size: .65rem;
  border-radius: 0 5px 5px 0;
  transition: all .2s;
  opacity: 0;
}
.sidebar-toggle:hover { color: var(--accent); background: var(--surface2); opacity: 1 !important; }
.main-layout:hover .sidebar-toggle { opacity: 1; }
.sidebar-toggle-icon { transition: transform .28s cubic-bezier(.4,0,.2,1); }
.sidebar-toggle-icon.flipped { transform: rotate(180deg); }

.sidebar-header {
  padding: 12px 14px 8px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 6px;
}
.sidebar-title { font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; flex: 1; }

/* Botão collapse dentro do header */
.sidebar-collapse-btn {
  background: none; border: none; color: var(--muted);
  cursor: pointer; padding: 2px 4px; border-radius: 3px;
  font-size: .75rem; line-height: 1; transition: color .15s;
  display: flex; align-items: center;
}
.sidebar-collapse-btn:hover { color: var(--accent); }

/* Sort bar */
.sort-bar {
  display: flex; align-items: center; gap: 4px;
  padding: 6px 14px 6px; border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.sort-label { font-size: .65rem; color: var(--muted); text-transform: uppercase; letter-spacing: .8px; margin-right: 2px; white-space: nowrap; }
.sort-btn {
  background: none; border: 1px solid transparent;
  color: var(--muted); font-family: 'JetBrains Mono', monospace;
  font-size: .68rem; padding: 2px 7px; border-radius: 3px;
  cursor: pointer; transition: all .15s; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 3px;
}
.sort-btn:hover { color: var(--text); border-color: var(--border); }
.sort-btn.active { color: var(--accent); border-color: var(--accent); background: var(--accent-dim); }
.sort-dir-btn {
  background: none; border: none; color: var(--muted);
  font-size: .75rem; cursor: pointer; padding: 2px 4px;
  border-radius: 3px; margin-left: auto; transition: all .15s;
  display: flex; align-items: center;
}
.sort-dir-btn:hover { color: var(--accent); }
.sort-dir-btn i { transition: transform .2s; }
.sort-dir-btn.asc i { transform: rotate(180deg); }

.sidebar-search {
  background: var(--input-bg); border: 1px solid var(--border);
  color: var(--text); font-family: 'JetBrains Mono', monospace;
  font-size: .78rem; padding: 6px 10px; border-radius: 4px;
  outline: none; width: 100%; transition: border-color .2s;
}
.sidebar-search:focus { border-color: var(--accent); }
.sidebar-search::placeholder { color: var(--muted); }

.notes-list { flex: 1; overflow-y: auto; padding: 6px 0; }
.notes-list::-webkit-scrollbar { width: 4px; }
.notes-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.note-item {
  padding: 10px 14px; border-left: 3px solid transparent;
  transition: all .15s; text-decoration: none; display: block;
  position: relative; color: var(--text);
}
.note-item:hover { background: var(--surface2); color: var(--text); }
.note-item.active { background: var(--accent-dim); border-left-color: var(--accent); }

.note-item-title {
  font-size: .82rem; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 26px;
}
.note-item.active .note-item-title { color: var(--accent); }
.note-item-meta { font-size: .68rem; color: var(--muted); margin-top: 2px; display: flex; gap: 8px; }
.note-item-preview { font-size: .72rem; color: var(--muted); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.note-del {
  position: absolute; right: 8px; top: 12px;
  background: transparent; border: none; color: var(--muted);
  font-size: .75rem; opacity: 0; cursor: pointer;
  padding: 2px 5px; border-radius: 3px; transition: all .15s;
}
.note-item:hover .note-del { opacity: 1; }
.note-del:hover { color: var(--danger); background: rgba(255,77,77,.1); }

.empty-sidebar {
  text-align: center; padding: 40px 20px;
  color: var(--muted); font-size: .78rem; line-height: 1.8;
}

/* ===================== EDITOR ===================== */
.editor-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; position: relative; }
.editor-wrapper { flex: 1; overflow: hidden; }

#editor {
  width: 100%; height: 100%; background: var(--editor-bg); color: var(--text);
  border: none; outline: none; resize: none;
  font-family: 'JetBrains Mono', monospace; font-size: .9rem; line-height: 1.75;
  padding: 2rem 3rem; caret-color: var(--accent);
  transition: background .25s, color .25s;
}
#editor::selection { background: var(--accent-dim); }
#editor::placeholder { color: var(--muted); }

.editor-footer {
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 6px 16px; display: flex; gap: 16px;
  font-size: .7rem; color: var(--muted); align-items: center;
  transition: background .25s;
}

.empty-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px; color: var(--muted);
}
.empty-state i { font-size: 3rem; opacity: .2; }
.empty-state p { font-size: .85rem; margin: 0; }

/* ===================== LOGIN SCREEN ===================== */
.login-screen {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.login-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 40px 36px;
  width: 100%; max-width: 360px;
  box-shadow: 0 24px 60px var(--shadow);
}
.login-logo {
  font-family: 'Syne', sans-serif; font-weight: 800;
  font-size: 1.6rem; color: var(--accent); margin-bottom: 6px;
}
.login-subtitle { font-size: .75rem; color: var(--muted); margin-bottom: 28px; }

.login-field {
  width: 100%; background: var(--input-bg);
  border: 1px solid var(--border); border-radius: 5px;
  color: var(--text); font-family: 'JetBrains Mono', monospace;
  font-size: .88rem; padding: 10px 14px; outline: none;
  transition: border-color .2s; margin-bottom: 12px;
}
.login-field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.login-field::placeholder { color: var(--muted); }

.login-btn {
  width: 100%; background: var(--accent); color: var(--accent-text);
  border: none; border-radius: 5px;
  font-family: 'JetBrains Mono', monospace; font-weight: 600;
  font-size: .88rem; padding: 10px; cursor: pointer;
  transition: opacity .15s; margin-top: 4px;
}
.login-btn:hover { opacity: .88; }
.login-btn:disabled { opacity: .5; cursor: not-allowed; }

.login-error {
  font-size: .75rem; color: var(--danger);
  min-height: 18px; margin-top: -4px; margin-bottom: 8px;
}
.login-ip { font-size: .7rem; color: var(--muted); text-align: center; margin-top: 16px; }

/* ===================== MODALS ===================== */
.modal-content {
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); font-family: 'JetBrains Mono', monospace;
  box-shadow: 0 20px 60px var(--shadow);
}
.modal-header, .modal-footer { border-color: var(--border); }
.modal-title { font-size: .95rem; font-family: 'Syne', sans-serif; }
[data-theme="dark"] .btn-close { filter: invert(1) opacity(.4); }

.form-control, .form-control:focus {
  background: var(--input-bg) !important; border-color: var(--border) !important;
  color: var(--text) !important; font-family: 'JetBrains Mono', monospace; font-size: .85rem;
}
.form-control:focus { border-color: var(--accent) !important; box-shadow: 0 0 0 2px var(--accent-dim) !important; }
.form-label { font-size: .78rem; color: var(--muted); }
.modal-error { font-size: .75rem; color: var(--danger); min-height: 18px; margin-top: 5px; }

/* ===================== DELETE MODAL ===================== */
.delete-modal-icon {
  width: 52px; height: 52px; border-radius: 50%;
  background: rgba(255,77,77,.12);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 14px;
  font-size: 1.4rem; color: var(--danger);
}
.delete-modal-name {
  background: var(--surface2); border-radius: 4px;
  padding: 4px 10px; font-size: .82rem;
  color: var(--accent); display: inline-block; margin-top: 4px;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.delete-confirm-input {
  width: 100%; background: var(--input-bg);
  border: 1px solid var(--border); border-radius: 5px;
  color: var(--text); font-family: 'JetBrains Mono', monospace;
  font-size: .85rem; padding: 9px 12px; outline: none;
  transition: border-color .2s; margin-top: 10px;
}
.delete-confirm-input:focus { border-color: var(--danger); box-shadow: 0 0 0 2px rgba(255,77,77,.15); }
.delete-confirm-input::placeholder { color: var(--muted); }

@media (max-width: 768px) {
  .sidebar { width: 0 !important; min-width: 0 !important; border-right: none; }
  #editor { padding: 1rem; }
  .note-title-input { width: 120px; }
}