/* Schnell-Notiz — eigenes Design: Notizzettel-Gelb auf neutralem Grund */
:root {
  color-scheme: light;
  --accent: #facc15;
  --accent-strong: #eab308;
  --accent-soft: #fef9c3;
  --accent-ink: #713f12;

  --bg: #f4f4f5;
  --bg-elev: #ffffff;
  --bg-sunken: #e9e9ec;
  --card: #fffdf2;
  --card-hover: #fefce8;
  --border: #e0e0e4;
  --border-strong: #cfcfd6;

  --text: #18181b;
  --text-soft: #52525b;
  --text-faint: #8b8b94;

  --danger: #dc2626;
  --danger-soft: #fee2e2;

  --shadow: 0 1px 2px rgba(24, 24, 27, 0.06), 0 6px 18px rgba(24, 24, 27, 0.07);
  --shadow-card: 0 1px 2px rgba(24, 24, 27, 0.05);

  --radius: 14px;
  --radius-sm: 10px;
  --tap: 44px;

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

[data-theme="dark"] {
  color-scheme: dark;
  /* warmes Bernstein im Darkmode */
  --accent: #f59e0b;
  --accent-strong: #fbbf24;
  --accent-soft: #422006;
  --accent-ink: #fde68a;

  --bg: #1a1614;
  --bg-elev: #241e1a;
  --bg-sunken: #16120f;
  --card: #2a221b;
  --card-hover: #332921;
  --border: #3a2f25;
  --border-strong: #4a3c2e;

  --text: #f5ede2;
  --text-soft: #c9bba9;
  --text-faint: #9c8d79;

  --danger: #f87171;
  --danger-soft: #3a1d1d;

  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.45);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  overflow-x: hidden;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  z-index: 200;
  font-weight: 600;
}
.skip-link:focus { left: calc(8px + var(--safe-l)); top: calc(8px + var(--safe-t)); }

/* ===== Header ===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + var(--safe-t)) calc(16px + var(--safe-r)) 10px calc(16px + var(--safe-l));
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: var(--accent-ink);
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.35);
  color: var(--accent-ink);
  flex: none;
}
[data-theme="dark"] .brand-mark { background: rgba(0, 0, 0, 0.25); }
.brand h1 {
  font-size: 1.18rem;
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-actions { display: flex; gap: 8px; flex: none; }

.icon-btn {
  display: grid;
  place-items: center;
  min-width: var(--tap);
  min-height: var(--tap);
  width: var(--tap);
  height: var(--tap);
  border: none;
  border-radius: 12px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 1.2rem;
  transition: background 0.15s ease, transform 0.1s ease;
}
.app-header .icon-btn:hover { background: rgba(255, 255, 255, 0.28); }
[data-theme="dark"] .app-header .icon-btn:hover { background: rgba(0, 0, 0, 0.25); }
.icon-btn:active { transform: scale(0.94); }

/* ===== Layout ===== */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 0;
  min-height: 0;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
}

/* ===== Sidebar ===== */
.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--border);
  background: var(--bg-elev);
  padding-left: var(--safe-l);
}
.toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-elev);
  z-index: 10;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: var(--shadow-card);
}
.btn-primary:hover { background: var(--accent-strong); }
.btn-primary span[aria-hidden] { font-size: 1.3rem; line-height: 1; margin-top: -2px; }

.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.search-icon {
  position: absolute;
  left: 12px;
  display: grid;
  place-items: center;
  color: var(--text-faint);
  pointer-events: none;
}
#search {
  width: 100%;
  min-height: var(--tap);
  padding: 0 38px 0 36px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-sunken);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}
#search::placeholder { color: var(--text-faint); }
#search:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.clear-search {
  position: absolute;
  right: 6px;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-soft);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}
.clear-search:hover { background: var(--bg-sunken); color: var(--text); }

.note-list {
  list-style: none;
  margin: 0;
  padding: 10px;
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.note-card {
  position: relative;
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  padding: 12px 14px;
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.08s ease;
  overflow: hidden;
}
.note-card:hover { background: var(--card-hover); border-color: var(--border-strong); }
.note-card:active { transform: scale(0.99); }
.note-card.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
  background: var(--card-hover);
}
.note-card.is-active::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--accent);
}

