/* ==========================================================================
   Ledenportaal – premium design system
   ========================================================================== */

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

:root {
  /* Palette */
  --c-ink:         #0F172A;
  --c-text:        #1F2A3A;
  --c-muted:       #6B7280;
  --c-muted-soft:  #9AA3B0;

  --c-primary:     #1B3A5C;
  --c-primary-900: #0F2540;
  --c-primary-100: #EEF3F8;
  --c-primary-50:  #F6F9FC;

  --c-accent:      #4A90A4;
  --c-accent-soft: rgba(74,144,164,0.12);

  --c-gold:        #C8994A;
  --c-gold-light:  #E3BE76;
  --c-gold-soft:   rgba(200,153,74,0.12);

  --c-bg:          #FAF7F0;
  --c-bg-alt:      #F5EFE2;
  --c-surface:     #FFFFFF;
  --c-surface-2:   #FBF8F1;

  --c-border:      #EDE6D4;
  --c-border-soft: #F3EFE1;
  --c-border-strong:#D9CFB8;

  --c-success:     #0E9F6E;
  --c-success-soft:rgba(14,159,110,0.12);
  --c-danger:      #B91C1C;
  --c-danger-soft: rgba(185,28,28,0.1);

  /* Radii */
  --r-xs: 6px;
  --r-sm: 10px;
  --r:    14px;
  --r-lg: 20px;
  --r-xl: 28px;
  --r-full: 999px;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(15,37,64,0.04);
  --shadow-sm: 0 1px 2px rgba(15,37,64,0.05), 0 2px 6px rgba(15,37,64,0.04);
  --shadow:    0 1px 2px rgba(15,37,64,0.05), 0 8px 24px rgba(15,37,64,0.07);
  --shadow-lg: 0 1px 2px rgba(15,37,64,0.05), 0 20px 48px rgba(15,37,64,0.12);
  --shadow-xl: 0 20px 60px rgba(15,37,64,0.22);

  /* Motion */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --t-fast: 140ms var(--ease);
  --t:      220ms var(--ease);
  --t-slow: 420ms var(--ease-out);

  /* Layout */
  --header-h: 74px;
}

html, body { height: 100%; }

body {
  font-family: 'Source Sans 3', system-ui, -apple-system, Segoe UI, sans-serif;
  background: var(--c-bg);
  background-image:
    radial-gradient(1200px 600px at 80% -200px, rgba(200,153,74,0.10), transparent 70%),
    radial-gradient(900px 500px at -10% 10%, rgba(27,58,92,0.08), transparent 70%);
  background-attachment: fixed;
  color: var(--c-text);
  line-height: 1.55;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.005em;
}

::selection { background: var(--c-gold-soft); color: var(--c-primary-900); }

a { color: inherit; text-decoration: none; }

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.75rem;
}

i[class*="ph-"] { line-height: 1; display: inline-flex; vertical-align: middle; }

/* ==========================================================================
   Login
   ========================================================================== */

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background:
    radial-gradient(900px 500px at 15% 20%, rgba(74,144,164,0.35), transparent 60%),
    radial-gradient(900px 500px at 85% 80%, rgba(200,153,74,0.25), transparent 60%),
    linear-gradient(135deg, #0F2540 0%, #1B3A5C 45%, #2C5577 100%);
  position: relative;
  overflow: hidden;
}

.login-card {
  background: var(--c-surface);
  padding: 2.75rem 2.5rem;
  border-radius: var(--r-lg);
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-xl);
  animation: cardIn 540ms var(--ease-out);
  position: relative;
  overflow: hidden;
}

.login-card::before {
  content: "";
  position: absolute; inset: 0 0 auto 0;
  height: 4px;
  background: linear-gradient(90deg, var(--c-gold), var(--c-accent), var(--c-gold));
}

.login-card__logo {
  display: block;
  max-width: 260px;
  width: 100%;
  height: auto;
  margin: 0 auto 1.25rem;
}

.login-card h1 {
  font-family: 'Playfair Display', serif;
  font-size: 1.75rem;
  color: var(--c-primary-900);
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: 0.35rem;
  text-align: center;
}

.login-card__sub { text-align: center; }

.login-card__sub {
  color: var(--c-muted);
  font-size: 0.95rem;
  margin-bottom: 1.75rem;
}

.form-group { margin-bottom: 1.1rem; }

