*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Design Tokens (KSBS Styleguide) ─────────────────────────────────────── */
:root {
  --bg:          #f5f3ef;
  --surface:     #ffffff;
  --surface-2:   #faf9f7;
  --border:      #e8e4dd;
  --border-2:    #e8e4dd;
  --text:        #1a1714;
  --text-2:      #7a7068;
  --muted:       #7a7068;
  
  --accent:      #c8773a;
  --accent-d:    #b5672b;
  --accent-glow: rgba(200, 119, 58, 0.3);
  --accent-bg:   rgba(200, 119, 58, 0.12);
  
  --danger:      #c0392b;
  --danger-bg:   rgba(192, 57, 43, 0.12);
  
  --success:     #2d6a4f;
  --success-bg:  rgba(45, 106, 79, 0.12);
  
  --warning:     #c8773a;
  
  --r:           14px;
  --r-sm:        8px;
  --r-xs:        6px;
  
  --sh-sm:       0 2px 16px rgba(0,0,0,0.07);
  --sh:          0 2px 16px rgba(0,0,0,0.07);
  --sh-lg:       0 8px 40px rgba(0,0,0,0.10);
  
  --ease:        cubic-bezier(.22,1,.36,1);
  --spring:      cubic-bezier(.22,1,.36,1);
}

/* Kein Darkmode laut Styleguide */

/* ── Base ──────────────────────────────────────────────────────────────── */
html { scroll-behavior: smooth; }
body {
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  font-weight: 400;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, .modal-ttl, .v-ttl, .logo {
  font-family: 'DM Serif Display', serif;
  font-weight: 400;
  letter-spacing: -0.5px;
}

/* ── Header ────────────────────────────────────────────────────────────── */
header {
  position: sticky; top: 0; z-index: 50;
  background: rgba(253, 251, 247, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1.5px solid var(--border);
  height: 62px;
  padding: 0 36px;
  display: flex; align-items: center; gap: 16px;
}

.logo {
  display: flex; align-items: center; gap: 10px;
  font-size: 22px;
  color: var(--text);
  white-space: nowrap; text-decoration: none;
  flex-shrink: 0;
}

.logo-mark {
  width: 30px; height: 30px;
  background: var(--accent);
  border-radius: var(--r-xs);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 8px var(--accent-glow);
}

.logo-mark svg { color: white; }

/* Search */
.search-wrap {
  flex: 1; max-width: 380px;
  position: relative;
}

.search-wrap input {
  width: 100%;
  padding: 10px 14px 10px 38px;
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px; font-family: inherit;
  outline: none;
  transition: all 0.2s var(--ease);
}

.search-wrap input::placeholder { color: var(--muted); }

.search-wrap input:focus {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-bg);
}

.search-ico {
  position: absolute; left: 12px; top: 50%;
  transform: translateY(-50%);
  color: var(--muted); pointer-events: none; display: flex;
}

.header-end { margin-left: auto; display: flex; align-items: center; gap: 12px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 10px 20px;
  border: none; border-radius: var(--r-sm);
  cursor: pointer; font-size: 13px; font-weight: 500;
  font-family: inherit; line-height: 1;
  transition: all 0.2s var(--ease);
  white-space: nowrap; outline: none;
  position: relative;
}

.btn-sm {
  padding: 6px 12px !important;
  font-size: 11px !important;
}

.btn-primary {
  background: var(--accent); color: white;
  box-shadow: var(--accent-glow);
}
.btn-primary:hover {
  background: var(--accent-d);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(200,119,58,0.4);
}
.btn-primary:active { transform: translateY(0); }

.btn-ghost {
  background: transparent; color: var(--text-2);
  border: 1.5px solid var(--border);
}
.btn-ghost:hover {
  background: var(--surface); color: var(--text);
  border-color: var(--text-2);
}

/* Icon-only button */
.btn-icon {
  width: 36px; height: 36px; padding: 0;
  display: flex; align-items: center; justify-content: center;
  background: transparent; color: var(--text-2);
  border: 1.5px solid var(--border); border-radius: var(--r-sm);
  cursor: pointer; transition: all 0.2s var(--ease); font-family: inherit;
}
.btn-icon:hover { background: var(--surface); color: var(--text); border-color: var(--text-2); }

/* ── Layout ────────────────────────────────────────────────────────────── */
.wrap {
  max-width: 1280px; margin: 0 auto;
  padding: 32px 36px 60px;
}

/* ── Filters ───────────────────────────────────────────────────────────── */
.filter-bar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
  margin-bottom: 12px;
}

