/* ===== Notizen PWA – Keep-inspiriert, datenschutzorientiert ===== */
:root {
  --bg: #fffbf7;
  --bg-card: #fff;
  --text: #202124;
  --text-secondary: #5f6368;
  --border: #e8eaed;
  --accent: #1a73e8;
  --accent-hover: #1765cc;
  --danger: #d93025;
  --header-height: 56px;
  --safe-top: env(safe-area-inset-top, 0);
  --safe-bottom: env(safe-area-inset-bottom, 0);
  --shadow: 0 1px 3px rgba(60,64,67,.3);
  --shadow-card: 0 1px 2px rgba(60,64,67,.3);
  --radius: 8px;
  --radius-card: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #202124;
    --bg-card: #292a2d;
    --text: #e8eaed;
    --text-secondary: #9aa0a6;
    --border: #3c4043;
    --accent: #8ab4f8;
    --accent-hover: #aecbfa;
    --danger: #f28b82;
  }
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}

#app {
  height: 100%;
  overflow: hidden;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  transition: opacity 0.2s ease;
}

.screen.hidden {
  display: none;
}

/* ----- Unlock (Master-Passwort) ----- */
#unlock-screen {
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-top: calc(var(--safe-top) + 24px);
}

.unlock-card {
  width: 100%;
  max-width: 360px;
  padding: 32px 24px;
  background: var(--bg-card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
}

.unlock-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  background: var(--text-secondary);
  opacity: 0.3;
  border-radius: 50%;
}

.unlock-card h1 {
  margin: 0 0 8px;
  font-size: 1.5rem;
  font-weight: 500;
  text-align: center;
}

.unlock-hint, .unlock-first {
  margin: 0 0 20px;
  font-size: 0.875rem;
  color: var(--text-secondary);
  text-align: center;
  line-height: 1.4;
}

.unlock-first { margin-bottom: 0; }

#unlock-form input {
  width: 100%;
  padding: 12px 16px;
  margin-bottom: 12px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
}

#unlock-form button {
  width: 100%;
  padding: 12px;
  font-size: 1rem;
  font-weight: 500;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
}

#unlock-form button:active {
  background: var(--accent-hover);
}

.note-lock-title { margin-bottom: 16px; text-align: center; }

.text-btn {
  display: block;
  margin: 12px auto 0;
  padding: 8px 16px;
  font-size: 0.875rem;
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
}

/* ----- Header ----- */
.header {
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--header-height);
  padding: 0 8px;
  padding-top: var(--safe-top);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.search-wrap {
  flex: 1;
  min-width: 0;
}

.header input[type="search"] {
  width: 100%;
  height: 44px;
  padding: 0 16px;
  font-size: 1rem;
  border: none;
  border-radius: 24px;
  background: var(--bg-card);
  color: var(--text);
  box-shadow: var(--shadow-card);
}

.header input[type="search"]::placeholder {
  color: var(--text-secondary);
}

.icon-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn::before {
  content: "";
  width: 24px;
  height: 24px;
  background: currentColor;
  mask-size: contain;
  mask-position: center;
  mask-repeat: no-repeat;
  -webkit-mask-size: contain;
  -webkit-mask-position: center;
  -webkit-mask-repeat: no-repeat;
}

#btn-menu::before { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Cpath d='M3 6h18M3 12h18M3 18h18'/%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Cpath d='M3 6h18M3 12h18M3 18h18'/%3E%3C/svg%3E"); }
#btn-sort::before { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Cpath d='M3 6h6M3 12h12M3 18h18'/%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Cpath d='M3 6h6M3 12h12M3 18h18'/%3E%3C/svg%3E"); }
#editor-back::before { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Cpath d='M19 12H5M12 19l-7-7 7-7'/%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Cpath d='M19 12H5M12 19l-7-7 7-7'/%3E%3C/svg%3E"); }
#editor-reminder::before { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 6v6l4 2'/%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 6v6l4 2'/%3E%3C/svg%3E"); }
#editor-pin::before { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Cpath d='M12 2v8M12 22V2M5 12h14l-2 8H7l-2-8z'/%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Cpath d='M12 2v8M12 22V2M5 12h14l-2 8H7l-2-8z'/%3E%3C/svg%3E"); }
#editor-lock::before { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Crect x='3' y='11' width='18' height='11' rx='2'/%3E%3Cpath d='M7 11V7a5 5 0 0110 0v4'/%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Crect x='3' y='11' width='18' height='11' rx='2'/%3E%3Cpath d='M7 11V7a5 5 0 0110 0v4'/%3E%3C/svg%3E"); }
#editor-more::before { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='currentColor'%3E%3Ccircle cx='12' cy='6' r='1.5'/%3E%3Ccircle cx='12' cy='12' r='1.5'/%3E%3Ccircle cx='12' cy='18' r='1.5'/%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='currentColor'%3E%3Ccircle cx='12' cy='6' r='1.5'/%3E%3Ccircle cx='12' cy='12' r='1.5'/%3E%3Ccircle cx='12' cy='18' r='1.5'/%3E%3C/svg%3E"); }

