/* Aurex Sales IQ: workspace styles. System fonts only. */

:root {
  --ink: #0F1B3D;
  --ink-2: #16244B;
  --ink-text: #C9D2E8;
  --ink-muted: #8D9ABA;
  --canvas: #F5F7FB;
  --card: #FFFFFF;
  --border: #E2E8F0;
  --border-strong: #CBD5E1;
  --row-line: #EEF2F6;
  --text: #0F172A;
  --text-2: #334155;
  --muted: #64748B;
  --primary: #4F46E5;
  --primary-hover: #4338CA;
  --primary-soft: #EEF2FF;
  --primary-text: #4338CA;
  --teal: #14B8A6;
  --teal-strong: #0F766E;
  --teal-soft: #CCFBF1;
  --danger: #DC2626;
  --danger-hover: #B91C1C;
  --danger-soft: #FEF2F2;
  --amber-text: #B45309;
  --amber-bg: #FEF3C7;
  --amber-border: #FDE68A;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(15, 27, 61, 0.05);
  --shadow: 0 6px 18px rgba(15, 27, 61, 0.08);
  --shadow-lg: 0 24px 60px rgba(15, 27, 61, 0.22);
  --focus-ring: 0 0 0 3px rgba(79, 70, 229, 0.28);
  --sidebar-w: 248px;
  --sidebar-w-collapsed: 72px;
  --topbar-h: 60px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--topbar-h) + 16px); }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14.5px;
  line-height: 1.5;
  color: var(--text);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

img, svg { display: block; max-width: 100%; }
svg.icon { flex: none; }
a { color: var(--primary-text); }
a:hover { color: var(--primary-hover); }
p { margin: 0; }
h1, h2, h3 { line-height: 1.25; }
code, .mono, kbd, pre { font-family: var(--mono); }
kbd {
  font-size: 11px;
  padding: 1px 5px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: #fff;
  color: var(--text-2);
}

:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }
[tabindex="-1"]:focus { outline: none; }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 8px;
  top: -60px;
  z-index: 300;
  background: var(--ink);
  color: #fff;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  text-decoration: none;
}
.skip-link:focus { top: 8px; color: #fff; }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.prewrap { white-space: pre-wrap; overflow-wrap: anywhere; }
.span-all { grid-column: 1 / -1; }

/* ---- Boot ---------------------------------------------------------------- */

.boot {
  min-height: 100vh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  color: var(--muted);
}

/* ---- Buttons -------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 38px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); color: #fff; }
.btn-secondary { background: #fff; color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: #F8FAFC; border-color: #94A3B8; color: var(--text); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: #EEF2F6; color: var(--text); }
.btn-teal { background: var(--teal-strong); color: #fff; }
.btn-teal:hover:not(:disabled) { background: #115E59; color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); color: #fff; }
.btn-ghost-danger { background: transparent; color: var(--danger); }
.btn-ghost-danger:hover:not(:disabled) { background: var(--danger-soft); color: var(--danger-hover); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; gap: 6px; }
.btn-lg { height: 44px; font-size: 15px; }
.btn-block { width: 100%; }
.btn.is-busy { opacity: 0.85; cursor: progress; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex: none;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
}
.icon-btn:hover:not(:disabled) { background: #EEF2F6; color: var(--text); }
.icon-btn-danger:hover:not(:disabled) { background: var(--danger-soft); color: var(--danger); }
.icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.link-btn {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  overflow-wrap: anywhere;
}
.link-btn:hover { color: var(--primary); text-decoration: underline; }

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

.chip {
  height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  cursor: pointer;
}
.chip:hover { border-color: var(--primary); color: var(--primary-text); }

/* ---- Forms ------------------------------------------------------------------ */

input[type="text"], input[type="email"], input[type="password"], input[type="url"], input[type="number"],
input[type="search"], select, textarea {
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  min-height: 38px;
  width: 100%;
  min-width: 0;
  transition: border-color 0.15s, box-shadow 0.15s;
}
textarea { resize: vertical; line-height: 1.45; }
select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px;
}
input:hover, select:hover, textarea:hover { border-color: #94A3B8; }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--amber-text); }
input[readonly], textarea[readonly] { background: #F8FAFC; }
input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; margin: 0; accent-color: var(--primary); cursor: pointer; flex: none; }
input[type="checkbox"]:disabled, input[type="radio"]:disabled { cursor: not-allowed; opacity: 0.45; }
input[type="checkbox"]:focus-visible, input[type="radio"]:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; box-shadow: none; }
.input-narrow { max-width: 140px; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.field-label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.req { color: var(--muted); }
.field-hint { font-size: 12.5px; color: var(--muted); }
.field-error { font-size: 12.5px; font-weight: 600; color: var(--amber-text); }
.field-error:empty { display: none; }
.counter { font-size: 12px; color: var(--muted); font-weight: 500; }
.counter.ok { color: var(--teal-strong); }
code.expected {
  background: #F1F5F9;
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--text);
  user-select: all;
  overflow-wrap: anywhere;
}

