:root {
  --green: #2dbe60;
  --green-dark: #239e4f;
  --bg: #f7f8f9;
  --panel: #ffffff;
  --border: #e3e6e8;
  --text: #1f2933;
  --muted: #7b8794;
  --hover: #eef6f0;
  --active: #e0f1e6;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  height: 100vh;
  overflow: hidden;
}
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; }

/* ---------- Auth ---------- */
.auth-body {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100vh; background: linear-gradient(135deg, #2dbe60, #1a8c47);
}
.auth-card {
  background: #fff; padding: 40px; border-radius: 14px; width: 360px;
  box-shadow: 0 12px 40px rgba(0,0,0,.2);
}
.logo { font-size: 28px; text-align: center; margin-bottom: 6px; }
.auth-sub { text-align: center; color: var(--muted); margin-bottom: 22px; }
.auth-card input {
  width: 100%; padding: 12px 14px; margin-bottom: 12px;
  border: 1px solid var(--border); border-radius: 8px; font-size: 15px;
}
.auth-card input:focus { outline: none; border-color: var(--green); }
.auth-error {
  background: #fde8e8; color: #c0392b; padding: 10px;
  border-radius: 8px; margin-bottom: 12px; font-size: 14px;
}
.auth-toggle { text-align: center; margin-top: 16px; font-size: 14px; color: var(--muted); }
.auth-toggle a { color: var(--green); text-decoration: none; font-weight: 600; }
.auth-copyright { text-align: center; color: rgba(255,255,255,.75); font-size: 12px; margin-top: 18px; }

.btn-primary {
  background: var(--green); color: #fff; border: none;
  padding: 12px 16px; border-radius: 8px; font-size: 15px; font-weight: 600;
  transition: background .15s;
}
.btn-primary:hover { background: var(--green-dark); }
.btn-primary.full { width: 100%; margin-bottom: 16px; }

/* ---------- App-Layout ---------- */
.app { display: grid; grid-template-columns: 240px 320px 1fr; height: 100vh; }

.sidebar {
  background: #2f3640; color: #cdd3da; padding: 16px;
  display: flex; flex-direction: column; overflow-y: auto;
}
.sidebar-footer {
  margin-top: auto; padding-top: 16px; font-size: 11px;
  color: #7b8794; text-align: center;
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px;
}
.logo-sm { font-weight: 700; font-size: 16px; color: #fff; }
.icon-btn {
  background: transparent; border: none; color: #cdd3da;
  font-size: 16px; width: 28px; height: 28px; border-radius: 6px;
}
.icon-btn:hover { background: rgba(255,255,255,.1); }

.nav { margin-bottom: 8px; }
.nav-item, .list a {
  display: block; padding: 8px 10px; border-radius: 6px;
  color: #cdd3da; text-decoration: none; font-size: 14px; margin-bottom: 2px;
}
.nav-item:hover, .list a:hover { background: rgba(255,255,255,.08); }
.nav-item.active, .list a.active { background: var(--green); color: #fff; }

.section-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  color: #7b8794; margin: 16px 0 6px;
}
.list a { display: flex; justify-content: space-between; }
.list .count { color: #7b8794; font-size: 12px; }

.import-btn {
  display: block; text-align: center; margin-top: 10px;
  padding: 8px; font-size: 13px; color: #cdd3da;
  border: 1px dashed #4b5563; border-radius: 6px; cursor: pointer;
}
.import-btn:hover { background: rgba(255,255,255,.08); border-color: var(--green); }

/* ---------- Notizliste ---------- */
.note-list-pane {
  background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
}
.search-bar { padding: 12px; border-bottom: 1px solid var(--border); }
.search-bar input {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 14px;
}
.search-bar input:focus { outline: none; border-color: var(--green); }
.note-list { overflow-y: auto; flex: 1; }
.note-card {
  padding: 14px 16px; border-bottom: 1px solid var(--border); cursor: pointer;
}
.note-card:hover { background: var(--hover); }
.note-card.active { background: var(--active); border-left: 3px solid var(--green); }
.note-card h3 {
  font-size: 15px; margin-bottom: 4px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.note-card p { font-size: 13px; color: var(--muted); line-height: 1.4; max-height: 36px; overflow: hidden; }
.note-card .meta { font-size: 11px; color: var(--muted); margin-top: 6px; }
.note-card .chip {
  display: inline-block; background: var(--active); color: var(--green-dark);
  padding: 1px 7px; border-radius: 10px; font-size: 11px; margin-right: 4px;
}

/* ---------- Editor ---------- */
.editor-pane { background: var(--panel); overflow-y: auto; }
.editor-empty {
  height: 100%; display: flex; align-items: center; justify-content: center;
  color: var(--muted);
}
.editor { padding: 24px 32px; display: flex; flex-direction: column; height: 100%; }
.editor[hidden] { display: none; }
.note-preview[hidden], #shareActive[hidden] { display: none; }
.note-title-input {
  font-size: 24px; font-weight: 700; border: none; outline: none;
  margin-bottom: 12px; width: 100%;
}
.editor-meta { display: flex; gap: 10px; margin-bottom: 12px; }
.meta-select, .meta-tags {
  padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px;
}
.meta-tags { flex: 1; }
.editor-toolbar {
  display: flex; align-items: center; gap: 10px;
  padding-bottom: 12px; border-bottom: 1px solid var(--border); margin-bottom: 12px;
}
.attach-btn {
  background: var(--bg); border: 1px solid var(--border); padding: 6px 12px;
  border-radius: 6px; font-size: 13px; cursor: pointer;
}
.attach-btn:hover { background: var(--hover); }
.spacer { flex: 1; }
.save-state { font-size: 12px; color: var(--muted); }
.note-content {
  flex: 1; border: none; outline: none; font-size: 15px;
  line-height: 1.6; resize: none; min-height: 200px;
}
.attachments { display: flex; flex-wrap: wrap; gap: 10px; padding-top: 12px; }
.att-item {
  display: flex; align-items: center; gap: 8px; background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; font-size: 13px;
}
.att-item img { max-height: 40px; border-radius: 4px; }
.att-item a { color: var(--green-dark); text-decoration: none; }
.att-item .del { color: #c0392b; cursor: pointer; font-weight: 700; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar, .note-list-pane { display: none; }
}

/* ---------- Sortier-Dropdown ---------- */
.search-bar { display: flex; gap: 8px; }
.sort-select {
  border: 1px solid var(--border); border-radius: 8px; font-size: 12px;
  padding: 0 6px; background: var(--panel); color: var(--text); cursor: pointer;
}
body.dark .sort-select option, body.dark .meta-select option,
body.dark .meta-select, body.dark .search-bar input,
body.dark .note-title-input, body.dark .note-content,
body.dark .meta-tags, body.dark .note-content::placeholder {
  background: var(--panel); color: var(--text);
}

/* ---------- Format-Toolbar ---------- */
.format-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px;
  padding: 8px 0; border-bottom: 1px solid var(--border); margin-bottom: 4px;
}
.format-toolbar button {
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 9px; font-size: 13px; cursor: pointer; color: var(--text); min-width: 30px;
}
.format-toolbar button:hover { background: var(--hover); border-color: var(--green); }
.format-toolbar .divider { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }
.preview-toggle { font-weight: 600; }
.preview-toggle.active { background: var(--green) !important; color: #fff; border-color: var(--green) !important; }

/* ---------- Vorschau ---------- */
.note-preview {
  flex: 1; overflow-y: auto; padding: 8px 2px; font-size: 15px; line-height: 1.65;
}
.note-preview h1 { font-size: 26px; margin: 14px 0 8px; }
.note-preview h2 { font-size: 21px; margin: 12px 0 7px; }
.note-preview h3 { font-size: 17px; margin: 10px 0 6px; }
.note-preview p { margin: 8px 0; }
.note-preview ul, .note-preview ol { margin: 8px 0 8px 24px; }
.note-preview code { background: #f4f5f6; padding: 2px 5px; border-radius: 4px; font-size: 13px; }
.note-preview pre { background: #f4f5f6; padding: 12px; border-radius: 8px; overflow: auto; }
.note-preview pre code { background: none; padding: 0; }
.note-preview blockquote { border-left: 3px solid var(--green); margin: 8px 0; padding-left: 14px; color: #555; }
.note-preview table { border-collapse: collapse; margin: 8px 0; }
.note-preview td, .note-preview th { border: 1px solid var(--border); padding: 6px 10px; }
.note-preview img { max-width: 100%; border-radius: 6px; }
.note-preview input[type=checkbox] { margin-right: 7px; transform: scale(1.15); }
.note-preview li.task-item { list-style: none; margin-left: -20px; }

/* ---------- Modals ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal[hidden] { display: none; }
.modal-box {
  background: #fff; border-radius: 12px; padding: 20px; width: 460px;
  max-width: 90vw; max-height: 80vh; overflow-y: auto; box-shadow: 0 18px 50px rgba(0,0,0,.3);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-text { font-size: 13px; color: var(--muted); margin-bottom: 14px; line-height: 1.5; }
.history-list .ver {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; cursor: pointer;
}
.history-list .ver:hover { background: var(--hover); border-color: var(--green); }
.history-list .ver .when { font-size: 12px; color: var(--muted); }
.history-list .ver .prev { font-size: 13px; margin-top: 3px; color: var(--text); }
.share-url { width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; margin-bottom: 10px; }
.link-btn { background: none; border: none; color: #c0392b; cursor: pointer; font-size: 13px; width: 100%; margin-top: 8px; }

/* ---------- Verschachtelte Notizbücher ---------- */
.list a.child { padding-left: 26px; font-size: 13px; opacity: .92; }
.list a.child::before { content: "└ "; color: #6b7682; }

/* ---------- Dark Mode ---------- */
body.dark {
  --bg: #1c2128; --panel: #22272e; --border: #373e47; --text: #e6edf3;
  --muted: #8b949e; --hover: #2d333b; --active: #2d3b30; --sidebar: #161b22;
}
body.dark .note-preview code, body.dark .note-preview pre { background: #2d333b; }
.darkmode-btn {
  display: block; width: 100%; text-align: center; margin-top: 8px; padding: 7px;
  font-size: 12px; color: #cdd3da; border: 1px solid #4b5563; border-radius: 6px;
  background: none; cursor: pointer;
}
.darkmode-btn:hover { background: rgba(255,255,255,.08); }

/* ---------- Settings-Overlay (Evernote-Stil) ---------- */
.settings-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  z-index: 200; display: flex; align-items: center; justify-content: center;
}
.settings-overlay[hidden] { display: none; }
.settings-panel {
  display: grid; grid-template-columns: 220px 1fr;
  width: 90vw; max-width: 960px; height: 80vh;
  background: var(--panel); border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0,0,0,.3); overflow: hidden;
}
.settings-sidebar {
  background: #2f3640; color: #cdd3da; padding: 20px 16px;
  display: flex; flex-direction: column; overflow-y: auto;
}
.settings-sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.settings-title { font-weight: 700; font-size: 15px; color: #fff; }
.settings-close { color: #cdd3da; font-size: 18px; }
.settings-close:hover { color: #fff; }
.settings-nav { display: flex; flex-direction: column; gap: 2px; }
.settings-nav-item {
  display: block; padding: 9px 12px; border-radius: 6px; font-size: 14px;
  color: #cdd3da; text-decoration: none; transition: background .12s;
}
.settings-nav-item:hover { background: rgba(255,255,255,.08); }
.settings-nav-item.active { background: var(--green); color: #fff; }

.settings-content {
  padding: 28px 36px; overflow-y: auto;
}
.settings-heading {
  font-size: 22px; font-weight: 700; margin-bottom: 24px;
  padding-bottom: 12px; border-bottom: 1px solid var(--border);
}
.settings-card {
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 20px 24px; margin-bottom: 20px;
}
.settings-card h3 {
  font-size: 15px; font-weight: 600; margin-bottom: 14px;
}
.settings-form { display: flex; flex-direction: column; gap: 10px; }
.settings-label {
  font-size: 13px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .3px;
}
.settings-input {
  padding: 10px 14px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; background: var(--panel); color: var(--text); width: 100%;
}
.settings-input:focus { outline: none; border-color: var(--green); }
.settings-desc {
  font-size: 14px; color: var(--muted); line-height: 1.55; margin-bottom: 14px;
}
.settings-desc.small { font-size: 12px; }
.settings-msg {
  padding: 10px 14px; border-radius: 8px; font-size: 13px;
}
.settings-msg.error { background: #fde8e8; color: #c0392b; }
.settings-msg.success { background: #e8fde8; color: #239e4f; }
.btn-secondary {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  padding: 10px 16px; border-radius: 8px; font-size: 14px; font-weight: 500;
  transition: all .15s;
}
.btn-secondary:hover { border-color: var(--green); background: var(--hover); }
.btn-secondary.danger { color: #c0392b; border-color: #e8c0c0; }
.btn-secondary.danger:hover { border-color: #c0392b; background: #fde8e8; }

/* Stat-Cards */
.stat-cards {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px; margin-bottom: 24px;
}
.stat-card {
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 18px 20px; text-align: center;
}
.stat-card .stat-value {
  font-size: 28px; font-weight: 700; color: var(--green); line-height: 1.2;
}
.stat-card .stat-label {
  font-size: 12px; color: var(--muted); text-transform: uppercase;
  letter-spacing: .4px; margin-top: 4px;
}

/* Info-Table */
.info-table {
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  overflow: hidden;
}
.info-row {
  display: flex; padding: 12px 20px; border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.info-row:last-child { border-bottom: none; }
.info-row .info-label {
  width: 140px; flex-shrink: 0; color: var(--muted); font-weight: 500;
}
.info-row .info-value { color: var(--text); }

/* User-Table */
.user-table {
  width: 100%; border-collapse: collapse; font-size: 14px;
}
.user-table th {
  text-align: left; padding: 10px 14px; font-size: 12px;
  text-transform: uppercase; letter-spacing: .3px; color: var(--muted);
  border-bottom: 2px solid var(--border); font-weight: 600;
}
.user-table td {
  padding: 12px 14px; border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.user-table tr:hover td { background: var(--hover); }
.user-table .badge {
  display: inline-block; padding: 2px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 600;
}
.badge-admin { background: #e8f0fe; color: #1a56db; }
.badge-user { background: var(--active); color: var(--green-dark); }
.badge-active { background: #e8fde8; color: #239e4f; }
.badge-blocked { background: #fde8e8; color: #c0392b; }
.user-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.user-actions select {
  padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px;
  font-size: 12px; background: var(--panel); color: var(--text); cursor: pointer;
}
.twofa-qr { display: block; margin: 0 auto 14px; max-width: 200px; }
.backup-codes {
  background: var(--bg); padding: 14px; border-radius: 8px;
  font-size: 14px; line-height: 1.8; margin-bottom: 14px;
}
#twofaSecret { background: var(--bg); padding: 2px 6px; border-radius: 4px; }

/* Dark-Mode fuer Settings */
body.dark .settings-input { background: var(--panel); color: var(--text); }
body.dark .settings-card { background: var(--hover); border-color: var(--border); }
body.dark .stat-card { background: var(--hover); border-color: var(--border); }
body.dark .info-table { background: var(--hover); border-color: var(--border); }
body.dark .settings-msg.error { background: #3d2020; color: #f87171; }
body.dark .settings-msg.success { background: #1a3d1a; color: #6ee7b7; }
body.dark .share-url, body.dark #twofaCode, body.dark #disable2faPw { background: var(--panel); color: var(--text); }
body.dark .backup-codes, body.dark #twofaSecret { background: var(--hover); color: var(--text); }
body.dark .badge-admin { background: #1e3a5f; color: #93c5fd; }
body.dark .badge-user { background: #1a3d1a; color: #6ee7b7; }
body.dark .badge-active { background: #1a3d1a; color: #6ee7b7; }
body.dark .badge-blocked { background: #3d2020; color: #f87171; }
body.dark .user-table th { border-color: var(--border); }
body.dark .user-table td { border-color: var(--border); }
body.dark .user-actions select { background: var(--panel); color: var(--text); border-color: var(--border); }
body.dark .btn-secondary { background: var(--hover); color: var(--text); border-color: var(--border); }
body.dark .btn-secondary.danger { color: #f87171; }