/* ----- Drawer ----- */
.drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 280px;
  max-width: 85vw;
  background: var(--bg-card);
  box-shadow: 2px 0 8px rgba(0,0,0,.15);
  z-index: 100;
  transform: translateX(-100%);
  transition: transform 0.2s ease;
  padding-top: var(--safe-top);
}

.drawer.open {
  transform: translateX(0);
}

.drawer.closed { pointer-events: none; }

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  font-weight: 500;
}

.drawer-list {
  list-style: none;
  margin: 0;
  padding: 8px 0;
}

.drawer-item {
  width: 100%;
  padding: 12px 24px;
  text-align: left;
  font-size: 1rem;
  color: var(--text);
  background: none;
  border: none;
  cursor: pointer;
}

.drawer-item:hover { background: var(--border); }
.drawer-item.active { color: var(--accent); font-weight: 500; }

.drawer-footer {
  margin-top: auto;
  padding: 16px;
  border-top: 1px solid var(--border);
}

.drawer-hint {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin: 8px 0 0;
}

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 99;
  transition: opacity 0.2s;
}

.backdrop.hidden { display: none; opacity: 0; pointer-events: none; }
.backdrop:not(.hidden) { display: block; }

/* ----- Main & Grid ----- */
.main {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  padding-bottom: calc(80px + var(--safe-bottom));
}

.notes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  align-content: start;
}

.note-card {
  position: relative;
  padding: 16px;
  background: var(--bg-card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  cursor: pointer;
  transition: box-shadow 0.15s ease;
  break-inside: avoid;
}

.note-card:active {
  box-shadow: 0 2px 6px rgba(60,64,67,.25);
}

.note-card.pinned { border-left: 4px solid var(--accent); }

.note-card .note-title {
  margin: 0 0 4px;
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.note-card .note-body {
  margin: 0;
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.note-card .note-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.note-card .note-meta .reminder-badge {
  background: var(--border);
  padding: 2px 8px;
  border-radius: 4px;
}

.empty-state {
  text-align: center;
  color: var(--text-secondary);
  padding: 48px 24px;
}

/* ----- FAB ----- */
.fab {
  position: fixed;
  right: 16px;
  bottom: calc(16px + var(--safe-bottom));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(26,115,232,.4);
  z-index: 50;
}

.fab::before { content: "+"; }
.fab:active { transform: scale(0.96); }

/* ----- Editor ----- */
#editor-screen {
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

.editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px;
  flex-shrink: 0;
}

.editor-actions { display: flex; gap: 4px; }

.editor-content {
  flex: 1;
  padding: 0 16px 16px;
  overflow-y: auto;
}

.editor-title {
  width: 100%;
  padding: 8px 0;
  font-size: 1.25rem;
  font-weight: 500;
  border: none;
  background: transparent;
  color: var(--text);
}

.editor-title::placeholder, .editor-body::placeholder {
  color: var(--text-secondary);
}

.editor-body {
  width: 100%;
  min-height: 120px;
  padding: 8px 0;
  font-size: 1rem;
  line-height: 1.5;
  border: none;
  resize: none;
  background: transparent;
  color: var(--text);
}

.editor-reminder-list {
  margin-top: 8px;
}

.editor-reminder-list .reminder-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  margin: 4px 4px 0 0;
  font-size: 0.8125rem;
  background: var(--border);
  border-radius: 16px;
}

.editor-reminder-list .reminder-chip button {
  padding: 0;
  width: 18px;
  height: 18px;
  border: none;
  background: var(--text-secondary);
  color: var(--bg-card);
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}

/* ----- More panel (Farben, Archiv, Löschen) ----- */
.more-panel {
  position: absolute;
  top: 100%;
  left: 16px;
  right: 16px;
  padding: 16px;
  background: var(--bg-card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  z-index: 10;
}

.more-panel.hidden { display: none; }

.color-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  margin: 4px;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
  background: var(--bg-card);
}

.color-btn[data-color]:not([data-color=""]) {
  background: attr(data-color);
  background: var(--card-color, #fff);
}

.more-panel hr { margin: 12px 0; border: none; border-top: 1px solid var(--border); }

.more-btn {
  display: block;
  width: 100%;
  padding: 12px;
  text-align: left;
  font-size: 1rem;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
}

.more-btn.danger { color: var(--danger); }

/* ----- Reminder Picker ----- */
.reminder-picker {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 16px;
  padding-bottom: calc(16px + var(--safe-bottom));
  background: var(--bg-card);
  border-radius: var(--radius-card) var(--radius-card) 0 0;
  box-shadow: 0 -2px 12px rgba(0,0,0,.1);
  z-index: 20;
}

.reminder-picker.hidden { display: none; }

.reminder-picker p { margin: 0 0 12px; font-weight: 500; }

.reminder-picker input[type="datetime-local"] {
  width: 100%;
  padding: 12px;
  margin-bottom: 12px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
}

.reminder-quick {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.reminder-quick button {
  padding: 8px 12px;
  font-size: 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}

.primary-btn {
  width: 100%;
  padding: 12px;
  font-size: 1rem;
  font-weight: 500;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
}

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