/* ================================================
   MORTENS NOTER – STYLESHEET
   Supports: dark / light theme via data-theme attr
   ================================================ */

/* ---------- CSS Variables ---------- */
:root {
  --bg:            #1e1e2e;
  --surface:       #181825;
  --surface2:      #24273a;
  --border:        #313244;
  --text:          #cdd6f4;
  --text-muted:    #a6adc8;
  --text-faint:    #585b70;
  --accent:        #89b4fa;
  --accent-hover:  #74c7ec;
  --danger:        #f38ba8;
  --danger-hover:  #eba0ac;
  --success:       #a6e3a1;
  --sidebar-bg:    #11111b;
  --sidebar-sel:   #313244;
  --topbar-bg:     #181825;
  --shadow:        rgba(0,0,0,0.4);
  --radius:        8px;
  --font:          'Segoe UI', system-ui, sans-serif;
  --mono:          'Consolas', 'Fira Code', monospace;
}

[data-theme="light"] {
  --bg:            #f5f5f5;
  --surface:       #ffffff;
  --surface2:      #efefef;
  --border:        #d0d0d0;
  --text:          #1a1a2e;
  --text-muted:    #555577;
  --text-faint:    #aaaacc;
  --accent:        #4f46e5;
  --accent-hover:  #4338ca;
  --danger:        #dc2626;
  --danger-hover:  #b91c1c;
  --success:       #16a34a;
  --sidebar-bg:    #e8e8f0;
  --sidebar-sel:   #d0d0e8;
  --topbar-bg:     #ffffff;
  --shadow:        rgba(0,0,0,0.1);
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
}

ul { list-style: none; }
a { color: var(--accent); text-decoration: none; }

/* ---------- Utilities ---------- */
.hidden { display: none !important; }

/* ---------- Buttons ---------- */
.btn-primary {
  background: var(--accent);
  color: #1e1e2e;
  border: none;
  border-radius: var(--radius);
  padding: 7px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 16px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-secondary:hover { background: var(--border); }

.btn-danger {
  background: var(--danger);
  color: #1e1e2e;
  border: none;
  border-radius: var(--radius);
  padding: 7px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-danger:hover { background: var(--danger-hover); }

.btn-danger-sm {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  padding: 5px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-danger-sm:hover { background: var(--danger); color: #1e1e2e; }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
  line-height: 1;
}
.icon-btn:hover { background: var(--surface2); color: var(--text); }

/* ================================================
   LOGIN PAGE
   ================================================ */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 48px 40px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  box-shadow: 0 8px 32px var(--shadow);
}

.login-logo { font-size: 48px; margin-bottom: 12px; }
.login-title { font-size: 24px; font-weight: 700; margin-bottom: 32px; color: var(--text); }

.login-form { text-align: left; }
.login-label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 6px; font-weight: 500; }

.login-input {
  display: block;
  width: 100%;
  padding: 10px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s;
  margin-bottom: 8px;
}
.login-input:focus { border-color: var(--accent); }

.login-error {
  color: var(--danger);
  font-size: 13px;
  margin-bottom: 12px;
  padding: 8px 12px;
  background: rgba(243,139,168,0.1);
  border-radius: 6px;
}

.login-btn { width: 100%; padding: 11px; font-size: 15px; margin-top: 8px; }

/* ================================================
   APP LAYOUT
   ================================================ */
.app-body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Top Bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  height: 52px;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 100;
}

.topbar-sidebar-toggle { font-size: 20px; }
.topbar-title { font-weight: 700; font-size: 16px; white-space: nowrap; }

.topbar-search {
  display: flex;
  align-items: center;
  flex: 1;
  max-width: 400px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2px 6px;
}

.search-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 14px;
  padding: 4px 6px;
}
.search-input::placeholder { color: var(--text-faint); }

.topbar-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }

/* ---------- Layout ---------- */
.layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 220px;
  min-width: 220px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.2s, min-width 0.2s;
}

.sidebar.collapsed { width: 0; min-width: 0; border-right: none; }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 10px;
  flex-shrink: 0;
}

.sidebar-heading { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-faint); }

.topics-list { flex: 1; overflow-y: auto; padding: 4px 8px 8px; }

.topic-item {
  display: flex;
  align-items: center;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.12s;
  gap: 6px;
  position: relative;
}
.topic-item:hover { background: var(--sidebar-sel); }
.topic-item.active { background: var(--sidebar-sel); color: var(--accent); }

.topic-item-name {
  flex: 1;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topic-actions { display: none; gap: 2px; }
.topic-item:hover .topic-actions { display: flex; }

.topic-action-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  padding: 2px 4px;
  border-radius: 4px;
  color: var(--text-faint);
  transition: color 0.12s;
}
.topic-action-btn:hover { color: var(--text); }

/* ---------- Notes Panel ---------- */
.notes-panel {
  width: 280px;
  min-width: 280px;
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.notes-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 16px 16px 12px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  gap: 10px;
}

.notes-topic-name { font-size: 16px; font-weight: 700; }
.notes-topic-desc { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.notes-list { flex: 1; overflow-y: auto; padding: 8px; }

.note-item {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s;
  margin-bottom: 4px;
  border: 1px solid transparent;
}
.note-item:hover { background: var(--surface2); }
.note-item.active { background: var(--surface2); border-color: var(--accent); }

.note-item-title { font-size: 14px; font-weight: 600; margin-bottom: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-item-meta { font-size: 11px; color: var(--text-faint); display: flex; justify-content: space-between; align-items: center; }

.note-delete-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-faint);
  font-size: 14px;
  padding: 0 2px;
  opacity: 0;
  transition: opacity 0.12s, color 0.12s;
}
.note-item:hover .note-delete-btn { opacity: 1; }
.note-delete-btn:hover { color: var(--danger); }

