:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #6b7684;
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --danger: #ef4444;
  --ok: #22c55e;
  --border: #e3e8ef;
  --radius: 12px;
  --input-bg: #ffffff;
  --day-bg: #f0f2f6;
  --weekend-bg: #e8ebf1;
  --bar-bg: #e5e9f0;
  --toggle-bg: #eef1f5;
  --hover-bg: #eef1f5;
  --holiday-bg: #fdf2d8;
  --holiday-text: #92700a;
  --preview-bg: #eef4ff;
  --preview-bad-bg: #fef2f2;
  --table-hover: #f7f9fc;
}
[data-theme="dark"] {
  --bg: #0f1420;
  --card: #1a2130;
  --text: #e4e9f2;
  --muted: #8a94a6;
  --primary: #3b82f6;
  --primary-dark: #2b6fd4;
  --border: #2a3345;
  --input-bg: #121826;
  --day-bg: #222b3d;
  --weekend-bg: #1c2435;
  --bar-bg: #222b3d;
  --toggle-bg: #222b3d;
  --hover-bg: #222b3d;
  --holiday-bg: #3d3319;
  --holiday-text: #e5c15c;
  --preview-bg: #1c2a45;
  --preview-bad-bg: #3d1f24;
  --table-hover: #202939;
}
* { box-sizing: border-box; margin: 0; }
body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased;
}
#app { max-width: 1200px; margin: 0 auto; padding: 16px; }
button {
  font: inherit; border: none; border-radius: 8px; padding: 10px 18px;
  background: var(--primary); color: #fff; cursor: pointer; font-weight: 600;
}
button:hover { background: var(--primary-dark); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
button.ghost:hover { background: var(--hover-bg); }
button.danger { background: var(--danger); }
input, select {
  font: inherit; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; width: 100%; background: var(--input-bg); color: var(--text);
}
label { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin: 12px 0 4px; }
.card { background: var(--card); border-radius: var(--radius); border: 1px solid var(--border); padding: 20px; }

/* Login */
.login-wrap { max-width: 400px; margin: 10vh auto 0; }
.login-wrap h1 { font-size: 1.5rem; margin-bottom: 4px; }
.login-wrap .sub { color: var(--muted); font-size: .9rem; margin-bottom: 16px; }
.login-toggle { display: flex; gap: 6px; background: var(--toggle-bg); border-radius: 10px; padding: 4px; margin-bottom: 8px; }
.login-toggle button { flex: 1; background: transparent; color: var(--muted); padding: 8px; }
.login-toggle button.active { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

/* Header */
header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
header h1 { font-size: 1.3rem; }
.userbox { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; display: inline-flex; align-items: center;
  justify-content: center; color: #fff; font-weight: 700; font-size: .8rem; flex-shrink: 0;
}
.presence { display: flex; gap: -6px; }
.presence .avatar { width: 28px; height: 28px; font-size: .7rem; margin-left: -6px; border: 2px solid var(--bg); }
.typing { color: var(--muted); font-size: .85rem; min-height: 1.2em; }

/* Budget-Karte */
.budgetcard { display: flex; gap: 24px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: 16px; }
.budgetline { display: flex; gap: 14px; align-items: center; }
.budgetnum.big { font-size: 2.2rem; font-weight: 800; color: var(--primary); }
.budgetlabel { font-weight: 700; }
.budgetsub { color: var(--muted); font-size: .85rem; }
.budgetbars { display: flex; flex-direction: column; gap: 8px; flex: 1; min-width: 240px; max-width: 480px; }
.budgetbar-item .budgetbar-title { font-size: .78rem; color: var(--muted); margin-bottom: 3px; }
.budgetbar-item .bar { height: 8px; }
.bar-rest { height: 100%; background: #f59e0b; border-radius: 5px; transition: width .3s; }
.bar-normal { height: 100%; background: var(--primary); border-radius: 5px; transition: width .3s; }

/* Budget bar */
.budgetbar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.budgetbar .bar { flex: 1; min-width: 150px; height: 10px; background: var(--bar-bg); border-radius: 5px; overflow: hidden; }
.budgetbar .bar > div { height: 100%; background: var(--primary); border-radius: 5px; transition: width .3s; }

/* Kalender */
.yeargrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
.month h3 { font-size: .95rem; margin-bottom: 8px; }
.dow, .days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.dow { font-size: .68rem; color: var(--muted); text-align: center; margin-bottom: 4px; font-weight: 600; }
.day {
  aspect-ratio: 1; border-radius: 6px; background: var(--day-bg); font-size: .72rem;
  display: flex; align-items: center; justify-content: center; position: relative; color: var(--muted);
}
.day.out { visibility: hidden; }
.day.weekend { background: var(--weekend-bg); }
.day.holiday { background: var(--holiday-bg); color: var(--holiday-text); font-weight: 600; }
.day .vac {
  position: absolute; inset: 0; border-radius: 6px; opacity: .85;
  display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700;
}
.day.mine .vac { outline: 2px solid var(--text); outline-offset: -2px; cursor: pointer; }
.legend { display: flex; flex-wrap: wrap; gap: 10px; margin: 16px 0; }
.legend .item { display: flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--muted); }
.legend .swatch { width: 14px; height: 14px; border-radius: 4px; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex;
  align-items: center; justify-content: center; padding: 16px; z-index: 50;
}
.modal { background: var(--card); border-radius: var(--radius); padding: 24px; width: 100%; max-width: 420px; }
.modal h2 { font-size: 1.1rem; margin-bottom: 8px; }
.modal .row { display: flex; gap: 10px; }
.modal .row > div { flex: 1; }
.preview { margin: 14px 0; padding: 12px; border-radius: 8px; background: var(--preview-bg); font-size: .9rem; }
.preview.bad { background: var(--preview-bad-bg); color: var(--danger); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }

/* Admin */
.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }

/* Toasts */
#toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px); }
.toast { background: #2a3550; color: #fff; padding: 12px 16px; border-radius: 10px; font-size: .9rem; animation: slideup .25s ease; }
.toast.error { background: var(--danger); }
@keyframes slideup { from { opacity: 0; transform: translateY(10px); } }

@media (max-width: 640px) {
  .admin-grid { grid-template-columns: 1fr; }
  .yeargrid { grid-template-columns: 1fr; }
  #app { padding: 10px; }
  .card { padding: 14px; }
}

/* Kalenderwochen-Spalte */
.days.withkw { grid-template-columns: 1.6em repeat(7, 1fr); }
.dow.withkw { grid-template-columns: 1.6em repeat(7, 1fr); }
.day.kwcell { background: transparent; color: var(--muted); font-size: .62rem; font-weight: 700; display: flex; align-items: center; justify-content: center; border-right: 1px solid var(--border); }
.dow .kw { font-size: .62rem; color: var(--muted); font-weight: 700; display: flex; align-items: center; justify-content: center; }

/* Urlaubssperre + Ereignisse */
.day.blocked { background: repeating-linear-gradient(45deg, #ef444422, #ef444422 4px, #ef444444 4px, #ef444444 8px); cursor: help; }
.day.has-event { box-shadow: inset 0 0 0 2px #f59e0b; cursor: help; }
.day.has-event::after { content: '⭐'; position: absolute; top: 1px; right: 2px; font-size: .55rem; }

/* Legenden-Swatches */
.swatch.holiday-swatch { background: var(--holiday-bg, #fecaca); }
.swatch.blocked-swatch { background: repeating-linear-gradient(45deg, #ef444466, #ef444466 3px, #ef444499 3px, #ef444499 6px); }
.swatch.event-swatch { background: #f59e0b; }

button.danger { color: #dc2626; }

/* Tages-Tooltip (Tap/Klick) */
.day-tooltip { position: fixed; z-index: 1000; background: var(--card-bg, #fff); color: var(--text, #111); border: 1px solid var(--border, #ddd); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.18); padding: 10px 12px; font-size: .85rem; pointer-events: auto; }
.day-tooltip .tt-head { font-weight: 700; margin-bottom: 6px; border-bottom: 1px solid var(--border, #eee); padding-bottom: 4px; }
.day-tooltip .tt-line { display: flex; gap: 6px; align-items: baseline; padding: 2px 0; }
.day-tooltip .tt-icon { flex: 0 0 auto; }
.day-tooltip .tt-edit { margin-top: 8px; width: 100%; padding: 6px 10px; font-size: .8rem; }
[data-theme="dark"] .day-tooltip { background: #1d2438; color: #e7ecf5; border-color: #33405e; }
