/* Flohmarkt-Radar — Vintage Senfgelb + Petrol */
:root {
  --mustard: #d8a531;
  --mustard-dark: #b9871f;
  --mustard-soft: #f0d99a;
  --petrol: #1f5f63;
  --petrol-dark: #16484b;
  --petrol-soft: #d7e7e7;

  --bg: #f7f1e3;
  --bg-grain: #f2e9d4;
  --surface: #fffdf6;
  --surface-2: #f4ecd8;
  --text: #2a2620;
  --text-soft: #6b6356;
  --line: #e2d6ba;
  --danger: #b5462f;
  --danger-soft: #f3ddd5;
  --shadow: 0 6px 22px rgba(40, 30, 10, 0.12);
  --radius: 16px;
  --radius-sm: 10px;
  --maxw: 720px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

[data-theme="dark"] {
  --mustard: #e3b552;
  --mustard-dark: #c89834;
  --mustard-soft: #4a3c1c;
  --petrol: #4fb0b5;
  --petrol-dark: #2c7d81;
  --petrol-soft: #15363a;

  --bg: #18211f;
  --bg-grain: #1c2624;
  --surface: #222d2b;
  --surface-2: #2a3735;
  --text: #ece5d6;
  --text-soft: #a9a392;
  --line: #36433f;
  --danger: #e07a60;
  --danger-soft: #3a2420;
  --shadow: 0 6px 22px rgba(0, 0, 0, 0.42);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  background:
    radial-gradient(circle at 12% -10%, rgba(216,165,49,0.10), transparent 45%),
    radial-gradient(circle at 90% 5%, rgba(31,95,99,0.08), transparent 40%),
    var(--bg);
  color: var(--text);
  line-height: 1.45;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-text-size-adjust: 100%;
  padding-bottom: calc(96px + var(--safe-b));
}

h1, h2, h3 { margin: 0; font-weight: 700; }

p { margin: 0 0 0.5em; overflow-wrap: anywhere; word-break: break-word; }

.visually-hidden, .skip-link {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}
.skip-link:focus {
  position: fixed; top: 8px; left: 8px;
  width: auto; height: auto; clip: auto;
  background: var(--petrol); color: #fff;
  padding: 10px 14px; border-radius: 8px; z-index: 1000;
}

/* ===== Header ===== */
.app-header {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 12px;
  background: linear-gradient(135deg, var(--mustard), var(--mustard-dark));
  color: #2a2208;
  box-shadow: 0 2px 14px rgba(40,30,10,0.16);
}
[data-theme="dark"] .app-header { color: #1a1407; }
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-mark {
  display: grid; place-items: center;
  width: 42px; height: 42px; flex: none;
  border-radius: 12px;
  background: rgba(255,255,255,0.28);
  color: var(--petrol-dark);
}
[data-theme="dark"] .brand-mark { background: rgba(20,15,5,0.3); color: #16484b; }
.brand-text { min-width: 0; }
.brand-text h1 { font-size: 1.28rem; letter-spacing: -0.01em; line-height: 1.1; }
.tagline { margin: 0; font-size: 0.74rem; opacity: 0.82; font-weight: 600; }
.header-actions { display: flex; gap: 8px; flex: none; }

.icon-btn {
  display: grid; place-items: center;
  width: 42px; height: 42px;
  border: none; border-radius: 12px;
  background: rgba(255,255,255,0.26);
  color: inherit; cursor: pointer;
  transition: background 0.18s, transform 0.12s;
}
.icon-btn:hover { background: rgba(255,255,255,0.42); }
.icon-btn:active { transform: scale(0.94); }
.app-header .icon-btn { color: #2a2208; }
[data-theme="dark"] .app-header .icon-btn { color: #1a1407; }

#themeBtn .ico-moon { display: none; }
[data-theme="dark"] #themeBtn .ico-sun { display: none; }
[data-theme="dark"] #themeBtn .ico-moon { display: block; }

/* ===== Main ===== */
.app-main {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 16px;
}

/* Next card */
.next-card {
  background: linear-gradient(135deg, var(--petrol), var(--petrol-dark));
  color: #f4f9f8;
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.next-label {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.12em;
  opacity: 0.8; margin-bottom: 6px; font-weight: 700;
}
.next-content .next-title { font-size: 1.25rem; margin-bottom: 4px; }
.next-content .next-meta { font-size: 0.92rem; opacity: 0.95; }
.next-content .next-count {
  display: inline-block; margin-top: 10px;
  font-size: 1.6rem; font-weight: 800;
  background: rgba(255,255,255,0.16);
  padding: 4px 14px; border-radius: 999px;
}
.next-content .next-empty { font-size: 0.96rem; opacity: 0.92; }

/* Tabs */
.tabs {
  display: flex; gap: 6px;
  background: var(--surface-2);
  padding: 5px; border-radius: 999px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
}
.tab {
  flex: 1; padding: 9px 4px;
  border: none; border-radius: 999px;
  background: transparent; color: var(--text-soft);
  font-size: 0.92rem; font-weight: 700; cursor: pointer;
  transition: background 0.18s, color 0.18s;
}
.tab.is-active { background: var(--mustard); color: #2a2208; }
[data-theme="dark"] .tab.is-active { color: #1a1407; }

.view { animation: fade 0.22s ease; }
.view[hidden] { display: none; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* List toolbar */
.list-toolbar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.field-inline { display: flex; flex: 1 1 140px; min-width: 0; }
.search-wrap { flex: 2 1 200px; }
.field-inline .select, .field-inline .input { width: 100%; }

/* Inputs */
.input, .select, .textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}
.textarea { resize: vertical; }
.input:focus, .select:focus, .textarea:focus,
.tab:focus-visible, .btn:focus-visible, .icon-btn:focus-visible,
.fab:focus-visible, .day:focus-visible, .check-row:focus-within {
  outline: 3px solid var(--petrol);
  outline-offset: 2px;
}
.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236b6356' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

/* Event list */
.event-list { display: flex; flex-direction: column; gap: 12px; }
.event-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 5px solid var(--mustard);
  border-radius: var(--radius);
  padding: 14px 15px;
  box-shadow: var(--shadow);
  position: relative;
}
.event-card.is-past { opacity: 0.62; border-left-color: var(--text-soft); }
.event-card.is-soon { border-left-color: var(--petrol); }
.ec-top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.ec-title { font-size: 1.1rem; line-height: 1.25; }
.ec-when { font-size: 0.92rem; color: var(--petrol); font-weight: 700; margin-top: 3px; }
[data-theme="dark"] .ec-when { color: var(--petrol); }
.ec-place { font-size: 0.9rem; color: var(--text-soft); margin-top: 2px; }
.ec-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.badge {
  font-size: 0.72rem; font-weight: 700;
  padding: 3px 9px; border-radius: 999px;
  background: var(--mustard-soft); color: var(--mustard-dark);
}
[data-theme="dark"] .badge { color: var(--mustard); }
.badge-recur { background: var(--petrol-soft); color: var(--petrol-dark); }
[data-theme="dark"] .badge-recur { color: var(--petrol); }
.badge-count { background: var(--surface-2); color: var(--text-soft); }
.ec-note { font-size: 0.9rem; color: var(--text-soft); margin-top: 8px; white-space: pre-wrap; }
.ec-items { margin: 10px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; }
.ec-items li { display: flex; align-items: center; gap: 8px; font-size: 0.88rem; }
.ec-items input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--petrol); flex: none; }
.ec-items li.done span { text-decoration: line-through; color: var(--text-soft); }
.ec-items li span { overflow-wrap: anywhere; }
.ec-actions { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; }

.btn-icon-sm {
  display: inline-flex; align-items: center; gap: 5px;
  border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text-soft);
  padding: 6px 11px; border-radius: 8px; font-size: 0.82rem; font-weight: 700;
  cursor: pointer;
}
.btn-icon-sm:hover { color: var(--text); border-color: var(--mustard); }
.btn-icon-sm.danger:hover { color: var(--danger); border-color: var(--danger); }

.empty-hint {
  text-align: center; color: var(--text-soft);
  padding: 38px 16px; font-size: 0.96rem;
  background: var(--surface); border: 1px dashed var(--line);
  border-radius: var(--radius);
}

/* Month view */
.month-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.month-bar .icon-btn { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); }
.month-bar .icon-btn:hover { background: var(--mustard-soft); }
.month-title { font-size: 1.15rem; text-align: center; flex: 1; }
.weekdays { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 4px; }
.weekdays span { text-align: center; font-size: 0.72rem; font-weight: 700; color: var(--text-soft); }
.month-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.day {
  aspect-ratio: 1 / 1;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  padding: 4px 2px; cursor: pointer; position: relative;
  font-size: 0.86rem; color: var(--text);
  transition: background 0.15s;
}
.day.empty { background: transparent; border-color: transparent; cursor: default; }
.day.today { border-color: var(--mustard); box-shadow: inset 0 0 0 1px var(--mustard); font-weight: 800; }
.day.has-events { background: var(--surface-2); }
.day.selected { background: var(--petrol); color: #fff; border-color: var(--petrol); }
.day .dots { display: flex; gap: 2px; margin-top: auto; padding-bottom: 2px; }
.day .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--mustard); }
.day.selected .dot { background: #fff; }
.month-day-list { margin-top: 16px; display: flex; flex-direction: column; gap: 12px; }
.month-day-head { font-size: 0.95rem; font-weight: 700; color: var(--petrol); }

/* Cards (tools) */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.card h2 { font-size: 1.08rem; margin-bottom: 8px; color: var(--petrol); }
[data-theme="dark"] .card h2 { color: var(--petrol); }
.muted { color: var(--text-soft); font-size: 0.92rem; }
.small { font-size: 0.82rem; }

.template-list { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.template-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface-2);
}
.template-info { min-width: 0; }
.template-info b { font-size: 0.94rem; }
.template-info span { display: block; font-size: 0.8rem; color: var(--text-soft); overflow-wrap: anywhere; }

/* Buttons */
.btn {
  border: none; border-radius: 10px;
  padding: 11px 16px; font-size: 0.95rem; font-weight: 700;
  cursor: pointer; font-family: inherit;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line);
  transition: transform 0.1s, filter 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--mustard); color: #2a2208; border-color: var(--mustard-dark); }
[data-theme="dark"] .btn-primary { color: #1a1407; }
.btn-primary:hover { filter: brightness(1.05); }
.btn-ghost { background: transparent; }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { filter: brightness(1.06); }
.btn-small { padding: 8px 12px; font-size: 0.9rem; flex: none; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.btn-row .btn { flex: 1 1 auto; }
#wipeBtn { margin-top: 4px; }

/* FAB */
.fab {
  position: fixed;
  right: 18px; bottom: calc(18px + var(--safe-b));
  width: 60px; height: 60px;
  border-radius: 50%; border: none;
  background: linear-gradient(135deg, var(--mustard), var(--mustard-dark));
  color: #2a2208;
  box-shadow: 0 8px 22px rgba(40,30,10,0.32);
  cursor: pointer; z-index: 40;
  display: grid; place-items: center;
  transition: transform 0.14s;
}
[data-theme="dark"] .fab { color: #1a1407; }
.fab:hover { transform: scale(1.06); }
.fab:active { transform: scale(0.95); }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-end; justify-content: center; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(20,15,5,0.5); backdrop-filter: blur(2px); }
.modal-box {
  position: relative;
  width: 100%; max-width: var(--maxw);
  max-height: 92vh; max-height: 92dvh;
  overflow-y: auto;
  background: var(--bg-grain);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -8px 30px rgba(0,0,0,0.3);
  animation: slideup 0.25s ease;
  padding-bottom: var(--safe-b);
}
.modal-box-sm { border-radius: 18px; max-width: 420px; align-self: center; margin: 0 16px; }
@keyframes slideup { from { transform: translateY(40px); opacity: 0.6; } to { transform: none; opacity: 1; } }
.modal-head {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px 12px;
  background: var(--bg-grain);
  border-bottom: 1px solid var(--line);
}
.modal-head h2 { font-size: 1.15rem; color: var(--petrol); }
[data-theme="dark"] .modal-head h2 { color: var(--petrol); }
.modal-head .icon-btn { background: var(--surface-2); color: var(--text); }
.modal-body { padding: 16px 18px; }
.field { display: block; margin-bottom: 14px; }
.field-label { display: block; font-size: 0.82rem; font-weight: 700; color: var(--text-soft); margin-bottom: 5px; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.recur-box { border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: var(--surface); }
.recur-box legend { padding: 0 6px; }
.hint { color: var(--text-soft); margin: 4px 0 0; }
.modal-foot { display: flex; gap: 10px; margin-top: 18px; }
.modal-foot .btn { flex: 1; }

.checklist-add { display: flex; gap: 8px; }
.checklist-add .input { flex: 1; }
.checklist { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.checklist li {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 10px; font-size: 0.9rem;
}
.checklist li span { flex: 1; overflow-wrap: anywhere; }
.checklist .rm {
  border: none; background: transparent; color: var(--danger);
  cursor: pointer; font-size: 1.1rem; line-height: 1; padding: 2px 6px;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%; bottom: calc(90px + var(--safe-b));
  transform: translateX(-50%);
  background: var(--petrol-dark); color: #fff;
  padding: 12px 18px; border-radius: 12px;
  font-size: 0.92rem; font-weight: 600;
  box-shadow: var(--shadow); z-index: 200;
  max-width: 90vw; text-align: center;
  animation: toastIn 0.2s ease;
}
.toast[hidden] { display: none; }
.toast.toast-warn { background: var(--mustard-dark); color: #2a2208; }
.toast.toast-err { background: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }

@media (min-width: 560px) {
  .modal { align-items: center; }
  .modal-box { border-radius: 20px; margin: 0 16px; }
}

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