.folder-bar {
  display: flex; gap: 6px; margin-bottom: 12px; overflow-x: auto;
  padding-bottom: 4px;
}

.ftag, .folder-tab {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.3px;
  border: 1.5px solid var(--border);
  background: var(--surface); color: var(--text-2);
  cursor: pointer; user-select: none;
  transition: all 0.2s var(--ease);
}
.ftag:hover, .folder-tab:hover { border-color: var(--accent); color: var(--accent); }
.ftag.on, .folder-tab.on {
  background: var(--accent-bg); border-color: transparent;
  color: var(--accent);
}
.ftag .cnt, .folder-tab .cnt {
  font-size: 10px; font-variant-numeric: tabular-nums;
  background: var(--surface-2);
  padding: 2px 6px; border-radius: 10px;
}
.ftag.on .cnt, .folder-tab.on .cnt { background: rgba(200, 119, 58, 0.2); }

/* Stats */
.stats {
  font-size: 12px; color: var(--text-2);
  margin-bottom: 24px; display: flex; align-items: center; gap: 8px;
}
.stats-sep { width: 4px; height: 4px; border-radius: 50%; background: var(--border); }

/* ── Grid ──────────────────────────────────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 20px;
  align-items: start;
}

/* Empty state */
.empty {
  grid-column: 1/-1;
  display: flex; flex-direction: column; align-items: center;
  padding: 80px 24px; gap: 14px; text-align: center;
  animation: fadeUp 0.4s var(--ease) both;
}
.empty-ring {
  width: 72px; height: 72px; border-radius: 20px;
  background: var(--surface); border: 1.5px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); margin-bottom: 6px;
  box-shadow: var(--sh-sm);
}
.empty h3 { font-size: 22px; color: var(--text); }
.empty p  { font-size: 13px; color: var(--text-2); max-width: 270px; line-height: 1.6; }

/* ── Card ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r);
  padding: 24px;
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: var(--sh-sm);
  position: relative; overflow: hidden;
  transition: all 0.2s var(--ease);
  animation: fadeUp 0.4s var(--ease) both;
  cursor: pointer;
}

@keyframes fadeUp {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.card:hover {
  box-shadow: var(--sh-lg);
  transform: translateY(-2px);
}

/* Card header */
.card-top {
  display: flex; justify-content: space-between;
  align-items: flex-start; gap: 10px;
}

.card-title {
  font-size: 14px; font-weight: 600; line-height: 1.4;
  color: var(--text); word-break: break-word;
  font-family: 'DM Sans', sans-serif; /* Im Styleguide: Kartenüberschriften 14px (Sans) */
}

/* Actions – hidden until hover */
.card-acts {
  display: flex; gap: 4px; flex-shrink: 0;
  opacity: 0; transform: translateX(6px);
  transition: opacity 0.2s, transform 0.2s;
}
.card:hover .card-acts { opacity: 1; transform: translateX(0); }

.ico-btn {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  border: none; border-radius: var(--r-sm);
  cursor: pointer; background: transparent; color: var(--text-2);
  transition: all 0.2s; font-family: inherit;
}
.ico-btn:hover { background: var(--surface-2); color: var(--text); }
.ico-btn.del:hover { color: var(--danger); background: var(--danger-bg); }
.ico-btn.copy.ok  { color: var(--success); background: var(--success-bg); }
.ico-btn.pin.active { color: var(--warning); opacity: 1 !important; }

/* Card body – rendered rich text */
.card-body {
  font-size: 13px; color: var(--text-2);
  line-height: 1.6;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
}
.card-body b, .card-body strong { color: var(--text); font-weight: 600; }
.card-body i, .card-body em { font-style: italic; }
.card-body h1, .card-body h2 { font-size: 14px; font-weight: 600; color: var(--text); }
.card-body code {
  font-family: ui-monospace, monospace;
  font-size: 11px;
  background: var(--surface-2); padding: 2px 6px; border-radius: 4px;
}
.card-body pre {
  background: var(--surface-2); border-radius: 6px;
  padding: 10px 12px; overflow: hidden;
}
.card-body pre code { background: none; padding: 0; }
.card-body blockquote {
  border-left: 3px solid var(--accent); padding-left: 10px; color: var(--muted);
}
.card-body ul, .card-body ol { padding-left: 18px; }

/* Card footer */
.card-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-top: auto;
}

.card-tags { display: flex; flex-wrap: wrap; gap: 6px; }

