/* TeamLayer design system - tokens + light/dark (inspired by design 18).
 *
 * Real palettes via CSS variables (NOT filter-invert). Light values match the
 * legacy Tailwind look so light mode is visually unchanged; dark mode is the
 * new capability. Toggle lives in wl-theme.js (floating button, html.wl-dark).
 *
 * Two layers:
 *  1) Semantic utilities (.wl-surface, .wl-text, .wl-bd, .wl-accent...) used by
 *     the migrated shell chrome + dashboard + login. Authoritative, clean.
 *  2) A scoped dark "bridge" (html.wl-dark .wl-darkbridge ...) that recolors the
 *     common legacy Tailwind utilities still present on not-yet-migrated pages,
 *     so dark mode stays coherent app-wide without touching every view. Scoped
 *     so it never leaks into modals / global widgets.
 */

:root {
  --wl-bg: #f5f5f7;
  --wl-surface: #ffffff;
  --wl-surface-2: #f8fafc;
  --wl-surface-3: #eef0f4;
  --wl-text: #1e293b;
  --wl-text-dim: #64748b;
  --wl-text-mute: #94a3b8;
  --wl-border: #e2e8f0;
  --wl-border-soft: #eef0f4;
  --wl-accent: #5b5fc7;
  --wl-accent-strong: #4b4fb5;
  --wl-accent-soft: #eef0fc;
  --wl-accent-on: #ffffff;
  --wl-rail: #3a3a55;
  --wl-rail-text: rgba(255, 255, 255, .72);
  --wl-rail-active: rgba(255, 255, 255, .14);
  --wl-danger: #ef4444;
  --wl-shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .08);
  --wl-shadow-lg: 0 12px 32px -12px rgba(15, 23, 42, .25);
}

html.wl-dark {
  --wl-bg: #0b1020;
  --wl-surface: #141a2b;
  --wl-surface-2: #1a2236;
  --wl-surface-3: #222d45;
  --wl-text: #e7ecf5;
  --wl-text-dim: #9aa6bd;
  --wl-text-mute: #6b7890;
  --wl-border: #283449;
  --wl-border-soft: #1f2940;
  --wl-accent: #8b91f0;
  --wl-accent-strong: #a3a8f5;
  --wl-accent-soft: #232a4a;
  --wl-accent-on: #ffffff;
  --wl-rail: #0a0e1c;
  --wl-rail-text: rgba(226, 232, 240, .7);
  --wl-rail-active: rgba(139, 145, 240, .22);
  --wl-danger: #f87171;
  --wl-shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --wl-shadow-lg: 0 16px 40px -12px rgba(0, 0, 0, .6);
}

/* Smooth the flip between themes (chrome only; avoid animating text). */
html.wl-theme-ready body,
html.wl-theme-ready .wl-surface,
html.wl-theme-ready .wl-surface-2,
html.wl-theme-ready .wl-surface-3,
html.wl-theme-ready .wl-app-bg,
html.wl-theme-ready .wl-rail {
  transition: background-color .18s ease, border-color .18s ease;
}

/* ---- Layer 1: semantic utilities ---- */
.wl-app-bg { background: var(--wl-bg); }
.wl-surface { background: var(--wl-surface); }
.wl-surface-2 { background: var(--wl-surface-2); }
.wl-surface-3 { background: var(--wl-surface-3); }
.wl-text { color: var(--wl-text); }
.wl-text-dim { color: var(--wl-text-dim); }
.wl-text-mute { color: var(--wl-text-mute); }
.wl-bd { border-color: var(--wl-border) !important; }
.wl-bd-soft { border-color: var(--wl-border-soft) !important; }
.wl-accent { color: var(--wl-accent); }
.wl-accent-bg { background: var(--wl-accent); color: var(--wl-accent-on); }
.wl-accent-bg:hover { background: var(--wl-accent-strong); }
.wl-accent-soft { background: var(--wl-accent-soft); color: var(--wl-accent); }
.wl-rail { background: var(--wl-rail); }
/* Design 18 cards are flat: surface + 1px border, no drop shadow. */
.wl-card { background: var(--wl-surface); border: 1px solid var(--wl-border); }
.wl-hover:hover { background: var(--wl-surface-3); }
.wl-shadow { box-shadow: var(--wl-shadow); }
.wl-shadow-lg { box-shadow: var(--wl-shadow-lg); }

