/* ═══════════════════════════════════════════════════════════════════════════
   Notify PWA — Main Stylesheet
   ═══════════════════════════════════════════════════════════════════════════ */

/* ─── Custom Properties ──────────────────────────────────────────────────── */
:root {
  /* Brand */
  --color-primary:        #2563eb;
  --color-primary-hover:  #1d4ed8;
  --color-primary-light:  #dbeafe;
  --color-primary-text:   #ffffff;

  /* Neutrals */
  --color-bg:             #f8fafc;
  --color-surface:        #ffffff;
  --color-surface-alt:    #f1f5f9;
  --color-border:         #e2e8f0;
  --color-border-strong:  #cbd5e1;

  /* Text */
  --color-text:           #0f172a;
  --color-text-secondary: #64748b;
  --color-text-muted:     #94a3b8;
  --color-text-inverted:  #ffffff;

  /* Status colors */
  --status-available:     #22c55e;
  --status-busy:          #f97316;
  --status-lunch:         #eab308;
  --status-off-duty:      #ef4444;
  --status-vacation:      #8b5cf6;
  --status-unknown:       #94a3b8;

  /* Semantic */
  --color-success:        #22c55e;
  --color-warning:        #f59e0b;
  --color-danger:         #ef4444;
  --color-info:           #3b82f6;

  /* Message bubbles */
  --bubble-out-bg:        #2563eb;
  --bubble-out-text:      #ffffff;
  --bubble-in-bg:         #f1f5f9;
  --bubble-in-text:       #0f172a;

  /* Layout */
  --sidebar-width:        320px;
  --sidebar-min:          260px;
  --sidebar-max:          480px;
  --header-height:        56px;
  --input-bar-height:     72px;

  /* Radii */
  --radius-sm:  4px;
  --radius:     8px;
  --radius-md:  12px;
  --radius-lg:  16px;
  --radius-xl:  24px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm:  0 1px 2px rgba(0,0,0,.06), 0 1px 3px rgba(0,0,0,.1);
  --shadow:     0 2px 8px rgba(0,0,0,.08), 0 1px 3px rgba(0,0,0,.05);
  --shadow-md:  0 4px 16px rgba(0,0,0,.1), 0 2px 6px rgba(0,0,0,.06);
  --shadow-lg:  0 8px 32px rgba(0,0,0,.12), 0 4px 12px rgba(0,0,0,.08);
  --shadow-xl:  0 16px 48px rgba(0,0,0,.16);

  /* Transitions */
  --transition-fast:   150ms ease;
  --transition:        250ms ease;
  --transition-slow:   400ms ease;

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "Cascadia Code", "Fira Code", "Consolas", monospace;
  --text-xs:   0.75rem;
  --text-sm:   0.875rem;
  --text-base: 1rem;
  --text-lg:   1.125rem;
  --text-xl:   1.25rem;
  --text-2xl:  1.5rem;
  --text-3xl:  1.875rem;
}

/* Dark theme */
[data-theme="dark"] {
  --color-bg:             #0f172a;
  --color-surface:        #1e293b;
  --color-surface-alt:    #293548;
  --color-border:         #334155;
  --color-border-strong:  #475569;
  --color-text:           #f1f5f9;
  --color-text-secondary: #94a3b8;
  --color-text-muted:     #64748b;
  --bubble-in-bg:         #293548;
  --bubble-in-text:       #f1f5f9;
  --color-primary-light:  #1e3a5f;
}

