/* ═══════════════════════════════════════════
   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; }
: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-glass-heavy);
  backdrop-filter: blur(var(--blur-heavy));
  -webkit-backdrop-filter: blur(var(--blur-heavy));
  border-right: 1px solid var(--c-border-subtle);
  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-glass);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  border-bottom: 1px solid var(--c-border-subtle);
  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; }

/* ── 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;
}

/* ── 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-glass-heavy);
  backdrop-filter: blur(var(--blur-heavy));
  -webkit-backdrop-filter: blur(var(--blur-heavy));
  border-top: 1px solid var(--c-border-subtle);
  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-glass-heavy);
  backdrop-filter: blur(var(--blur-heavy));
  -webkit-backdrop-filter: blur(var(--blur-heavy));
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  padding: var(--sp-xs) 0;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.3);
  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: manipulation;
  -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; }
