/* ============================================================
   CSG Chat — shared chrome (top nav, design tokens, components)
   Linked by every operator page so the topbar is identical and
   one place owns the design tokens.
   ============================================================ */

:root {
  /* Brand red — same in both themes */
  --csg-red: #D71920;
  --csg-red-dark: #A8121A;
  --csg-red-soft: #FEE2E2;

  /* Light theme palette (default) */
  --csg-black: #0A0A0A;
  --csg-charcoal: #1F1F1F;
  --csg-graphite: #2D2D2D;
  --csg-bg: #F5F5F7;
  --csg-surface: #FFFFFF;
  --csg-surface-2: #FAFAFA;    /* hovers, alt-row backgrounds */
  --csg-border: #E5E5E5;
  --csg-border-soft: #F0F0F0;
  --csg-text: #0A0A0A;
  --csg-muted: #6B6B6B;
  --csg-muted-2: #9A9A9A;
  --csg-bubble-incoming: #ECECEC;   /* visitor msg bg in agent view, agent msg bg in widget */
  --csg-bubble-incoming-text: #0A0A0A;
  --csg-bubble-outgoing: #0A0A0A;   /* agent's own msg bg in agent view; flips to red in dark */
  --csg-bubble-outgoing-text: #FFFFFF;
  --csg-chart-secondary: #0A0A0A;   /* second slice on the donut, bars; flips in dark mode */
  --csg-pill-active: #0A0A0A;       /* dark filter pill bg; flips to red in dark */

  --csg-warn-bg: #FEF3C7;           /* urgent-warn yellow */
  --csg-warn-bg-hover: #FDE68A;
  --csg-warn-border: #FCD34D;
  --csg-alarm-bg: #FEE2E2;           /* urgent-alarm light red */
  --csg-alarm-bg-hover: #FECACA;

  --csg-success: #16A34A;
  --csg-info: #2563EB;
  --shadow-md: 0 4px 12px rgba(0,0,0,0.10);
  --shadow-lg: 0 20px 35px -10px rgba(0,0,0,0.20);
}

/* ---- Dark theme overrides (applied to <html> by chrome.js) ---- */
html.theme-dark {
  --csg-bg: #0F0F10;
  --csg-surface: #1A1A1B;
  --csg-surface-2: #232325;
  --csg-border: #2D2D2F;
  --csg-border-soft: #232325;
  --csg-text: #EDEDED;
  --csg-muted: #B0B0B0;
  --csg-muted-2: #8A8A8A;
  --csg-red-soft: rgba(215, 25, 32, 0.22);
  --csg-bubble-incoming: #2D2D2F;
  --csg-bubble-incoming-text: #EDEDED;
  --csg-bubble-outgoing: #D71920;    /* red in dark so the agent's own bubble pops */
  --csg-bubble-outgoing-text: #FFFFFF;
  --csg-chart-secondary: #EDEDED;
  --csg-pill-active: #D71920;
  --csg-warn-bg: rgba(252, 211, 77, 0.16);
  --csg-warn-bg-hover: rgba(252, 211, 77, 0.26);
  --csg-warn-border: rgba(252, 211, 77, 0.45);
  --csg-alarm-bg: rgba(215, 25, 32, 0.20);
  --csg-alarm-bg-hover: rgba(215, 25, 32, 0.32);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.50);
  --shadow-lg: 0 20px 35px -10px rgba(0,0,0,0.70);
  color-scheme: dark;
}
/* "Follow system" mode: dark when the OS says dark, light otherwise. */
@media (prefers-color-scheme: dark) {
  html.theme-system {
    --csg-bg: #0F0F10;
    --csg-surface: #1A1A1B;
    --csg-surface-2: #232325;
    --csg-border: #2D2D2F;
    --csg-border-soft: #232325;
    --csg-text: #EDEDED;
    --csg-muted: #B0B0B0;
    --csg-muted-2: #8A8A8A;
    --csg-red-soft: rgba(215, 25, 32, 0.22);
    --csg-bubble-incoming: #2D2D2F;
    --csg-bubble-incoming-text: #EDEDED;
    --csg-bubble-outgoing: #D71920;
    --csg-bubble-outgoing-text: #FFFFFF;
    --csg-chart-secondary: #EDEDED;
    --csg-pill-active: #D71920;
    --csg-warn-bg: rgba(252, 211, 77, 0.16);
    --csg-warn-bg-hover: rgba(252, 211, 77, 0.26);
    --csg-warn-border: rgba(252, 211, 77, 0.45);
    --csg-alarm-bg: rgba(215, 25, 32, 0.20);
    --csg-alarm-bg-hover: rgba(215, 25, 32, 0.32);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.50);
    --shadow-lg: 0 20px 35px -10px rgba(0,0,0,0.70);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  background: var(--csg-bg);
  color: var(--csg-text);
  line-height: 1.5;
}

