/* ═══════════════════════════════════════════
   Base — Reset + App Shell
   ═══════════════════════════════════════════ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: var(--lh-normal);
  color: var(--c-text);
  background: var(--c-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
  overscroll-behavior: none;
  padding-top: var(--safe-top);
  background: var(--c-bg);
  color: var(--c-text);
}

a { color: inherit; text-decoration: none; }
img, svg { display: block; max-width: 100%; }
button, input, select, textarea {
  font: inherit;
  color: inherit;
  border: none;
  background: none;
  outline: none;
}
button { cursor: pointer; }

/* ⛔ **231 §C.1 — der Doppeltipp-Zoom, an genau einer Stelle.**
 *
 * Gemessen gegen Prod (Cowork, 30.08.): das PIN-Feld hat **kein Eingabefeld**,
 * die Ziffern sind zwölf `<button>`; die bekannte 16-px-Mechanik greift hier
 * gar nicht. Ursache ist `touch-action: auto` — damit behält iOS Safari die
 * **Doppeltipp-zum-Zoomen**-Geste, und zwei Ziffern in schneller Folge liegen
 * unter dem Doppeltipp-Fenster.
 *
 * > ***Deshalb passiert es beim schnellen Eingeben und beim langsamen nicht.***
 *
 * `manipulation` nimmt **genau** diese Geste und lässt das Aufziehen mit zwei
 * Fingern unberührt — der Unterschied ist der ganze Punkt.
 *
 * ⛔ **Kein `user-scalable=no`, kein `maximum-scale`.** *Wer das Hineinzoomen
 * abschaltet, weil es an der falschen Stelle passiert, nimmt es auch dem, der
 * es braucht. Das ist keine Reparatur, das ist ein zweiter Fehler mit ruhigerem
 * Symptom.*
 *
 * ⚠️ **Warum die Liste länger ist als `button`:** die vier Fundstellen, die
 * `manipulation` schon trugen, hängen nicht alle an einem Knopf — gemessen ist
 * `.bnav-more-item` ein `<a>` und `.calendar-view-btn` **auch** ein `<div>`.
 * *Ein reines `button { … }` hätte sie stillschweigend verloren, und die
 * Reparatur wäre an zwei Stellen verschwunden, wo sie vorher stand.*
 */
button,
[role="button"],
.bnav-more-item,
.calendar-view-btn {
  touch-action: manipulation;
}
:focus-visible {
  outline: 2px solid var(--c-primary);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* ── App Container ── */
#app {
  display: flex;
  min-height: 100dvh;
}

notes-app {
  width: 100%;
  min-height: 100dvh;
}

/* ── Sidebar (Desktop/Tablet) ── */
.app-sidebar {
  display: none; /* mobile: hidden */
  width: var(--sidebar-w);
  background: var(--c-bg-elevated);
  border-right: 1px solid var(--c-border);
  padding: var(--sp-lg) 0;
  flex-shrink: 0;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: var(--z-nav);
  flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sidebar-header {
  padding: 0 var(--sp-md);
  margin-bottom: var(--sp-xl);
}

.sidebar-logo {
  font-size: var(--fs-lg);
  font-weight: var(--fw-bold);
  color: var(--c-text);
  letter-spacing: -0.3px;
}

.sidebar-subtitle {
  font-size: var(--fs-xs);
  color: var(--c-text-muted);
  margin-top: var(--sp-2xs);
}

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--sp-xs);
  padding: 0 var(--sp-sm);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  padding: 10px var(--sp-md);
  border-radius: var(--r-md);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--c-text-secondary);
  transition: all var(--tr-normal);
  position: relative;
  user-select: none;
  -webkit-user-select: none;
}

.nav-item:hover {
  background: var(--c-primary-soft);
  color: var(--c-primary);
}

.nav-item.active {
  background: var(--c-primary-soft);
  color: var(--c-primary);
  font-weight: var(--fw-semibold);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 3px;
  background: var(--c-primary);
  border-radius: 0 var(--r-xs) var(--r-xs) 0;
}

.nav-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.nav-icon svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 1.8;
  fill: none;
}

.nav-badge {
  margin-left: auto;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--r-full);
  background: var(--c-primary);
  color: white;
  font-size: var(--fs-2xs);
  font-weight: var(--fw-bold);
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-footer {
  padding: var(--sp-md);
  margin-top: auto;
  border-top: 1px solid var(--c-border-subtle);
  display: flex;
  flex-direction: column;
  gap: var(--sp-sm);
}

/* ── Theme Toggle ── */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-sm);
  width: 100%;
  padding: var(--sp-sm);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  color: var(--c-text-secondary);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  transition: all var(--tr-normal);
  cursor: pointer;
}
.theme-toggle svg { width: 16px; height: 16px; }
.theme-toggle:hover {
  background: var(--c-primary-soft);
  color: var(--c-primary);
  border-color: var(--c-primary);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  padding: var(--sp-sm);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background var(--tr-normal);
}

.sidebar-user:hover { background: var(--c-surface-hover); }