.form-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--c-primary-900);
  margin-bottom: 0.4rem;
  letter-spacing: 0.01em;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--c-text);
  background: var(--c-surface);
  transition: border-color var(--t), box-shadow var(--t), background var(--t);
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--c-accent);
  box-shadow: 0 0 0 4px rgba(74,144,164,0.15);
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn-member {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.7rem 1.15rem;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: 0.005em;
  cursor: pointer;
  text-decoration: none;
  background: var(--c-surface);
  color: var(--c-text);
  transition: transform var(--t), box-shadow var(--t), background var(--t), border-color var(--t), color var(--t);
  user-select: none;
  white-space: nowrap;
}

.btn-member i[class*="ph-"] { font-size: 1.05em; }

.btn-member:hover { transform: translateY(-1px); }
.btn-member:active { transform: translateY(0); }
.btn-member:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

.btn-member--primary {
  background: linear-gradient(180deg, var(--c-primary) 0%, var(--c-primary-900) 100%);
  color: #fff;
  box-shadow: 0 4px 12px rgba(27,58,92,0.22);
}
.btn-member--primary:hover { box-shadow: 0 6px 18px rgba(27,58,92,0.32); }

.btn-member--gold {
  background: linear-gradient(180deg, var(--c-gold-light) 0%, var(--c-gold) 100%);
  color: var(--c-primary-900);
  box-shadow: 0 4px 12px rgba(200,153,74,0.28);
}
.btn-member--gold:hover { box-shadow: 0 6px 18px rgba(200,153,74,0.38); }

.btn-member--success {
  background: var(--c-success);
  color: #fff;
  box-shadow: 0 4px 12px rgba(14,159,110,0.22);
}
.btn-member--success:hover { box-shadow: 0 6px 18px rgba(14,159,110,0.32); }

.btn-member--ghost {
  background: transparent;
  border-color: var(--c-border-strong);
  color: var(--c-primary-900);
}
.btn-member--ghost:hover {
  background: var(--c-primary-50);
  border-color: var(--c-primary);
}

.btn-member--sm { padding: 0.45rem 0.8rem; font-size: 0.85rem; border-radius: var(--r-xs); }

/* Icon-only button */
.btn-icon {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-full);
  border: 1px solid var(--c-border);
  background: var(--c-surface);
  color: var(--c-primary);
  cursor: pointer;
  transition: all var(--t);
  font-size: 1.1rem;
}
.btn-icon:hover {
  background: var(--c-primary-50);
  border-color: var(--c-primary);
  color: var(--c-primary-900);
}

/* ==========================================================================
   App shell
   ========================================================================== */

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(255,255,255,0.85);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--c-border-soft);
}

.app-header__inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1.75rem;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 2rem;
}

.app-header__brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
  transition: opacity var(--t);
}

.app-header__brand:hover { opacity: 0.85; }

.app-header__teken { height: 32px; width: auto; aspect-ratio: 138.9 / 206.35; color: var(--c-primary); flex: none; }

.app-header__wordmark {
  font-family: 'Playfair Display', serif;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--c-primary-900);
  letter-spacing: -0.015em;
  line-height: 1;
}

.app-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex: 1;
}

.app-nav__link {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.85rem;
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--c-muted);
  border-radius: var(--r-sm);
  transition: color var(--t), background var(--t);
}

.app-nav__link i[class*="ph-"] {
  font-size: 1.05rem;
  opacity: 0.8;
  transition: opacity var(--t), transform var(--t);
}

.app-nav__link:hover {
  color: var(--c-primary-900);
  background: var(--c-primary-50);
}

.app-nav__link:hover i[class*="ph-"] { opacity: 1; }

.app-nav__link.active {
  color: var(--c-primary-900);
  background: var(--c-primary-100);
}

.app-nav__link.active::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -6px;
  transform: translateX(-50%);
  width: 18px;
  height: 2px;
  border-radius: 2px;
  background: var(--c-gold);
  animation: navSlide 320ms var(--ease-out);
}

.app-header__actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.app-user {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.3rem 0.75rem 0.3rem 0.3rem;
  border: 1px solid var(--c-border-soft);
  border-radius: var(--r-full);
  background: var(--c-surface);
  transition: border-color var(--t), box-shadow var(--t);
}

.app-user:hover {
  border-color: var(--c-border-strong);
  box-shadow: var(--shadow-xs);
}

.app-user__avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--c-primary) 0%, var(--c-accent) 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.85rem;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