/* ─── Reset & Base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  height: 100%;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  height: 100%;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}


/* ─── Reset & Base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  height: 100%;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  height: 100%;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img { display: block; max-width: 100%; }
button { cursor: pointer; font-family: inherit; }
input, textarea, select { font-family: inherit; }
a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Utility Classes ─────────────────────────────────────────────────────── */
.hidden   { display: none !important; }
.sr-only  { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.text-muted { color: var(--color-text-muted); font-size: var(--text-sm); }
.link { color: var(--color-primary); font-size: var(--text-sm); }
.link:hover { text-decoration: underline; }

@media (min-width: 769px) {
  .mobile-only { display: none !important; }
}
@media (max-width: 768px) {
  .desktop-only { display: none !important; }
}

/* ─── Spinner ─────────────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .375rem;
  padding: .5rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-weight: 500;
  line-height: 1.25;
  transition: background var(--transition-fast), color var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast);
  white-space: nowrap;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

.btn--primary {
  background: var(--color-primary);
  color: var(--color-primary-text);
  border-color: var(--color-primary);
}
.btn--primary:not(:disabled):hover { background: var(--color-primary-hover); border-color: var(--color-primary-hover); }

.btn--secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}
.btn--secondary:not(:disabled):hover { background: var(--color-surface-alt); }

.btn--ghost {
  background: transparent;
  color: var(--color-text-secondary);
  border-color: transparent;
}
.btn--ghost:not(:disabled):hover { background: var(--color-surface-alt); color: var(--color-text); }

.btn--danger { background: var(--color-danger); color: #fff; border-color: var(--color-danger); }
.btn--danger:not(:disabled):hover { background: #dc2626; }

.btn--icon { padding: .5rem; border-radius: var(--radius); width: 36px; height: 36px; }
.btn--sm   { padding: .375rem .75rem; font-size: var(--text-xs); }
.btn--lg   { padding: .75rem 1.5rem; font-size: var(--text-base); }
.btn--full { width: 100%; }

.btn__spinner { width: 14px; height: 14px; }

/* ─── Forms ───────────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: .375rem; }
.form-group--row { flex-direction: row; align-items: center; justify-content: space-between; }
.form-label { font-size: var(--text-sm); font-weight: 500; color: var(--color-text); }

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: .625rem .875rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  color: var(--color-text);
  background: var(--color-surface);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  outline: none;
}
.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
.form-input.is-error  { border-color: var(--color-danger); }
.form-textarea { resize: vertical; min-height: 80px; }

.form-error {
  font-size: var(--text-xs);
  color: var(--color-danger);
  min-height: 1.2em;
}
.form-error--banner {
  padding: .5rem .75rem;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  display: none;
}
.form-error--banner:not(:empty) { display: block; }

.input-group { position: relative; display: flex; }
.input-group .form-input { padding-right: 2.5rem; }
.input-group__toggle {
  position: absolute;
  right: .5rem; top: 50%; transform: translateY(-50%);
  background: none; border: none;
  color: var(--color-text-muted);
  padding: .25rem;
  line-height: 0;
}
.input-group__toggle:hover { color: var(--color-text); }

.checkbox-label {
  display: flex; align-items: center; gap: .5rem;
  font-size: var(--text-sm); cursor: pointer;
}
.checkbox-label input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--color-primary); }

/* Search box */
.search-box {
  position: relative;
  display: flex;
  align-items: center;
}
.search-box svg {
  position: absolute;
  left: .75rem;
  color: var(--color-text-muted);
  pointer-events: none;
  flex-shrink: 0;
}
.search-box input {
  width: 100%;
  padding: .5rem .75rem .5rem 2.25rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  background: var(--color-surface-alt);
  color: var(--color-text);
  outline: none;
  transition: border-color var(--transition-fast), background var(--transition-fast);
}
.search-box input:focus {
  background: var(--color-surface);
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}

/* ─── Avatar ──────────────────────────────────────────────────────────────── */
.avatar {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  color: #fff;
  font-weight: 600;
  flex-shrink: 0;
  overflow: visible;
}
.avatar--xs  { width: 28px; height: 28px; font-size: var(--text-xs); }
.avatar--sm  { width: 32px; height: 32px; font-size: var(--text-xs); }
.avatar--md  { width: 40px; height: 40px; font-size: var(--text-sm); }
.avatar--lg  { width: 56px; height: 56px; font-size: var(--text-xl); }
.avatar--xl  { width: 80px; height: 80px; font-size: var(--text-2xl); }
.avatar__img { border-radius: var(--radius-full); width: 100%; height: 100%; object-fit: cover; }
.avatar__initials { line-height: 1; }

/* Status dot on avatar */
.status-dot {
  position: absolute;
  bottom: -1px; right: -1px;
  width: 11px; height: 11px;
  border-radius: var(--radius-full);
  border: 2px solid var(--color-surface);
  background: var(--status-unknown);
}
.avatar--lg .status-dot  { width: 14px; height: 14px; }
.avatar--xl .status-dot  { width: 18px; height: 18px; }
.status-dot--available { background: var(--status-available); }
.status-dot--busy      { background: var(--status-busy); }
.status-dot--lunch     { background: var(--status-lunch); }
.status-dot--off-duty  { background: var(--status-off-duty); }
.status-dot--vacation  { background: var(--status-vacation); }

/* Status badge (text + dot) */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: .375rem;
  font-size: var(--text-xs);
  font-weight: 500;
}
.status-badge::before {
  content: '';
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: var(--radius-full);
  background: var(--status-unknown);
  flex-shrink: 0;
}
.status-badge--available { color: var(--status-available); }
.status-badge--available::before { background: var(--status-available); }
.status-badge--busy      { color: var(--status-busy);      }
.status-badge--busy::before      { background: var(--status-busy);      }
.status-badge--lunch     { color: var(--status-lunch);     }
.status-badge--lunch::before     { background: var(--status-lunch);     }
.status-badge--off-duty  { color: var(--status-off-duty);  }
.status-badge--off-duty::before  { background: var(--status-off-duty);  }
.status-badge--vacation  { color: var(--status-vacation);  }
.status-badge--vacation::before  { background: var(--status-vacation);  }