.form-error {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: var(--amber-bg);
  color: #78350F;
  border: 1px solid var(--amber-border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 14px;
}
.form-error:empty { display: none; }
.form-error svg { color: var(--amber-text); margin-top: 1px; }
.form-error-text { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.form-error-text code { background: rgba(255, 255, 255, 0.6); padding: 0 4px; border-radius: 4px; }
.error-list { margin: 0; padding-left: 18px; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid > .field-wide, .form-grid .field-wide { grid-column: 1 / -1; }
.form-stack { display: flex; flex-direction: column; gap: 16px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; }
.inline-input { display: flex; gap: 8px; align-items: center; }
.inline-input input { flex: 1; }
.check-row, .radio-row { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; color: var(--text); }
.check-row label, .radio-row label { cursor: pointer; }
.field-inline { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--text-2); }
.field-inline select { width: auto; min-height: 34px; padding-top: 4px; padding-bottom: 4px; }

/* ---- Atoms ---------------------------------------------------------------------- */

.avatar {
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  font-weight: 700;
  flex: none;
  letter-spacing: 0.02em;
  line-height: 1;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
  vertical-align: middle;
}
.pill-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.pill-teal { background: var(--teal-soft); color: var(--teal-strong); }
.pill-teal .pill-dot { background: var(--teal); }
.pill-amber { background: var(--amber-bg); color: var(--amber-text); }
.pill-amber .pill-dot { background: #F59E0B; }
.pill-gray { background: #F1F5F9; color: #475569; }
.pill-gray .pill-dot { background: #94A3B8; }
.pill-indigo { background: var(--primary-soft); color: var(--primary-text); }
.pill-indigo .pill-dot { background: #6366F1; }
.pill-red { background: var(--danger-soft); color: var(--danger-hover); }
.pill-red .pill-dot { background: var(--danger); }

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.dot-teal { background: var(--teal); }
.dot-amber { background: #F59E0B; }
.dot-red { background: var(--danger); }
.dot-indigo { background: #6366F1; }
.dot-gray { background: #94A3B8; }

.skeleton {
  display: block;
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(90deg, #EEF2F6 25%, #E2E8F0 37%, #EEF2F6 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}
.skeleton-block { display: flex; flex-direction: column; gap: 10px; padding: 8px 0; width: 100%; }
.skeleton-row td { padding: 14px 12px; }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 44px 20px;
  gap: 6px;
}
.empty-compact { padding: 24px 16px; }
.empty-mark { opacity: 0.95; margin-bottom: 4px; }
.empty-title { font-weight: 650; font-size: 15px; color: var(--text); }
.empty-body { color: var(--muted); max-width: 48ch; }
.empty .btn { margin-top: 10px; }
.empty-error .empty-icon { color: var(--amber-text); }

.notice {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 14px;
}
.notice > svg { margin-top: 2px; }
.notice-amber { background: var(--amber-bg); color: #78350F; border: 1px solid var(--amber-border); }
.notice-amber > svg { color: var(--amber-text); }
.notice a { color: #78350F; font-weight: 600; }
.plain-list { margin: 6px 0; padding-left: 18px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  min-width: 0;
}
.card:has(> .table-wrap) { overflow: hidden; }
.card-pad { padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.card-title { font-size: 15px; font-weight: 700; margin: 0; }
.card-link { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 600; text-decoration: none; }

/* ---- Login ------------------------------------------------------------------------ */

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background:
    radial-gradient(900px 500px at 0% -10%, #E0E7FF 0, transparent 60%),
    radial-gradient(800px 480px at 105% 110%, #CCFBF1 0, transparent 55%),
    var(--canvas);
}
.login-main { width: min(440px, 100%); display: flex; flex-direction: column; gap: 16px; outline: none; }
.login-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 32px 32px;
  box-shadow: var(--shadow);
}
.login-brand { padding: 4px 0 28px; }
.login-brand img { width: 220px; height: auto; }
.login-title { font-size: 21px; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
.login-sub { color: var(--muted); margin: 6px 0 24px; }
.login-form { display: flex; flex-direction: column; gap: 16px; }
.login-form .btn { margin-top: 4px; }
.login-error {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: var(--amber-bg);
  color: #78350F;
  border: 1px solid var(--amber-border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.login-error:empty { display: none; }
.login-error svg { color: var(--amber-text); margin-top: 2px; }
.login-foot { display: flex; align-items: center; justify-content: center; gap: 6px; color: var(--muted); font-size: 13px; text-align: center; }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 68px; }
.pw-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: none;
  color: var(--primary-text);
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
}
.pw-toggle:hover { background: var(--primary-soft); }

/* ---- Shell -------------------------------------------------------------------------- */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}
.shell.is-collapsed { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); }

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--ink);
  color: var(--ink-text);
  display: flex;
  flex-direction: column;
  scrollbar-width: thin;
  scrollbar-color: #2A3A66 transparent;
}
.sidebar :focus-visible { outline-color: #A5B4FC; }
.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  /* Clear space around the logo: at least the bubble's height (about 20px). */
  padding: 22px 20px 22px 22px;
  min-height: 72px;
}
.brand-link { display: block; border-radius: 6px; }
.logo-full { width: 176px; height: auto; }
.logo-mark { display: none; width: 32px; height: 32px; }

.sidebar-nav { flex: 1; padding-bottom: 16px; }
.nav-group { margin-top: 6px; }
.nav-group-label {
  font-size: 11px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-muted);
  padding: 14px 24px 6px;
  font-weight: 700;
}
.nav-list { list-style: none; margin: 0; padding: 0; }
.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: calc(100% - 24px);
  margin: 1px 12px;
  padding: 8px 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--ink-text);
  font: inherit;
  font-size: 14px;
  font-weight: 550;
  text-decoration: none;
  text-align: left;
  cursor: pointer;
  min-height: 38px;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.07); color: #fff; }
.nav-item.active { background: rgba(129, 140, 248, 0.18); color: #fff; }
.nav-item.active::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: #818CF8;
}
.nav-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.nav-badge {
  margin-left: auto;
  background: #FBBF24;
  color: var(--ink);
  font-size: 11px;
  font-weight: 800;
  border-radius: 999px;
  padding: 1px 7px;
  min-width: 20px;
  text-align: center;
  line-height: 18px;
}
.access-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; margin: 0 5px; }
.access-allowed { background: var(--teal); }
.access-pending { background: #FBBF24; }
.access-suspended { background: #64748B; }
.sidebar-foot { padding: 8px 0 16px; border-top: 1px solid rgba(255, 255, 255, 0.08); }
.collapse-btn[aria-pressed="true"] svg { transform: scaleX(-1); }
.drawer-close { display: none; color: var(--ink-text); }
.drawer-close:hover { background: rgba(255, 255, 255, 0.08) !important; color: #fff !important; }
.drawer-backdrop { display: none; }

@media (min-width: 800px) {
  .is-collapsed .logo-full { display: none; }
  .is-collapsed .logo-mark { display: block; }
  .is-collapsed .sidebar-brand { justify-content: center; padding: 20px 0; }
  .is-collapsed .nav-label {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap;
  }
  .is-collapsed .nav-group-label { font-size: 0; padding: 10px 0 4px; height: 18px; border-top: 1px solid rgba(255, 255, 255, 0.08); margin: 6px 16px 0; }
  .is-collapsed .nav-item { justify-content: center; padding: 10px 0; }
  .is-collapsed .nav-badge { position: absolute; top: 2px; right: 6px; padding: 0 5px; min-width: 16px; line-height: 16px; font-size: 10px; }
  .is-collapsed .access-dot { margin: 0; }
}

.main-col { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--border);
}
.menu-btn, .topbar-mark { display: none; }
.topbar-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.company-name { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.switch-wrap { position: relative; display: flex; align-items: center; min-width: 0; }
.company-switch {
  font-weight: 700;
  font-size: 15px;
  border-color: var(--border);
  padding: 6px 34px 6px 34px;
  min-height: 38px;
  max-width: 320px;
  background-image: none;
  text-overflow: ellipsis;
}
.switch-icon { position: absolute; left: 11px; color: var(--muted); pointer-events: none; }
.switch-caret { position: absolute; right: 11px; color: var(--muted); pointer-events: none; }
.topbar-spacer { flex: 1; }
.topbar-links { display: flex; gap: 4px; }
.top-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
}
.top-link:hover { background: #EEF2F6; color: var(--text); }
.top-link.active { background: var(--primary-soft); color: var(--primary-text); }

.user-menu { position: relative; }
.user-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid transparent;
  background: none;
  padding: 3px 8px 3px 3px;
  border-radius: 999px;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}
.user-btn:hover, .user-btn[aria-expanded="true"] { background: #EEF2F6; }
.user-name { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 250px;
  max-width: calc(100vw - 24px);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 50;
}
.menu-head { padding: 10px 10px 12px; border-bottom: 1px solid var(--border); margin-bottom: 6px; display: flex; flex-direction: column; gap: 2px; font-size: 13.5px; }
.menu-head span { color: var(--muted); overflow-wrap: anywhere; font-size: 13px; }
.menu-role { font-size: 12px !important; }
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  background: none;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.menu-item svg { color: var(--muted); }
.menu-item:hover, .menu-item:focus-visible { background: #EEF2F6; outline: none; }
.menu-item:focus-visible { box-shadow: inset 0 0 0 2px var(--primary); }
.mobile-only { display: none; }

.view { padding: 24px; outline: none; min-width: 0; flex: 1; }

/* ---- Page scaffolding ------------------------------------------------------------------------ */

.page { max-width: 1280px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.page-narrow { max-width: 940px; }
.page-header { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: flex-end; justify-content: space-between; }
.page-header-compact { align-items: center; }
.page-titles { min-width: 0; flex: 1 1 320px; }
.page-eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--primary-text); font-weight: 700; margin-bottom: 2px; }
.page-title { font-size: 23px; font-weight: 750; margin: 0; letter-spacing: -0.015em; }
.page-subtitle { margin-top: 4px; color: var(--muted); max-width: 80ch; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 700; margin: 6px 0 8px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; min-width: 0; }
.toolbar-slot { display: contents; }
.search { position: relative; flex: 1 1 220px; max-width: 360px; min-width: 0; }
.search-icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search .search-input { padding-left: 34px; }

.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  max-width: 100%;
  background: #E9EDF3;
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}
.seg-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  cursor: pointer;
  white-space: nowrap;
}
.seg-btn:hover { color: var(--text); }
.seg-btn[aria-pressed="true"] { background: #fff; color: var(--text); box-shadow: 0 1px 2px rgba(15, 27, 61, 0.14); }
.seg-count { font-size: 11px; background: #DDE3EC; border-radius: 999px; padding: 0 6px; line-height: 17px; color: var(--text-2); }
.seg-btn[aria-pressed="true"] .seg-count { background: var(--primary-soft); color: var(--primary-text); }
.segmented.chips { background: transparent; padding: 0; gap: 6px; }
.chips .seg-btn { border: 1px solid var(--border-strong); background: #fff; border-radius: 999px; }
.chips .seg-btn[aria-pressed="true"] { background: var(--primary-soft); border-color: #C7D2FE; color: var(--primary-text); box-shadow: none; }

/* ---- Tables ----------------------------------------------------------------------------------- */

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 250px);
  min-height: 120px;
  -webkit-overflow-scrolling: touch;
}
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; }
.table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #F8FAFC;
  text-align: left;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td { padding: 10px 12px; border-bottom: 1px solid var(--row-line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:not(.skeleton-row):not(.detail-row):hover td { background: #FAFBFD; }
.table tr.is-selected td { background: var(--primary-soft) !important; }
.table th:first-child, .table td:first-child { padding-left: 16px; }
.table th:last-child, .table td:last-child { padding-right: 16px; }
.col-check { width: 40px; }
.col-actions { width: 1%; white-space: nowrap; text-align: right; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cell-person { display: flex; align-items: center; gap: 10px; min-width: 0; }
.cell-title { font-weight: 600; color: var(--text); overflow-wrap: anywhere; }
.cell-url { display: inline-block; min-width: 16ch; max-width: 32ch; font-family: var(--mono); font-size: 12.5px; color: var(--text-2); overflow-wrap: anywhere; }
.table .link-btn { white-space: nowrap; }
.cell-clip {
  color: var(--text-2);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  max-width: 48ch;
  min-width: 18ch;
}
.cell-summary { min-width: 20ch; max-width: 60ch; overflow-wrap: anywhere; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; align-items: center; }
.row-actions .btn-sm { padding: 0 10px; }
.table-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; min-height: 32px; }
.load-more { display: flex; justify-content: center; }
.detail-row td { background: #F8FAFC; }
.json {
  margin: 0;
  background: var(--ink);
  color: #E2E8F0;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  overflow: auto;
  max-height: 320px;
  white-space: pre;
}
.chev { transition: transform 0.15s; }
[aria-expanded="true"] > .chev { transform: rotate(90deg); }
code.shortcut {
  background: var(--primary-soft);
  color: #3730A3;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 13px;
  white-space: nowrap;
}
.mod-chips { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; min-width: 120px; }
.mod-chip { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 8px; background: var(--primary-soft); color: var(--primary-text); }
.mod-count { margin-left: 4px; white-space: nowrap; }
.removal { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; color: var(--text-2); min-width: 15ch; }
.unassigned { font-style: italic; }
.col-item { min-width: 22ch; }

.bulk-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 8px 8px 8px 16px;
  background: var(--ink);
  color: #fff;
  border-radius: 10px;
}
.bulk-bar[hidden] { display: none; }
.bulk-count { font-weight: 700; margin-right: auto; }
.bulk-bar .btn-ghost { color: #E2E8F0; }
.bulk-bar .btn-ghost:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 0;
  background: none;
  cursor: pointer;
  padding: 4px;
  border-radius: 999px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}
.switch:disabled { cursor: not-allowed; opacity: 0.55; }
.switch-track { position: relative; width: 36px; height: 20px; border-radius: 999px; background: #CBD5E1; transition: background-color 0.15s; flex: none; }
.switch-thumb { position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); transition: transform 0.15s; }
.switch[aria-checked="true"] .switch-track { background: var(--teal-strong); }
.switch[aria-checked="true"] .switch-thumb { transform: translateX(16px); }
.switch[aria-checked="true"] .switch-text { color: var(--teal-strong); }

/* ---- Tabs -------------------------------------------------------------------------- */

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: thin; }
.tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--primary-text); border-bottom-color: var(--primary); }
.tab-count { background: #EEF2F6; border-radius: 999px; padding: 0 7px; font-size: 12px; color: var(--text-2); line-height: 18px; }
.tab-panel { outline: none; }
.tab-panel-head { padding: 12px 16px; border-bottom: 1px solid var(--row-line); }

/* ---- Modals ------------------------------------------------------------------------------- */

dialog.modal {
  padding: 0;
  border: 0;
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  width: min(560px, calc(100vw - 32px));
  max-width: none;
  max-height: calc(100dvh - 48px);
  background: #fff;
  color: var(--text);
  overflow: hidden;
}
dialog.modal::backdrop { background: rgba(15, 27, 61, 0.55); }
dialog.modal[open] { animation: modal-in 0.16s ease-out; }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }
.modal-sm { width: min(440px, calc(100vw - 32px)) !important; }
.modal-lg { width: min(760px, calc(100vw - 32px)) !important; }
.modal-xl { width: min(1100px, calc(100vw - 32px)) !important; }
.modal-card { display: flex; flex-direction: column; max-height: calc(100dvh - 48px); }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 20px 20px 4px 24px; }
.modal-titles { min-width: 0; }
.modal-title { font-size: 18px; font-weight: 700; margin: 0; overflow-wrap: anywhere; letter-spacing: -0.01em; }
.modal-desc { margin-top: 4px; color: var(--muted); font-size: 13.5px; overflow-wrap: anywhere; }
.modal-close { margin: -6px -8px 0 0; }
.modal-body { padding: 16px 24px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; min-height: 0; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 24px;
  border-top: 1px solid var(--border);
  background: #F8FAFC;
}
.modal-footer:empty { display: none; }
.footer-note { margin-right: auto; }
.details-list { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 8px 16px; margin: 0; }
.details-list dt { color: var(--muted); font-size: 13px; }
.details-list dd { margin: 0; overflow-wrap: anywhere; }

.policy-box { background: #F8FAFC; border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.policy-title { font-weight: 700; font-size: 13px; margin-bottom: 8px; color: var(--text-2); }
.policy-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 13.5px; color: var(--text-2); }
.policy-list li { display: flex; gap: 8px; align-items: flex-start; }
.policy-list svg { color: var(--muted); margin-top: 2px; }
.retention-line { display: flex; gap: 8px; align-items: flex-start; color: var(--muted); font-size: 13px; }
.retention-line svg { margin-top: 2px; }
.title-list { margin: 0; padding-left: 20px; max-height: 190px; overflow: auto; font-size: 14px; overflow-wrap: anywhere; }
.title-list li + li { margin-top: 2px; }

/* ---- Toasts ------------------------------------------------------------------------------ */

.toasts {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}
/* Popover reset: the UA stylesheet would otherwise stretch the region over the whole viewport. */
.toasts[popover] {
  inset: auto 16px 16px auto;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  overflow: visible;
  height: auto;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--ink);
  color: #fff;
  padding: 12px 10px 12px 14px;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  animation: toast-in 0.2s ease-out;
}
.toast > svg { margin-top: 1px; }
.toast-success > svg { color: #5EEAD4; }
.toast-error > svg { color: #FCD34D; }
.toast-info > svg { color: #A5B4FC; }
.toast-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.toast-close { border: 0; background: none; color: #CBD5E1; cursor: pointer; padding: 2px; border-radius: 4px; display: inline-flex; }
.toast-close:hover { color: #fff; }
.toast-close:focus-visible { outline-color: #A5B4FC; }
.toast.leaving { opacity: 0; transform: translateY(6px); transition: opacity 0.2s, transform 0.2s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---- Dashboard ---------------------------------------------------------------------------- */

.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(210px, 100%), 1fr)); gap: 12px; }
.stat-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "label icon" "value value" "note note";
  gap: 2px 8px;
  padding: 16px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
  min-height: 112px;
}
a.stat-card:hover { border-color: #C7D2FE; box-shadow: var(--shadow); color: inherit; }
.stat-card.is-loading { display: block; }
.stat-label { grid-area: label; font-size: 13px; font-weight: 650; color: var(--text-2); align-self: center; }
.stat-icon { grid-area: icon; width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary-text); }
.stat-value { grid-area: value; font-size: 30px; font-weight: 750; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.2; margin-top: 6px; }
.stat-note { grid-area: note; font-size: 12.5px; color: var(--muted); }
.stat-teal .stat-icon { background: var(--teal-soft); color: var(--teal-strong); }
.stat-teal .stat-value { color: var(--teal-strong); }
.stat-amber { border-color: var(--amber-border); background: #FFFBEB; }
.stat-amber .stat-icon { background: var(--amber-bg); color: var(--amber-text); }

.activity-list { list-style: none; margin: 0; padding: 0; }
.activity-list > li:not(.activity) { padding: 8px 20px; }
.activity { display: flex; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--row-line); align-items: flex-start; }
.activity:last-child { border-bottom: 0; }
.activity-body { min-width: 0; }
.activity-text { overflow-wrap: anywhere; }
.activity-meta { margin-top: 2px; color: var(--muted); font-size: 12.5px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-family: var(--font); }

/* ---- Companies ----------------------------------------------------------------------------- */

.company-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(340px, 100%), 1fr)); gap: 16px; }
.company-card { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.company-head { display: flex; gap: 12px; align-items: flex-start; }
.company-logo { width: 42px; height: 42px; border-radius: 10px; background: var(--ink); color: #fff; display: grid; place-items: center; font-weight: 750; flex: none; letter-spacing: 0.02em; }
.company-titles { flex: 1; min-width: 0; }
.company-name-h { font-size: 16px; margin: 0; overflow-wrap: anywhere; }
.company-name-h a { color: inherit; text-decoration: none; }
.company-name-h a:hover { color: var(--primary); text-decoration: underline; }
.company-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 0; padding: 12px 14px; background: #F8FAFC; border-radius: 10px; }
.company-stats dt { font-size: 12px; color: var(--muted); }
.company-stats dd { margin: 0; font-size: 19px; font-weight: 750; font-variant-numeric: tabular-nums; }
.company-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; }

.split { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 16px; align-items: start; }

/* ---- Conversations ------------------------------------------------------------------------- */

.page-conv { max-width: 1440px; }
.conv-layout {
  display: grid;
  grid-template-columns: clamp(260px, 32%, 360px) minmax(0, 1fr);
  gap: 16px;
  height: calc(100dvh - var(--topbar-h) - 48px - 76px);
  min-height: 480px;
}
.conv-list-pane, .conv-thread-pane { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.conv-filters { padding: 12px; display: flex; flex-direction: column; gap: 8px; border-bottom: 1px solid var(--border); }
.conv-filters .search { max-width: none; flex: none; }
.conv-filters .segmented { align-self: flex-start; }
.conv-list-status { padding: 6px 14px; border-bottom: 1px solid var(--row-line); }
.conv-list-scroll { overflow-y: auto; flex: 1; min-height: 0; }
.conv-list { list-style: none; margin: 0; padding: 0; }
.conv-skeleton { padding: 12px 14px; border-bottom: 1px solid var(--row-line); }
.conv-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border: 0;
  border-bottom: 1px solid var(--row-line);
  background: #fff;
  cursor: pointer;
  font: inherit;
  color: inherit;
}
.conv-item:hover { background: #FAFBFD; }
.conv-item.active { background: var(--primary-soft); box-shadow: inset 3px 0 0 var(--primary); }
.conv-item:focus-visible { outline-offset: -2px; }
.conv-item-top { display: flex; gap: 8px; align-items: baseline; justify-content: space-between; min-width: 0; }
.conv-subject { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.conv-item.is-closed .conv-subject { color: var(--text-2); font-weight: 550; }
.conv-time { font-size: 12px; color: var(--muted); white-space: nowrap; flex: none; }
.conv-item-meta { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; }
.conv-item-meta svg { color: var(--muted); }

.thread-header { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); min-height: 64px; }
.thread-back { display: none; }
.thread-titles { flex: 1 1 220px; min-width: 0; }
.thread-title { font-size: 16px; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; outline: none; }
.thread-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.thread-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.thread-context { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 16px; }
.thread-context:not(:empty) { padding: 8px 16px; border-bottom: 1px solid var(--row-line); background: #FCFCFE; }
.ctx-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-2); overflow-wrap: anywhere; }
.messages-scroll { flex: 1; overflow-y: auto; padding: 16px 20px; background: #F8FAFC; min-height: 0; outline: none; }
.messages-scroll:focus-visible { box-shadow: inset 0 0 0 2px var(--primary); }
.messages { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.msg { display: flex; gap: 8px; max-width: min(78%, 640px); align-items: flex-end; }
.msg-visitor { align-self: flex-start; }
.msg-agent { align-self: flex-end; }
.msg-col { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.msg-meta { display: flex; gap: 8px; align-items: baseline; font-size: 12px; color: var(--muted); }
.msg-sender { font-weight: 650; color: var(--text-2); }
.msg-agent .msg-meta { justify-content: flex-end; }
.msg-bubble {
  padding: 9px 13px;
  border-radius: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 14.5px;
  line-height: 1.45;
}
.msg-visitor .msg-bubble { background: #fff; border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg-agent .msg-bubble { background: #E0E7FF; color: #1E1B4B; border-bottom-right-radius: 4px; }
.msg-self .msg-bubble { background: var(--primary); color: #fff; }
.msg-system { align-self: center; max-width: 90%; color: var(--muted); font-size: 13px; flex-direction: column; align-items: center; gap: 0; text-align: center; }
.msg-day { align-self: stretch; display: flex; align-items: center; gap: 12px; font-size: 12px; color: var(--muted); font-weight: 600; }
.msg-day::before, .msg-day::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.msg-empty { align-self: stretch; }

.composer-slot { border-top: 1px solid var(--border); background: #fff; }
.composer { position: relative; padding: 12px 16px 10px; }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { resize: none; min-height: 44px; max-height: 180px; }
.composer-send { height: 44px; }
.composer-hint { font-size: 12px; color: var(--muted); margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.composer-error { font-size: 13px; color: var(--amber-text); font-weight: 600; margin-top: 6px; }
.composer-error:empty { display: none; }
.composer-locked { display: flex; gap: 8px; align-items: center; padding: 14px 16px; color: var(--muted); font-size: 13.5px; }
.canned-list {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: calc(100% - 6px);
  max-height: 280px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  list-style: none;
  margin: 0;
  padding: 4px;
  z-index: 5;
}
.canned-option { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px 10px; padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer; align-items: baseline; }
.canned-option.active, .canned-option:hover { background: var(--primary-soft); }
.canned-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.canned-body { grid-column: 1 / -1; color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }

/* ---- Requests ----------------------------------------------------------------------------- */

.request-list { display: flex; flex-direction: column; gap: 12px; }
.request-card { padding: 16px 20px; display: flex; flex-direction: column; gap: 12px; }
.request-head { display: flex; gap: 12px; align-items: flex-start; }
.request-titles { flex: 1; min-width: 0; }
.request-title { margin: 0; font-size: 15px; font-weight: 650; overflow-wrap: anywhere; }
.reason {
  margin: 0;
  border-left: 3px solid var(--border-strong);
  padding: 6px 12px;
  background: #F8FAFC;
  border-radius: 0 8px 8px 0;
  color: var(--text-2);
  overflow-wrap: anywhere;
}
.reason-label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 700; margin-bottom: 2px; }
.request-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.decision-line { display: flex; align-items: center; gap: 6px; color: var(--text-2); font-size: 13.5px; flex-wrap: wrap; }
.decision-note { color: var(--muted); font-style: italic; }

/* ---- Setup -------------------------------------------------------------------------------- */

.setup-nav { display: flex; flex-wrap: wrap; gap: 8px; }
.setup-section { scroll-margin-top: calc(var(--topbar-h) + 16px); }
.setup-head { padding: 20px 20px 0; display: flex; flex-direction: column; gap: 4px; }
.setup-head .card-title { outline: none; }
.setup-body { padding: 16px 20px 20px; display: flex; flex-direction: column; gap: 16px; }
.setup-foot { padding: 12px 20px; border-top: 1px solid var(--border); background: #F8FAFC; display: flex; justify-content: flex-end; border-radius: 0 0 var(--radius) var(--radius); }
.access-row { display: flex; gap: 16px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.access-state { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; max-width: 60ch; }
.widget-grid { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 20px; }
.widget-grid .embed { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 6px; }
.widget-side { display: flex; flex-direction: column; gap: 6px; }
.color-row { display: flex; gap: 8px; align-items: center; }
.color-row input[type="text"] { max-width: 140px; text-transform: uppercase; }
.color-picker { width: 46px; height: 38px; padding: 3px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: #fff; cursor: pointer; flex: none; }
.snippet { font-size: 12.5px; resize: none; }
.embed-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.widget-preview {
  position: relative;
  height: 240px;
  border-radius: var(--radius);
  border: 1px dashed var(--border-strong);
  background: repeating-linear-gradient(0deg, transparent 0 23px, #EEF2F6 23px 24px), #FAFBFD;
  overflow: hidden;
}
.wp-panel { position: absolute; right: 14px; bottom: 74px; width: 210px; background: #fff; border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; border: 1px solid var(--border); }
.wp-head { padding: 10px 12px; font-weight: 700; font-size: 13px; }
.wp-greeting { padding: 10px 12px; font-size: 12.5px; color: var(--text-2); overflow-wrap: anywhere; }
.wp-bubble { position: absolute; right: 14px; bottom: 14px; width: 50px; height: 50px; border-radius: 50%; display: grid; place-items: center; box-shadow: var(--shadow); }
.danger-zone { border-color: #FECACA; }
.btn-outline-danger { border-color: #FECACA; background: #fff; }
.danger-zone .card-title { color: var(--danger-hover); }
.danger-row { display: flex; gap: 16px; align-items: center; justify-content: space-between; flex-wrap: wrap; }

/* ---- Permissions editor ------------------------------------------------------------------- */

.perm-legend { font-size: 13.5px; }
.perm-legend summary { cursor: pointer; font-weight: 600; color: var(--primary-text); }
.perm-legend dl { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 16px; margin: 10px 0 0; }
.perm-legend dt { font-weight: 650; }
.perm-legend dd { margin: 0; color: var(--text-2); }
.perm-wrap { max-height: none; border: 1px solid var(--border); border-radius: 10px; }
.perm-table { width: 100%; border-collapse: separate; border-spacing: 0; min-width: 780px; font-size: 14px; }
.perm-table th, .perm-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.perm-table thead th { position: sticky; top: 0; background: #F8FAFC; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); text-align: left; z-index: 1; }
.perm-table thead th.perm-col { text-align: center; }
.perm-table tbody th { text-align: left; font-weight: 400; vertical-align: top; }
.perm-col { text-align: center; width: 92px; }
.perm-col input { margin: 0 auto; }
.perm-mod { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.perm-desc { display: block; color: var(--muted); font-size: 12.5px; margin-top: 2px; max-width: 34ch; }
.perm-row:not(.is-on) .perm-mod { color: var(--muted); }
.policy-row td { background: #F8FAFC; padding: 14px 16px 18px; }
.policy-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px 20px; }
.policy-item { display: flex; flex-direction: column; gap: 4px; border: 0; margin: 0; padding: 0; min-width: 0; }
.policy-item legend { padding: 0; margin-bottom: 4px; }
.policy-scope .radio-row { font-weight: 500; }
.policy-help { font-size: 12.5px; color: var(--muted); }

/* ---- Responsive ----------------------------------------------------------------------------- */

@media (max-width: 1100px) {
  .widget-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 960px) {
  .split { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 899.98px) {
  .conv-layout { grid-template-columns: minmax(0, 1fr); height: calc(100dvh - var(--topbar-h) - 32px - 70px); min-height: 420px; }
  .conv-layout .conv-thread-pane { display: none; }
  .conv-layout.has-selection .conv-list-pane { display: none; }
  .conv-layout.has-selection .conv-thread-pane { display: flex; }
  .thread-back { display: inline-flex; }
  .page-conv:has(.has-selection) > .page-header { display: none; }
  .conv-layout.has-selection { height: calc(100dvh - var(--topbar-h) - 32px); }
  .msg { max-width: 88%; }
}

@media (max-width: 799.98px) {
  .shell, .shell.is-collapsed { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(300px, 86vw);
    height: 100dvh;
    z-index: 80;
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 0.22s ease, visibility 0s linear 0.22s;
    box-shadow: var(--shadow-lg);
  }
  .drawer-open .sidebar { transform: none; visibility: visible; transition: transform 0.22s ease; }
  .drawer-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 70;
    background: rgba(15, 27, 61, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
  }
  .drawer-open .drawer-backdrop { opacity: 1; pointer-events: auto; }
  .drawer-close { display: inline-flex; }
  .sidebar-foot { display: none; }
  .menu-btn { display: inline-flex; margin-left: -6px; }
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar-mark { display: block; width: 26px; height: 26px; }
  .topbar-links { display: none; }
  .user-name, .user-btn > svg { display: none; }
  .user-btn { padding: 3px; }
  .company-switch { max-width: 100%; font-size: 14px; padding-left: 12px; }
  .switch-icon { display: none; }
  .topbar-title { flex: 1; }
  .topbar-title .pill { display: none; }
  .switch-wrap { flex: 1; }
  .topbar-spacer { display: none; }
  .mobile-only { display: flex; }
  .view { padding: 16px; }
  .page-title { font-size: 20px; }
  .table-wrap { max-height: 70vh; }
  .table { min-width: 640px; }
  .company-actions .btn { flex: 1 1 auto; }
}

@media (max-width: 600px) {
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  dialog.modal, .modal-sm, .modal-lg, .modal-xl {
    width: 100vw !important;
    max-width: 100vw;
    max-height: 92dvh;
    margin: auto 0 0 0;
    border-radius: 16px 16px 0 0;
  }
  .modal-card { max-height: 92dvh; }
  .modal-header { padding: 16px 16px 4px; }
  .modal-body { padding: 12px 16px 16px; }
  .modal-footer { padding: 12px 16px; }
  .modal-footer .btn { flex: 1 1 auto; }
  .footer-note { flex-basis: 100%; }
  .details-list { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .details-list dd { margin-bottom: 8px; }
  .login-card { padding: 28px 20px 24px; }
  .search { max-width: none; flex-basis: 100%; }
  .stat-value { font-size: 24px; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat-card { min-height: 0; padding: 12px; }
  .stat-icon { width: 28px; height: 28px; }
  .thread-actions .btn .btn-label { display: none; }
  .request-card { padding: 14px 16px; }
  .perm-legend dl { grid-template-columns: minmax(0, 1fr); }
  .perm-legend dd { margin-bottom: 6px; }
  .composer-send .send-label { display: none; }
  .composer-send { width: 44px; padding: 0; }
  .toasts { left: 16px; right: 16px; bottom: 16px; width: auto; }
}

/* Stacked rows on phones for tables whose row actions matter most. */
@media (max-width: 600px) {
  .table.table-stack { min-width: 0; }
  .table-stack thead { display: none; }
  .table-stack tbody tr { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--row-line); }
  .table-stack tbody tr:last-child { border-bottom: 0; }
  .table-stack tbody td { display: block; padding: 0 !important; border: 0 !important; white-space: normal; }
  .table-stack td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 2px;
  }
  .table-stack .col-actions { text-align: left; width: auto; }
  .table-stack .row-actions { justify-content: flex-start; flex-wrap: wrap; }
  .table-stack .mod-chips { min-width: 0; max-width: none; }
  .table-stack .col-item, .table-stack .cell-summary { min-width: 0; }
}

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