.app-user__meta {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.app-user__name {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--c-primary-900);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-user__logout {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.76rem;
  color: var(--c-muted);
  transition: color var(--t);
}

.app-user__logout:hover { color: var(--c-danger); }

.app-beheer {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--c-border-strong);
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--c-primary);
  text-decoration: none;
  transition: background var(--t);
}
.app-beheer:hover { background: var(--c-primary-100); }
.app-beheer[hidden] { display: none; }

.app-header__toggle {
  display: none;
  width: 40px;
  height: 40px;
  border-radius: var(--r-sm);
  border: 1px solid var(--c-border);
  background: var(--c-surface);
  color: var(--c-primary);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
}

.app-main {
  flex: 1;
  padding: 2rem 0 3rem;
}

#pageContent {
  animation: pageIn 480ms var(--ease-out);
}

/* ==========================================================================
   Page header (h2 blocks)
   ========================================================================== */

.page-head {
  margin-bottom: 1.75rem;
}

.page-head__eyebrow {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--c-gold);
  margin-bottom: 0.4rem;
  display: block;
}

.page-head__title {
  font-family: 'Playfair Display', serif;
  font-size: 2.1rem;
  font-weight: 700;
  color: var(--c-primary-900);
  letter-spacing: -0.015em;
  line-height: 1.1;
}

.page-head__sub {
  color: var(--c-muted);
  margin-top: 0.4rem;
  font-size: 0.98rem;
}

.section-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--c-primary-900);
  letter-spacing: -0.01em;
  margin: 2rem 0 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.section-title i[class*="ph-"] {
  color: var(--c-accent);
  font-size: 1.1rem;
}

/* ==========================================================================
   Stats grid
   ========================================================================== */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  position: relative;
  background: var(--c-surface);
  border: 1px solid var(--c-border-soft);
  border-radius: var(--r);
  padding: 1.2rem 1.25rem;
  box-shadow: var(--shadow-xs);
  overflow: hidden;
  transition: transform var(--t), box-shadow var(--t), border-color var(--t);
}

.stat-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; bottom: 0;
  width: 3px;
  background: linear-gradient(180deg, var(--c-gold) 0%, var(--c-gold-light) 100%);
  opacity: 0.85;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  border-color: var(--c-border);
}

.stat-card__icon {
  width: 40px;
  height: 40px;
  border-radius: var(--r-sm);
  background: var(--c-primary-50);
  color: var(--c-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  margin-bottom: 0.85rem;
}

.stat-card__value {
  font-family: 'Playfair Display', serif;
  font-size: 2.1rem;
  font-weight: 700;
  color: var(--c-primary-900);
  line-height: 1;
  letter-spacing: -0.02em;
  margin-bottom: 0.2rem;
}

.stat-card__label {
  color: var(--c-muted);
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.01em;
}

/* ==========================================================================
   Content cards
   ========================================================================== */

.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border-soft);
  border-radius: var(--r);
  padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow-xs);
  transition: transform var(--t), box-shadow var(--t), border-color var(--t);
  margin-bottom: 0.75rem;
}

.card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
  border-color: var(--c-border);
}

.card--row {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.card__body { flex: 1; min-width: 220px; }

.card__title {
  font-weight: 600;
  color: var(--c-primary-900);
  font-size: 1.02rem;
  margin-bottom: 0.2rem;
  letter-spacing: -0.005em;
}

.card__meta {
  color: var(--c-muted);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.card__meta-sep { color: var(--c-muted-soft); }

.card__actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

/* Date chip used on event/payment cards */
.date-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 62px;
  height: 62px;
  background: linear-gradient(145deg, var(--c-primary) 0%, var(--c-primary-900) 100%);
  color: #fff;
  border-radius: var(--r-sm);
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(27,58,92,0.2);
  position: relative;
  overflow: hidden;
}

.date-chip::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 14px;
  background: var(--c-gold);
  opacity: 0.95;
}

.date-chip__day {
  font-family: 'Playfair Display', serif;
  font-size: 1.45rem;
  font-weight: 700;
  line-height: 1;
  margin-top: 10px;
}

.date-chip__month {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  margin-top: 2px;
  opacity: 0.92;
}

/* Type chip */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.6rem;
  border-radius: var(--r-full);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: var(--c-primary-100);
  color: var(--c-primary-900);
}

.chip i[class*="ph-"] { font-size: 0.88rem; }