/* ─── Install / Update Banners ────────────────────────────────────────────── */
.install-banner, .update-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .75rem 1.25rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow);
  animation: slideDown var(--transition-slow) ease;
}
@keyframes slideDown { from { transform: translateY(-100%); } to { transform: translateY(0); } }

.install-banner__icon img { border-radius: var(--radius); }
.install-banner__text { flex: 1; display: flex; flex-direction: column; }
.install-banner__text strong { font-size: var(--text-sm); }
.install-banner__text span   { font-size: var(--text-xs); color: var(--color-text-secondary); }
.install-banner__actions     { display: flex; gap: .5rem; align-items: center; }
.update-banner { justify-content: center; gap: 1rem; font-size: var(--text-sm); background: #eff6ff; border-color: #bfdbfe; }

/* ─── App Root ────────────────────────────────────────────────────────────── */
#app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }

/* Views */
.view { display: none; flex: 1; overflow: hidden; }
.view.is-active { display: flex; flex-direction: column; }

/* ─── LOGIN VIEW ──────────────────────────────────────────────────────────── */
.view--login {
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a5f 0%, #1e293b 50%, #0f172a 100%);
  padding: 1.5rem;
  min-height: 100vh;
  min-height: 100dvh;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
}

.login-card__header {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2.5rem 2rem 1.5rem;
  background: linear-gradient(135deg, var(--color-primary) 0%, #1d4ed8 100%);
  color: #fff;
  gap: .75rem;
}
.login-card__logo { filter: drop-shadow(0 4px 12px rgba(0,0,0,.3)); }
.login-card__title { font-size: var(--text-2xl); font-weight: 700; letter-spacing: -.02em; }
.login-card__subtitle { font-size: var(--text-sm); opacity: .85; }

.login-card__form {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding: 2rem;
}

.login-card__footer {
  padding: 1rem 2rem 1.5rem;
  text-align: center;
  border-top: 1px solid var(--color-border);
}

/* ─── APP HEADER ──────────────────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  gap: .75rem;
  height: var(--header-height);
  padding: 0 1rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
  z-index: 100;
}
.app-header__left  { display: flex; align-items: center; gap: .5rem; flex: 0 0 auto; }
.app-header__center { flex: 1; max-width: 400px; }
.app-header__right  { display: flex; align-items: center; gap: .25rem; margin-left: auto; }
.app-header__logo   { border-radius: var(--radius); }
.app-header__title  { font-size: var(--text-lg); font-weight: 700; color: var(--color-text); }
.app-header__chat-title { font-size: var(--text-base); font-weight: 600; color: var(--color-text); }

/* ─── APP BODY (Split Layout) ─────────────────────────────────────────────── */
.view--app { flex-direction: column; }
.app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* ─── SIDEBAR ─────────────────────────────────────────────────────────────── */
.app-sidebar {
  display: flex;
  flex-direction: column;
  width: var(--sidebar-width);
  min-width: var(--sidebar-min);
  max-width: var(--sidebar-max);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  overflow: hidden;
  flex-shrink: 0;
  transition: transform var(--transition);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .875rem 1rem;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}
.sidebar-header__title { font-size: var(--text-base); font-weight: 600; }
.sidebar-search { padding: .5rem .75rem; border-bottom: 1px solid var(--color-border); flex-shrink: 0; }

/* ─── CONVERSATIONS LIST ──────────────────────────────────────────────────── */
.conversations-list {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.conversations-list::-webkit-scrollbar { width: 4px; }
.conversations-list::-webkit-scrollbar-track { background: transparent; }
.conversations-list::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: var(--radius-full); }

.conversations-list__empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 3rem 1.5rem;
  text-align: center;
  color: var(--color-text-muted);
}
.conversations-list__empty svg { opacity: .4; }
.conversations-list__empty p   { font-size: var(--text-sm); }

/* Conversation item */
.conv-item {
  display: flex;
  align-items: center;
  gap: .875rem;
  padding: .875rem 1rem;
  cursor: pointer;
  border-bottom: 1px solid var(--color-border);
  transition: background var(--transition-fast);
  position: relative;
  -webkit-tap-highlight-color: transparent;
}
.conv-item:hover    { background: var(--color-surface-alt); }
.conv-item.is-active { background: var(--color-primary-light); }

[data-theme="dark"] .conv-item.is-active { background: var(--color-primary-light); }

.conv-item__avatar { flex-shrink: 0; }
.conv-item__body   { flex: 1; min-width: 0; }
.conv-item__header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: .2rem; }
.conv-item__name   { font-size: var(--text-sm); font-weight: 600; color: var(--color-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item__time   { font-size: var(--text-xs); color: var(--color-text-muted); white-space: nowrap; margin-left: .5rem; }
.conv-item__preview { display: flex; align-items: center; gap: .25rem; }
.conv-item__preview-text { font-size: var(--text-xs); color: var(--color-text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.conv-item.is-unread .conv-item__preview-text { color: var(--color-text); font-weight: 500; }
.conv-item.is-unread .conv-item__name { font-weight: 700; }
.conv-item__badge {
  min-width: 18px; height: 18px;
  padding: 0 5px;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-left: auto;
}

.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .75rem;
  padding: 2rem;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

/* ─── RESIZE HANDLE ───────────────────────────────────────────────────────── */
.resize-handle {
  width: 4px;
  cursor: col-resize;
  background: var(--color-border);
  transition: background var(--transition-fast);
  flex-shrink: 0;
  position: relative;
}
.resize-handle::after {
  content: '';
  position: absolute;
  inset: 0 -4px;
  z-index: 10;
}
.resize-handle:hover,
.resize-handle.is-resizing { background: var(--color-primary); }

/* ─── CHAT PANEL ──────────────────────────────────────────────────────────── */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--color-bg);
  min-width: 0;
}

.chat-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 2rem;
  text-align: center;
  color: var(--color-text-secondary);
}
.chat-placeholder__icon { opacity: .3; }
.chat-placeholder h2    { font-size: var(--text-xl); color: var(--color-text); }
.chat-placeholder p     { font-size: var(--text-sm); color: var(--color-text-secondary); }

.chat-active { display: flex; flex-direction: column; flex: 1; overflow: hidden; }

/* Chat Header */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}
.chat-header__info    { display: flex; align-items: center; gap: .75rem; }
.chat-header__text    { display: flex; flex-direction: column; }
.chat-header__name    { font-size: var(--text-base); font-weight: 600; }
.chat-header__status  { font-size: var(--text-xs); }
.chat-header__actions { display: flex; gap: .25rem; }