/* ---- Brand logo (inline SVG mark + wordmark, currentColor) ---- */
.wl-logo { display: inline-flex; align-items: center; gap: 6px; color: var(--wl-accent); text-decoration: none; line-height: 1; }
/* Fill = the surface the logo sits on, so overlapping layers occlude cleanly
 * (white on light, dark on dark) without a stray white block. On colored
 * backgrounds (accent rail / gradient) the fill is transparent. */
.wl-logo svg { width: 1.9em; height: 1.9em; flex: 0 0 auto; fill: var(--wl-surface); }
.wl-accent-bg .wl-logo svg, .wl-logo.wl-logo-light svg { fill: var(--wl-accent); }
.wl-logo .wl-logo-text { font: 800 1.3rem/1 'Inter', ui-sans-serif, system-ui, sans-serif; letter-spacing: -0.02em; color: inherit; white-space: nowrap; }
/* White-label uploaded logo (replaces the TeamLayer mark+wordmark) */
.wl-logo-img { height: 32px; width: auto; max-width: 180px; object-fit: contain; display: block; }
/* Logo na tle akcentu / gradiencie - bialy */
.wl-accent-bg .wl-logo, .wl-logo.wl-logo-light { color: #fff; }

/* ---- Reusable bits (design 18): chips, status dots, list rows ---- */
.wl-chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 700; line-height: 1;
  padding: 3px 7px; border-radius: 6px;
  background: var(--wl-surface-3); color: var(--wl-text-dim);
}
.wl-dot { width: 8px; height: 8px; border-radius: 9999px; display: inline-block; flex: 0 0 auto; }
.wl-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: 10px; transition: background-color .12s ease; }
.wl-row:hover { background: var(--wl-surface-2); }
.wl-divide-y > * + * { border-top: 1px solid var(--wl-border-soft); }

/* Grupowanie wiadomosci: kolejne od tego samego nadawcy (w oknie czasu)
 * chowaja avatar i naglowek (nazwa+czas), zostaje sama tresc - jak Slack/Teams. */
.wl-msg-grouped .wl-grp-avatar { visibility: hidden; height: 0; }
.wl-msg-grouped .wl-grp-meta { display: none; }
.wl-msg-grouped .wl-grp-head { margin-bottom: 0 !important; min-height: 0; }
.wl-msg-grouped { margin-top: 0 !important; }
.wl-avatar {
  width: 26px; height: 26px; border-radius: 9999px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 600; color: #fff;
}

