:root {
  --bg: #f8f4ee;
  --card: #fffdfa;
  --ink: #3b2a20;
  --muted: #8a7768;
  --title: #c2410c;
  --title-dark: #9a3412;
  --orange-1: #f97316;
  --orange-2: #ea580c;
  --peach: #ffedd5;
  --peach-ink: #c2410c;
  --line: #f3d9bf;
  --danger: #ef4444;
  --slate: #475569;
  --blue: #2563eb;
  --shadow: 0 6px 18px rgba(154, 52, 18, 0.10), 0 1px 3px rgba(154, 52, 18, 0.08);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1612;
    --card: #2a211b;
    --ink: #f5e9df;
    --muted: #b7a393;
    --title: #fb923c;
    --title-dark: #fdba74;
    --peach: #43291a;
    --peach-ink: #fdba74;
    --line: #4a3628;
    --shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}
[hidden] { display: none !important; }
a { color: var(--orange-2); }

/* ---------- Buttons ---------- */
.btn {
  border: 0;
  border-radius: 10px;
  padding: 8px 14px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: transform .08s ease, filter .15s ease, box-shadow .15s ease;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:focus-visible, .chip:focus-visible, input:focus-visible { outline: 3px solid rgba(249, 115, 22, .45); outline-offset: 2px; }
.btn.primary { background: linear-gradient(135deg, var(--orange-1), var(--orange-2)); color: #fff; box-shadow: 0 3px 8px rgba(234, 88, 12, .3); }
.btn.soft { background: var(--peach); color: var(--peach-ink); }
.btn.slate { background: var(--slate); color: #fff; }
.btn.blue { background: var(--blue); color: #fff; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.wide { width: 100%; padding: 11px; font-size: 15px; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.icon-btn { background: transparent; color: var(--muted); padding: 4px 8px; font-size: 18px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- App-Layout ---------- */
.app { max-width: 1000px; margin: 0 auto; padding: 18px 16px 40px; }
.top { position: relative; text-align: center; padding-top: 6px; }
.title {
  margin: 4px 0 14px;
  font-size: clamp(26px, 5vw, 38px);
  font-weight: 900;
  letter-spacing: -0.5px;
  color: var(--title);
  text-shadow: 0 2px 0 rgba(154, 52, 18, .12);
}
.top-menu { position: absolute; right: 0; top: 0; display: flex; align-items: center; gap: 6px; }
.menu {
  position: absolute; right: 0; top: 38px; z-index: 20;
  background: var(--card); border-radius: 12px; box-shadow: var(--shadow);
  border: 1px solid var(--line); min-width: 250px; padding: 6px; text-align: left;
}
.menu button { display: block; width: 100%; background: none; border: 0; text-align: left; padding: 9px 12px; border-radius: 8px; font: inherit; color: var(--ink); cursor: pointer; }
.menu button:hover { background: var(--peach); }
.menu button.danger { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.sync { font-size: 12px; color: var(--muted); }
.sync.error { color: var(--danger); font-weight: 600; }

.search { position: relative; max-width: 320px; margin: 0 auto 22px; }
.search input {
  width: 100%; padding: 9px 34px 9px 14px; border-radius: 10px;
  border: 1.5px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-size: 14px;
}
.search-icon { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--orange-1); font-size: 18px; }

.block { margin-bottom: 26px; }
.block-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.block-title {
  margin: 0; font-size: 20px; font-weight: 800; color: var(--title);
  padding-bottom: 4px; border-bottom: 2px solid var(--orange-1); display: inline-block;
}
.empty { color: var(--muted); font-size: 14px; margin: 6px 2px; }

/* ---------- Chips (Links & Kopier-Buttons) ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.chip {
  position: relative; display: flex; align-items: center; min-height: 44px;
  background: linear-gradient(135deg, var(--orange-1), var(--orange-2));
  color: #fff; border-radius: 12px; box-shadow: 0 4px 10px rgba(234, 88, 12, .25);
  font-weight: 700; font-size: 13px; cursor: pointer; user-select: none;
  transition: transform .1s ease, box-shadow .15s ease;
}
.chip:hover { box-shadow: 0 6px 16px rgba(234, 88, 12, .35); }
.chip:active { transform: scale(.98); }
.chip-main {
  flex: 1; min-width: 0; padding: 12px 6px 12px 14px; color: inherit; text-decoration: none;
  background: none; border: 0; font: inherit; text-align: left; cursor: pointer;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip-edit {
  flex: none; background: rgba(255, 255, 255, .18); border: 0; color: #fff; cursor: pointer;
  border-radius: 8px; margin-right: 8px; width: 28px; height: 28px; font-size: 13px; opacity: .85;
}
.chip-edit:hover { background: rgba(255, 255, 255, .32); opacity: 1; }
.chip.copied { background: linear-gradient(135deg, #22c55e, #16a34a); box-shadow: 0 4px 10px rgba(22, 163, 74, .3); }
.chip.dragging { opacity: .45; }
.chip.drop-before::before, .chip.drop-after::after {
  content: ""; position: absolute; top: 4px; bottom: 4px; width: 3px; border-radius: 2px; background: var(--title-dark);
}
.chip.drop-before::before { left: -7px; }
.chip.drop-after::after { right: -7px; }

/* ---------- Bereiche ---------- */
.section {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px 16px; margin-bottom: 16px; border: 1px solid rgba(243, 217, 191, .6);
}
.section-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.order { display: flex; flex-direction: column; }
.order button {
  background: none; border: 0; color: var(--orange-1); cursor: pointer; font-size: 11px; line-height: 1;
  padding: 2px 4px; border-radius: 4px; opacity: .75;
}
.order button:hover:not(:disabled) { opacity: 1; background: var(--peach); }
.order button:disabled { opacity: .2; cursor: default; }
.section-title {
  flex: 1; max-width: 300px; min-width: 0; border: 0; border-bottom: 2px solid var(--orange-1); background: transparent;
  color: var(--title-dark); font: inherit; font-size: 18px; font-weight: 800; padding: 2px 2px 3px;
}
.section-title:focus { outline: none; border-bottom-color: var(--title-dark); }
.section-tools { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.trash { background: none; border: 0; color: var(--danger); cursor: pointer; font-size: 16px; padding: 4px 6px; border-radius: 6px; }
.trash:hover { background: rgba(239, 68, 68, .1); }
.section .grid { min-height: 8px; }
.section .grid.drop-target { outline: 2px dashed var(--orange-1); outline-offset: 4px; border-radius: 8px; }

.foot { text-align: center; color: var(--muted); font-size: 12px; margin-top: 30px; }

/* ---------- Dialog ---------- */
dialog {
  border: 0; border-radius: 16px; padding: 0; width: min(440px, calc(100vw - 32px));
  background: var(--card); color: var(--ink); box-shadow: 0 20px 50px rgba(0, 0, 0, .25);
}
dialog::backdrop { background: rgba(40, 20, 10, .45); }
#dlg-form { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
#dlg-form h3 { margin: 0 0 4px; color: var(--title); font-size: 19px; }
#dlg-form p { margin: 0; }
.dlg-actions { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.dlg-actions .right { display: flex; gap: 8px; margin-left: auto; }

label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
:where(input:not([type=checkbox]):not([type=file]), textarea, select) {
  font: inherit; font-size: 15px; color: var(--ink); background: var(--bg);
  border: 1.5px solid var(--line); border-radius: 10px; padding: 9px 12px; width: 100%;
}
textarea { min-height: 110px; resize: vertical; font-family: inherit; }
.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-right: 42px !important; }
.pw-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); background: none; border: 0; cursor: pointer; font-size: 16px; opacity: .6; }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: min(420px, 100%); background: var(--card); border-radius: 18px; box-shadow: var(--shadow); padding: 26px 24px; }
.brand { margin: 0 0 14px; text-align: center; color: var(--title); font-weight: 900; font-size: 30px; }
.auth-view { display: flex; flex-direction: column; gap: 13px; }
.auth-view h2 { margin: 0; font-size: 19px; color: var(--title-dark); }
.muted { color: var(--muted); font-size: 13px; margin: 0; }
.auth-links { text-align: center; margin: 0; font-size: 13px; }
.auth-error { color: var(--danger); font-size: 14px; margin: 12px 0 0; min-height: 1em; text-align: center; }
.auth-error:empty { display: none; }
.auth-busy { color: var(--muted); font-size: 13px; text-align: center; margin: 10px 0 0; }
.recovery-key {
  font-family: Consolas, "SF Mono", Menlo, monospace; font-size: 17px; font-weight: 700; letter-spacing: 1px;
  background: var(--peach); color: var(--peach-ink); border-radius: 10px; padding: 14px; text-align: center; word-break: break-word;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: #3b2a20; color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease; z-index: 50; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 600px) {
  .app { padding-top: 12px; }
  .top { padding-top: 34px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
  .block-head { flex-direction: column; align-items: flex-start; }
  .section { padding: 12px; }
  .section-tools .btn { padding: 5px 8px; }
}