/* Messages Container */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .375rem;
  overscroll-behavior: contain;
}
.messages-container::-webkit-scrollbar { width: 4px; }
.messages-container::-webkit-scrollbar-track { background: transparent; }
.messages-container::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: var(--radius-full); }

/* Date separator */
.msg-date-separator {
  text-align: center;
  margin: .75rem 0;
}
.msg-date-separator span {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  background: var(--color-bg);
  padding: .25rem .75rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
}

/* Message bubbles */
.msg-row {
  display: flex;
  align-items: flex-end;
  gap: .5rem;
  max-width: 75%;
}
.msg-row--out { align-self: flex-end; flex-direction: row-reverse; }
.msg-row--in  { align-self: flex-start; }

.msg-avatar { flex-shrink: 0; margin-bottom: 2px; }

.msg-bubble-wrap { display: flex; flex-direction: column; gap: .125rem; }
.msg-row--out .msg-bubble-wrap { align-items: flex-end; }

.msg-bubble {
  padding: .625rem .875rem;
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  line-height: 1.5;
  word-break: break-word;
  position: relative;
  max-width: 100%;
}
.msg-row--out .msg-bubble {
  background: var(--bubble-out-bg);
  color: var(--bubble-out-text);
  border-bottom-right-radius: var(--radius-sm);
}
.msg-row--in .msg-bubble {
  background: var(--bubble-in-bg);
  color: var(--bubble-in-text);
  border-bottom-left-radius: var(--radius-sm);
}