.note-card-head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}
.note-pin {
  flex: none;
  color: var(--accent-strong);
  display: inline-flex;
}
[data-theme="dark"] .note-pin { color: var(--accent); }
.note-title {
  font-weight: 600;
  font-size: 0.98rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}
.note-title.is-untitled { color: var(--text-faint); font-weight: 500; font-style: italic; }
.note-preview {
  font-size: 0.86rem;
  color: var(--text-soft);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-clamp: 2;
  overflow: hidden;
  word-break: break-word;
  min-height: 1.1em;
}
.note-meta {
  margin-top: 6px;
  font-size: 0.72rem;
  color: var(--text-faint);
}
mark.hl {
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 3px;
  padding: 0 1px;
}

.empty-state {
  padding: 32px 20px;
  text-align: center;
  color: var(--text-faint);
  font-size: 0.95rem;
}

/* ===== Editor ===== */
.editor-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
  padding-right: var(--safe-r);
}
.editor-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
}
.editor-pane .icon-btn { color: var(--text-soft); }
.editor-pane .icon-btn:hover { background: var(--bg-sunken); color: var(--text); }
.pin-btn[aria-pressed="true"] {
  color: var(--accent-strong);
  background: var(--accent-soft);
}
[data-theme="dark"] .pin-btn[aria-pressed="true"] { color: var(--accent); }
.delete-btn:hover { color: var(--danger); background: var(--danger-soft); }

.saved-flag {
  flex: 1;
  font-size: 0.82rem;
  color: var(--text-faint);
  text-align: center;
  transition: opacity 0.3s ease, color 0.3s ease;
}
.saved-flag.is-saving { color: var(--accent-strong); }
[data-theme="dark"] .saved-flag.is-saving { color: var(--accent); }

.editor {
  flex: 1;
  width: 100%;
  border: none;
  resize: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 1.05rem;
  line-height: 1.65;
  padding: 18px 18px 8px;
  min-height: 0;
}
.editor:focus-visible { outline: none; }
.editor::placeholder { color: var(--text-faint); }

.editor-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 16px calc(10px + var(--safe-b));
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
  font-size: 0.78rem;
  color: var(--text-faint);
  flex-wrap: wrap;
}
.counter { font-variant-numeric: tabular-nums; }

.editor-pane.is-empty .editor,
.editor-pane.is-empty .editor-bar,
.editor-pane.is-empty .editor-footer {
  opacity: 0.45;
  pointer-events: none;
}
.editor-pane.is-empty .editor::placeholder { color: var(--text-faint); }

/* ===== Toasts ===== */
.toast-host {
  position: fixed;
  left: 50%;
  bottom: calc(18px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(440px, calc(100vw - 24px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--text);
  color: var(--bg-elev);
  padding: 12px 14px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 0.92rem;
  animation: toast-in 0.22s ease;
}
[data-theme="dark"] .toast { background: #f5ede2; color: #1a1614; }
.toast .toast-msg { flex: 1; min-width: 0; }
.toast .toast-action {
  flex: none;
  border: none;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  padding: 7px 12px;
  border-radius: 9px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.88rem;
}
.toast .toast-action:hover { background: var(--accent-strong); }
.toast.is-leaving { animation: toast-out 0.2s ease forwards; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateY(12px); }
}

/* ===== Focus visibility ===== */
:focus-visible {
  outline: 3px solid var(--accent-strong);
  outline-offset: 2px;
  border-radius: 6px;
}
[data-theme="dark"] :focus-visible { outline-color: var(--accent); }

/* ===== Mobile ===== */
@media (max-width: 760px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  /* Mobile: zeige entweder Liste ODER Editor */
  body[data-view="list"] .editor-pane { display: none; }
  body[data-view="editor"] .sidebar { display: none; }
  body[data-view="editor"] .editor-bar { position: relative; }
  /* Zurück-Button im Editor */
  .back-btn { display: none; }
  body[data-view="editor"] .back-btn { display: grid; }
}
@media (min-width: 761px) {
  .back-btn { display: none !important; }
}

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