.chip--gold { background: var(--c-gold-soft); color: #7A5E1F; }
.chip--success { background: var(--c-success-soft); color: var(--c-success); }
.chip--muted { background: var(--c-primary-50); color: var(--c-muted); }

.amount {
  font-family: 'Playfair Display', serif;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--c-primary-900);
}

.paid-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--c-success);
  font-weight: 600;
  font-size: 0.9rem;
}

/* Empty / loading states */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--c-muted);
}

.empty-state__icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 1rem;
  border-radius: var(--r);
  background: var(--c-primary-50);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--c-accent);
  font-size: 1.9rem;
}

.empty-state__title {
  font-family: 'Playfair Display', serif;
  font-size: 1.2rem;
  color: var(--c-primary-900);
  margin-bottom: 0.3rem;
}

.loading-skeleton {
  background: linear-gradient(90deg, var(--c-surface-2) 0%, var(--c-border-soft) 50%, var(--c-surface-2) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
  border-radius: var(--r-sm);
}

.error-msg {
  background: var(--c-danger-soft);
  color: var(--c-danger);
  padding: 0.75rem 1rem;
  border-radius: var(--r-sm);
  font-size: 0.88rem;
  border: 1px solid rgba(185,28,28,0.2);
}

/* ==========================================================================
   Calendar
   ========================================================================== */

.calendar {
  background: var(--c-surface);
  border: 1px solid var(--c-border-soft);
  border-radius: var(--r);
  padding: 1.4rem 1.5rem;
  box-shadow: var(--shadow-xs);
}

.calendar__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.calendar__title {
  font-family: 'Playfair Display', serif;
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--c-primary-900);
  text-transform: capitalize;
  letter-spacing: -0.01em;
}

.calendar__nav-group { display: flex; gap: 0.5rem; }

.calendar__nav {
  width: 36px;
  height: 36px;
  border-radius: var(--r-full);
  border: 1px solid var(--c-border);
  background: var(--c-surface);
  color: var(--c-primary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--t);
  font-size: 1.05rem;
}

.calendar__nav:hover {
  background: var(--c-primary);
  color: #fff;
  border-color: var(--c-primary);
}

.calendar__grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.calendar__day-header {
  text-align: center;
  padding: 0.4rem 0;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--c-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.calendar__day {
  min-height: 42px;
  padding: 0.3rem 0 0.55rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-sm);
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--c-text);
  position: relative;
  transition: background var(--t), color var(--t), transform var(--t);
  cursor: default;
}

.calendar__day:hover { background: var(--c-primary-50); }

.calendar__day--other {
  color: var(--c-muted-soft);
  opacity: 0.55;
}

.calendar__day--today {
  background: var(--c-primary);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(27,58,92,0.25);
}

.calendar__day--today:hover { background: var(--c-primary-900); }

.calendar__day--event::after {
  content: "";
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--c-gold);
}

.calendar__day--today.calendar__day--event::after { background: var(--c-gold-light); }

/* ==========================================================================
   Chat / Overleg
   ========================================================================== */

.chat {
  background: var(--c-surface);
  border: 1px solid var(--c-border-soft);
  border-radius: var(--r-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--header-h) - 180px);
  min-height: 520px;
  box-shadow: var(--shadow);
}

.chat__messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  background:
    radial-gradient(600px 300px at 90% 0%, rgba(200,153,74,0.05), transparent 60%),
    var(--c-surface-2);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  scroll-behavior: smooth;
}

.chat__messages::-webkit-scrollbar { width: 8px; }
.chat__messages::-webkit-scrollbar-thumb {
  background: var(--c-border-strong);
  border-radius: 4px;
}
.chat__messages::-webkit-scrollbar-thumb:hover { background: var(--c-muted-soft); }

.chat__day-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 1rem 0 0.5rem;
}

.chat__day-divider span {
  background: var(--c-surface);
  border: 1px solid var(--c-border-soft);
  color: var(--c-muted);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.3rem 0.85rem;
  border-radius: var(--r-full);
  box-shadow: var(--shadow-xs);
}

.chat__msg-row {
  display: flex;
  gap: 0.65rem;
  align-items: flex-end;
  animation: msgIn 340ms var(--ease-out);
}

.chat__msg-row--own { flex-direction: row-reverse; }

.chat__avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.78rem;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(15,37,64,0.15);
}

.chat__msg-row--grouped .chat__avatar { visibility: hidden; }
.chat__msg-row--grouped .chat__msg-header { display: none; }
.chat__msg-row--grouped { margin-top: -0.25rem; }