.ctag {
  display: inline-flex;
  padding: 3px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.3px;
  background: var(--accent-bg); color: var(--accent);
  cursor: pointer; border: none;
  transition: all 0.2s;
}
.ctag:hover { filter: brightness(0.95); }

.card-date { font-size: 11px; color: var(--muted); white-space: nowrap; flex-shrink: 0; }

/* ── Modal ─────────────────────────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(26, 23, 20, 0.4);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  opacity: 0; pointer-events: none;
  transition: opacity 0.3s var(--ease);
}
.overlay.open { opacity: 1; pointer-events: all; }

.modal {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r);
  width: 100%; max-width: 660px;
  max-height: 92vh;
  display: flex; flex-direction: column;
  box-shadow: var(--sh-lg);
  transform: translateY(20px) scale(0.98);
  transition: all 0.3s var(--ease);
  overflow: hidden;
}
.overlay.open .modal { transform: translateY(0) scale(1); }

.modal-head {
  padding: 28px 32px 0;
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}

.modal-ttl {
  font-size: 22px;
}

.modal-x {
  width: 32px; height: 32px; border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  border: none; cursor: pointer; background: transparent; color: var(--text-2);
  transition: all 0.2s; font-family: inherit;
}
.modal-x:hover { background: var(--surface-2); color: var(--text); }

.modal-body {
  padding: 24px 32px;
  display: flex; flex-direction: column; gap: 20px;
  overflow-y: auto; flex: 1;
}

.modal-foot {
  padding: 20px 32px 24px;
  display: flex; justify-content: flex-end; gap: 12px;
  flex-shrink: 0; border-top: 1.5px solid var(--border);
}

/* Form fields */
.field label {
  display: block; font-size: 11px; font-weight: 500;
  color: var(--text-2); margin-bottom: 8px;
  text-transform: uppercase; letter-spacing: 1.5px;
}

.field input[type="text"], .field input[type="file"], .field select {
  width: 100%; padding: 10px 14px;
  border: 1.5px solid var(--border); border-radius: var(--r-sm);
  background: var(--surface-2); color: var(--text);
  font-size: 13px; font-family: inherit; outline: none;
  transition: all 0.2s var(--ease);
}
.field input[type="text"]::placeholder { color: var(--muted); }
.field input[type="text"]:focus, .field select:focus {
  border-color: var(--accent); background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-bg);
}

/* ── Rich Text Editor ──────────────────────────────────────────────────── */
.editor-wrap {
  border: 1.5px solid var(--border); border-radius: var(--r-sm); overflow: hidden;
  transition: all 0.2s var(--ease);
  display: flex; flex-direction: column;
}
.editor-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}

.toolbar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 2px;
  padding: 8px 10px; background: var(--surface-2);
  border-bottom: 1.5px solid var(--border);
}

.tb {
  width: 32px; height: 30px; border: none; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; background: transparent; color: var(--text-2);
  font-size: 13px; font-weight: 600; font-family: inherit;
  transition: all 0.2s;
}
.tb:hover { background: var(--border); color: var(--text); }
.tb.lit   { background: var(--accent-bg); color: var(--accent); }

.tb-div { width: 1.5px; height: 16px; background: var(--border); margin: 0 6px; flex-shrink: 0; }

.editor {
  padding: 16px 20px;
  min-height: 180px; max-height: 350px;
  overflow-y: auto; outline: none;
  font-size: 13px; line-height: 1.6;
  color: var(--text); background: var(--surface);
  caret-color: var(--accent);
}

.editor:empty::before {
  content: attr(data-ph); color: var(--muted); pointer-events: none;
}

/* Editor content styles */
.editor h1 { font-family: 'DM Serif Display', serif; font-size: 22px; margin: 10px 0 6px; line-height: 1.3; }
.editor h2 { font-family: 'DM Serif Display', serif; font-size: 18px; margin: 8px 0 4px; line-height: 1.35; }
.editor b, .editor strong { font-weight: 600; }
.editor ul, .editor ol   { padding-left: 22px; margin: 6px 0; }
.editor li { margin: 4px 0; }
.editor blockquote {
  border-left: 3px solid var(--accent); padding-left: 14px;
  color: var(--muted); margin: 8px 0; font-style: italic;
}
.editor code {
  font-family: ui-monospace, monospace;
  font-size: 12px;
  background: var(--surface-2); padding: 2px 6px; border-radius: 4px;
}
.editor pre {
  background: var(--surface-2); border-radius: 8px;
  padding: 14px 16px; margin: 8px 0;
  font-family: ui-monospace, monospace;
  font-size: 12px; overflow-x: auto; border: 1.5px solid var(--border);
}
.editor pre code { background: none; padding: 0; }