/* ---- Icon rail (Teams-style primary nav, design 18) ---- */
.wl-rail-item {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  width: 100%; padding: 8px 4px; border-radius: 10px;
  color: var(--wl-rail-text); font-size: 10px; font-weight: 600;
  text-decoration: none; position: relative;
  transition: color .15s ease;
}
.wl-rail-item span { line-height: 1.1; text-align: center; }
.wl-rail-item:hover { color: #fff; }
.wl-rail-item:hover .wl-rail-ico { background: rgba(255, 255, 255, .07); }
.wl-rail-item.active { color: #fff; }
.wl-rail-item.active .wl-rail-ico { background: var(--wl-rail-active); }
.wl-rail-ico {
  width: 40px; height: 34px; display: flex; align-items: center; justify-content: center;
  border-radius: 10px; transition: background-color .15s ease;
}
.wl-rail-ico svg { width: 20px; height: 20px; }
.wl-rail-badge {
  position: absolute; top: 3px; right: 13px;
  min-width: 16px; height: 16px; padding: 0 4px; border-radius: 9999px;
  background: var(--wl-danger); color: #fff; font-size: 9px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; border: 2px solid var(--wl-rail);
}

/* Header search trigger (opens command palette) */
.wl-search-btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 36px; padding: 0 12px; min-width: 200px;
  border-radius: 10px; cursor: pointer; text-align: left;
  background: var(--wl-surface-2); border: 1px solid var(--wl-border);
  color: var(--wl-text-mute); font-size: 13px;
}
.wl-search-btn:hover { border-color: var(--wl-accent); }
.wl-search-btn kbd {
  margin-left: auto; font: 600 10px/1 'Inter', sans-serif;
  padding: 3px 5px; border-radius: 5px; background: var(--wl-surface-3); color: var(--wl-text-dim);
}

/* Inputs / selects styled with tokens (used in migrated views). */
.wl-input {
  background: var(--wl-surface);
  border: 1px solid var(--wl-border);
  color: var(--wl-text);
}
.wl-input::placeholder { color: var(--wl-text-mute); }
.wl-input:focus { outline: none; border-color: var(--wl-accent); box-shadow: 0 0 0 3px var(--wl-accent-soft); }

/* ---- Floating theme toggle ---- */
#wlThemeToggle {
  position: fixed;
  bottom: 16px;
  right: 16px;
  /* Below modals/drawers (voice-video, confirm, command palette all sit at z>=50);
     the floating fallback only appears on standalone pages anyway. */
  z-index: 40;
  height: 40px;
  padding: 0 14px;
  border-radius: 9999px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font: 600 12px/1 'Inter', ui-sans-serif, system-ui, sans-serif;
  cursor: pointer;
  background: var(--wl-surface);
  color: var(--wl-text);
  border: 1px solid var(--wl-border);
  box-shadow: var(--wl-shadow-lg);
  transition: transform .15s ease, background-color .18s ease;
}
#wlThemeToggle:hover { transform: translateY(-1px); }
#wlThemeToggle svg { width: 16px; height: 16px; }
/* When mounted inline in the header (next to search) instead of floating. */
#wlThemeToggle.wl-theme-inline {
  position: static; bottom: auto; right: auto;
  height: 36px; padding: 0 12px; box-shadow: none;
  background: var(--wl-surface-2); border-radius: 10px;
}
#wlThemeToggle.wl-theme-inline:hover { transform: none; border-color: var(--wl-accent); }

/* ---- Layer 2: scoped dark bridge for legacy Tailwind classes ----
 * Only active in dark mode AND only inside an opted-in container
 * (.wl-darkbridge on the app content area). Keeps un-migrated pages coherent. */
html.wl-dark .wl-darkbridge .bg-white { background: var(--wl-surface) !important; }
html.wl-dark .wl-darkbridge .bg-gray-50 { background: var(--wl-bg) !important; }
html.wl-dark .wl-darkbridge .bg-gray-100 { background: var(--wl-surface-3) !important; }
html.wl-dark .wl-darkbridge .hover\:bg-gray-50:hover,
html.wl-dark .wl-darkbridge .hover\:bg-gray-100:hover { background: var(--wl-surface-3) !important; }

html.wl-dark .wl-darkbridge .border-gray-100,
html.wl-dark .wl-darkbridge .border-gray-200,
html.wl-dark .wl-darkbridge .border-gray-300 { border-color: var(--wl-border) !important; }

html.wl-dark .wl-darkbridge .text-gray-900,
html.wl-dark .wl-darkbridge .text-gray-800,
html.wl-dark .wl-darkbridge .text-gray-700 { color: var(--wl-text) !important; }
html.wl-dark .wl-darkbridge .text-gray-600,
html.wl-dark .wl-darkbridge .text-gray-500 { color: var(--wl-text-dim) !important; }
html.wl-dark .wl-darkbridge .text-gray-400 { color: var(--wl-text-mute) !important; }
html.wl-dark .wl-darkbridge .text-blue-600,
html.wl-dark .wl-darkbridge .text-blue-700 { color: var(--wl-accent) !important; }

/* Form controls on legacy pages. */
html.wl-dark .wl-darkbridge select,
html.wl-dark .wl-darkbridge input:not([type="checkbox"]):not([type="radio"]),
html.wl-dark .wl-darkbridge textarea {
  background: var(--wl-surface-2) !important;
  border-color: var(--wl-border) !important;
  color: var(--wl-text) !important;
}
html.wl-dark .wl-darkbridge .shadow-sm { box-shadow: var(--wl-shadow) !important; }