.chat__msg {
  background: var(--c-surface);
  border: 1px solid var(--c-border-soft);
  border-radius: var(--r);
  padding: 0.65rem 0.9rem;
  max-width: min(70%, 560px);
  box-shadow: var(--shadow-xs);
  position: relative;
  transition: box-shadow var(--t);
}

.chat__msg:hover { box-shadow: var(--shadow-sm); }

.chat__msg-row--own .chat__msg {
  background: var(--c-bg-alt);
  border-color: #E8DFC8;
  color: var(--c-text);
}

.chat__msg-row--own .chat__msg:hover { box-shadow: var(--shadow-sm); }

.chat__msg-header {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.78rem;
  margin-bottom: 0.3rem;
  align-items: baseline;
}

.chat__msg-name {
  font-weight: 700;
  color: var(--c-primary-900);
  letter-spacing: -0.005em;
}

.chat__msg-row--own .chat__msg-name { color: var(--c-primary-900); }

.chat__msg-time {
  color: var(--c-muted);
  font-size: 0.72rem;
}

.chat__msg-body {
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  font-size: 0.95rem;
  line-height: 1.5;
}

.chat__msg-body--deleted {
  color: var(--c-muted);
  font-style: italic;
  font-size: 0.88rem;
}

.chat__msg-quote {
  border-left: 3px solid var(--c-accent);
  background: var(--c-accent-soft);
  padding: 0.4rem 0.6rem;
  margin-bottom: 0.45rem;
  font-size: 0.85rem;
  border-radius: 4px;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
}

.chat__msg-quote i[class*="ph-"] {
  font-size: 0.9rem;
  color: var(--c-accent);
  flex-shrink: 0;
  margin-top: 2px;
}

.chat__msg-quote-name {
  font-weight: 700;
  color: var(--c-primary-900);
}

.chat__event-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--c-gold-soft);
  color: #7A5E1F;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.25rem 0.65rem;
  border-radius: var(--r-full);
  text-decoration: none;
  margin-bottom: 0.45rem;
  transition: all var(--t);
  border: 1px solid rgba(200,153,74,0.2);
}

.chat__event-badge:hover { transform: translateY(-1px); filter: brightness(0.98); }

.chat__event-badge i[class*="ph-"] { font-size: 0.88rem; }

.chat__msg-actions {
  display: flex;
  gap: 0.2rem;
  margin-top: 0.4rem;
  opacity: 0;
  transition: opacity var(--t);
}

.chat__msg:hover .chat__msg-actions { opacity: 1; }

.chat__msg-action {
  background: none;
  border: none;
  color: inherit;
  font-size: 0.72rem;
  cursor: pointer;
  padding: 0.25rem 0.45rem;
  border-radius: var(--r-xs);
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  opacity: 0.6;
  transition: all var(--t);
  font-family: inherit;
  font-weight: 500;
}

.chat__msg-action:hover {
  background: rgba(15,37,64,0.06);
  opacity: 1;
}

.chat__msg-action i[class*="ph-"] { font-size: 0.88rem; }

.chat__msg-action--danger:hover {
  color: var(--c-danger);
  background: var(--c-danger-soft);
}

/* Compose */
.chat__compose {
  border-top: 1px solid var(--c-border-soft);
  padding: 1rem 1.25rem 1.1rem;
  background: var(--c-surface);
}

.chat__compose-meta { margin-bottom: 0.6rem; }

.chat__quote-preview {
  position: relative;
  border-left: 3px solid var(--c-accent);
  background: var(--c-accent-soft);
  padding: 0.55rem 2.2rem 0.55rem 0.75rem;
  border-radius: var(--r-xs);
  font-size: 0.85rem;
  animation: slideDown 220ms var(--ease-out);
}

.chat__quote-preview-label {
  font-weight: 700;
  color: var(--c-primary-900);
  font-size: 0.72rem;
  margin-bottom: 0.2rem;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.chat__quote-preview-body {
  color: var(--c-text);
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.chat__quote-cancel {
  position: absolute;
  top: 0.35rem;
  right: 0.45rem;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--c-muted);
  line-height: 1;
  padding: 4px;
  border-radius: var(--r-full);
  transition: all var(--t);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
}

.chat__quote-cancel:hover {
  background: rgba(15,37,64,0.08);
  color: var(--c-danger);
}

.chat__textarea {
  width: 100%;
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  padding: 0.7rem 0.9rem;
  font-family: inherit;
  font-size: 0.95rem;
  resize: vertical;
  background: var(--c-surface);
  color: var(--c-text);
  transition: border-color var(--t), box-shadow var(--t);
  line-height: 1.5;
}

.chat__textarea:focus {
  outline: none;
  border-color: var(--c-accent);
  box-shadow: 0 0 0 4px rgba(74,144,164,0.15);
}

.chat__textarea--inline { margin-top: 0.35rem; }

.chat__compose-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.6rem;
  flex-wrap: wrap;
}