/* ---------- Empty States ---------- */
.empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
  color: var(--text-faint);
  font-size: 14px;
  line-height: 1.8;
}

/* ---------- Editor Panel ---------- */
.editor-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.save-status { font-size: 12px; color: var(--success); margin-left: 8px; }

.note-title-input {
  width: 100%;
  padding: 14px 20px;
  font-size: 20px;
  font-weight: 700;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  outline: none;
  flex-shrink: 0;
}
.note-title-input::placeholder { color: var(--text-faint); }

/* ---------- Editor Tabs ---------- */
.editor-tabs {
  display: flex;
  gap: 4px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.tab-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.12s, color 0.12s;
}
.tab-btn:hover { background: var(--surface2); color: var(--text); }
.tab-btn.active { background: var(--surface2); color: var(--accent); }

.tab-pane { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-height: 0; }
.tab-pane.hidden { display: none; }

.editor-textarea {
  flex: 1;
  width: 100%;
  padding: 20px;
  background: var(--bg);
  color: var(--text);
  border: none;
  outline: none;
  resize: none;
  font-size: 15px;
  line-height: 1.75;
  font-family: var(--font);
}

.code-textarea {
  font-family: var(--mono);
  font-size: 14px;
  background: var(--surface);
  tab-size: 2;
}

/* ---------- Markdown Preview ---------- */
.preview-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
  color: var(--text);
  line-height: 1.75;
}

.preview-content h1 { font-size: 28px; font-weight: 700; margin: 0 0 16px; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.preview-content h2 { font-size: 22px; font-weight: 700; margin: 24px 0 12px; }
.preview-content h3 { font-size: 18px; font-weight: 600; margin: 20px 0 10px; }
.preview-content p { margin-bottom: 14px; }
.preview-content ul, .preview-content ol { padding-left: 24px; margin-bottom: 14px; }
.preview-content li { margin-bottom: 4px; }
.preview-content code {
  font-family: var(--mono);
  font-size: 13px;
  background: var(--surface2);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--accent);
}
.preview-content pre {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  overflow-x: auto;
  margin-bottom: 16px;
}
.preview-content pre code { background: none; padding: 0; color: var(--text); }
.preview-content blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 14px;
  color: var(--text-muted);
  margin-bottom: 14px;
}
.preview-content strong { font-weight: 700; }
.preview-content em { font-style: italic; }
.preview-content hr { border: none; border-top: 1px solid var(--border); margin: 24px 0; }
.preview-content a { color: var(--accent); text-decoration: underline; }

/* ---------- Search Panel ---------- */
#searchPanel { display: flex; flex-direction: column; height: 100%; }
#searchPanel.hidden { display: none !important; }

.search-note-topic {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 2px;
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 16px 48px var(--shadow);
}

.modal-heading { font-size: 18px; font-weight: 700; margin-bottom: 18px; }
.modal-label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 5px; font-weight: 500; }
.modal-text { color: var(--text-muted); margin-bottom: 20px; font-size: 14px; }

.modal-input {
  display: block;
  width: 100%;
  padding: 9px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  margin-bottom: 14px;
  transition: border-color 0.15s;
}
.modal-input:focus { border-color: var(--accent); }

.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }

/* ---------- Scrollbars ---------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* ---------- Responsive ---------- */
@media (max-width: 700px) {
  /* Sidebar: glider ind som overlay fra venstre */
  .sidebar {
    position: fixed;
    top: 52px;
    left: 0;
    bottom: 0;
    z-index: 200;
    width: 260px;
    min-width: 260px;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    border-right: 1px solid var(--border);
  }
  .sidebar.collapsed {
    width: 260px;
    min-width: 260px;
    border-right: 1px solid var(--border);
    transform: translateX(-100%);
  }
  .sidebar:not(.collapsed) {
    transform: translateX(0);
  }

  /* Mørkt overlay bag åben sidebar */
  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 52px 0 0 0;
    background: rgba(0,0,0,0.5);
    z-index: 199;
  }
  .sidebar-backdrop.visible { display: block; }

  /* Notes-panel fylder hele bredden */
  .notes-panel { min-width: 0; width: 100%; border-right: none; }

  /* Editor fylder hele skærmen */
  .editor-panel { display: none; }
  .editor-panel.mobile-show {
    display: flex;
    position: fixed;
    inset: 52px 0 0 0;
    z-index: 50;
  }

  /* Topbar: søgefelt skjult som standard, kun ikon synligt */
  .topbar-title { display: none; }
  .topbar-search {
    flex: 0;
    max-width: none;
    background: none;
    border: none;
    padding: 0;
  }
  .search-input { display: none; }

  /* Søge-tilstand: søgefelt fylder topbaren, alt andet gemmes */
  .topbar.search-active .topbar-search {
    flex: 1;
    background: var(--surface2);
    border: 1px solid var(--border);
    padding: 2px 6px;
  }
  .topbar.search-active .search-input { display: block; }
  .topbar.search-active .topbar-actions { display: none; }
  .topbar.search-active .topbar-sidebar-toggle { display: none; }

  /* Emne-handlinger altid synlige (ingen hover på touch) */
  .topic-actions { display: flex; }

  /* Slet-knap altid synlig */
  .note-delete-btn { opacity: 1; }

  /* Større touch-targets */
  .topic-item { padding: 12px 10px; min-height: 44px; }
  .note-item { padding: 12px; }
  .icon-btn { padding: 8px 10px; min-height: 44px; }
  .tab-btn { padding: 10px 14px; }

  /* Modal */
  .modal { margin: 0 16px; padding: 20px; max-width: none; }
}