/* ---- Mobile shell (design 18): rail hidden, tree as drawer, bottom nav ---- */
#wlBottomNav { display: none; }
@media (max-width: 767px) {
  #wlRail { display: none !important; }
  #sidebarCollapsedRail { display: none !important; }
  /* Tree becomes an off-canvas drawer */
  #sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 60; width: 18rem;
    transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: var(--wl-shadow-lg);
  }
  body.wl-drawer-open #sidebar { transform: translateX(0); }
  #wlMobileBackdrop {
    position: fixed; inset: 0; z-index: 55; background: rgba(0, 0, 0, .45);
    opacity: 0; pointer-events: none; transition: opacity .22s ease;
  }
  body.wl-drawer-open #wlMobileBackdrop { opacity: 1; pointer-events: auto; }
  /* Bottom nav */
  #wlBottomNav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    height: calc(56px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    display: flex; align-items: stretch; justify-content: space-around;
    background: var(--wl-surface); border-top: 1px solid var(--wl-border);
  }
  #appMain { padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px)); }
  /* Nothing in the shell should produce horizontal scroll on a phone. */
  html, body { max-width: 100%; overflow-x: hidden; }
}
@media (min-width: 768px) {
  #wlMobileBackdrop, #wlHamburger { display: none !important; }
}
#wlBottomNav .wl-bottom-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 10px; font-weight: 600; color: var(--wl-text-dim); text-decoration: none;
  position: relative;
}
#wlBottomNav .wl-bottom-item.active { color: var(--wl-accent); }
#wlBottomNav .wl-bottom-item svg { width: 20px; height: 20px; }
#wlBottomNav .wl-bottom-badge {
  position: absolute; top: 6px; right: 50%; margin-right: -18px;
  min-width: 15px; height: 15px; padding: 0 4px; border-radius: 9999px;
  background: var(--wl-danger); color: #fff; font-size: 9px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}

/* ---- Confirm modal ---- */
.wl-modal-overlay {
  position: fixed; inset: 0; z-index: 120; padding: 16px;
  background: rgba(0, 0, 0, .45);
  display: flex; align-items: center; justify-content: center;
}
/* wl-theme.css laduje sie po styles.css, wiec .wl-modal-overlay{display:flex}
   bilby nadpisal Tailwindowy .hidden. Jawny override przywraca chowanie. */
.wl-modal-overlay.hidden { display: none; }
.wl-modal-box {
  width: 100%; max-width: 380px; padding: 20px;
  background: var(--wl-surface); border: 1px solid var(--wl-border);
  border-radius: 14px; box-shadow: var(--wl-shadow-lg);
}

/* ---- Message hover actions (flat icons + kebab) ---- */
.wl-msg-actions {
  position: absolute; top: 4px; right: 8px; z-index: 5;
  display: flex; align-items: center; gap: 2px;
  opacity: 0; transition: opacity .12s ease;
  background: var(--wl-surface); border: 1px solid var(--wl-border);
  border-radius: 8px; padding: 2px; box-shadow: var(--wl-shadow);
}
.message-item:hover .wl-msg-actions, .wl-msg-actions.open { opacity: 1; }
.wl-icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 6px;
  color: var(--wl-text-dim); cursor: pointer; background: none; border: none;
}
.wl-icon-btn:hover { background: var(--wl-surface-3); color: var(--wl-text); }
.wl-icon-btn.danger:hover { color: var(--wl-danger); }
.wl-icon-btn svg { width: 16px; height: 16px; }
.wl-kebab-menu {
  position: absolute; z-index: 130; min-width: 180px; padding: 4px;
  background: var(--wl-surface); border: 1px solid var(--wl-border);
  border-radius: 10px; box-shadow: var(--wl-shadow-lg);
}
.wl-kebab-menu a, .wl-kebab-menu button {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 8px 10px; border-radius: 7px; font-size: 13px; text-align: left;
  color: var(--wl-text); background: none; border: none; cursor: pointer; text-decoration: none;
}
.wl-kebab-menu a:hover, .wl-kebab-menu button:hover { background: var(--wl-surface-3); }
.wl-kebab-menu svg { width: 15px; height: 15px; color: var(--wl-text-dim); }
.wl-edited { font-size: 11px; color: var(--wl-text-mute); font-style: italic; }

