* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { min-height: 100vh; }


:root {
  --bg-primary: #111318;
  --bg-secondary: #1A1C23;
  --bg-tertiary: #09090C;
  --bg-hover: #3C4253;
  --bg-active: #224EBF;

  --text-primary: #D6DCEA;
  --text-secondary: #BCC5DC;
  --text-muted: #A1AECE;

  --accent: #224EBF;
  --accent-hover: #224EBF;

  --border: #111318;
  --border-light: #224EBF;
  --input-bg: #22262F;

  --radius: 8px;
  --shadow: 0 10px 30px rgba(0,0,0,0.25);

  color-scheme: dark;
}

html[data-theme="light"] {
  --bg-primary: #F3F4F6;
  --bg-secondary: #ffffff;
  --bg-tertiary: #E7E9EE;
  --bg-hover: #D0D3DD;
  --bg-active: #224EBF;

  --text-primary: #0E111B;
  --text-secondary: #151A29;
  --text-muted: #1B2336;

  --accent: #224EBF;
  --accent-hover: #5167A0;

  --border: #F3F4F6;
  --border-light: #224EBF;
  --input-bg: #DCDEE5;

  color-scheme: light;
}

body {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
}

/* TOPBAR */
.topbar {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* SEARCH */
.search-wrap { position: relative; width: min(520px, 52vw); }
.search-container { position: relative; width: 100%; }

.search-input {
  width: 100%;
  padding: 10px 36px 10px 40px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
}
.search-input::placeholder { color: var(--text-muted); }
.search-input:focus { border-color: var(--accent); background: var(--bg-tertiary); }

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  opacity: .65;
}
.search-icon img { width: 16px; height: 16px; }

.search-clear-btn {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  width: 28px;
  height: 28px;
  border-radius: 8px;
}
.search-clear-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

/* Dropdown muss sichtbar sein */
.search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  z-index: 9999;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  list-style: none;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.search-results:empty { display: none; }
.search-results li {
  padding: 10px 12px;
  cursor: pointer;
  color: var(--text-primary);
}
.search-results li:hover { background: var(--bg-hover); }

/* BUTTONS */
.icon-button {
  min-width: 44px;
  height: 44px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.icon-button img { width: 18px; height: 18px; opacity: .9; }
.icon-button:hover {
  background: var(--bg-hover);
  border-color: var(--border-light);
  color: var(--text-primary);
}
.icon-button.primary { color: var(--accent); }
.icon-button.primary:hover {
  background: rgba(99,102,241,0.10);
  border-color: rgba(99,102,241,0.35);
  color: var(--accent-hover);
}
.icon-button.danger { border-color: rgba(255,80,80,0.35); }
.icon-button.danger:hover {
  background: rgba(255,80,80,0.08);
  border-color: rgba(255,80,80,0.55);
}

#save-btn { position: relative; }
.save-dot {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: transparent;
  opacity: 0;
}
#save-btn[data-state="dirty"] .save-dot { background: #fbbf24; opacity: 1; }
#save-btn[data-state="saving"] .save-dot { background: #60a5fa; opacity: 1; }
#save-btn[data-state="saved"] .save-dot { background: #34d399; opacity: 1; }
#save-btn[data-state="error"] .save-dot { background: #fb7185; opacity: 1; }

/* APP LAYOUT */
.app-container {
  display: flex;
  height: calc(100vh - 72px);
  width: 100%;
}

/* SIDEBAR */
.sidebar {
  width: 320px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.sidebar.collapsed {
  width: 0;
  border-right: none;
}

/* Tree muss Höhe haben */
.tree-view {
  padding: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

.tree-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px 10px;
  color: var(--accent);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .5px;
  user-select: none;
  cursor: pointer;
}

#tree-root.tree-root {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: auto;
  flex: 1 1 auto;
  min-height: 120px;
  padding-right: 4px;
}

#tree-root::-webkit-scrollbar { width: 6px; }
#tree-root::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 999px; }

/* Tree Items */
.tree-item {
  display: flex;
  align-items: center;
  border-radius: 6px;
  transition: background .15s ease;
  cursor: pointer;
  min-height: 44px;
}
.tree-item:hover { background: var(--bg-hover); }
.drag-over { outline: 1px dashed var(--accent); }
.dragging { opacity: .5; }

.tree-indent {
  width: 24px;
  height: 44px;
  position: relative;
  flex: 0 0 24px;
}
.tree-indent::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  width: 1px;
  height: 100%;
  background: var(--border);
}
.tree-toggle {
  width: 36px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  flex: 0 0 36px;
}
.tree-label {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
}
.tree-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
  font-size: 14px;
}
.tree-icon img { width: 16px; height: 16px; opacity: .9; }

