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

:root {
  --primary:   #2563eb;
  --primary-h: #1d4ed8;
  --danger:    #dc2626;
  --success:   #16a34a;
  --warn:      #d97706;
  --bg:        #f1f5f9;
  --card:      #ffffff;
  --border:    #e2e8f0;
  --text:      #1e293b;
  --muted:     #64748b;
  --radius:    8px;
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  padding-bottom: 2rem; /* Platz für Footer */
}

.site-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  text-align: center;
  font-size: .72rem;
  color: var(--muted);
  padding: .3rem 1rem;
  background: var(--bg);
  border-top: 1px solid var(--border);
  pointer-events: none;
  z-index: 10;
}

/* ── Nav ── */
.nav {
  background: var(--primary);
  color: #fff;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  height: 56px;
  flex-wrap: nowrap;
  position: sticky;
  top: 0;
  z-index: 200;
}
.nav-brand { font-weight: 700; font-size: 1.1rem; text-decoration: none; color: #fff; white-space: nowrap; flex-shrink: 0; }
.nav-links  { display: flex; gap: 1rem; margin-left: auto; flex-shrink: 1; min-width: 0; }
.nav-links a {
  color: rgba(255,255,255,.85);
  text-decoration: none;
  font-size: .9rem;
  padding: .25rem .5rem;
  border-radius: 4px;
  transition: background .15s;
  white-space: nowrap;
}
.nav-links a:hover { background: rgba(255,255,255,.15); color: #fff; }
.nav-user {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .85rem;
  opacity: .85;
  white-space: nowrap;
  flex-shrink: 0;
}
.nav-user a { color: rgba(255,255,255,.8); text-decoration: none; font-size: .85rem; }
.nav-user a:hover { color: #fff; }

/* ── Layout ── */
.container { max-width: none; width: 100%; margin: 0; padding: 1rem 1rem 0; }
.page-title { font-size: 1.4rem; font-weight: 700; margin-bottom: 1.25rem; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  overflow-x: auto;
  width: 100%;
}
.fc {
  font-family: inherit;
  max-width: 100%;
  width: 100%;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .45rem 1rem;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: .9rem;
  font-weight: 500;
  transition: background .15s, opacity .15s;
  text-decoration: none;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary   { background: var(--primary);  color: #fff; }
.btn-primary:hover { background: var(--primary-h); }
.btn-danger    { background: var(--danger);   color: #fff; }
.btn-danger:hover { opacity: .85; }
.btn-success   { background: var(--success);  color: #fff; }
.btn-success:hover { opacity: .85; }
.btn-secondary { background: var(--border);   color: var(--text); }
.btn-secondary:hover { background: #cbd5e1; }
.btn-sm { padding: .3rem .7rem; font-size: .82rem; }

/* ── Forms ── */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: .85rem; font-weight: 500; margin-bottom: .35rem; }
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: .5rem .75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .9rem;
  font-family: inherit;
  transition: border-color .15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

/* ── Auth ── */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
}
.auth-logo { font-size: 1.4rem; font-weight: 800; color: var(--primary); margin-bottom: .25rem; }
.auth-sub  { color: var(--muted); font-size: .9rem; margin-bottom: 1.5rem; }
.auth-tabs { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 1.5rem; }
.auth-tab  {
  padding: .5rem 1rem;
  cursor: pointer;
  font-weight: 500;
  font-size: .9rem;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .15s, border-color .15s;
}
.auth-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ── Alerts ── */
.alert {
  padding: .65rem 1rem;
  border-radius: 6px;
  font-size: .875rem;
  margin-bottom: 1rem;
}
.alert-error   { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }
.alert-info    { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }

/* ── Table ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: .65rem .9rem; text-align: left; border-bottom: 1px solid var(--border); }
th { background: var(--bg); font-weight: 600; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }
.fc tr:hover td { background: unset; }

/* ── Badge ── */
.badge {
  display: inline-block;
  padding: .15rem .55rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
}
.badge-admin     { background: #ede9fe; color: #6d28d9; }
.badge-verwalter { background: #dbeafe; color: #1d4ed8; }
.badge-nutzer    { background: #f1f5f9; color: #475569; }
.badge-pending   { background: #fef9c3; color: #a16207; }
.badge-approved  { background: #dcfce7; color: #15803d; }
.badge-rejected  { background: #fee2e2; color: #b91c1c; }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.75rem;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}
.modal-title { font-size: 1.1rem; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--muted); }
.modal-footer { display: flex; justify-content: flex-end; gap: .75rem; margin-top: 1.25rem; }

/* ── Calendar override ── */
.fc { font-family: inherit; }
.fc .fc-toolbar-title { font-size: 1.1rem; font-weight: 700; }
.fc .fc-button { font-size: .85rem; }
.fc .fc-button-primary { background: var(--primary) !important; border-color: var(--primary) !important; }
.fc .fc-button-primary:hover { background: var(--primary-h) !important; }
.fc-event { cursor: pointer; font-size: .85rem; }
.fc .fc-daygrid-event, .fc .fc-timegrid-event, .fc .fc-list-event {
  border-radius: 12px;
  padding: .25rem .4rem;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .08);
  transition: transform .15s ease, box-shadow .15s ease;
  min-height: 2.8rem;
}
/* Timegrid: kleinerer Radius, damit nebeneinander liegende Raumspalten
   optisch nahe beieinander bleiben statt durch Kurven auseinanderzudriften */
.fc .fc-timegrid-event { border-radius: 4px; }
.fc .fc-daygrid-event:hover, .fc .fc-timegrid-event:hover, .fc .fc-list-event:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(15, 23, 42, .12);
}
.fc .fc-daygrid-event-dot { display: none; }
.fc .fc-event-main-frame {
  display: flex;
  flex-direction: column;
  gap: .1rem;
  align-items: flex-start;
  text-align: left;
  font-size: .7rem;
  font-weight: 600;
}
.fc .fc-event-time,
.fc .fc-event-title,
.fc .fc-event-room {
  font-size: inherit;
  font-weight: inherit;
  line-height: 1.2;
  opacity: .92;
}
.fc .fc-event-title {
  white-space: normal;
}
.fc .fc-list-event-time {
  min-width: 5rem;
  font-weight: 700;
}
.fc .fc-daygrid-more-link {
  font-size: .8rem;
  opacity: .88;
}
.fc-theme-standard .fc-scrollgrid {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.card { overflow-x: auto; }
.fc .fc-col-header-cell,
.fc .fc-daygrid-day-top,
.fc .fc-timegrid-col {
  min-width: 14rem !important;
}
.fc .fc-daygrid-day {
  min-width: 14rem !important;
}
.fc .fc-scrollgrid {
  width: auto !important;
}

/* ── Toolbar ── */
.toolbar { display: flex; align-items: center; gap: .75rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.toolbar-right { margin-left: auto; display: flex; gap: .5rem; }

/* ── Room filter checkboxes ── */
.room-filter-wrap  { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.room-filter-label { font-size: .82rem; color: var(--muted); white-space: nowrap; }
.room-filter-checks { display: flex; gap: .35rem; flex-wrap: wrap; }
.room-filter-item  {
  display: inline-flex; align-items: center; gap: .3rem;
  font-size: .82rem; cursor: pointer;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 999px; padding: .2rem .65rem;
  user-select: none; transition: background .15s, border-color .15s;
}
.room-filter-item:hover { border-color: var(--primary); }
.room-filter-item input { accent-color: var(--primary); cursor: pointer; }

/* ── Calendar page: sticky band (nav + toolbar + FC toolbar) ── */
/* App toolbar sticks below the nav on desktop */
.page-calendar .toolbar {
  position: sticky;
  top: var(--nav-h, 56px);
  z-index: 150;
  background: var(--bg);
  padding-top: .5rem;
  padding-bottom: .5rem;
  margin-top: -.25rem;
  box-shadow: 0 1px 0 var(--border);
}

/* FC toolbar is moved outside .card by JS so .card's overflow can't block sticky */
#fc-toolbar-wrap {
  position: sticky;
  top: var(--sticky-fc-top, 118px);
  z-index: 100;
  background: var(--card);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: .5rem 1rem .25rem;
  margin-bottom: -1px;
}
#fc-toolbar-wrap .fc-header-toolbar { margin: 0; }
.page-calendar .card {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}

/* FC toolbar styling when moved outside .fc (FC scopes its own CSS to .fc ancestor) */
#fc-toolbar-wrap .fc-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
#fc-toolbar-wrap .fc-toolbar-chunk {
  display: flex;
  align-items: center;
  gap: .5rem;
}
#fc-toolbar-wrap .fc-button-group { display: inline-flex; gap: 2px; }
#fc-toolbar-wrap .fc-button {
  font-size: .88rem;
  padding: .38rem .75rem;
  border-radius: var(--radius) !important;
}
#fc-toolbar-wrap .fc-toolbar-chunk { gap: .6rem; }
#fc-toolbar-wrap .fc-button-primary {
  background: var(--primary) !important;
  border-color: var(--primary) !important;
  color: #fff;
}
#fc-toolbar-wrap .fc-button-primary:hover { background: var(--primary-h) !important; border-color: var(--primary-h) !important; }
#fc-toolbar-wrap .fc-button-primary:not(:disabled).fc-button-active,
#fc-toolbar-wrap .fc-button-primary:not(:disabled):active {
  background: var(--primary-h) !important;
  border-color: var(--primary-h) !important;
  box-shadow: inset 0 2px 4px rgba(0,0,0,.2) !important;
}
#fc-toolbar-wrap .fc-toolbar-title { font-size: 1.15rem; font-weight: 700; }

@media (max-width: 767px) {
  /* Toolbar too tall on mobile — only nav + FC toolbar stick */
  .page-calendar .toolbar {
    position: static;
    margin-top: 0;
    box-shadow: none;
    padding-top: 0;
    padding-bottom: 0;
  }
  /* Nav is now a fixed 52px single row on mobile */
  #fc-toolbar-wrap { top: 52px; }

  /* FC footer toolbar (view switcher) */
  #fc-toolbar-wrap + .card .fc-footer-toolbar,
  .fc-footer-toolbar {
    display: flex;
    justify-content: center;
    padding: .4rem 0 .2rem;
    border-top: 1px solid var(--border);
    margin-top: .25rem;
  }
  .fc-footer-toolbar .fc-toolbar-chunk { display: flex; gap: .3rem; }
}

/* ── Color swatch ── */
input[type=color] { width: 3rem; height: 2rem; padding: .1rem; border-radius: 4px; cursor: pointer; }

/* ── Hamburger button (hidden on desktop) ── */
.nav-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: .3rem .4rem;
  border-radius: 4px;
  flex-direction: column;
  gap: 5px;
  flex-shrink: 0;
}
.nav-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: #fff;
  border-radius: 2px;
  transition: transform .2s, opacity .2s;
}
.nav.open .nav-toggle span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav.open .nav-toggle span:nth-child(2) { opacity: 0; }
.nav.open .nav-toggle span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

@media (max-width: 767px) {
  /* Nav: single row with hamburger */
  .nav {
    height: 52px;
    padding: 0 .75rem;
    gap: .5rem;
    flex-wrap: nowrap;
    position: sticky;
  }
  .nav-brand { font-size: 1rem; flex: 1; }
  .nav-toggle { display: flex; }
  .nav-user   { font-size: .8rem; }
  .nav-user-name { display: none; }

  /* Nav links: hidden dropdown, opens on .nav.open */
  .nav-links {
    display: none;
    position: absolute;
    top: 52px;
    left: 0; right: 0;
    background: var(--primary);
    flex-direction: column;
    gap: 0;
    padding: .25rem 0 .5rem;
    z-index: 201;
    box-shadow: 0 4px 12px rgba(0,0,0,.25);
    border-top: 1px solid rgba(255,255,255,.15);
    margin-left: 0;
  }
  .nav.open .nav-links { display: flex; }
  .nav-links a { font-size: .95rem; padding: .65rem 1rem; border-radius: 0; }
  .nav-links a:hover { background: rgba(255,255,255,.12); }

  /* Toolbar: vertikal stapeln */
  .toolbar { flex-direction: column; align-items: stretch; gap: .5rem; }
  .toolbar-right { margin-left: 0; flex-wrap: wrap; }
  .toolbar-right .btn { flex: 1; justify-content: center; }
  #roomFilter { width: 100%; }

  /* Kalender-Spalten: min-width aufheben (Listenansicht braucht das nicht) */
  .fc .fc-col-header-cell,
  .fc .fc-daygrid-day-top,
  .fc .fc-timegrid-col,
  .fc .fc-daygrid-day { min-width: 0 !important; }

  .fc { font-size: 0.85rem; }
  .fc .fc-toolbar-title { font-size: 1rem; }
  .fc .fc-button { font-size: .8rem; padding: .35rem .6rem; }

  /* Card: weniger Innenabstand */
  .card { padding: .5rem; }

  /* Modals: vollflächig */
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal {
    max-width: 100%;
    width: 100%;
    max-height: 92vh;
    border-radius: var(--radius) var(--radius) 0 0;
    margin: 0;
  }

  /* Legende ausblenden – spart Platz */
  .legend-box { display: none; }

  /* Form-Zeilen: einspaltig */
  .form-row { grid-template-columns: 1fr; }
}

@media (min-width: 1200px) {
  .fc .fc-col-header-cell,
  .fc .fc-daygrid-day-top,
  .fc .fc-timegrid-col {
    min-width: 12rem !important;
  }
  .fc .fc-daygrid-day {
    min-width: 12rem !important;
  }
}

@media (min-width: 1600px) {
  .fc .fc-col-header-cell,
  .fc .fc-daygrid-day-top,
  .fc .fc-timegrid-col {
    min-width: 16rem !important;
  }
  .fc .fc-daygrid-day {
    min-width: 16rem !important;
  }
}

/* ── Calendar page: choice buttons (series vs. single) ── */
.choice-btn { flex: 1; padding: .75rem; font-size: .95rem; text-align: center; border-radius: 8px; cursor: pointer; border: 2px solid var(--border); background: var(--card); transition: border-color .15s, background .15s; }
.choice-btn:hover { border-color: var(--primary); background: #eff6ff; }
.choice-btn strong { display: block; font-size: 1rem; margin-bottom: .2rem; }
.choice-btn small { color: var(--muted); font-size: .8rem; }

/* ── Calendar page: form field visibility ── */
#seriesFieldsRow { display: none; }
#onceFieldsRow   { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

/* ── Calendar page: event readability ── */
.fc .fc-event { padding: 2px !important; }
.fc-event-title { font-weight: 600; font-size: 0.9rem; line-height: 1.2; }
.fc-event-room  { font-size: 0.75rem; color: rgba(0,0,0,.6); font-weight: 400; margin-top: 2px; }

/* ── Calendar page: tooltip ── */
@keyframes tooltipFadeIn {
  from { opacity: 0; transform: translateX(-50%) translateY(4px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.event-with-tooltip { cursor: default; }

#globalTooltip {
  position: fixed;
  background: rgba(0,0,0,.5);
  color: #fff;
  padding: 8px 12px;
  border-radius: 4px;
  font-size: .85rem;
  white-space: nowrap;
  z-index: 10000;
  pointer-events: none;
  animation: tooltipFadeIn .25s ease-out forwards;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
  display: none;
}

#globalTooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: rgba(0,0,0,.5);
  pointer-events: none;
}

/* ── Calendar page: colour legend ── */
.legend-box {
  margin-top: 2rem;
  padding: 1.5rem;
  background: var(--card);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.legend-box h3 {
  margin: 0 0 1rem;
  font-size: .95rem;
  font-weight: 600;
  color: var(--text);
}

.legend-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.5rem;
}

.legend-section-title {
  margin: 0 0 .75rem;
  font-size: .85rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
}

.legend-items { display: flex; flex-direction: column; gap: .5rem; }

.legend-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  font-size: .9rem;
}

.legend-swatch {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  flex-shrink: 0;
}

/* ── Chat page ── */
.page-chat {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh; /* dynamic viewport — shrinks with iOS Safari toolbar */
}

.page-chat .container {
  padding: 0;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.chat-layout {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* ── Sidebar ── */
.chat-sidebar {
  width: 360px;
  flex-shrink: 0;
  border-right: 1px solid #ddd;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #fff;
}

.chat-sidebar-header {
  padding: .875rem 1.25rem;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  flex-shrink: 0;
}
.chat-sidebar-header h2 { font-size: 1.05rem; font-weight: 700; margin: 0; color: #fff; }

.chat-new-wrap { position: relative; flex-shrink: 0; }
.chat-new-btn {
  background: rgba(255,255,255,.2);
  color: #fff;
  border: 1px solid rgba(255,255,255,.4);
  border-radius: 6px;
  padding: .4rem .9rem;
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s;
}
.chat-new-btn:hover { background: rgba(255,255,255,.32); }

.chat-user-picker {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,.15);
  z-index: 300;
  max-height: 280px;
  overflow-y: auto;
  min-width: 230px;
}
.chat-user-picker-item {
  padding: .65rem 1rem;
  cursor: pointer;
  font-size: .95rem;
  border-bottom: 1px solid #f0f0f0;
  display: flex;
  align-items: center;
  gap: .75rem;
}
.chat-user-picker-item:last-child { border-bottom: none; }
.chat-user-picker-item:hover { background: #f5f5f5; }

.chat-list { flex: 1; overflow-y: auto; }
.chat-list-empty { padding: 2rem 1.25rem; text-align: center; color: #999; font-size: .9rem; }

/* Avatar circle */
.chat-avatar {
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  text-transform: uppercase;
  user-select: none;
}

.chat-list-item {
  padding: .75rem 1rem;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
  display: flex;
  align-items: center;
  gap: .875rem;
  transition: background .12s;
}
.chat-list-item:hover { background: #f5f5f5; }
.chat-list-item.active { background: #eff6ff; }
.chat-list-item-info { flex: 1; min-width: 0; }
.chat-list-item-name-row { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.chat-list-item-name { font-size: .975rem; font-weight: 600; }
.conv-expiry {
  font-size: .68rem;
  font-weight: 600;
  padding: .05rem .4rem;
  border-radius: 999px;
  background: #e0f2fe;
  color: #0369a1;
  white-space: nowrap;
  flex-shrink: 0;
}
.conv-expiry--warn { background: #fef3c7; color: #b45309; }
.conv-expiry--urgent { background: #fee2e2; color: #b91c1c; }
.conv-expiry--gone  { background: #f3f4f6; color: #9ca3af; }
.chat-list-item-preview {
  font-size: .82rem;
  color: #888;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: .15rem;
}

/* ── Main panel ── */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.chat-header {
  padding: .75rem 1rem;
  background: #f0f2f5;
  border-bottom: 1px solid #ddd;
  display: flex;
  align-items: center;
  gap: .875rem;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.chat-header-info { flex: 1; }
.chat-header h3 { font-size: 1rem; font-weight: 700; margin: 0; }
.chat-back-btn {
  background: none; border: none; font-size: 1.4rem;
  cursor: pointer; color: #666; display: none; padding: 0; line-height: 1;
}

.chat-placeholder {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #aaa;
  background: #efeae2;
  font-size: 1rem;
}

/* ── Messages ── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: .875rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .2rem;
  background: #efeae2;
}

.chat-empty-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #aaa;
  font-size: .95rem;
}

.msg-row {
  display: flex;
  padding: 1px 0;
}
.msg-row.mine   { justify-content: flex-end; }
.msg-row.theirs { justify-content: flex-start; }

.msg-bubble {
  max-width: 72%;
  padding: .5rem .875rem .4rem;
  border-radius: 8px;
  font-size: .95rem;
  line-height: 1.5;
  word-break: break-word;
  box-shadow: 0 1px 1px rgba(0,0,0,.12);
}
.msg-row.theirs .msg-bubble {
  background: #fff;
  border-radius: 0 8px 8px 8px;
  color: #111;
}
.msg-row.mine .msg-bubble {
  background: #d9f8c4;
  border-radius: 8px 0 8px 8px;
  color: #111;
}

.msg-body { white-space: pre-wrap; }

.msg-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: .35rem;
  margin-top: .25rem;
}
.msg-time { font-size: .7rem; color: #8a8a8a; white-space: nowrap; }
.msg-delete-btn {
  background: none; border: none; cursor: pointer;
  font-size: .75rem; color: #bbb; padding: 0;
  opacity: 0; transition: opacity .15s; line-height: 1;
}
.msg-row:hover .msg-delete-btn { opacity: 1; }
.msg-delete-btn:hover { color: var(--danger); }

/* ── Input row ── */
.chat-deleted-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .6rem 1rem;
  background: #fef3c7;
  border-top: 1px solid #fde68a;
  font-size: .875rem;
  color: #92400e;
  flex-shrink: 0;
}
.chat-deleted-notice .btn {
  flex-shrink: 0;
  font-size: .8rem;
  padding: .25rem .65rem;
}
.chat-input-row {
  padding: .625rem .875rem;
  padding-bottom: max(.625rem, env(safe-area-inset-bottom));
  background: #f0f2f5;
  display: flex;
  align-items: flex-end;
  gap: .625rem;
  flex-shrink: 0;
}
.chat-input {
  flex: 1;
  padding: .625rem 1rem;
  border: none;
  border-radius: 22px;
  font-size: .95rem;
  font-family: inherit;
  resize: none;
  line-height: 1.45;
  max-height: 130px;
  overflow-y: auto;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.1);
}
.chat-input:focus { outline: none; }
.chat-send-btn {
  background: var(--primary); color: #fff;
  border: none; border-radius: 50%;
  width: 2.75rem; height: 2.75rem;
  font-size: 1.2rem; cursor: pointer;
  flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.chat-send-btn:hover { background: var(--primary-h); }

#btnDeleteConv { font-size: .8rem; padding: .35rem .75rem; }

@media (max-width: 700px) {
  .chat-sidebar { width: 100%; }
  .chat-main    { display: none; width: 100%; }
  .chat-layout.show-chat .chat-sidebar { display: none; }
  .chat-layout.show-chat .chat-main    { display: flex; }
  .chat-back-btn { display: block !important; }
}