/* Group bubbles */
.msg-row--out.is-first .msg-bubble  { border-top-right-radius: var(--radius-lg); }
.msg-row--out.is-middle .msg-bubble { border-top-right-radius: var(--radius-sm); }
.msg-row--out.is-last .msg-bubble   { border-bottom-right-radius: var(--radius-sm); }
.msg-row--in.is-first .msg-bubble   { border-top-left-radius: var(--radius-lg); }
.msg-row--in.is-middle .msg-bubble  { border-top-left-radius: var(--radius-sm); }
.msg-row--in.is-last .msg-bubble    { border-bottom-left-radius: var(--radius-sm); }

.msg-meta {
  display: flex;
  align-items: center;
  gap: .375rem;
  font-size: 10px;
  color: var(--color-text-muted);
  padding: 0 .25rem;
}
.msg-row--out .msg-meta { flex-direction: row-reverse; }

/* Message status icons */
.msg-status { color: var(--color-text-muted); line-height: 0; }
.msg-status--sent     { color: var(--color-text-muted); }
.msg-status--received { color: var(--color-text-muted); }
.msg-status--read     { color: var(--color-primary); }
.msg-status--deleted  { color: var(--color-danger); }

.msg-deleted { font-style: italic; opacity: .6; }

/* Typing indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .5rem 1rem;
  flex-shrink: 0;
}
.typing-indicator__dots {
  display: flex;
  gap: .25rem;
  background: var(--bubble-in-bg);
  padding: .5rem .75rem;
  border-radius: var(--radius-lg);
}
.typing-indicator__dots span {
  width: 6px; height: 6px;
  border-radius: var(--radius-full);
  background: var(--color-text-muted);
  animation: typingBounce 1.2s infinite;
}
.typing-indicator__dots span:nth-child(2) { animation-delay: .2s; }
.typing-indicator__dots span:nth-child(3) { animation-delay: .4s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%            { transform: translateY(-5px); }
}
.typing-indicator__name { font-size: var(--text-xs); color: var(--color-text-muted); }

/* Chat Input Bar */
.chat-input-bar {
  display: flex;
  align-items: flex-end;
  gap: .5rem;
  padding: .75rem 1rem;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
}
.chat-input-wrap {
  flex: 1;
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: .5rem .875rem;
  transition: border-color var(--transition-fast);
}
.chat-input-wrap:focus-within {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
.chat-input {
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  color: var(--color-text);
  font-size: var(--text-sm);
  line-height: 1.5;
  resize: none;
  max-height: 120px;
  overflow-y: auto;
  display: block;
}
.chat-input::placeholder { color: var(--color-text-muted); }

/* ─── MODAL VIEW (Profile, Address Book) ──────────────────────────────────── */
.modal-view { position: fixed; inset: 0; z-index: 500; }
.modal-view.is-active { display: flex !important; }

.modal-view__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(2px);
}
.modal-view__panel {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  margin-top: auto;
  width: 100%;
  max-height: 90vh;
  box-shadow: var(--shadow-xl);
  animation: slideUp var(--transition) ease;
  overflow: hidden;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

@media (min-width: 769px) {
  .modal-view__panel {
    margin: auto;
    border-radius: var(--radius-xl);
    max-width: 540px;
    max-height: 85vh;
    width: 100%;
    animation: modalIn var(--transition) ease;
  }
  .modal-view__panel--wide { max-width: 840px; }
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(.96); }
  to   { opacity: 1; transform: scale(1); }
}

.modal-view__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.125rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}
.modal-view__header-actions { display: flex; align-items: center; gap: .5rem; }
.modal-view__title { font-size: var(--text-lg); font-weight: 600; }
.modal-view__body  { flex: 1; overflow-y: auto; padding: 1.25rem; }