.sidebar-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--r-full);
  background: var(--c-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  flex-shrink: 0;
}

.sidebar-user-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sidebar-user-name {
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  font-size: var(--fs-xs);
  color: var(--c-text-muted);
}

/* ── Main Content ── */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  min-width: 0;
}

/* ── Header ── */
.app-header {
  height: var(--header-h);
  padding: 0 var(--sp-md);
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  background: var(--c-bg-elevated);
  border-bottom: 1px solid var(--c-border);
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  flex-shrink: 0;
}

.header-title {
  font-size: var(--fs-lg);
  font-weight: var(--fw-bold);
  white-space: nowrap;
  letter-spacing: -0.3px;
}

.header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
}

.header-sync-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--r-full);
  background: var(--c-success);
  transition: background var(--tr-normal);
}

.header-sync-dot.offline { background: var(--c-text-muted); }
.header-sync-dot.syncing { background: var(--c-warning); animation: pulse 1.5s infinite; }

/* 237 A-006 T2 — geparkte Offline-Queue-Einträge: dezent (kleine Schrift,
   Warnfarbe nur als Text, kein Icon-Alarm), NICHT wegklickbar (kein Button,
   kein Dialog) — dieselbe Bauart wie .app-footer oben. */
.header-parked-badge {
  font-size: var(--fs-xs);
  color: var(--c-warning);
  border: 1px solid var(--c-warning);
  border-radius: var(--r-full);
  padding: 1px var(--sp-xs);
  white-space: nowrap;
}

/* ── Content Area ── */
.app-content {
  flex: 1;
  padding: var(--sp-md);
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + var(--sp-md));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ── App Footer (227 §C.3 / A-005) — ständige Freizeichnung, an der Shell
   verankert (ein Ort, jede Seite NACH der Anmeldung), dezent, nicht
   wegklickbar. Auf Mobile sitzt .app-bottom-nav fixed am Viewport-Rand —
   der Footer bekommt dort Raum darüber reserviert, sonst überdeckt der
   Nav ihn. */
.app-footer {
  flex-shrink: 0;
  padding: var(--sp-xs) var(--sp-md);
  font-size: var(--fs-xs);
  color: var(--c-text-muted);
  border-top: 1px solid var(--c-border);
  background: var(--c-bg-elevated);
}

@media (max-width: 767px) {
  .app-footer {
    margin-bottom: calc(var(--nav-h) + var(--safe-bottom));
  }
}

/* ── Bottom Nav (Mobile) ── */
.app-bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--c-bg-elevated);
  border-top: 1px solid var(--c-border);
  box-shadow: 0 -1px 10px rgba(15, 23, 42, 0.04);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: var(--z-nav);
}

.bnav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--sp-xs) var(--sp-sm);
  min-width: 48px;
  min-height: 48px;
  justify-content: center;
  color: var(--c-text-muted);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-medium);
  transition: color var(--tr-fast);
  position: relative;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

.bnav-item svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  stroke-width: 1.8;
  fill: none;
}

.bnav-item.active {
  color: var(--c-primary);
}

.bnav-item .bnav-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: var(--r-full);
  background: var(--c-error);
  color: white;
  font-size: 9px;
  font-weight: var(--fw-bold);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Bottom Nav "Mehr" Menu ── */
.bnav-more-wrap {
  position: relative;
  cursor: pointer;
}
.bnav-more-backdrop {
  position: fixed;
  inset: 0;
  z-index: calc(var(--z-nav) - 1);
}
.bnav-more-menu {
  position: absolute;
  bottom: calc(100% + var(--sp-sm));
  right: 0;
  min-width: 200px;
  background: var(--c-bg-elevated);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  padding: var(--sp-xs) 0;
  box-shadow: var(--shadow-lg);
  z-index: calc(var(--z-nav) + 1);
}
.bnav-more-item {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  padding: var(--sp-sm) var(--sp-md);
  color: var(--c-text);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  text-decoration: none;
  /* touch-action: hineingefaltet nach oben (231 S3) */
  -webkit-tap-highlight-color: transparent;
}
.bnav-more-item:hover,
.bnav-more-item:active {
  background: var(--c-surface);
}
.bnav-more-item.active {
  color: var(--c-primary);
}
.bnav-more-item svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 1.8;
  fill: none;
  flex-shrink: 0;
}
.bnav-more-version {
  padding: var(--sp-xs) var(--sp-md);
  font-size: var(--fs-2xs);
  color: var(--c-text-muted);
  border-top: 1px solid var(--c-border-subtle);
  margin-top: var(--sp-xs);
  text-align: center;
}

/* ── Toast Container ── */
#toast-container {
  position: fixed;
  top: calc(var(--safe-top) + var(--sp-md));
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--sp-sm);
  pointer-events: none;
  width: calc(100% - var(--sp-xl));
  max-width: 400px;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--c-border); border-radius: var(--r-full); }

/* ── Animations ── */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes slideDown { from { opacity: 0; transform: translateY(-12px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Utility ── */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