/* CONTENT */
.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.title-input {
  width: 100%;
  flex: 1;
  padding: 8px 12px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  outline: none;
}
.title-input::placeholder { color: var(--text-muted); }
.title-input:focus { border-color: var(--accent); background: var(--bg-tertiary); }

/* TOOLBAR */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.toolbar-group { display: flex; gap: 4px; }

.toolbar-button {
  min-width: 40px;
  height: 40px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
  padding: 0 8px;
}
.toolbar-button:hover {
  background: var(--bg-hover);
  border-color: var(--border-light);
  color: var(--text-primary);
}

/* EDITOR */
.editor-area {
  flex: 1;
  display: flex;
  overflow: hidden;
  padding: 16px;
  gap: 0;
}

.editor-panel,
.preview-panel {
  flex: 1;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  padding: 16px;
}

.editor-textarea {
  width: 100%;
  height: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 14px;
  line-height: 1.6;
  resize: none;
}
.editor-textarea::placeholder { color: var(--text-muted); }

.divider {
  width: 1px;
  background: var(--border);
  margin: 0 12px;
  position: relative;
}
.divider::before {
  content: "";
  position: absolute;
  top: -16px;
  bottom: -16px;
  left: -10px;
  right: -10px;
  cursor: col-resize;
}

/* Preview basics */
/* --- Markdown basics: make emphasis visible again (preview only) --- */
.preview-panel strong,
.preview-panel b {
  font-weight: 700 !important;
}

.preview-panel em,
.preview-panel i {
  font-style: italic !important;
}

.preview-panel s,
.preview-panel del,
.preview-panel strike {
  text-decoration: line-through !important;
}

.preview-panel mark {
  background: rgba(255, 230, 0, 0.35) !important;
  padding: 0 .15em;
  border-radius: 0.2em;
}

.preview-panel h1,
.preview-panel h2,
.preview-panel h3 {
  margin: 16px 0 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.preview-panel p { margin: 8px 0; }
.preview-panel ul, .preview-panel ol { margin: 8px 0 8px 22px; }
.preview-panel li { margin: 4px 0; }
.preview-panel table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  overflow: hidden;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.preview-panel th, .preview-panel td {
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
  text-align: left;
}

@media (max-width: 760px) {
  .editor-area { flex-direction: column; }
  .divider { width: 100%; height: 1px; margin: 12px 0; }
  .divider::before { left: 0; right: 0; top: -10px; bottom: -10px; cursor: row-resize; }
  .search-wrap { width: 100%; }
}


body.share-view #editor-left,
body.share-view #editor-toolbar,
body.share-view #save-btn,
body.share-view #delete-btn,
body.share-view #app-header {
  display: none !important;
}

body.share-view #preview {
  border: none;
  width: 100%;
}
/* Share Note: wirklich nur Preview sichtbar */
body.share-note #sidebar { display:none !important; }
body.share-note #main { width:100% !important; }
body.share-note #main > *:not(#preview) { display:none !important; }

/* Share Folder: nur Sidebar + Preview */
body.share-folder #main > *:not(#preview) { display:none !important; }
body.share-folder #preview { border:none !important; }

/* sicherheitshalber: alles Drag&Drop visuell neutral */
body.share-folder .drag-over,
body.share-folder .dragging { outline:none !important; }
/* Share: Note – nur Preview, ohne Abstände */
body.share-note-view,
body.share-note-view #main {
  margin: 0 !important;
  padding: 0 !important;
}

body.share-note-view #preview {
  margin: 0 !important;
  padding: 0 !important;
  border: none !important;
  background: transparent !important;
}

/* --------------------------------------------------------------------------
   Preview: tables + embeds
---------------------------------------------------------------------------*/
#preview table{ border-collapse:collapse; width:100%; }
#preview th, #preview td{ border:1px solid rgba(127,127,127,.35); padding:6px 8px; vertical-align:top; }
#preview thead th{ background: rgba(127,127,127,.12); }
#preview .embed-ref{ cursor: help; border-bottom: 1px dotted rgba(127,127,127,.6); }