/* ─── PROFILE VIEW ────────────────────────────────────────────────────────── */
.profile-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 1.5rem;
}
.profile-avatar-wrap { position: relative; }
.profile-avatar-edit {
  position: absolute;
  bottom: 0; right: 0;
  background: var(--color-primary);
  color: #fff;
  border: 2px solid var(--color-surface);
  border-radius: var(--radius-full);
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.profile-name  { font-size: var(--text-2xl); font-weight: 700; }
.profile-dept  { font-size: var(--text-sm);  color: var(--color-text-secondary); }

.profile-status-grid {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  margin: 1rem 0;
}
.status-btn {
  display: flex;
  align-items: center;
  gap: .375rem;
  padding: .375rem .75rem;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-full);
  background: transparent;
  font-size: var(--text-xs);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.status-btn::before {
  content: '';
  width: 8px; height: 8px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}
.status-btn.is-active   { border-color: currentColor; background: currentColor; color: #fff; }
.status-btn[data-status="available"]::before { background: var(--status-available); }
.status-btn[data-status="available"]         { color: var(--status-available); }
.status-btn[data-status="busy"]::before      { background: var(--status-busy); }
.status-btn[data-status="busy"]              { color: var(--status-busy); }
.status-btn[data-status="lunch"]::before     { background: var(--status-lunch); }
.status-btn[data-status="lunch"]             { color: #854d0e; }
.status-btn[data-status="off-duty"]::before  { background: var(--status-off-duty); }
.status-btn[data-status="off-duty"]          { color: var(--status-off-duty); }
.status-btn[data-status="vacation"]::before  { background: var(--status-vacation); }
.status-btn[data-status="vacation"]          { color: var(--status-vacation); }
.status-btn.is-active::before                { background: #fff; }

.profile-form { display: flex; flex-direction: column; gap: 1.25rem; }
.profile-form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 480px) { .profile-form-row { grid-template-columns: 1fr; } }

.profile-actions {
  display: flex;
  gap: .75rem;
  padding-top: 1rem;
  border-top: 1px solid var(--color-border);
  margin-top: 1rem;
  flex-wrap: wrap;
}
.profile-actions .btn--danger { margin-left: auto; }

/* ─── ADDRESS BOOK ────────────────────────────────────────────────────────── */
.ab-tabs {
  display: flex;
  gap: .25rem;
  padding: .75rem 1.25rem .5rem;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}
.ab-tab {
  padding: .375rem .875rem;
  border-radius: var(--radius-full);
  border: none;
  background: transparent;
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  font-weight: 500;
}
.ab-tab:hover  { background: var(--color-surface-alt); color: var(--color-text); }
.ab-tab.active { background: var(--color-primary-light); color: var(--color-primary); }

.ab-toolbar {
  display: flex;
  gap: .5rem;
  padding: .75rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
  flex-wrap: wrap;
  flex-shrink: 0;
}
.ab-search { flex: 1; min-width: 180px; }
.ab-filter { padding: .4rem .75rem; border: 1px solid var(--color-border); border-radius: var(--radius); background: var(--color-surface); color: var(--color-text); font-size: var(--text-xs); }

/* Contact grid */
.contacts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
  padding: 1.25rem;
}

.contact-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .75rem;
  cursor: pointer;
  transition: box-shadow var(--transition-fast), transform var(--transition-fast);
  text-align: center;
}
.contact-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }

.contact-card__name   { font-size: var(--text-sm); font-weight: 600; }
.contact-card__dept   { font-size: var(--text-xs); color: var(--color-text-secondary); }
.contact-card__phone  { font-size: var(--text-xs); color: var(--color-text-muted); }
.contact-card__actions {
  display: flex;
  gap: .5rem;
  width: 100%;
  margin-top: .25rem;
  padding-top: .75rem;
  border-top: 1px solid var(--color-border);
}
.contact-card__actions .btn { flex: 1; font-size: var(--text-xs); }

/* Contact Detail / Edit Panel */
.contact-detail-panel {
  position: absolute;
  inset: 0;
  background: var(--color-surface);
  z-index: 10;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.contact-detail-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}
.contact-detail-body { padding: 1.25rem; display: flex; flex-direction: column; gap: 1.25rem; }

/* Avatar upload */
.avatar-upload { display: flex; flex-direction: column; align-items: center; gap: .75rem; }
.avatar-upload__input { display: none; }
.avatar-upload__btn {
  font-size: var(--text-xs);
  color: var(--color-primary);
  cursor: pointer;
  text-decoration: underline;
}