/* ----- Top bar ----- */
.topbar {
  background: var(--csg-black);
  color: #fff;
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 2px solid var(--csg-red);
  font-size: 13px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
}
.brand .mark {
  /* White CSG graphic mark (arcs only — no wordmark) on the dark top bar.
     The "CSG" text is hidden (font-size:0); image shown as a contained bg. */
  background: url('/assets/logo-mark-light.png') center / contain no-repeat;
  width: 66px;
  height: 24px;
  border-radius: 0;
  display: inline-block;
  font-size: 0;
  color: transparent;
}
.brand .name { font-weight: 700; }
.brand .tagline { opacity: 0.6; font-weight: 400; font-size: 13px; margin-left: 6px; }

.tabs { display: flex; gap: 4px; align-items: center; }
.tab {
  background: rgba(255,255,255,0.08);
  color: #fff;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  border: none;
  font-family: inherit;
  text-decoration: none;
  white-space: nowrap;
}
.tab:hover { background: rgba(255,255,255,0.16); }
.tab.active {
  background: var(--csg-red);
  color: #fff;
  font-weight: 600;
}
.tab.tab-hidden { display: none; }

.live-pill {
  background: rgba(22,163,74,0.15);
  color: #4ade80;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-right: 8px;
}
.live-pill::before {
  content: '';
  width: 6px; height: 6px;
  background: #4ade80;
  border-radius: 3px;
  box-shadow: 0 0 6px rgba(74,222,128,0.8);
}

/* User pill is a button (clickable) → opens a small dropdown */
.user-pill-wrap { position: relative; margin-left: 12px; }
.user-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.08);
  padding: 4px 12px 4px 4px;
  border-radius: 18px;
  font-size: 13px;
  font-weight: 600;
  border: none;
  color: inherit;
  cursor: pointer;
  font-family: inherit;
}
.user-pill:hover { background: rgba(255,255,255,0.16); }
.user-pill .user-avatar {
  width: 28px; height: 28px;
  border-radius: 14px;
  background: var(--csg-red);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 11px;
  overflow: hidden;
  flex-shrink: 0;
}
.user-pill .user-avatar.dk { background: var(--csg-black); }
.user-pill .user-avatar img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.user-pill .role-chip { margin-left: 2px; }
.user-pill .chev { font-size: 10px; opacity: 0.7; }

/* Dropdown menu anchored under the user pill */
.user-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 200px;
  background: var(--csg-surface);
  color: var(--csg-text);
  border: 1px solid var(--csg-border);
  border-radius: 10px;
  padding: 6px;
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  display: none;
}
.user-menu.open { display: block; }
.user-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 6px;
  color: var(--csg-text);
  text-decoration: none;
  background: transparent;
  border: none;
  cursor: pointer;
  width: 100%;
  text-align: left;
  font-family: inherit;
}
.user-menu-item:hover { background: var(--csg-surface-2); }
.user-menu-item.danger { color: var(--csg-red); }
.user-menu-divider { height: 1px; background: var(--csg-border); margin: 4px 2px; }

.signout-btn {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.85);
  padding: 5px 11px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  margin-left: 8px;
}
.signout-btn:hover { background: rgba(255,255,255,0.1); border-color: rgba(255,255,255,0.4); color: #fff; }

/* ----- Role / dept chips ----- */
.role-chip {
  display: inline-block;
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--csg-red-soft);
  color: var(--csg-red-dark);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.role-chip.admin      { background: var(--csg-red);             color: #fff; }
.role-chip.supervisor { background: var(--csg-black);           color: #fff; }
.role-chip.agent      { background: var(--csg-bubble-incoming); color: var(--csg-bubble-incoming-text); }

.dept-chip {
  display: inline-block;
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--csg-red-soft);
  color: var(--csg-red-dark);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.dept-chip.support { background: var(--csg-bubble-incoming); color: var(--csg-bubble-incoming-text); }
.dept-chip.both    { background: var(--csg-black);           color: #fff; }

/* ----- Avatar circle ----- */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border-radius: 14px;
  background: var(--csg-black);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}
.avatar.red       { background: var(--csg-red); }
.avatar.lg        { width: 36px; height: 36px; border-radius: 18px; font-size: 13px; }
.avatar.sm        { width: 22px; height: 22px; border-radius: 11px; font-size: 9px; }

/* ----- Buttons ----- */
.btn {
  padding: 7px 13px;
  border: 1px solid var(--csg-border);
  background: var(--csg-surface);
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  color: var(--csg-text);
  font-weight: 500;
}
.btn:hover { background: var(--csg-surface-2); }
.btn.primary {
  background: var(--csg-red);
  color: #fff;
  border-color: var(--csg-red);
  font-weight: 700;
}
.btn.primary:hover { background: var(--csg-red-dark); border-color: var(--csg-red-dark); }
.btn.danger  { color: var(--csg-red); border-color: #FCA5A5; }
.btn.danger:hover { background: var(--csg-red-soft); }

/* ----- Common card ----- */
.card {
  background: var(--csg-surface);
  border-radius: 10px;
  border: 1px solid var(--csg-border);
  padding: 20px;
}

/* ----- Status dot ----- */
.status-dot {
  display: inline-block;
  width: 8px; height: 8px; border-radius: 4px;
  vertical-align: middle;
  margin-right: 6px;
}
.status-dot.online  { background: var(--csg-success); }
.status-dot.away    { background: #f59e0b; }
.status-dot.offline { background: var(--csg-muted-2); }