/* --------------------------------------------------------------------------
   Embed autosuggest
---------------------------------------------------------------------------*/
#embed-suggest .item{
  display:flex; gap:8px; align-items:center;
  padding:8px 10px; border-radius:8px;
  cursor:pointer; user-select:none;
  color: var(--text-primary, #e5e7eb);
  font-size: 13px;
}
#embed-suggest .item .meta{
  opacity:.7; font-size:12px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
}
#embed-suggest .item.active{
  background: rgba(99,102,241,.18);
  outline: 1px solid rgba(99,102,241,.45);
}

/* --------------------------------------------------------------------------
   Tree: special rows
---------------------------------------------------------------------------*/
.tree-item.tree-special .tree-label{ opacity: .95; }
.tree-item.tree-special.active{ background: rgba(99,102,241,.14); }
.tree-divider{ height:10px; }

/* --------------------------------------------------------------------------
   Dashboard
---------------------------------------------------------------------------*/
.dash{
  padding: 18px;
  max-width: 1200px;
  margin: 0 auto;
}
.dash-header{
  display:flex; align-items:flex-end; justify-content:space-between;
  gap:12px; margin-bottom: 14px;
}
.dash-title{ font-size: 22px; font-weight: 700; }
.dash-sub{ opacity:.7; font-size: 13px; }
.dash-grid{
  display:grid;
  grid-template-columns: repeat(12, 1fr);
  gap:12px;
}
.dash-card{
  grid-column: span 3;
  background: rgba(127,127,127,.08);
  border: 1px solid rgba(127,127,127,.18);
  border-radius: 14px;
  padding: 14px;
}
.dash-card.big{ grid-column: span 6; }
.dash-kpi-label{ font-size: 12px; opacity:.75; margin-bottom: 8px; }
.dash-kpi-value{ font-size: 24px; font-weight: 700; letter-spacing: .2px; }
.dash-kpi-sub{ margin-top: 6px; font-size: 12px; opacity:.75; }
.dash-list{ margin:0; padding-left: 18px; }
.dash-list li{ margin: 6px 0; }
.mini-bar{
  display:flex; gap:6px; align-items:flex-end;
  height: 90px;
  padding: 8px 2px 2px 2px;
}
.mini-bar .b{
  flex:1 1 0;
  background: rgba(99,102,241,.35);
  border: 1px solid rgba(99,102,241,.55);
  border-radius: 8px;
}
.mini-bar .b:hover{ background: rgba(99,102,241,.45); }

/* --------------------------------------------------------------------------
   Trash
---------------------------------------------------------------------------*/
.trash{
  padding: 18px;
  max-width: 1200px;
  margin: 0 auto;
}
.trash-header{ display:flex; justify-content:space-between; align-items:end; gap:12px; margin-bottom: 10px; }
.trash-title{ font-size: 20px; font-weight: 700; }
.trash-sub{ opacity:.7; font-size: 13px; }
.trash-table{ width:100%; border-collapse: collapse; overflow:hidden; border-radius: 12px; }
.trash-table th, .trash-table td{ border:1px solid rgba(127,127,127,.22); padding: 10px; vertical-align: top; }
.trash-table th{ background: rgba(127,127,127,.10); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; opacity:.85; }
.trash-actions{ display:flex; gap:8px; flex-wrap:wrap; }
.btn-mini{
  appearance:none;
  border:1px solid rgba(127,127,127,.28);
  background: rgba(127,127,127,.10);
  color: inherit;
  border-radius: 10px;
  padding: 7px 10px;
  font-size: 12px;
  cursor:pointer;
}
.btn-mini.primary{ border-color: rgba(99,102,241,.55); background: rgba(99,102,241,.18); }
.btn-mini.danger{ border-color: rgba(239,68,68,.55); background: rgba(239,68,68,.14); }
.btn-mini:hover{ filter: brightness(1.08); }


.tree-item.drag-over{
  outline: 2px dashed rgba(99,102,241,.6);
  background: rgba(99,102,241,.10);
}


/* -----------------------------
   Mobile sticky header + layout
----------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 1000;
}

/* iOS Safari: stabilere Viewport-Höhe */
html, body {
  height: 100%;
}

.app-container {
  min-height: calc(100dvh - 72px);
}
/* preview hidden must win everywhere (desktop + mobile) */
body.preview-hidden #preview {
  display: none !important;
}
body.preview-hidden #editor-resizer {
  display: none !important;
}