.chat__compose-actions {
  display: flex;
  gap: 0.55rem;
  align-items: center;
  flex-wrap: wrap;
}

.chat__event-select {
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  padding: 0.42rem 0.65rem;
  padding-left: 2rem;
  font-family: inherit;
  font-size: 0.85rem;
  background: var(--c-surface);
  color: var(--c-text);
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--c-muted) 50%),
    linear-gradient(135deg, var(--c-muted) 50%, transparent 50%);
  background-position: right 10px top 55%, right 5px top 55%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  padding-right: 1.8rem;
  cursor: pointer;
  transition: all var(--t);
}

.chat__event-select:hover { border-color: var(--c-border-strong); }
.chat__event-select:focus {
  outline: none;
  border-color: var(--c-accent);
  box-shadow: 0 0 0 4px rgba(74,144,164,0.15);
}

.chat__event-select-wrap {
  position: relative;
  display: inline-block;
}

.chat__event-select-wrap i[class*="ph-"] {
  position: absolute;
  left: 0.6rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--c-accent);
  font-size: 0.95rem;
  pointer-events: none;
}

.chat__hint {
  color: var(--c-muted);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}

/* Typing hint (when offline/sending) */
.chat__sending-dot {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--c-accent);
  margin-right: 0.35rem;
  animation: pulse 1.2s ease-in-out infinite;
}

/* ==========================================================================
   Documents
   ========================================================================== */

.doc-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--c-surface);
  border: 1px solid var(--c-border-soft);
  border-radius: var(--r);
  padding: 1rem 1.2rem;
  margin-bottom: 0.7rem;
  box-shadow: var(--shadow-xs);
  transition: all var(--t);
}

.doc-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
  border-color: var(--c-border);
}

.doc-card__icon {
  width: 48px;
  height: 48px;
  border-radius: var(--r-sm);
  background: var(--c-primary-50);
  color: var(--c-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  flex-shrink: 0;
}

.doc-card__body { flex: 1; min-width: 200px; }

/* ==========================================================================
   Animations
   ========================================================================== */

@keyframes cardIn {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes pageIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

@keyframes navSlide {
  from { transform: translateX(-50%) scaleX(0); }
  to   { transform: translateX(-50%) scaleX(1); }
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

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

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 960px) {
  .app-header__inner { gap: 1rem; padding: 0 1rem; }
  .app-user__meta { display: none; }
  .app-user { padding: 0.2rem; }
  .page-head__title { font-size: 1.7rem; }
}

@media (max-width: 768px) {
  :root { --header-h: 62px; }

  .app-nav {
    position: absolute;
    top: var(--header-h);
    left: 0; right: 0;
    flex-direction: column;
    background: var(--c-surface);
    border-bottom: 1px solid var(--c-border);
    padding: 0.5rem;
    gap: 0.15rem;
    box-shadow: var(--shadow);
    max-height: 0;
    overflow: hidden;
    transition: max-height 320ms var(--ease-out);
  }

  .app-nav.active { max-height: 480px; }

  .app-nav__link { justify-content: flex-start; padding: 0.7rem 0.9rem; }
  .app-nav__link.active::after { display: none; }
  .app-nav__link.active {
    background: var(--c-primary);
    color: #fff;
  }

  .app-header__toggle { display: inline-flex; }
  .app-header__inner { position: relative; }

  .container { padding: 0 1.1rem; }
  .app-main { padding: 1.25rem 0 2rem; }
  .page-head__title { font-size: 1.5rem; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .stat-card__value { font-size: 1.75rem; }

  .chat { height: calc(100vh - var(--header-h) - 80px); border-radius: var(--r); }
  .chat__messages { padding: 1rem; }
  .chat__msg { max-width: 85%; }
  .chat__avatar { width: 30px; height: 30px; font-size: 0.72rem; }

  .calendar { padding: 1rem; }
  .calendar__day { font-size: 0.8rem; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
}