/* Dept group */
.dept-group { display: flex; flex-direction: column; gap: .75rem; }
.dept-group-header {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .75rem 1.25rem;
  background: var(--color-surface-alt);
  font-weight: 600;
  font-size: var(--text-sm);
  cursor: pointer;
}
.dept-group-contacts { padding: .5rem .5rem; }

/* Contact picker (new conversation) */
.contact-picker-list { display: flex; flex-direction: column; max-height: 360px; overflow-y: auto; }
.contact-picker-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .625rem .75rem;
  cursor: pointer;
  border-radius: var(--radius);
  transition: background var(--transition-fast);
}
.contact-picker-item:hover { background: var(--color-surface-alt); }
.contact-picker-item__name { font-size: var(--text-sm); font-weight: 500; }
.contact-picker-item__dept { font-size: var(--text-xs); color: var(--color-text-secondary); }

/* ─── GENERIC MODAL ───────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(2px);
  z-index: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalIn var(--transition) ease;
}
.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.125rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}
.modal__header h3 { font-size: var(--text-base); font-weight: 600; }
.modal__body { padding: 1.25rem; overflow-y: auto; flex: 1; }

/* ─── CONTEXT MENU ────────────────────────────────────────────────────────── */
.context-menu {
  position: fixed;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 700;
  min-width: 160px;
  overflow: hidden;
  animation: menuIn var(--transition-fast) ease;
}
@keyframes menuIn { from { opacity: 0; transform: scale(.95); } to { opacity: 1; transform: scale(1); } }

.context-menu__item {
  display: flex;
  align-items: center;
  gap: .625rem;
  padding: .625rem 1rem;
  font-size: var(--text-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  color: var(--color-text);
}
.context-menu__item:hover { background: var(--color-surface-alt); }
.context-menu__item--danger { color: var(--color-danger); }
.context-menu__item--danger:hover { background: #fef2f2; }
.context-menu__divider { height: 1px; background: var(--color-border); margin: .25rem 0; }

/* ─── TOAST ───────────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 1.5rem; right: 1.5rem;
  display: flex;
  flex-direction: column-reverse;
  gap: .5rem;
  z-index: 900;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .75rem 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
  min-width: 240px;
  max-width: 380px;
  pointer-events: auto;
  animation: toastIn var(--transition) ease;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(100%); }
  to   { opacity: 1; transform: translateX(0); }
}
.toast.is-leaving {
  animation: toastOut var(--transition) ease forwards;
}
@keyframes toastOut {
  to { opacity: 0; transform: translateX(100%); }
}
.toast--success { border-left: 3px solid var(--color-success); }
.toast--warning { border-left: 3px solid var(--color-warning); }
.toast--error   { border-left: 3px solid var(--color-danger); }
.toast--info    { border-left: 3px solid var(--color-info); }
.toast__icon { flex-shrink: 0; line-height: 0; }
.toast__text { flex: 1; }
.toast__title   { font-weight: 600; margin-bottom: .125rem; }
.toast__message { color: var(--color-text-secondary); }
.toast__close { background: none; border: none; color: var(--color-text-muted); cursor: pointer; padding: .25rem; margin-left: auto; }

/* ─── RESPONSIVE: Mobile (<= 768px) ──────────────────────────────────────── */
@media (max-width: 768px) {
  :root {
    --header-height: 52px;
  }

  .app-body { position: relative; }

  /* Sidebar covers full width on mobile */
  .app-sidebar {
    position: absolute;
    inset: 0;
    width: 100% !important;
    max-width: 100% !important;
    z-index: 10;
    transition: transform var(--transition);
  }
  .app-sidebar.slide-out { transform: translateX(-100%); }

  /* Chat panel covers full width on mobile */
  .chat-panel { position: absolute; inset: 0; z-index: 5; }

  /* When chat is active on mobile */
  .mobile-chat-active .app-sidebar  { transform: translateX(-100%); }
  .mobile-chat-active .chat-panel   { z-index: 15; }

  .msg-row { max-width: 85%; }

  .contacts-grid { grid-template-columns: 1fr; padding: .75rem; }

  .modal-view__panel { max-height: 92vh; }

  .toast-container { bottom: 1rem; right: .75rem; left: .75rem; }
  .toast { max-width: 100%; }
}

/* ─── Scrollbar (non-webkit) ──────────────────────────────────────────────── */
* { scrollbar-width: thin; scrollbar-color: var(--color-border) transparent; }

/* ─── Reduced Motion ──────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