/* ── Tags Input ─────────────────────────────────────────────────────────── */
.tags-box {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 10px 14px;
  border: 1.5px solid var(--border); border-radius: var(--r-sm);
  background: var(--surface-2); min-height: 46px; cursor: text;
  transition: all 0.2s var(--ease);
}
.tags-box:focus-within {
  border-color: var(--accent); background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-bg);
}

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: 20px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.3px;
  background: var(--accent); color: white;
  animation: scaleIn 0.3s var(--ease) both;
}

@keyframes scaleIn {
  from { transform: scale(0.9); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

.chip-x {
  display: flex; cursor: pointer; opacity: 0.8;
  transition: opacity 0.2s;
}
.chip-x:hover { opacity: 1; }

.tag-inp {
  border: none; outline: none; background: transparent;
  color: var(--text); font-size: 13px; font-family: inherit;
  min-width: 90px; flex: 1;
}
.tag-inp::placeholder { color: var(--muted); }

.hint { font-size: 11px; color: var(--muted); margin-top: 6px; }

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  header { padding: 0 20px; flex-wrap: wrap; height: auto; gap: 12px; padding-block: 12px; }
  .search-wrap { order: 10; max-width: 100%; width: 100%; }
  .wrap { padding: 20px 20px 40px; }
  .grid { grid-template-columns: 1fr; }
  .modal { border-radius: 16px; max-height: 96vh; }
  .modal-head { padding: 20px 20px 0; }
  .modal-body { padding: 20px; }
  .modal-foot { padding: 16px 20px; }
}

/* ── Scrollbar ─────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ── View Modal ─────────────────────────────────────────────────────────── */
.v-modal { max-width: 760px; }

.v-modal .modal-head {
  padding-bottom: 24px;
  border-bottom: 1.5px solid var(--border);
  align-items: flex-start;
  gap: 16px; flex-wrap: wrap;
}

.v-head-left { min-width: 0; flex: 1; }

.v-ttl {
  font-size: 30px;
  line-height: 1.2; word-break: break-word;
}

.v-date { font-size: 12px; color: var(--muted); margin-top: 8px; }

.v-head-acts { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.v-body { padding: 32px 32px; overflow-y: auto; flex: 1; }

.v-content { font-size: 14px; line-height: 1.7; color: var(--text); }
.v-content h1 { font-size: 26px; margin: 16px 0 8px; }
.v-content h2 { font-size: 20px; margin: 14px 0 6px; }
.v-content h3 { font-size: 16px; margin: 12px 0 6px; font-family: 'DM Sans', sans-serif; font-weight: 600;}
.v-content b, .v-content strong { font-weight: 600; }
.v-content em, .v-content i { font-style: italic; }
.v-content u { text-decoration: underline; }
.v-content s, .v-content del { text-decoration: line-through; }
.v-content code {
  font-family: ui-monospace, monospace; font-size: 12px;
  background: var(--surface-2); padding: 3px 8px; border-radius: 6px;
}
.v-content pre {
  background: var(--surface-2); border-radius: var(--r-sm);
  padding: 16px 20px; margin: 12px 0; overflow-x: auto;
  font-family: ui-monospace, monospace; font-size: 12px;
  border: 1.5px solid var(--border);
}
.v-content pre code { background: none; padding: 0; }
.v-content blockquote {
  border-left: 3px solid var(--accent); padding-left: 16px;
  color: var(--muted); margin: 12px 0; font-style: italic;
  font-size: 15px;
}
.v-content ul, .v-content ol { padding-left: 24px; margin: 10px 0; }
.v-content li { margin: 6px 0; }

.v-footer {
  padding: 20px 32px; border-top: 1.5px solid var(--border); flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  background: var(--surface-2);
}

.v-tags { display: flex; flex-wrap: wrap; gap: 8px; }

/* Drag and Drop classes */
.card.dragging { opacity: 0.5; box-shadow: none; border-style: dashed; border-color: var(--muted); }
.card.drag-over { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }

/* PIN Box Styles */
.pin-box {
  width: 56px; height: 64px;
  font-size: 24px; font-weight: 600; text-align: center;
  border: 1.5px solid var(--border); border-radius: var(--r-sm);
  background: var(--surface-2); color: var(--text);
  outline: none; transition: all 0.3s var(--ease);
}
.pin-box:focus {
  border-color: var(--accent); background: var(--surface);
  box-shadow: 0 0 0 4px var(--accent-bg); transform: translateY(-2px);
}