@media (max-width: 720px) {
  #app-header .toolbar {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 8px;
  }

  #editor-toolbar.toolbar-actions {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 6px;
  }

  #editor-toolbar .toolbar-group {
    display: inline-flex;
    gap: 8px;
    margin-right: 8px;
  }

  .toolbar-button {
    width: 36px;
    height: 36px;
    padding: 0;
  }

  .toolbar-button img {
    width: 18px;
    height: 18px;
  }

  .toolbar-toggles {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 8px;
  }

}
/* Prevent iOS auto-zoom on focus */
input, textarea, select {
  font-size: 16px !important;
}


/* ============================
   App Shell (Left Tabs + App)
============================ */
.app-shell{
  display: flex;
  min-height: 100dvh;
  background: var(--bg-primary);
}

.app-frame{
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* ============================
   Left Vertical Tabs (like Nexlink)
============================ */
.app-navbar-tabs{
  width: 64px;
  flex: 0 0 64px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  gap: 10px;
}

.tabs-logo{
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  margin-bottom: 8px;
}
.tabs-logo img {
  width: 32px;
  height: 32px;
  margin: 8px;
}

.tabs-btn{
  width: 48px;
  height: 48px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--text-primary);
}

.tabs-btn:hover{
  background: var(--bg-hover);
}

.tabs-btn.active{
  background: var(--bg-active);
  border-color: var(--border-light);
}

.tabs-dot{
  font-size: 18px;
  line-height: 1;
}

.tabs-spacer{
  flex: 1 1 auto;
}

/* ============================
   Dashboard tab hides sidebar/tree
============================ */
body.section-dashboard #sidebar,
body.section-dashboard .sidebar,
body.section-dashboard #tree-root{
  display: none !important;
}

/* Optional: content area full width in dashboard */
body.section-dashboard #app.app-container{
  grid-template-columns: 1fr !important; /* falls du CSS Grid benutzt */
}

/* Ensure topbar sticky still works inside frame */
.topbar{
  position: sticky;
  top: 0;
  z-index: 1000;
}

/* Mobile: tabs slimmer */
@media (max-width: 720px){
  .app-navbar-tabs{
    width: 56px;
    flex-basis: 56px;
  }
  .tabs-btn, .tabs-logo{
    width: 40px;
    height: 40px;
    border-radius: 12px;
  }
}

.app-navbar-tabs{
  width: 56px;
  flex: 0 0 56px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 6px;
  gap: 10px;
}

.app-navbar-tabs .navtab{
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  text-decoration: none;
  background: transparent;
  border: 1px solid transparent;
}

.app-navbar-tabs .navtab:hover{
  background: var(--bg-hover);
}

.app-navbar-tabs .navtab.active{
  background: var(--bg-active);
  border-color: var(--border-light);
}

.app-navbar-tabs .navtab img{
  width: 20px;
  height: 20px;
  display: block;
}

/* eingeklappt: nur etwas schmaler, Icons bleiben */
.app-navbar-tabs.collapsed{
  width: 44px;
  flex-basis: 44px;
  padding: 10px 4px;
}

.app-navbar-tabs.collapsed .navtab{
  width: 36px;
  height: 36px;
  border-radius: 10px;
}

/* Mobile: Tabs bleiben sichtbar, Sidebar kann drüber/darunter kommen */
@media (max-width: 900px){
  .app-navbar-tabs{
    width: 52px;
    flex-basis: 52px;
  }
}
/* --- Left Tabs --- */
.app-navbar-tabs{
  width: 56px;
  flex: 0 0 56px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 6px;
  gap: 10px;
}

/* dein Logo */
.tabs-logo{
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  margin-bottom: 8px;
}
.tabs-logo img {
  width: 32px;
  height: 32px;
  margin: 8px;
}

.tabs-spacer{
  flex: 1 1 auto;
}

/* Tab Buttons */
.app-navbar-tabs .navtab{
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  text-decoration: none;
  background: transparent;
  border: 1px solid transparent;
}

.app-navbar-tabs .navtab:hover{
  background: var(--bg-hover);
}

.app-navbar-tabs .navtab.active{
  background: var(--bg-active);
  border-color: var(--border-light);
}

.app-navbar-tabs .navtab img{
  width: 20px;
  height: 20px;
  display: block;
}

/* ✅ WICHTIG: Wenn Sidebar toggled -> Tabs komplett ausblenden */
.app-navbar-tabs.is-hidden{
  display: none !important;
}