/* ---- Login / auth pro screen ---- */
.wl-auth {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr;
  background: var(--wl-bg);
  color: var(--wl-text);
  font-family: 'Inter', ui-sans-serif, system-ui, sans-serif;
}
@media (min-width: 900px) {
  .wl-auth { grid-template-columns: 1.05fr 1fr; }
}
.wl-auth-aside {
  display: none;
  position: relative;
  overflow: hidden;
  padding: 56px 56px;
  color: #fff;
  background:
    radial-gradient(900px 500px at 15% 0%, rgba(255, 255, 255, .12), transparent 60%),
    linear-gradient(150deg, #4b4fb5 0%, #5b5fc7 45%, #7c5cd6 100%);
}
@media (min-width: 900px) {
  .wl-auth-aside { display: flex; flex-direction: column; }
}
.wl-auth-aside .wl-auth-grid {
  position: absolute; inset: 0;
  background-image: linear-gradient(rgba(255,255,255,.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.06) 1px, transparent 1px);
  background-size: 38px 38px;
  mask-image: radial-gradient(700px 500px at 30% 30%, #000, transparent 75%);
}
.wl-auth-main {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 20px;
  background: var(--wl-surface);
}
/* Bez ramki/karty - formularz lezy bezposrednio na tle panelu. */
.wl-auth-card {
  width: 100%;
  max-width: 380px;
}
.wl-auth-field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--wl-text-dim);
  margin-bottom: 6px;
}
.wl-auth-field input {
  width: 100%;
  padding: 11px 13px;
  border-radius: 10px;
  font-size: 14px;
  background: var(--wl-surface);
  border: 1px solid var(--wl-border);
  color: var(--wl-text);
}
.wl-auth-field input::placeholder { color: var(--wl-text-mute); }
.wl-auth-field input:focus { outline: none; border-color: var(--wl-accent); box-shadow: 0 0 0 3px var(--wl-accent-soft); }
/* Keep browser autofill from painting its own (blue/yellow) background so both
   fields look identical whether autofilled, focused or empty. */
.wl-auth-field input:-webkit-autofill,
.wl-auth-field input:-webkit-autofill:hover,
.wl-auth-field input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--wl-text);
  -webkit-box-shadow: 0 0 0 1000px var(--wl-surface) inset;
  caret-color: var(--wl-text);
}
.wl-auth-submit {
  width: 100%;
  padding: 12px 16px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
  color: var(--wl-accent-on);
  background: var(--wl-accent);
  border: none;
  cursor: pointer;
  transition: background-color .15s ease;
}
.wl-auth-submit:hover { background: var(--wl-accent-strong); }

/* Logo is dark-on-transparent (made for light surfaces). On dark surfaces
 * invert it to white so it stays visible: login card + app sidebar brand. */
html.wl-dark .wl-auth-logo,
html.wl-dark .app-layout-brand img { filter: brightness(0) invert(1); }

/* @mentions: highlighted token in message bodies + composer chip. */
.wl-mention {
  color: var(--wl-accent);
  background: var(--wl-accent-soft);
  border-radius: 5px;
  padding: 0 4px;
  font-weight: 600;
  white-space: nowrap;
}
.wl-msg-editor .wl-mention { cursor: default; }

/* @mention picker dropdown (wl-mention-autocomplete.js, fixed-positioned). */
.wl-mention-menu {
  position: fixed;
  z-index: 10001;
  min-width: 220px;
  max-width: 300px;
  max-height: 240px;
  overflow-y: auto;
  padding: 4px;
  background: var(--wl-surface);
  border: 1px solid var(--wl-border);
  border-radius: 10px;
  box-shadow: var(--wl-shadow-lg);
}
.wl-mention-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  color: var(--wl-text);
}
.wl-mention-item.is-active { background: var(--wl-surface-3); }
.wl-mention-ava {
  width: 24px;
  height: 24px;
  border-radius: 9999px;
  object-fit: cover;
  flex: 0 0 auto;
}
.wl-mention-ava--fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--wl-accent);
  color: var(--wl-accent-on);
  font-size: 11px;
  font-weight: 600;
}
.wl-mention-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }

/* Reserve the reaction row height up-front so the lazily-fetched reactions do
 * not shift each message down ~150ms after first paint (CLS). wl-reactions.js
 * creates this row synchronously (empty) for every message; the fixed
 * min-height keeps the message height final whether it ends up with 0 or a
 * single row of reaction pills. */
.wl-reactions { min-height: 1.5rem; }
