/* Simple Notes Web – ein einziges Stylesheet, keine externen Ressourcen.
   Helles und dunkles Farbschema ueber prefers-color-scheme, sichtbarer
   Tastaturfokus, Ruecksicht auf prefers-reduced-motion. */

:root {
  --bg: #f6f6f4;
  --bg-raised: #ffffff;
  --bg-sunken: #ececE8;
  --fg: #1c1c1a;
  --fg-muted: #61615c;
  --border: #d9d9d2;
  --accent: #2f6f4e;
  --accent-fg: #ffffff;
  --danger: #a3301f;
  --focus: #1f6feb;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / 8%), 0 8px 24px rgb(0 0 0 / 6%);
  --sidebar-width: 320px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a;
    --bg-raised: #202225;
    --bg-sunken: #121315;
    --fg: #e8e8e5;
    --fg-muted: #9b9b95;
    --border: #34363a;
    --accent: #5fbf8d;
    --accent-fg: #0f2119;
    --danger: #ef7a68;
    --focus: #6aa8ff;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 8px 24px rgb(0 0 0 / 30%);
  }
}

* { box-sizing: border-box; }

/* Muss vor allen display-Regeln stehen: Autoren-Stile wie `.app { display: grid }`
   schlagen sonst das UA-Stylesheet fuer [hidden], und versteckte Bereiche
   (Anmeldung/App, Vorschau, Dialogtexte) blieben sichtbar. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ------------------------------------------------------------- Bausteine */

.btn {
  font: inherit;
  color: var(--fg);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 12px;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease;
}
.btn:hover { background: var(--bg-sunken); }
.btn:disabled { opacity: 0.55; cursor: default; }

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
  font-weight: 600;
}
.btn--primary:hover { filter: brightness(1.06); background: var(--accent); }

.btn--ghost { background: transparent; border-color: transparent; color: var(--fg-muted); }
.btn--ghost:hover { background: var(--bg-sunken); color: var(--fg); }

.btn--icon { padding: 6px 10px; font-size: 13px; }

input[type="text"], input[type="password"], input[type="search"], textarea, select {
  font: inherit;
  color: var(--fg);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  width: 100%;
}

textarea { resize: vertical; }

.hint { color: var(--fg-muted); font-size: 13px; margin: -4px 0 0; }
.error { color: var(--danger); min-height: 1.4em; margin: 0; }
.error:empty { min-height: 0; }

/* ------------------------------------------------------------- Anmeldung */

.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}

.login__card {
  width: min(420px, 100%);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 24px;
  display: grid;
  gap: 14px;
}

.login__title { margin: 0; font-size: 22px; }
.login__sub { margin: -8px 0 4px; color: var(--fg-muted); font-size: 14px; }

.field { display: grid; gap: 5px; font-size: 14px; }
.field > span { color: var(--fg-muted); }

.check { display: flex; align-items: center; gap: 9px; font-size: 14px; }
.check input { width: auto; }

/* --------------------------------------------------------------- Layout */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  height: 100%;
  min-height: 0;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--border);
  background: var(--bg-sunken);
}

.sidebar__top { padding: 12px; display: grid; gap: 10px; }
.sidebar__actions { display: flex; gap: 8px; }
.sidebar__actions .btn { flex: 1; }

.views {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 12px 10px;
  border-bottom: 1px solid var(--border);
}

.views__item {
  font: inherit;
  font-size: 13px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--fg-muted);
  border-radius: 999px;
  padding: 4px 11px;
  cursor: pointer;
}
.views__item[aria-current="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
  font-weight: 600;
}

.notes {
  list-style: none;
  margin: 0;
  padding: 6px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  display: grid;
  gap: 4px;
  align-content: start;
}

.notes__empty { color: var(--fg-muted); font-size: 14px; padding: 16px 10px; }

.notes__item {
  display: flex;
  align-items: stretch;
  gap: 0;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-raised);
  border: 1px solid transparent;
}
.notes__item.is-active { border-color: var(--accent); }

/* Die Notizfarbe kommt als background-color direkt aus dem color-Feld der Notiz. */
.notes__stripe { width: 4px; flex: 0 0 4px; background: transparent; }

.notes__button {
  flex: 1;
  min-width: 0;
  text-align: left;
  font: inherit;
  color: inherit;
  background: transparent;
  border: 0;
  padding: 9px 11px;
  cursor: pointer;
  display: grid;
  gap: 2px;
}
.notes__button:hover { background: var(--bg-sunken); }

.notes__head { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.notes__pin { font-size: 12px; }
.notes__title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.notes__preview,
.notes__meta {
  color: var(--fg-muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.notes__meta { font-size: 12px; }

.sidebar__bottom {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
}
.sync-status { flex: 1; color: var(--fg-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --------------------------------------------------------------- Editor */

.editor {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.editor__empty {
  flex: 1;
  display: grid;
  place-items: center;
  color: var(--fg-muted);
}

.editor__pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.editor__head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px 6px;
}

.editor__back { display: none; }

.editor__title {
  flex: 1;
  font-size: 19px;
  font-weight: 650;
  border: 0;
  background: transparent;
  padding: 4px 2px;
}

.save-status { font-size: 12px; color: var(--fg-muted); white-space: nowrap; }
.save-status[data-kind="saved"] { color: var(--accent); }
.save-status[data-kind="error"],
.save-status[data-kind="conflict"] { color: var(--danger); font-weight: 600; }

.editor__bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 0 16px 10px;
  border-bottom: 1px solid var(--border);
}
.editor__folder { max-width: 220px; flex: 0 1 auto; }
.editor__buttons { display: flex; gap: 6px; margin-left: auto; flex-wrap: wrap; }

.notice {
  margin: 10px 16px 0;
  padding: 8px 11px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--danger) 12%, var(--bg-raised));
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  font-size: 13px;
}

.text-editor {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 10px 16px 16px;
  gap: 8px;
}

.tabs { display: flex; gap: 6px; }
.tab {
  font: inherit;
  font-size: 13px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--fg-muted);
  border-radius: 999px;
  padding: 3px 12px;
  cursor: pointer;
}
.tab[aria-selected="true"] { background: var(--bg-sunken); color: var(--fg); font-weight: 600; }

.text-editor__area {
  flex: 1;
  min-height: 240px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px;
  line-height: 1.6;
}

/* ------------------------------------------------------------- Markdown */

.markdown {
  flex: 1;
  overflow-y: auto;
  min-height: 240px;
  padding: 4px 2px;
}
.markdown > :first-child { margin-top: 0; }
.markdown h1, .markdown h2, .markdown h3,
.markdown h4, .markdown h5, .markdown h6 { line-height: 1.25; margin: 1.2em 0 0.5em; }
.markdown h1 { font-size: 1.55em; }
.markdown h2 { font-size: 1.32em; }
.markdown h3 { font-size: 1.15em; }
.markdown p { margin: 0 0 0.85em; }
.markdown a { color: var(--focus); }
.markdown code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: var(--bg-sunken);
  border-radius: 5px;
  padding: 1px 5px;
}
.markdown pre {
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 13px;
  overflow-x: auto;
}
.markdown pre code { background: none; padding: 0; }
.markdown blockquote {
  margin: 0 0 0.85em;
  padding: 2px 14px;
  border-left: 3px solid var(--border);
  color: var(--fg-muted);
}
.markdown hr { border: 0; border-top: 1px solid var(--border); margin: 1.4em 0; }
.markdown ul, .markdown ol { padding-left: 1.5em; margin: 0 0 0.85em; }
.markdown ul.md-tasklist { list-style: none; padding-left: 0.2em; }
.markdown .md-task { display: flex; align-items: flex-start; gap: 8px; }
.markdown .md-task input { margin-top: 4px; }
.markdown .md-image { max-width: 100%; height: auto; border-radius: var(--radius); }
.markdown__missing { color: var(--fg-muted); font-style: italic; }

/* ----------------------------------------------------------- Checkliste */

.checklist {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 16px 20px;
}

.checklist__list { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 4px; }

.checklist__row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 4px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: var(--bg-raised);
}
.checklist__row.is-dragging { opacity: 0.45; }
.checklist__row.is-drop-target { border-color: var(--accent); }
.checklist__row.is-checked .checklist__text { color: var(--fg-muted); text-decoration: line-through; }

.checklist__handle {
  cursor: grab;
  color: var(--fg-muted);
  padding: 0 3px;
  user-select: none;
  touch-action: none;
}

.checklist__box { width: auto; flex: 0 0 auto; }
.checklist__text { border-color: transparent; background: transparent; }
.checklist__text:focus { border-color: var(--border); background: var(--bg); }
.checklist__remove { color: var(--fg-muted); }
.checklist__add { justify-self: start; }

/* --------------------------------------------------------------- Dialog */

.dialog {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0;
  background: var(--bg-raised);
  color: var(--fg);
  max-width: min(900px, 94vw);
  box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgb(0 0 0 / 45%); }

.dialog__inner { padding: 20px; margin: 0; display: grid; gap: 14px; }
.dialog__inner h2 { margin: 0; font-size: 19px; }
.dialog__lead { margin: 0; color: var(--fg-muted); font-size: 14px; }

.diff { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.diff__side {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 13px;
  min-width: 0;
}
.diff__side h3 { margin: 0 0 6px; font-size: 14px; }
.diff__meta { margin: 0 0 8px; font-size: 12px; color: var(--fg-muted); }
.diff__field { margin: 0 0 6px; }
.diff__body {
  margin: 0;
  max-height: 34vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  background: var(--bg-sunken);
  border-radius: 7px;
  padding: 9px;
}

.dialog__actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
  margin: 0;
  padding: 0;
}

/* ---------------------------------------------------------------- Toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  max-width: min(520px, 92vw);
  background: var(--fg);
  color: var(--bg);
  padding: 10px 15px;
  border-radius: 999px;
  font-size: 14px;
  box-shadow: var(--shadow);
  z-index: 40;
}

/* ---------------------------------------------------------------- Mobil */

@media (max-width: 759px) {
  .app { grid-template-columns: 1fr; }
  .sidebar, .editor { grid-column: 1; grid-row: 1; }

  .app[data-pane="list"] .editor { display: none; }
  .app[data-pane="editor"] .sidebar { display: none; }

  .editor__back { display: inline-block; }
  .diff { grid-template-columns: 1fr; }
  .dialog__actions { justify-content: stretch; }
  .dialog__actions .btn { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
