:root {
  --bg: #f7fbff;
  --bg-deep: #edf5ff;
  --surface: rgba(255, 255, 255, 0.88);
  --surface-solid: #ffffff;
  --surface-soft: #f2f8ff;
  --text: #0f1f33;
  --muted: #5f7691;
  --line: #d9e8f7;
  --line-strong: #c2d9f2;
  --primary: #3ba4f7;
  --primary-strong: #2495ee;
  --primary-active: #1687e1;
  --primary-soft: #ddf1ff;
  --primary-glow: rgba(121, 195, 255, 0.28);
  --accent: #79c3ff;
  --success: #21b26f;
  --warning: #f5a524;
  --danger: #f05d6c;
  --info: #5bb8ff;
  --shadow-sm: 0 4px 12px rgba(27, 80, 128, 0.06);
  --shadow-md: 0 12px 30px rgba(27, 80, 128, 0.1);
  --shadow-lg: 0 24px 60px rgba(27, 80, 128, 0.14);
  --radius-lg: 20px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --radius-pill: 999px;
  --font-display: Manrope, Inter, ui-sans-serif, system-ui, sans-serif;
  --font-body: Inter, ui-sans-serif, system-ui, sans-serif;
}

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

body {
  margin: 0;
  position: relative;
  overflow-x: hidden;
  font-family: var(--font-body);
  color: var(--text);
  line-height: 1.45;
  background:
    radial-gradient(980px 520px at 4% -8%, rgba(191, 230, 255, 0.32), transparent 58%),
    radial-gradient(900px 460px at 96% -4%, rgba(191, 230, 255, 0.26), transparent 60%),
    linear-gradient(180deg, #ffffff 0%, #f6fbff 45%, var(--bg) 100%);
}

body.app-booting,
body.app-boot-hidden {
  visibility: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(121, 195, 255, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(121, 195, 255, 0.06) 1px, transparent 1px);
  background-size: 30px 30px;
  mask-image: radial-gradient(circle at 50% 30%, black 0%, transparent 82%);
  opacity: 0.18;
  z-index: -2;
}

body::after {
  content: "";
  position: fixed;
  inset: -240px -180px auto auto;
  width: 720px;
  height: 720px;
  border-radius: 50%;
  background: radial-gradient(circle at center, rgba(191, 230, 255, 0.42), transparent 66%);
  filter: blur(10px);
  pointer-events: none;
  z-index: -1;
}

a {
  color: var(--primary-strong);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.hero {
  position: relative;
  padding: 84px 24px 78px;
  color: var(--text);
  border-bottom: 1px solid var(--line);
  background: linear-gradient(135deg, #ffffff 0%, #f3f9ff 45%, #e7f4ff 100%);
  box-shadow: inset 0 -1px 0 rgba(121, 195, 255, 0.22), 0 16px 34px rgba(27, 80, 128, 0.08);
}

.hero::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(121, 195, 255, 0.8), transparent);
}

.container {
  max-width: 1080px;
  margin: 0 auto;
}

.container-page {
  padding-top: 30px;
}

.hero h1 {
  font-family: var(--font-display);
  font-size: clamp(36px, 5vw, 56px);
  margin: 0 0 14px;
  letter-spacing: -0.02em;
  text-shadow: none;
}

.lead {
  max-width: 790px;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.6;
}

.actions {
  margin-top: 28px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.btn {
  position: relative;
  isolation: isolate;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 43px;
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  text-decoration: none;
  font-weight: 600;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background-color 0.18s ease, color 0.18s ease;
}

.btn:hover {
  transform: translateY(-2px);
  text-decoration: none;
}

.btn-primary {
  color: #ffffff;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-strong) 100%);
  box-shadow: 0 10px 24px rgba(59, 164, 247, 0.22);
}

.btn-primary:hover {
  box-shadow: 0 14px 28px rgba(59, 164, 247, 0.3);
}

.btn-secondary {
  color: var(--text);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
}

.btn-secondary:hover {
  background: var(--surface-soft);
}

.section {
  padding: 46px 24px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
}

.card {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-lg);
  padding: 20px;
  border: 1px solid var(--line);
  background: linear-gradient(150deg, rgba(255, 255, 255, 0.86), rgba(244, 249, 255, 0.74));
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow-sm);
}

.card::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(147, 197, 253, 0.95), transparent);
}

.small {
  color: var(--muted);
  font-size: 12px;
}

body.landing-page {
  min-height: 100vh;
  overflow: hidden;
}

.landing-shell {
  min-height: 100vh;
  padding: 24px;
  display: grid;
  align-items: center;
}

.landing-grid {
  width: min(1200px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(420px, 1.1fr) minmax(330px, 0.9fr);
  gap: 22px;
  align-items: stretch;
}

.landing-copy {
  border-radius: 24px;
  border: 1px solid rgba(147, 197, 253, 0.38);
  background:
    radial-gradient(560px 220px at 12% -8%, rgba(56, 189, 248, 0.22), transparent 55%),
    linear-gradient(150deg, rgba(7, 18, 45, 0.9), rgba(24, 69, 167, 0.84));
  box-shadow: 0 30px 56px rgba(8, 18, 46, 0.4), inset 0 1px 0 rgba(219, 234, 254, 0.2);
  padding: clamp(24px, 3vw, 38px);
  color: #dbeafe;
  display: grid;
  align-content: center;
  gap: 16px;
}

.landing-kicker {
  margin: 0;
  display: inline-flex;
  width: fit-content;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  font-weight: 700;
  color: #bfdbfe;
}

.landing-kicker::before {
  content: "";
  width: 34px;
  height: 1px;
  background: linear-gradient(90deg, rgba(125, 211, 252, 0.1), rgba(125, 211, 252, 1));
}

.landing-copy h1 {
  margin: 0;
  font-size: clamp(33px, 4vw, 54px);
  line-height: 1.07;
  letter-spacing: -0.03em;
  text-wrap: balance;
}

.landing-lead {
  margin: 0;
  max-width: 56ch;
  color: #d7e8ff;
  font-size: 16px;
}

.landing-points {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.landing-point {
  border-radius: 999px;
  border: 1px solid rgba(147, 197, 253, 0.48);
  padding: 6px 11px;
  font-size: 12px;
  font-weight: 600;
  background: rgba(15, 44, 110, 0.5);
  color: #dbeafe;
}

.landing-auth-stack {
  display: grid;
  gap: 12px;
  align-content: center;
}

.landing-auth-card {
  border-radius: 18px;
  border: 1px solid rgba(147, 197, 253, 0.42);
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.9), rgba(237, 246, 255, 0.82));
  box-shadow: 0 16px 34px rgba(18, 43, 96, 0.16);
  padding: 16px;
  display: grid;
  gap: 8px;
}

.landing-auth-card h2 {
  margin: 0;
  color: #163a74;
  letter-spacing: -0.01em;
}

.landing-auth-card p {
  margin: 0;
  color: #496288;
  font-size: 14px;
}

.landing-auth-card .btn {
  width: 100%;
  margin-top: 4px;
}

.landing-note {
  border-radius: 14px;
  border: 1px dashed rgba(147, 197, 253, 0.6);
  background: rgba(239, 246, 255, 0.75);
  color: #173f7d;
  font-size: 13px;
  font-weight: 600;
  padding: 11px 12px;
}

.auth-box {
  max-width: 470px;
  margin: 78px auto;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: linear-gradient(155deg, rgba(255, 255, 255, 0.85), rgba(244, 249, 255, 0.8));
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow-md);
  padding: 26px;
}

.auth-box h2 {
  margin: 0 0 14px;
  letter-spacing: -0.01em;
}

.auth-box form {
  display: grid;
  gap: 10px;
}

.auth-box label {
  display: block;
  font-size: 13px;
  color: #334155;
}

.auth-box input {
  width: 100%;
}

.auth-box button {
  width: 100%;
  margin-top: 5px;
}

.auth-box p {
  margin: 17px 0 0;
}

.error {
  color: #dc2626;
  margin: 0 0 10px;
}

/* ── Layout ── */
.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: visible;
  border-right: 1px solid #e2e8f0;
  background: #ffffff;
  padding: 0;
  display: flex;
  flex-direction: column;
  z-index: 100;
}

.sidebar-main {
  flex: 1;
  padding: 24px 12px 16px;
}

.sidebar-bottom {
  padding: 12px 12px 20px;
  border-top: 1px solid #f1f5f9;
}

/* Brand */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
  padding: 0 4px;
}

.sidebar-brand-icon {
  font-size: 20px;
  color: #2563eb;
  line-height: 1;
}

.sidebar-brand-name {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: #0f172a;
}

/* User info */
.sidebar-user {
  padding: 10px 12px;
  background: #f8fafc;
  border-radius: 8px;
  margin-bottom: 24px;
}

.sidebar-user-email {
  font-size: 12px;
  color: #475569;
  font-weight: 500;
  word-break: break-all;
  line-height: 1.4;
}

.sidebar-user-role {
  font-size: 11px;
  color: #94a3b8;
  margin-top: 2px;
  text-transform: capitalize;
}

/* Nav */
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-section-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #94a3b8;
  padding: 16px 12px 6px;
  margin: 0;
}

.nav-section-label:first-child {
  padding-top: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 14px;
  color: #475569;
  text-decoration: none;
  font-weight: 400;
  transition: background 0.12s, color 0.12s;
  cursor: pointer;
  line-height: 1.3;
}

.nav-item:hover {
  background: #f1f5f9;
  color: #1e293b;
  text-decoration: none;
}

.nav-item.active {
  background: #eff6ff;
  color: #1d4ed8;
  font-weight: 600;
}

.nav-item-icon {
  font-size: 15px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
  color: inherit;
  opacity: 0.7;
}

.nav-item.active .nav-item-icon {
  opacity: 1;
}

.nav-item-bottom {
  color: #64748b;
}

/* Keep old classes for backward-compat with admin links injected by server */
.navbtn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 14px;
  color: #475569;
  text-decoration: none;
  font-weight: 400;
  transition: background 0.12s, color 0.12s;
  border: none;
  background: none;
}

.navbtn:hover {
  background: #f1f5f9;
  color: #1e293b;
  text-decoration: none;
}

.navbtn.active {
  background: #eff6ff;
  color: #1d4ed8;
  font-weight: 600;
}

/* Legacy: keep nav-group for mobile toggle compatibility */
.nav-group { position: relative; }
.nav-group-header { display: none; }
.nav-group-items { display: flex; flex-direction: column; gap: 2px; }
.nav-group-toggle { display: none; }
.nav-sub { font-size: 14px; }
.nav-empty { color: #9ca3af !important; cursor: default; pointer-events: none; }
.nav-admin { display: flex; }

/* Meta (legacy compat) */
.meta {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 18px;
  line-height: 1.5;
}

/* Brand (legacy compat) */
.brand { display: none; }

.mobile-topbar {
  display: none;
}

.mobile-nav-backdrop {
  display: none;
}

.settings-mobile-tab-switch {
  display: none;
}

.main {
  padding: 22px;
  min-height: 100vh;
}

.main > section {
  display: grid;
  gap: 8px;
}

/* Desktop: chats section fills viewport height, no overflow */
/* Desktop chats layout — only when visible (:not(.hidden) prevents
   display:flex from overriding the .hidden { display:none } rule) */
#section-chats:not(.hidden) {
  height: calc(100vh - 66px);
  max-height: calc(100vh - 66px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#section-chats:not(.hidden) .chats-topbar {
  flex-shrink: 0;
}

#section-chats:not(.hidden) .chats-shell {
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
  border-radius: 8px;
}

/* List panel: fill available height, list scrolls */
#section-chats:not(.hidden) .chats-list-panel {
  height: 100%;
  overflow: hidden;
}

#section-chats:not(.hidden) .chats-list {
  flex: 1 1 0;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
}

/* Thread panel: fill height, messages scroll */
#section-chats:not(.hidden) .chats-thread-panel {
  height: 100%;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0,1fr) auto;
}

#section-chats:not(.hidden) .chat-messages {
  overflow-y: auto;
  min-height: 0;
  padding: 16px;
}

.main > section.hidden {
  display: none;
}

.section-title {
  margin: 0;
}

.panel {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.86), rgba(243, 248, 255, 0.8));
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow-sm);
  padding: 18px;
}

.panel::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(147, 197, 253, 0.9), transparent);
}

.panel h2,
.panel h3,
.panel h4,
.main > section > h3 {
  margin: 0 0 12px;
  letter-spacing: -0.01em;
  font-size: 24px;
  line-height: 1.25;
  font-weight: 700;
  color: #0f172a;
}

.row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.row + .row {
  margin-top: 12px;
}

.row-between {
  justify-content: space-between;
}

#templateVariablesBlock .table-wrap {
  margin-top: 14px;
}

input,
select,
textarea,
button {
  border-radius: var(--radius-sm);
  border: 1px solid rgba(148, 182, 238, 0.6);
  padding: 10px 12px;
  font-size: 14px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease, background-color 0.15s ease;
}

input,
select,
button {
  min-height: 40px;
}

input.small-check {
  min-height: 0;
  width: 16px;
  height: 16px;
  padding: 0;
  margin-right: 6px;
  accent-color: var(--primary);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: rgba(37, 99, 235, 0.74);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.22), 0 0 0 1px rgba(37, 99, 235, 0.2) inset;
}

textarea {
  min-height: 96px;
  min-width: 320px;
  resize: vertical;
}

.textarea-compact {
  min-height: 62px;
  min-width: 360px;
}

button {
  color: #dbeafe;
  border-color: rgba(37, 99, 235, 0.9);
  background: linear-gradient(150deg, #2563eb 0%, #1d4ed8 58%, #1e40af 100%);
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  font-weight: 600;
  cursor: pointer;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 11px 20px rgba(37, 99, 235, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.22);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

button.secondary {
  color: #1e40af;
  border-color: rgba(147, 197, 253, 0.7);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.88), rgba(239, 246, 255, 0.92));
  box-shadow: none;
}

button.secondary:hover {
  border-color: rgba(59, 130, 246, 0.72);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.96), rgba(230, 241, 255, 0.95));
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  text-align: left;
  border-bottom: 1px solid rgba(147, 175, 224, 0.25);
  padding: 10px 8px;
  vertical-align: middle;
}

th {
  color: #4a607f;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: rgba(239, 246, 255, 0.5);
}

tbody tr:hover {
  background: rgba(239, 246, 255, 0.62);
}

tr.review-row-send-error td {
  background: rgba(254, 242, 242, 0.62);
}

tr.review-row-send-error:hover td {
  background: rgba(254, 226, 226, 0.72);
}

tr.review-row-contradiction td {
  background: rgba(254, 249, 195, 0.20);
}

tr.review-row-contradiction:hover td {
  background: rgba(254, 249, 195, 0.30);
}

.review-contradiction-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #dc2626;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  margin-left: 6px;
  vertical-align: middle;
  cursor: help;
  flex-shrink: 0;
  position: relative;
}

.review-contradiction-badge[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  transform: none;
  background: #1e293b;
  color: #fff;
  font-size: 12px;
  font-weight: 400;
  padding: 5px 10px;
  border-radius: 6px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 100;
  max-width: 280px;
  white-space: normal;
  text-align: left;
  width: max-content;
}

.review-contradiction-badge[data-tip]:hover::after {
  opacity: 1;
}

.pill {
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
  display: inline-block;
  font-weight: 600;
}

.high {
  background: #fee2e2;
  color: #991b1b;
}

.medium {
  background: #fef3c7;
  color: #92400e;
}

.low {
  background: #dcfce7;
  color: #166534;
}

.hidden {
  display: none;
}

.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(147, 197, 253, 0.6);
}

.status-active {
  color: #166534;
  border-color: rgba(34, 197, 94, 0.45);
  background: rgba(220, 252, 231, 0.8);
}

.status-blocked {
  color: #991b1b;
  border-color: rgba(248, 113, 113, 0.5);
  background: rgba(254, 226, 226, 0.85);
}

.user-row-blocked {
  color: #991b1b;
}

button.secondary.danger {
  color: #991b1b;
  border-color: rgba(248, 113, 113, 0.65);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.92), rgba(254, 242, 242, 0.92));
}

button.secondary.danger:hover {
  border-color: rgba(239, 68, 68, 0.8);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.96), rgba(254, 226, 226, 0.96));
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
}

.stat {
  position: relative;
  border-radius: var(--radius-md);
  border: 1px solid rgba(147, 197, 253, 0.36);
  background: linear-gradient(155deg, rgba(255, 255, 255, 0.84), rgba(235, 245, 255, 0.76));
  padding: 14px;
}

.stat::before {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  top: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(147, 197, 253, 0.95), transparent);
}

.stat .value {
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 4px;
}

.settings-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.settings-tab-btn {
  color: #334155;
  border: 1px solid rgba(147, 197, 253, 0.42);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.88), rgba(242, 248, 255, 0.8));
}

.settings-tab-btn.active {
  color: var(--primary);
  border-color: rgba(59, 130, 246, 0.62);
  background: linear-gradient(150deg, rgba(239, 246, 255, 0.95), rgba(219, 234, 254, 0.86));
  font-weight: 700;
  box-shadow: 0 0 16px rgba(59, 130, 246, 0.2);
}

.source-form {
  margin-top: 12px;
  padding: 14px;
  border: 1px solid rgba(147, 197, 253, 0.4);
  border-radius: var(--radius-md);
  background: linear-gradient(160deg, rgba(248, 251, 255, 0.96), rgba(236, 245, 255, 0.84));
}

.tariff-form-panel {
  margin-top: 12px;
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(147, 197, 253, 0.42);
  background: linear-gradient(160deg, rgba(248, 251, 255, 0.95), rgba(236, 245, 255, 0.82));
}

#superAdminAiPanel .ai-settings-top-row {
  align-items: flex-start;
}

#superAdminAiPanel .ai-settings-top-row .ai-provider-col {
  flex: 1 1 260px;
  min-width: 240px;
}

#superAdminAiPanel .ai-settings-top-row .ai-provider-col select {
  width: 100%;
}

#superAdminAiPanel .ai-settings-top-row .ai-yandex-keys-col {
  flex: 2 1 520px;
  min-width: 320px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

#superAdminAiPanel .ai-settings-footer {
  justify-content: space-between;
  align-items: center;
}

#superAdminAiPanel .ai-settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

#superAdminAiPanel .ai-field-readonly {
  background: rgba(248, 250, 255, 0.92);
  color: #334155;
}

.ai-key-readonly {
  width: min(420px, 100%);
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(148, 182, 238, 0.6);
  background: rgba(245, 250, 255, 0.92);
  color: #1f2937;
}

.tariffs-list {
  margin-top: 12px;
  display: grid;
  gap: 10px;
}

.tariff-item {
  border: 1px solid rgba(147, 197, 253, 0.38);
  border-radius: 12px;
  padding: 12px;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.9), rgba(239, 246, 255, 0.82));
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.tariff-item-main {
  display: grid;
  gap: 4px;
}

.tariff-item-title {
  font-weight: 700;
  font-size: 15px;
}

.tariff-item-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.users-pagination-row {
  justify-content: space-between;
  align-items: center;
}

.sync-start-settings {
  margin-top: 12px;
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(147, 197, 253, 0.42);
  background: linear-gradient(160deg, rgba(248, 251, 255, 0.94), rgba(236, 245, 255, 0.8));
}

.sync-start-title {
  font-size: 15px;
  font-weight: 700;
}

.sync-start-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
}

.sync-start-toggle input[type="checkbox"] {
  min-height: 0;
}

.no-margin {
  margin: 0;
}

.mt-10 {
  margin-top: 10px;
}

.logout-link {
  margin: 0;
  display: inline-block;
}

.profile-password-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
}

.profile-password-toggle:hover {
  color: var(--primary-strong);
  text-decoration: none;
}

.reviews-buckets {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.reviews-top-controls {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.reviews-quick-controls {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.reviews-toolbar-panel {
  overflow: visible;
  z-index: 4;
}

.reviews-heading {
  margin: 0 0 12px;
}

.reviews-sync-row {
  margin: 0;
  min-height: 20px;
  align-items: center;
}

/* Chats top row: always horizontal, compact */
.chats-topbar {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 8px;
  min-height: 0;
  padding: 0 2px;
}

.sync-preview-modal-card {
  width: min(560px, 96vw);
}

.sync-preview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.sync-preview-table th,
.sync-preview-table td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid #e5e7eb;
}

.sync-preview-table th {
  font-weight: 600;
  color: #6b7280;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.sync-preview-table tr:last-child td {
  border-bottom: none;
}

.sync-preview-table .total-row td {
  font-weight: 600;
  border-top: 2px solid #e5e7eb;
  background: #f9fafb;
}

.sync-preview-count {
  font-weight: 600;
  color: #1d4ed8;
}

.sync-preview-count.zero {
  color: #9ca3af;
  font-weight: 400;
}

.sync-preview-loading {
  text-align: center;
  padding: 24px;
  color: #6b7280;
  font-size: 14px;
}

/* ── Reviews 3-column table ── */
.review-col-review { width: 38%; vertical-align: top; padding: 12px 10px; }
.review-col-reply  { width: 34%; vertical-align: top; padding: 12px 10px; }
.review-col-product{ width: 28%; vertical-align: top; padding: 12px 10px; }

.review-group-title {
  font-weight: 700;
  font-size: 13px;
  color: #1e40af;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.review-stars { margin-bottom: 6px; }

.review-text {
  font-size: 14px;
  margin-bottom: 6px;
  word-break: break-word;
}

.review-pros, .review-cons { margin-bottom: 4px; }

.review-subgroup-tag {
  display: inline-block;
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  margin-top: 4px;
}

.review-meta-small {
  font-size: 12px;
  color: #94a3b8;
  margin-top: 6px;
}

.review-reply-textarea {
  width: 100%;
  min-height: 90px;
  resize: vertical;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 8px;
  font-size: 13px;
  font-family: inherit;
  box-sizing: border-box;
  background: #f9fafb;
  transition: border-color 0.15s;
}

.review-reply-textarea:not([readonly]) {
  background: #fff;
  border-color: #2563eb;
}

.review-reply-answered {
  background: #f1f5f9;
  color: #475569;
  border-color: #e2e8f0;
  cursor: default;
  resize: none;
}

.review-reply-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  align-items: center;
}

.review-icon-btn {
  background: none;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 16px;
  cursor: pointer;
  width: auto !important;
  min-width: 34px;
}

.review-icon-btn:hover { background: #f3f4f6; }
.review-retry-btn { border-color: #fbbf24; color: #92400e; }
.review-retry-btn:hover { background: #fffbeb; border-color: #f59e0b; }

.review-product-name {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 6px;
  word-break: break-word;
}
.review-product-link {
  color: #1d4ed8;
  text-decoration: none;
}
.review-product-link:hover {
  text-decoration: underline;
}

.review-product-detail {
  color: #64748b;
  margin-bottom: 3px;
}

/* ── Stock module ── */
/* ── Stock settings page layout ── */
.stock-settings-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.stock-settings-title {
  font-size: 20px;
  font-weight: 700;
  color: #0f172a;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}

.stock-settings-subtitle {
  font-size: 13px;
  color: #64748b;
  margin: 0;
}

.stock-settings-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  align-items: center;
}

.stock-settings-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  margin-bottom: 16px;
  overflow: hidden;
}

.stock-settings-card-header {
  padding: 16px 20px 12px;
  border-bottom: 1px solid #f1f5f9;
}

.stock-settings-card-title {
  font-size: 14px;
  font-weight: 600;
  color: #1e293b;
  margin: 0;
}

.stock-settings-card .table-wrap {
  padding: 0;
}

.stock-settings-card .table-wrap table {
  border-radius: 0;
}

.stock-settings-params {
  display: flex;
  gap: 32px;
  padding: 16px 20px;
  flex-wrap: wrap;
}

.stock-settings-param {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stock-settings-param-label {
  font-size: 12px;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stock-settings-card-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  border-top: 1px solid #f1f5f9;
  background: #f8fafc;
  flex-wrap: wrap;
}

/* Stock work header */
.stock-work-header {
  padding: 4px 0 12px;
}

#section-stock-work {
  flex-direction: column;
  gap: 0;
  width: 100%;
}

#section-stock-work:not(.hidden) {
  display: flex;
}

.stock-work-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 0;
  margin-bottom: 0;
}

/* Panel that directly follows tabs — flush top border to match tabs */
.stock-work-panel {
  margin-top: 0 !important;
  border-top-left-radius: 0;
  overflow: hidden;
  padding: 0 !important;
  width: 100%;
  box-sizing: border-box;
}

.stock-tab-group {
  display: flex;
  align-items: stretch;
  gap: 0;
}

.stock-source-tab {
  padding: 9px 18px;
  border-radius: 10px 0 0 0;
  border: 1px solid #e2e8f0;
  border-bottom: 1px solid #fff;
  border-right: none;
  background: #f8fafc;
  color: #374151;
  cursor: pointer;
  font-size: 14px;
  width: auto !important;
  position: relative;
  bottom: -1px;
}

.stock-source-tab.active {
  background: #fff;
  color: #2563eb;
  font-weight: 600;
  border-color: #93c5fd;
  border-bottom-color: #fff;
}

.stock-tab-gear {
  padding: 9px 10px;
  border-radius: 0 10px 0 0;
  border: 1px solid #e2e8f0;
  border-bottom: 1px solid #fff;
  border-left: 1px solid #e2e8f0;
  background: #f8fafc;
  color: #64748b;
  cursor: pointer;
  font-size: 14px;
  width: auto !important;
  position: relative;
  bottom: -1px;
}

.stock-tab-gear:hover { background: #f1f5f9; color: #374151; }

/* Table container with sticky first 2 columns */
.stock-table-outer {
  overflow-x: auto;
  overflow-y: auto;
  height: calc(100vh - 130px);
  width: 100%;
}

.stock-data-table {
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
  table-layout: fixed;
  min-width: 100%;
}

.stock-data-table th,
.stock-data-table td {
  padding: 7px 10px;
  border-bottom: 1px solid #f1f5f9;
  white-space: nowrap;
  text-align: left;
  border-right: 1px solid #f1f5f9;
}

.stock-data-table th {
  background: #f8fafc;
  font-weight: 600;
  color: #64748b;
  font-size: 12px;
  position: sticky;
  top: 0;
  z-index: 3;
}

/* Sticky first two columns */
.stock-fixed-col {
  position: sticky;
  z-index: 4;
  background: #f8fafc;
}
.stock-data-table td.stock-product-cell,
.stock-data-table td.stock-num:first-of-type {
  position: sticky;
  background: #fff;
  z-index: 2;
}
.stock-col-product { left: 0; }
.stock-col-wbid    { border-right: 2px solid #e2e8f0 !important; }
.stock-data-table td.stock-product-cell { left: 0; }
.stock-data-table tbody td:nth-child(2) { position: sticky; background: #fff; z-index: 2; border-right: 2px solid #e2e8f0 !important; }

.stock-date-col { text-align: center; }
.stock-num { text-align: center; font-variant-numeric: tabular-nums; }

/* Warehouse header rows */
.stock-warehouse-row td {
  background: #f1f5f9 !important;
  font-weight: 600;
  font-size: 13px;
  padding: 8px 10px;
  border-top: 2px solid #e2e8f0;
}

.stock-warehouse-cell {
  display: flex;
  align-items: center;
  gap: 6px;
}

.stock-collapse-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 10px;
  color: #64748b;
  width: auto !important;
  padding: 2px 4px;
}

.stock-warehouse-name { font-weight: 600; color: #1e3a5f; }

/* Product rows */
.stock-product-cell { color: #374151; }

/* Low stock highlight */
.stock-row-low { background: #fff5f5 !important; }
.stock-cell-low { color: #dc2626 !important; font-weight: 600; }

/* Column resize handle */
.stock-resize-handle {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 5px;
  cursor: col-resize;
  background: transparent;
}
.stock-resize-handle:hover { background: #93c5fd; }

/* Settings modal warehouse list */
.stock-settings-wh-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  border-bottom: 1px solid #f1f5f9;
}

.stock-eye-btn {
  background: none;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 3px 6px;
  cursor: pointer;
  font-size: 14px;
  width: auto !important;
}

.stock-eye-btn.hidden-wh { opacity: 0.35; }
.stock-wh-label { font-size: 13px; flex: 1; }

/* Sync report modal */
.sync-report-card {
  width: min(600px, 96vw);
  max-height: 80vh;
  overflow-y: auto;
}

.sync-report-body {
  display: grid;
  gap: 12px;
}

.sync-report-account {
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 12px 14px;
  background: #f9fafb;
}

.sync-report-account-name {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 8px;
}

.sync-report-channels {
  display: grid;
  gap: 4px;
}

.sync-report-channel {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.sync-report-channel-name {
  width: 80px;
  color: #6b7280;
}

.sync-report-channel-ok { color: #16a34a; }
.sync-report-channel-err { color: #dc2626; }
.sync-report-channel-skip { color: #6b7280; font-style: italic; }

.sync-report-log-details {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 8px 12px;
}

.sync-report-log {
  font-size: 12px;
  font-family: monospace;
  color: #374151;
  background: #f1f5f9;
  padding: 8px;
  border-radius: 6px;
  max-height: 200px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
  margin-top: 8px;
}

.sync-preview-check-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.sync-preview-check {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: #2563eb;
  flex-shrink: 0;
}

.sync-progress-global {
  /* Fixed to top of main content area, not breaking the sidebar grid */
  position: fixed;
  top: 0;
  left: 294px; /* sidebar width */
  right: 0;
  z-index: 200;
  background: rgba(255,255,255,0.97);
  border-bottom: 1px solid #e5e7eb;
  padding: 8px 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.sync-progress-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sync-progress-label {
  font-size: 13px;
  font-weight: 700;
  color: #2563eb;
  white-space: nowrap;
  flex-shrink: 0;
}

.sync-progress-accounts {
  font-size: 12px;
  color: #6b7280;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sync-progress-pct {
  font-size: 12px;
  font-weight: 700;
  color: #2563eb;
  white-space: nowrap;
  flex-shrink: 0;
  min-width: 36px;
  text-align: right;
}

.sync-progress-detail {
  font-size: 12px;
  color: #374151;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sync-progress-track {
  height: 8px;
  background: #e5e7eb;
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}

.sync-progress-fill {
  height: 100%;
  width: 5%;
  background: linear-gradient(90deg, #3b82f6, #6366f1);
  border-radius: 6px;
  transition: width 0.6s ease;
  animation: sync-pulse 1.8s ease-in-out infinite;
}

@keyframes sync-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.65; }
}

.reviews-date-wrap {
  position: relative;
  z-index: 40;
}

.reviews-filter-icon-btn {
  min-width: 42px;
  width: 42px;
  padding: 0;
  font-size: 16px;
}

.conversations-filters-panel,
.questions-filters-panel,
.chats-filters-panel {
  margin-top: 12px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.bucket-tab {
  min-height: 36px;
  padding: 6px 16px;
  border-radius: 6px;
  border: 1px solid #e2e8f0;
  background: #fff;
  color: #475569;
  font-weight: 500;
  font-size: 14px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.bucket-tab:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
  color: #1e293b;
}

.bucket-tab.active {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
  font-weight: 600;
  box-shadow: 0 1px 4px rgba(37, 99, 235, 0.20);
}

.reviews-pagination-row {
  justify-content: space-between;
  margin-top: 14px;
}

.reviews-filter-row {
  align-items: center;
}

.reviews-filters-panel {
  margin-top: 12px;
  border: 1px solid rgba(147, 197, 253, 0.42);
  border-radius: 14px;
  padding: 12px;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.92), rgba(238, 246, 255, 0.82));
}

.reviews-date-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: min(760px, calc(100vw - 64px));
  border: 1px solid rgba(147, 197, 253, 0.42);
  border-radius: 14px;
  padding: 12px;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.92), rgba(238, 246, 255, 0.82));
  display: grid;
  grid-template-columns: minmax(180px, 220px) minmax(260px, 1fr);
  gap: 12px;
  box-shadow: 0 12px 26px rgba(15, 23, 42, 0.18);
  z-index: 60;
}

.reviews-date-panel.hidden {
  display: none;
}

.reviews-date-presets {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.reviews-date-presets button {
  justify-content: flex-start;
  text-align: left;
}

.reviews-date-controls {
  display: grid;
  gap: 10px;
}

.reviews-date-controls label {
  display: grid;
  gap: 6px;
  color: #2d4f80;
  font-size: 13px;
  font-weight: 600;
}

.actions-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
}

.question-date {
  white-space: nowrap;
  font-size: 13px;
  color: #64748b;
  min-width: 100px;
}

.users-actions-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.users-search-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.users-search-inline input[type="search"] {
  min-width: 260px;
}

.users-search-inline.collapsed {
  display: none;
}

.users-search-inline.collapsed input[type="search"],
.users-search-inline.collapsed button.users-search-clear {
  display: none;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(13, 27, 60, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1200;
  padding: 20px;
}

.modal-overlay.hidden {
  display: none !important;
}

.modal-card {
  width: min(940px, 96vw);
  max-height: 90vh;
  overflow: auto;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid rgba(56, 189, 248, 0.35);
  box-shadow: 0 24px 54px rgba(15, 23, 42, 0.24);
  border-radius: 14px;
  padding: 18px;
}

.team-manage-modal-card {
  width: min(1100px, 98vw);
}

.ai-test-review-modal-card {
  width: min(860px, 96vw);
}

.default-template-bulk-modal-card {
  width: min(900px, 96vw);
}

.ai-test-review-modal-card textarea {
  width: 100%;
  min-height: 140px;
  min-width: 0;
}

.default-template-bulk-modal-card textarea {
  width: 100%;
  min-height: 180px;
  min-width: 0;
}

.ai-test-review-modal-card pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid rgba(147, 197, 253, 0.42);
  background: rgba(248, 251, 255, 0.9);
}

.team-create-panel {
  margin-top: 10px;
  padding: 12px;
  border: 1px solid rgba(147, 197, 253, 0.42);
  border-radius: var(--radius-md);
  background: linear-gradient(160deg, rgba(248, 251, 255, 0.94), rgba(236, 245, 255, 0.8));
}

.manager-panel-card {
  width: min(980px, 96vw);
}

.manager-create-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.admin-actions-filters {
  align-items: flex-end;
  gap: 8px;
}

.admin-actions-filters input[type="search"] {
  min-width: 280px;
  flex: 1 1 320px;
}

.admin-actions-filters label {
  display: grid;
  gap: 6px;
  color: #2d4f80;
  font-size: 13px;
  font-weight: 600;
}

.icon-btn {
  min-width: 38px;
  min-height: 38px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
}

.icon-btn.danger {
  color: #991b1b;
  border-color: rgba(252, 165, 165, 0.7);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.9), rgba(254, 242, 242, 0.95));
}

.icon-btn.danger:hover {
  border-color: rgba(239, 68, 68, 0.78);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.94), rgba(254, 226, 226, 0.96));
}

.rating-stars {
  color: #fbbf24;
  letter-spacing: 1px;
  font-size: 14px;
  text-shadow: 0 0 8px rgba(251, 191, 36, 0.28);
}

.send-error-indicator {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: flex-end;
  width: 24px;
  height: 24px;
  margin-top: 2px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
  color: #b91c1c;
  background: rgba(254, 226, 226, 0.9);
  border: 1px solid rgba(248, 113, 113, 0.55);
}


.chats-shell {
  display: grid;
  grid-template-columns: minmax(280px, 320px) minmax(0, 1fr);
  gap: 0;
  align-items: stretch;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.chats-list-panel {
  border-right: 1px solid #e2e8f0;
  background: #fff;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 0;
  height: 100%;
}

.chats-list-head {
  display: flex;
  flex-direction: column;
  gap: 0;
  flex-shrink: 0;
  padding: 12px 12px 0;
  border-bottom: 1px solid #f1f5f9;
}

.chats-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 0;
  width: 100%;
  max-width: 100%;
}

.chats-list > .small {
  padding: 8px 16px;
  color: #94a3b8;
}

.chats-subtitle {
  color: #374151;
  font-weight: 600;
}

.chat-thread-header {
  color: #0f172a;
  font-weight: 600;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 12px 16px;
  border-bottom: 1px solid #f1f5f9;
  background: #fff;
  flex-shrink: 0;
}

#chatThreadTitle {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

/* Back button: always auto-width */
.chat-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: #2563eb;
  font-size: 14px;
  font-weight: 600;
  padding: 0;
  width: auto !important;
  min-width: 0;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

.chat-messages {
  border: none;
  border-radius: 0;
  padding: 16px;
  overflow-y: auto;
  max-height: none;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f8fafc;
}

.chat-compose {
  display: grid;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid #e2e8f0;
  background: #fff;
}

.chat-compose-actions {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

#chatReplyInput {
  width: 100%;
  font-size: 14px;
  line-height: 1.5;
  padding: 8px 12px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  background: #f8fafc;
  color: #0f172a;
  resize: vertical;
  min-height: 64px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
  font-family: inherit;
}

#chatReplyInput:focus {
  border-color: #2563eb;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(37,99,235,0.10);
}

#chatReplyInput::placeholder {
  color: #94a3b8;
}

/* Emoji button: plain, no blue background */
.chat-emoji-btn {
  min-width: 36px;
  min-height: 36px;
  width: 36px !important;
  font-size: 18px;
  padding: 0;
  background: transparent !important;
  border: 1px solid #e2e8f0 !important;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.chat-emoji-btn:hover {
  background: #f1f5f9 !important;
  border-color: #cbd5e1 !important;
}

/* Emoji wrap: hover triggers picker */
.chat-emoji-wrap {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
}

.chat-emoji-picker {
  display: none;
  position: absolute;
  bottom: calc(100% + 2px);
  left: 0;
  z-index: 300;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 4px;
  padding: 8px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 4px 16px rgba(0,0,0,0.10);
  max-width: 300px;
  width: 300px;
}

/* Chat order badge */
.chat-order-badge {
  font-size: 12px;
  font-weight: 500;
  color: #2563eb;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 4px;
  padding: 1px 7px;
  cursor: help;
  white-space: nowrap;
  position: relative;
  display: inline-block;
}

.chat-order-tooltip {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  padding-top: 4px;
  width: max-content;
  max-width: 300px;
  z-index: 200;
  background: #1e293b;
  color: #fff;
  font-size: 12px;
  font-weight: 400;
  padding: 4px 0 0;
  border-radius: 6px;
  overflow: hidden;
  cursor: default;
  user-select: text;
  -webkit-user-select: text;
  line-height: 1.5;
}

.chat-order-tooltip-content {
  padding: 8px 12px;
}

.chat-order-badge:hover .chat-order-tooltip,
.chat-order-tooltip:hover {
  display: block;
}

/* Invisible bridge between button and picker to prevent hover gap */
.chat-emoji-wrap:hover .chat-emoji-picker::after,
.chat-emoji-wrap.emoji-open .chat-emoji-picker::after {
  content: "";
  position: absolute;
  bottom: -8px;
  left: 0;
  width: 100%;
  height: 8px;
}

/* Show on hover over wrap, or when .emoji-open class set by JS */
.chat-emoji-wrap:hover .chat-emoji-picker,
.chat-emoji-wrap.emoji-open .chat-emoji-picker {
  display: grid;
}

.chat-emoji-item {
  min-width: 32px;
  min-height: 32px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
}

/* ── Unified quick templates modal (reviews / questions / chats) ── */
.qtempl-modal-card {
  width: min(540px, 96vw);
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
  overflow: hidden;
}

.qtempl-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid #f1f5f9;
}

.qtempl-title {
  font-size: 16px;
  font-weight: 600;
  color: #0f172a;
}

.qtempl-close {
  background: transparent !important;
  border: none !important;
  color: #94a3b8 !important;
  font-size: 16px !important;
  width: 28px !important;
  height: 28px !important;
  min-height: 0 !important;
  padding: 0 !important;
  cursor: pointer;
  border-radius: 4px !important;
  box-shadow: none !important;
  transition: color 0.12s, background 0.12s !important;
}

.qtempl-close:hover {
  color: #475569 !important;
  background: #f1f5f9 !important;
}

.qtempl-info {
  min-height: 0;
  font-size: 13px;
  color: #dc2626;
  padding: 0 24px;
  margin-top: 8px;
}

.qtempl-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  max-height: 44vh;
  overflow-y: auto;
  padding: 8px 24px;
  min-height: 48px;
}

.qtempl-list .chat-quick-template-item {
  border-left: none;
  border-right: none;
  border-top: none;
  border-radius: 0;
  border-bottom: 1px solid #f1f5f9;
  padding: 10px 0;
  background: transparent;
}

.qtempl-list .chat-quick-template-item:last-child {
  border-bottom: none;
}

.qtempl-list .chat-quick-template-item {
  cursor: pointer;
}

.qtempl-list .chat-quick-template-item:hover {
  background: #eff6ff;
  border-bottom-color: #dbeafe;
  margin: 0 -8px;
  padding-left: 8px;
  padding-right: 8px;
}

.qtempl-add-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 24px;
  border-top: 1px solid #e2e8f0;
  background: #f8fafc;
}

.qtempl-add-form.hidden { display: none !important; }

.qtempl-footer {
  display: flex;
  gap: 8px;
  padding: 12px 24px 16px;
  border-top: 1px solid #e2e8f0;
  align-items: center;
}

.qtempl-input {
  width: 100% !important;
  box-sizing: border-box;
}

.qtempl-textarea {
  width: 100% !important;
  box-sizing: border-box;
  min-height: 72px;
  resize: vertical;
}

.qtempl-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.chat-quick-templates-modal-card {
  width: min(760px, 96vw);
}

#chatQuickTemplateInput {
  width: 100%;
  min-height: 84px;
}

.chat-quick-templates-list {
  display: grid;
  gap: 8px;
  max-height: 46vh;
  overflow-y: auto;
  padding-right: 2px;
}

.chat-quick-template-item {
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  background: #fff;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  transition: background 0.12s;
}

.chat-quick-template-item:hover {
  background: #f8fafc;
}

.chat-quick-template-name {
  font-size: 14px;
  font-weight: 500;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-quick-template-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.qt-btn {
  width: 30px !important;
  height: 30px;
  min-width: 30px !important;
  padding: 0 !important;
  font-size: 16px;
  border-radius: 6px;
  background: transparent;
  border: 1px solid #e5e7eb;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #374151;
}

.qt-btn:hover { background: #f3f4f6; }
.qt-btn.qt-delete:hover { background: #fee2e2; color: #dc2626; border-color: #fca5a5; }
.qt-btn.qt-apply { font-size: 18px; }

.qt-edit-form {
  width: 100%;
  display: grid;
  gap: 6px;
}

.qt-edit-name,
.qt-edit-text {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 14px;
  font-family: inherit;
}

.qt-edit-text { resize: vertical; }

.chats-thread-panel {
  border: none;
  border-radius: 0;
  background: #fff;
  padding: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 0;
  min-height: 0;
  height: 100%;
}

.chat-list-item {
  width: 100%;
  min-width: 0;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 2px;
  border: none;
  border-bottom: 1px solid #f1f5f9;
  border-radius: 0;
  padding: 12px 16px;
  background: #fff;
  color: #0f172a;
  transition: background 0.12s;
  overflow: hidden;
}

.chat-list-item:hover {
  background: #f8fafc;
}

.chat-list-item.active {
  background: #eff6ff;
  border-left: 2px solid #2563eb;
  padding-left: 14px;
}

/* Row 1: tabs + controls */
.chats-buckets-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 4px;
  flex-wrap: nowrap;
  width: 100%;
  padding-bottom: 12px;
}

.chats-buckets-row .bucket-tab {
  flex: 1 1 0;
  min-width: 0;
  font-size: 13px;
  padding: 6px 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: auto !important;
}

/* Sort icon button */
.chats-sort-wrap {
  position: relative;
  flex-shrink: 0;
}

.chats-sort-btn {
  min-width: 32px !important;
  max-width: 32px !important;
  width: 32px !important;
  height: 32px;
  font-size: 15px;
  padding: 0;
  border-radius: 6px;
  background: transparent;
  border: 1px solid #e2e8f0;
  color: #64748b;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, border-color 0.12s;
}

.chats-sort-btn:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.chats-sort-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 100;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.10);
  min-width: 160px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chats-sort-dropdown.hidden {
  display: none !important;
}

.chats-sort-option {
  text-align: left;
  padding: 10px 14px;
  font-size: 14px;
  color: #374151;
  background: transparent;
  border: none;
  border-radius: 0;
  cursor: pointer;
  width: 100% !important;
  transition: background 0.12s;
}

.chats-sort-option:hover {
  background: #f8fafc;
}

.chats-sort-option.active {
  color: #2563eb;
  font-weight: 600;
  background: #eff6ff;
}

/* Search toggle button */
.chats-search-btn {
  min-width: 32px !important;
  max-width: 32px !important;
  width: 32px !important;
  height: 32px;
  font-size: 14px;
  padding: 0;
  border-radius: 6px;
  background: transparent;
  border: 1px solid #e2e8f0;
  color: #64748b;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.12s, border-color 0.12s;
}

.chats-search-btn:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

/* Search input row */
.chats-search-row {
  padding: 0 0 8px;
}

.chats-search-row.hidden {
  display: none !important;
}

.chats-search-input {
  width: 100% !important;
  font-size: 14px;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  outline: none;
  color: #0f172a;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.chats-search-input:focus {
  border-color: #2563eb;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(37,99,235,0.10);
}

/* "‹ Все чаты" back link — hidden on desktop, shown only on mobile */
.chat-back-btn {
  display: none;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  font-weight: 600;
  color: #2563eb;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  white-space: nowrap;
  width: auto !important;
  flex-shrink: 0;
}

.chat-list-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.chat-list-name {
  font-weight: 600;
  font-size: 14px;
  color: #0f172a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 1;
}

.chat-list-badge {
  font-size: 11px;
  font-weight: 600;
  color: #2563eb;
  background: #eff6ff;
  border-radius: 4px;
  padding: 1px 6px;
  white-space: nowrap;
  flex-shrink: 0;
  letter-spacing: 0.02em;
}

/* Row 2: message preview */
.chat-list-preview {
  font-size: 13px;
  color: #64748b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}

/* Row 1 right side: date + source + unread */
.chat-list-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.chat-list-date {
  font-size: 12px;
  color: #94a3b8;
  white-space: nowrap;
}

.chat-list-unread {
  font-size: 11px;
  font-weight: 700;
  background: #2563eb;
  color: #fff;
  border-radius: 10px;
  padding: 1px 7px;
  min-width: 20px;
  text-align: center;
  flex-shrink: 0;
}

/* ── Chat bubbles ── */
.chat-bubble {
  max-width: 75%;
  border-radius: 12px;
  padding: 8px 12px;
  border: none;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

.chat-bubble.outbound {
  align-self: flex-end;
  background: #2563eb;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-bubble.inbound {
  align-self: flex-start;
  background: #fff;
  border: 1px solid #e2e8f0;
  color: #0f172a;
  border-bottom-left-radius: 4px;
}

.chat-bubble.failed {
  background: #fef2f2;
  border: 1px solid #fca5a5;
  color: #0f172a;
}

.chat-bubble-text {
  word-break: break-word;
  white-space: pre-wrap;
  font-size: 14px;
  line-height: 1.5;
}

.chat-bubble-img {
  display: block;
  max-width: 240px;
  max-height: 280px;
  border-radius: 8px;
  cursor: zoom-in;
  object-fit: cover;
  transition: opacity 0.15s;
}
.chat-bubble-img:hover { opacity: 0.85; }

/* Lightbox overlay */
#chatImgLightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}
#chatImgLightbox.active { display: flex; }
#chatImgLightbox img {
  max-width: 92vw;
  max-height: 92vh;
  border-radius: 8px;
  object-fit: contain;
  box-shadow: 0 8px 40px rgba(0,0,0,0.5);
}

.chat-bubble-meta {
  font-size: 11px;
  color: #94a3b8;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.chat-bubble.outbound .chat-bubble-meta {
  color: rgba(255,255,255,0.65);
  justify-content: flex-end;
}

.chat-msg-time {
  font-size: 11px;
}


.switch {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 22px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
  min-height: 0;
}

.switch .slider {
  position: absolute;
  inset: 0;
  cursor: pointer;
  background: rgba(148, 163, 184, 0.44);
  border-radius: 999px;
  transition: 0.2s ease;
}

.switch .slider::before {
  content: "";
  position: absolute;
  height: 16px;
  width: 16px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: #ffffff;
  transition: 0.2s ease;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.2);
}

.switch input:checked + .slider {
  background: linear-gradient(160deg, #2563eb, #1d4ed8);
}

.switch input:checked + .slider::before {
  transform: translateX(20px);
}

.template-groups-accordion {
  display: grid;
  gap: 8px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.table-wrap > table {
  min-width: 720px;
}

#accountsTbody td.accounts-api-url-cell,
#accountsTbody td.accounts-api-key-cell,
#accountsTbody td.account-api-key-cell {
  width: 100px;
  max-width: 120px;
}

#accountsTbody .cell-break-anywhere {
  white-space: nowrap;
}

#accountsTbody .account-api-key-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

#accountsTbody .account-api-key-text {
  font-family: monospace;
  font-size: 13px;
  color: #475569;
  white-space: nowrap;
}

#accountsTbody .account-key-copy-btn {
  flex: 0 0 auto;
  min-width: 32px;
  min-height: 32px;
  padding: 0 6px;
  font-size: 14px;
}

#accountsTbody .account-key-copy-btn.copied {
  color: #065f46;
  border-color: rgba(16, 185, 129, 0.5);
  background: linear-gradient(160deg, rgba(236, 253, 245, 0.96), rgba(209, 250, 229, 0.92));
}

#accountsTbody .account-key-copy-btn:disabled {
  opacity: 0.46;
  cursor: not-allowed;
}

.template-group {
  border: 1px solid rgba(147, 197, 253, 0.35);
  border-radius: 12px;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.86), rgba(239, 246, 255, 0.78));
  overflow: hidden;
}

.template-group summary {
  cursor: pointer;
  list-style: none;
  padding: 11px 12px;
  font-weight: 700;
}

.template-group summary::-webkit-details-marker {
  display: none;
}

.template-subgroups-list {
  display: grid;
  gap: 8px;
  padding: 0 12px 12px;
}

.template-group > .template-subgroups-list {
  display: none;
}

.template-group[open] > .template-subgroups-list {
  display: grid;
}

.template-subgroup-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid rgba(147, 197, 253, 0.35);
  border-radius: 10px;
  background: rgba(248, 251, 255, 0.9);
  color: #1e293b;
}

.template-subgroup-row:hover {
  background: rgba(239, 246, 255, 0.95);
}

.template-subgroup-open-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 8px 10px;
  cursor: pointer;
}

.template-subgroup-delete-btn {
  margin-right: 6px;
}

.template-subgroup-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-right: 8px;
}

.template-subgroup-actions .icon-btn {
  min-width: 30px;
  min-height: 30px;
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 9px;
  border: 1px solid rgba(191, 219, 254, 0.9);
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
  color: #3b82f6;
  transition: transform 0.14s ease, box-shadow 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.template-subgroup-actions .icon-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: rgba(96, 165, 250, 0.95);
  box-shadow: 0 4px 10px rgba(59, 130, 246, 0.2);
  background: rgba(239, 246, 255, 0.95);
}

.template-subgroup-actions .icon-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.template-subgroup-actions .template-subgroup-edit-btn {
  color: #2563eb;
}

.template-subgroup-actions .template-subgroup-delete-btn {
  color: #ef4444;
  border-color: rgba(254, 202, 202, 0.95);
}

.template-subgroup-actions .template-subgroup-delete-btn:hover:not(:disabled) {
  border-color: rgba(248, 113, 113, 0.95);
  box-shadow: 0 4px 10px rgba(239, 68, 68, 0.18);
  background: rgba(254, 242, 242, 0.96);
}

.template-subgroup-add-row {
  display: flex;
  justify-content: flex-start;
}

.template-count-badge {
  min-width: 28px;
  height: 22px;
  border-radius: 999px;
  background: linear-gradient(150deg, #2563eb 0%, #1d4ed8 58%, #1e40af 100%);
  color: #fff;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
}

.template-editor-list {
  display: grid;
  gap: 8px;
  margin: 12px 0;
}

.template-editor-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.template-editor-input {
  min-height: 54px;
  width: 100%;
}

#superAdminDefaultTemplatesPanel .row {
  align-items: stretch;
}

#superAdminDefaultTemplatesPanel #defaultTemplateGroupsView,
#superAdminDefaultTemplatesPanel #defaultTemplateEditorView {
  width: 100%;
  flex: 1 1 100%;
}

#superAdminDefaultTemplatesPanel #defaultTemplateEditorView .row {
  width: 100%;
}

#superAdminDefaultTemplatesPanel .template-editor-list {
  width: 100%;
}

#superAdminDefaultTemplatesPanel .template-editor-row {
  grid-template-columns: minmax(0, 1fr) auto;
  width: 100%;
}

#superAdminDefaultTemplatesPanel .template-editor-input {
  width: 100%;
  min-height: 86px;
  min-width: 0;
}

.processing-rules-grid {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}

.processing-rule-card {
  border: 1px solid rgba(147, 197, 253, 0.42);
  border-radius: 14px;
  padding: 12px;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.9), rgba(240, 247, 255, 0.82));
  display: grid;
  gap: 10px;
}

.processing-rule-title {
  font-weight: 700;
  font-size: 18px;
}

.processing-rule-select {
  width: 100%;
}

#recommendationsTbody input[type="text"] {
  width: 100%;
}

@media (max-width: 1200px) {
  .main {
    padding: 18px;
  }

  .panel {
    padding: 16px;
  }

  .stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }
}

@media (max-width: 1024px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    box-shadow: none;
    padding: 12px 10px;
  }

  .sidebar-main,
  .sidebar-bottom {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
  }

  .sidebar-bottom {
    padding-top: 8px;
    margin-top: 8px;
  }

  .meta {
    width: 100%;
    margin-bottom: 8px;
  }

  .navbtn {
    margin-bottom: 0;
  }

  .main {
    padding: 16px;
  }

  .reviews-date-panel {
    right: auto;
    left: 0;
    width: min(92vw, 760px);
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  body.landing-page {
    overflow: auto;
  }

  .landing-shell {
    padding: 16px;
  }

  .landing-grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .landing-copy h1 {
    font-size: clamp(28px, 7vw, 40px);
  }

  .main {
    padding: 16px;
  }

  .panel {
    padding: 14px;
  }

  .row {
    flex-direction: column;
    align-items: stretch;
  }

  .row.row-between {
    align-items: stretch;
  }

  input,
  select,
  textarea,
  button:not(.icon-btn):not(.mobile-copy-key-btn):not([class*="emoji"]):not(.mobile-nav-toggle):not(.bucket-tab):not(.small-btn):not(.chat-back-btn) {
    width: 100%;
  }

  .small-btn {
    width: auto !important;
    flex-shrink: 0;
  }

  .reviews-quick-controls {
    width: 100%;
  }

  .reviews-pagination-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .reviews-top-controls {
    flex-direction: column;
    align-items: flex-start;
  }

  .settings-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 4px;
  }

  .settings-tab-btn {
    white-space: nowrap;
    width: auto;
  }

  .tariff-item {
    flex-direction: column;
    align-items: stretch;
  }

  .tariff-item-actions {
    width: 100%;
  }

  .table-wrap {
    margin: 0 -4px;
    padding: 0 4px;
  }

  .table-wrap > table {
    min-width: 640px;
  }

  .admin-actions-pagination {
    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .admin-actions-pagination .row {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }

  textarea,
  .textarea-compact {
    min-width: 100%;
  }
}

/* ── Analytics ───────────────────────────────────────────────────────────── */

.an-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.an-kpi-card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 16px;
}

.an-kpi-card.an-kpi-positive { border-left: 3px solid #16a34a; }
.an-kpi-card.an-kpi-negative { border-left: 3px solid #dc2626; }

.an-kpi-value {
  font-size: 28px;
  font-weight: 700;
  color: #0f172a;
  line-height: 1.1;
}

.an-kpi-label {
  font-size: 13px;
  color: #64748b;
  margin-top: 4px;
}

.an-kpi-sub {
  font-size: 12px;
  color: #94a3b8;
  margin-top: 2px;
}

.an-charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.an-chart-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.an-chart-title {
  font-size: 14px;
  font-weight: 600;
  color: #0f172a;
}

.an-chart-body {
  display: flex;
  align-items: flex-start;
  gap: 20px;
}

.an-donut {
  flex-shrink: 0;
  width: 120px;
  height: 120px;
}

.an-legend {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-width: 0;
}

.an-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  min-width: 0;
}

.an-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}

.an-legend-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #374151;
}

.an-legend-val {
  font-weight: 600;
  color: #0f172a;
  white-space: nowrap;
}

.an-legend-pct {
  font-weight: 400;
  color: #94a3b8;
  font-size: 12px;
}

.an-source-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.an-source-table th {
  text-align: left;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid #e2e8f0;
}

.an-source-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #f1f5f9;
  color: #0f172a;
}

.an-source-table tr:last-child td { border-bottom: none; }

.an-pct {
  font-size: 12px;
  color: #94a3b8;
  margin-left: 4px;
}

.an-positive { color: #16a34a !important; }
.an-negative { color: #dc2626 !important; }

@media (max-width: 768px) {
  /* Hide emoji button in chat compose on mobile */
  .chat-emoji-wrap {
    display: none !important;
  }

  .main {
    padding: 14px;
  }

  .panel {
    border-radius: 14px;
    padding: 12px;
  }

  .row {
    gap: 8px;
  }

  .table-wrap > table {
    min-width: 580px;
  }

  /* ── Chats topbar: always a row on mobile ── */
  .chats-topbar {
    display: flex;
    flex-direction: row !important;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 4px 0;
    flex-shrink: 0;
  }

  .chats-topbar-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .chats-clear-btn {
    flex-shrink: 0;
    width: auto !important;
    font-size: 12px;
    padding: 6px 10px;
  }

  /* ── Mobile chat layout: one panel at a time ── */
  /* Remove .main side padding for chats so it fills the full viewport width */
  .main:has(#section-chats:not(.hidden)) {
    padding-left: 0;
    padding-right: 0;
  }

  #section-chats:not(.hidden) {
    min-height: 0;
    display: flex;
    flex-direction: column;
    height: calc(100dvh - var(--mobile-topbar-height, 62px));
    overflow: hidden;
    width: 100%;
    max-width: 100%;
  }

  .chats-topbar {
    flex-shrink: 0;
    padding: 0 12px;
  }

  #section-chats .chats-shell {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0;
    border: none;
    border-radius: 0;
    background: #fff;
    box-shadow: none;
    gap: 0;
    max-width: 100%;
    width: 100%;
  }

  /* List panel fills the screen; hidden when a chat is open */
  .chats-list-panel {
    flex: 1 1 0;
    min-height: 0;
    border-radius: 0;
    border-right: none;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    max-width: 100%;
    width: 100%;
  }

  .chats-list-panel.mobile-hidden {
    display: none !important;
  }

  /* Thread panel hidden until a chat is selected */
  .chats-thread-panel {
    display: none;
    flex: 1 1 0;
    min-height: 0;
    grid-template-rows: auto 1fr auto;
    height: 100%;
    overflow: hidden;
  }

  .chats-thread-panel.mobile-visible {
    display: grid;
  }

  /* Messages area must scroll, not push compose off screen */
  .chats-thread-panel .chat-messages {
    min-height: 0;
    overflow-y: auto;
    max-height: none;
  }

  /* Compose area: fixed height, no overflow */
  .chats-thread-panel .chat-compose {
    min-height: 0;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px 12px 8px;
    border-top: 1px solid #e2e8f0;
    background: #fff;
  }

  /* List height: fill available space */
  .chats-list {
    max-height: none;
    flex: 1 1 0;
    min-height: 0;
  }

  /* Thread header on mobile */
  .chat-thread-header {
    min-width: 0;
    overflow: hidden;
    padding: 12px;
  }

  /* Back button visible on mobile */
  .chat-back-btn {
    display: inline-flex;
  }

  /* Sort select stays compact */
  .chats-buckets-row .bucket-tab {
    font-size: 12px;
    padding: 6px 4px;
  }

  /* Textarea: compact on mobile, 2 rows */
  #chatReplyInput {
    width: 100% !important;
    font-size: 14px;
    resize: none;
    min-height: 52px;
    max-height: 80px;
  }

  /* Compose action row: horizontal scrollable strip */
  .chat-compose-actions {
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 6px;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    align-items: center;
  }

  .chat-compose-actions::-webkit-scrollbar {
    display: none;
  }

  /* Every button in the actions row: compact, auto width */
  .chat-compose-actions button {
    flex-shrink: 0 !important;
    white-space: nowrap !important;
    width: auto !important;
    min-width: auto !important;
    font-size: 13px;
    padding: 8px 14px;
  }

  .chat-compose-actions .icon-btn {
    min-width: 38px !important;
    max-width: 38px !important;
    padding: 0 !important;
  }

  /* Emoji picker */
  .chat-emoji-picker {
    max-width: 100%;
    grid-template-columns: repeat(10, minmax(0, 1fr));
  }

  /* Thread header: row with back btn + title */
  #chatThreadHeader {
    flex-direction: row !important;
    align-items: center;
    gap: 8px;
    padding: 4px 0 6px;
    flex-shrink: 0;
  }

  #chatThreadTitle {
    font-size: 13px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  .template-editor-row {
    grid-template-columns: 1fr;
  }

  .template-editor-row button {
    width: 100%;
  }

  .users-search-inline input[type="search"] {
    min-width: 0;
    width: 100%;
  }

  .admin-actions-filters input[type="search"] {
    min-width: 0;
    width: 100%;
    flex-basis: 100%;
  }

  .processing-rules-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .main {
    padding: 12px;
  }

  .panel {
    border-radius: 14px;
    padding: 12px;
  }

  .brand {
    font-size: 16px;
    margin-bottom: 6px;
  }

  .reviews-buckets {
    width: 100%;
  }

  .bucket-tab {
    flex: 1 1 auto;
    min-width: 0;
  }

  .reviews-date-panel {
    width: min(94vw, 540px);
  }

  .settings-tab-btn {
    font-size: 13px;
    padding: 8px 10px;
  }
}

/* Settings section: dedicated mobile adaptation without logic changes */
@media (max-width: 900px) {
  #section-settings .settings-tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    overflow: visible;
    padding-bottom: 0;
  }

  #section-settings .settings-tab-btn {
    width: 100%;
    white-space: normal;
    text-align: center;
    min-height: 42px;
  }

  #section-settings .row.row-between {
    gap: 8px;
  }

  #section-settings .sync-start-settings .row {
    gap: 8px;
  }

  #section-settings .source-form,
  #section-settings .sync-start-settings {
    padding: 10px;
  }

  #section-settings .template-editor-input {
    min-width: 0;
  }

  #section-settings #settings-pane-recommendations .row.row-between > .row {
    width: 100%;
  }

  #section-settings #teamPermissionsPreview {
    display: block;
  }
}

@media (max-width: 560px) {
  #section-settings .settings-tabs {
    grid-template-columns: 1fr;
  }
}

/* Mobile navigation + settings switcher (mobile only) */
@media (max-width: 900px) {
  body {
    --mobile-topbar-height: 62px;
  }

  .mobile-topbar {
    position: sticky;
    top: 0;
    z-index: 1400;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(244, 249, 255, 0.9));
    backdrop-filter: blur(10px);
    min-height: var(--mobile-topbar-height);
  }

  .mobile-nav-toggle {
    width: 42px;
    min-height: 42px;
    padding: 0;
    font-size: 22px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .mobile-topbar-title {
    font-size: 18px;
    font-weight: 800;
    color: #0f172a;
    line-height: 1.2;
  }

  .mobile-nav-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1300;
    background: rgba(15, 23, 42, 0.42);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }

  .mobile-nav-backdrop.open {
    opacity: 1;
    pointer-events: auto;
  }

  .layout > .sidebar {
    position: fixed;
    top: var(--mobile-topbar-height);
    left: 0;
    width: min(82vw, 320px);
    max-width: 320px;
    height: calc(100vh - var(--mobile-topbar-height));
    z-index: 1350;
    transform: translateX(-104%);
    transition: transform 0.24s ease;
    border-right: 1px solid var(--line);
    border-top: 1px solid var(--line);
    border-bottom: 0;
    box-shadow: 16px 0 38px rgba(15, 23, 42, 0.2);
    overflow-y: auto;
    padding-top: 12px;
  }

  .layout > .sidebar .sidebar-main,
  .layout > .sidebar .sidebar-bottom {
    display: block;
  }

  .layout > .sidebar .sidebar-main {
    flex: 0 0 auto;
  }

  .layout > .sidebar .sidebar-bottom {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
    flex: 0 0 auto;
  }

  .layout > .sidebar .meta {
    margin-bottom: 14px;
  }

  .layout > .sidebar .navbtn {
    width: 100%;
    margin-bottom: 9px;
  }

  /* Mobile nav groups: +/- toggle, no flyout */
  .nav-group-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px !important;
    height: 28px;
    background: #f1f5f9;
    border-radius: 6px;
    color: #475569;
    font-size: 18px;
  }

  .nav-group:hover > .nav-group-items {
    display: none; /* disable hover on mobile */
  }

  .nav-group.open > .nav-group-items {
    display: flex;
    flex-direction: column;
    width: 100%;
    /* override desktop flyout styles */
    position: static;
    background: none;
    border: none;
    box-shadow: none;
    border-radius: 0;
    padding: 0 0 0 10px;
    border-left: 2px solid var(--line);
    margin-left: 6px;
    min-width: unset;
  }

  .nav-group.open > .nav-group-items .navbtn,
  .nav-group.open > .nav-group-items .nav-sub {
    padding: 8px 12px;
    border-radius: 8px;
  }

  .nav-group-title {
    margin-bottom: 0;
  }

  .nav-group-header {
    margin-bottom: 9px;
  }

  .layout > .sidebar.open {
    transform: translateX(0);
  }

  body.mobile-nav-open {
    overflow: hidden;
  }

  .settings-mobile-tab-switch {
    display: grid;
    gap: 6px;
    margin-top: 10px;
  }

  .settings-mobile-tab-switch label {
    font-weight: 600;
  }

  #section-settings .settings-tabs {
    display: none;
  }

  /* Section title duplicates mobile topbar title */
  .main > section > .section-title {
    display: none;
  }

  /* Keep settings layout strictly within viewport width on mobile */
  #section-settings {
    min-width: 0;
    overflow-x: hidden;
  }

  #section-settings > .panel,
  #section-settings .panel,
  #section-settings .row,
  #section-settings .sync-start-settings,
  #section-settings .source-form,
  #section-settings .settings-mobile-tab-switch {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  #section-settings .settings-mobile-tab-switch select,
  #section-settings input,
  #section-settings select,
  #section-settings textarea,
  #section-settings button {
    max-width: 100%;
    min-width: 0;
  }

  #section-settings .table-wrap {
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 0;
  }

  /* Unify all settings panes to the same mobile width template */
  #section-settings > div[id^="settings-pane-"],
  #section-settings > div[id^="settings-pane-"] > .panel {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  #section-settings > div[id^="settings-pane-"] .row {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    margin-left: 0;
    margin-right: 0;
  }

  #section-settings > div[id^="settings-pane-"] .row > * {
    min-width: 0;
    max-width: 100%;
  }

  /* Date input in Sources pane - compact, not full-width */
  #section-settings #settings-pane-sources .sync-start-settings input[type="date"] {
    width: auto;
    max-width: 180px;
    min-width: 130px;
    flex: 1 1 140px;
  }

  #section-settings #settings-pane-sources .sync-start-settings label {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    font-size: 13px;
    color: #6b7280;
  }

  #section-settings > div[id^="settings-pane-"] .row button,
  #section-settings > div[id^="settings-pane-"] .row .navbtn {
    width: 100%;
    white-space: normal;
  }

  #section-settings > div[id^="settings-pane-"] .table-wrap {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    margin: 0;
    padding: 0;
  }

  #section-settings > div[id^="settings-pane-"] .table-wrap > table {
    min-width: 560px;
  }
}

/* ─── Mobile card layout for Settings tables ─────────────────────────── */
@media (max-width: 900px) {

  /* ── Accounts (sources) pane ── */
  .accounts-mobile-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 10px;
  }

  .account-card {
    background: linear-gradient(160deg, rgba(248,251,255,0.97), rgba(236,245,255,0.9));
    border: 1px solid rgba(147,197,253,0.42);
    border-radius: 14px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .account-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
  }

  .account-card-name {
    font-weight: 700;
    font-size: 15px;
    color: #0f172a;
  }

  .account-card-badge {
    font-size: 11px;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 20px;
    white-space: nowrap;
  }

  .account-card-badge.wb {
    background: rgba(59,130,246,0.12);
    color: #1d4ed8;
  }

  .account-card-badge.ozon {
    background: rgba(16,185,129,0.12);
    color: #065f46;
  }

  .account-card-badge.active {
    background: rgba(16,185,129,0.12);
    color: #065f46;
  }

  .account-card-badge.inactive {
    background: rgba(239,68,68,0.1);
    color: #b91c1c;
  }

  .account-card-row {
    display: flex;
    gap: 6px;
    align-items: baseline;
    font-size: 13px;
  }

  .account-card-label {
    color: #6b7280;
    min-width: 68px;
    flex-shrink: 0;
  }

  .account-card-value {
    color: #1e293b;
    word-break: break-all;
    min-width: 0;
    flex: 1;
    font-size: 12px;
  }

  .account-card-key-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    flex: 1;
  }

  /* Key text: truncate with ellipsis to keep card compact */
  .account-card-key-wrap > span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
    flex: 1;
    font-size: 12px;
    font-family: monospace;
    color: #475569;
  }

  /* Copy button stays small — never stretch to full width */
  .account-card-key-wrap .mobile-copy-key-btn,
  .mobile-copy-key-btn {
    width: auto !important;
    min-width: 34px !important;
    max-width: 34px !important;
    flex-shrink: 0;
    padding: 0 6px;
    font-size: 14px;
  }

  .account-card-actions {
    display: flex;
    gap: 8px;
    margin-top: 6px;
  }

  .account-card-actions button {
    flex: 1;
    width: auto;
  }

  /* Ensure action buttons are never full-width individually */
  .account-card-actions button,
  .account-card-actions .secondary {
    width: auto !important;
    flex: 1 1 0;
    min-width: 0;
  }

  /* mobile-copy-key-btn must always be a compact square */
  .mobile-copy-key-btn {
    width: 34px !important;
    min-width: 34px !important;
    max-width: 34px !important;
    height: 34px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 15px;
  }

  /* Hide the desktop table on mobile */
  #accountsTbody {
    display: none;
  }
  #accountsTbody.desktop-visible {
    display: table-row-group;
  }

  /* ── Add source form ── */
  #section-settings #addSourceForm .row {
    flex-direction: column;
    gap: 8px;
  }

  #section-settings #addSourceForm select,
  #section-settings #addSourceForm input,
  #section-settings #addSourceForm textarea {
    width: 100%;
  }

  /* ── Sync start date row ── */
  #section-settings .sync-start-settings .row {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
  }

  #section-settings .sync-start-settings label {
    width: 100%;
    font-size: 13px;
    color: #6b7280;
  }

  #section-settings .sync-start-settings input[type="date"] {
    flex: 1 1 140px;
    max-width: 180px;
    min-width: 130px;
    width: auto !important;
  }

  #section-settings .sync-start-settings button {
    flex: 0 0 auto;
    width: auto !important;
    padding: 0 16px;
    white-space: nowrap;
  }

  #section-settings .sync-start-settings .small {
    width: 100%;
    font-size: 12px;
  }

  /* ── Sync buttons row ── */
  #section-settings .sync-btn-row {
    flex-direction: column;
    gap: 8px;
  }

  /* ── Team pane ── */
  .team-mobile-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 10px;
  }

  .team-card {
    background: linear-gradient(160deg, rgba(248,251,255,0.97), rgba(236,245,255,0.9));
    border: 1px solid rgba(147,197,253,0.42);
    border-radius: 14px;
    padding: 13px;
    display: flex;
    flex-direction: column;
    gap: 5px;
  }

  .team-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
  }

  .team-card-email {
    font-weight: 700;
    font-size: 14px;
    word-break: break-all;
  }

  .team-card-row {
    font-size: 13px;
    color: #475569;
  }

  .team-card-row b {
    color: #1e293b;
  }

  .team-card-actions {
    display: flex;
    gap: 8px;
    margin-top: 4px;
    flex-wrap: wrap;
  }

  .team-card-actions button {
    flex: 1;
    min-width: 0;
  }

  /* Hide desktop tables */
  #teamTbody {
    display: none;
  }
  #teamTbody.desktop-visible {
    display: table-row-group;
  }

  /* ── Add manager form ── */
  #section-settings #settings-pane-team .row:not(.team-card-actions) {
    flex-direction: column;
    gap: 8px;
  }

  /* ── Recommendations ── */
  #section-settings #settings-pane-recommendations .row.row-between {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  #section-settings #settings-pane-recommendations .row.row-between > .row {
    flex-direction: column;
    gap: 8px;
  }

  /* ── Template variables table → cards ── */
  .template-variables-mobile-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 8px;
  }

  .template-variable-card {
    background: rgba(248,251,255,0.97);
    border: 1px solid rgba(147,197,253,0.4);
    border-radius: 12px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .template-variable-card-key {
    font-weight: 700;
    font-size: 13px;
    color: #1d4ed8;
  }

  .template-variable-card-desc {
    font-size: 12px;
    color: #6b7280;
  }

  .template-variable-card input {
    width: 100%;
    font-size: 13px;
  }

  /* Show mobile account/team lists only on mobile */
  .accounts-mobile-list,
  .team-mobile-list,
  .template-variables-mobile-list {
    display: flex;
  }
}

@media (min-width: 901px) {
  /* Hide mobile card lists on desktop */
  .accounts-mobile-list,
  .team-mobile-list,
  .template-variables-mobile-list {
    display: none !important;
  }
}

@media (max-width: 640px) {
  .an-charts-row { grid-template-columns: 1fr; }
  .an-kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .an-chart-body { flex-direction: column; align-items: center; }
}

/* ── Product catalog ─────────────────────────────────────────────────────── */
.product-thumb {
  display: block;
  width: 96px;
  height: 96px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid #e2e8f0;
  margin: 8px auto 0;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  cursor: zoom-in;
}

@media (min-width: 769px) {
  .product-thumb:hover {
    transform: scale(2);
    box-shadow: 0 4px 20px rgba(0,0,0,0.18);
    position: relative;
    z-index: 10;
  }
}

.product-thumb-empty {
  width: 48px;
  height: 48px;
  border-radius: 4px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
}

.products-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.products-table th {
  text-align: left;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid #e2e8f0;
}

.products-table td {
  padding: 8px 12px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}

.products-table tr:last-child td { border-bottom: none; }

/* ── Supply module ─────────────────────────────────────────────── */

/* Toolbar panel */
.supplies-toolbar-panel { padding: 10px 16px 8px; position: relative; z-index: 10; overflow: visible !important; }
.supplies-top-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: space-between;
}
.supplies-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.supplies-date-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  position: relative;
  z-index: 100;
}
.supplies-date-wrap input[type="date"] { width: 136px; }
.supplies-sync-info {
  margin-top: 4px;
  font-size: 12px;
  color: #64748b;
  min-height: 0;
}

/* Table panel */
.supplies-table-panel { padding: 0; overflow: hidden; }
.supplies-table-panel .table-wrap { border-radius: 0; }

/* Column widths */
.supplies-col-expand { width: 36px; text-align: center; }
.supplies-col-id     { width: 130px; }
.supplies-col-wh     { }
.supplies-col-date   { width: 120px; }
.supplies-col-qty    { width: 90px; text-align: right; }
.supplies-col-status { width: 140px; }
.supplies-col-links  { width: 80px; }

/* Expand button */
.supply-expand-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 9px;
  color: #94a3b8;
  padding: 4px 6px;
  border-radius: 4px;
  transition: color 0.12s, background 0.12s;
  line-height: 1;
}
.supply-expand-btn:hover { color: #475569; background: #f1f5f9; }
.supply-expand-btn.expanded { color: #6366f1; }

/* Supply ID */
.supply-id-text {
  font-family: monospace;
  font-size: 13px;
  font-weight: 600;
  color: #1e293b;
}

/* Cell alignment */
.supply-qty-cell { text-align: right; font-variant-numeric: tabular-nums; }
.supply-date-cell { color: #475569; }
.supply-wh-cell { color: #374151; }
.supply-links-cell { color: #94a3b8; font-size: 12px; }

/* Status badges */
.supply-status-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.supply-status-1 { background: #fef9c3; color: #854d0e; }
.supply-status-2 { background: #dbeafe; color: #1d4ed8; }
.supply-status-3 { background: #dbeafe; color: #1d4ed8; }
.supply-status-4 { background: #fce7f3; color: #9d174d; }
.supply-status-5 { background: #dcfce7; color: #166534; }

/* Goods expand row */
.supply-goods-row td { padding: 0 !important; background: #f8fafc; }
.supply-goods-container {
  padding: 12px 16px 12px 52px;
  border-top: 1px solid #e9f0fb;
}

/* Goods inner table */
.supply-goods-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.supply-goods-table th {
  text-align: left;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid #e2e8f0;
}
.supply-goods-table td {
  padding: 6px 10px;
  border-bottom: 1px solid #f1f5f9;
  color: #374151;
}
.supply-goods-table tr:last-child td { border-bottom: none; }

/* Footer with total + pagination */
.supplies-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-top: 1px solid rgba(147,175,224,0.2);
  background: #f8fafc;
  border-radius: 0 0 var(--radius-lg, 12px) var(--radius-lg, 12px);
}
.supplies-total { color: #64748b; font-size: 13px; }
.supplies-pagination { display: flex; align-items: center; gap: 8px; }
.supplies-pagination .small { font-size: 13px; color: #64748b; min-width: 60px; text-align: center; }

/* Supply sources table */
.supply-sources-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
}
.supply-sources-table th,
.supply-sources-table td {
  padding: 8px 10px;
  text-align: left;
  font-size: 13px;
  border-bottom: 1px solid #f1f5f9;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}
.supply-sources-table thead th {
  font-size: 11px;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 2px solid #e2e8f0;
  background: #f8fafc;
  padding: 6px 10px;
}
.supply-sources-table tr:last-child td { border-bottom: none; }
/* Column widths — must sum to 100% */
.supply-sources-table col.col-num   { width: 4%; }
.supply-sources-table col.col-name  { width: 28%; }
.supply-sources-table col.col-key   { width: 18%; }
.supply-sources-table col.col-act   { width: 10%; }
.supply-sources-table col.col-sync  { width: 20%; }
.supply-sources-table col.col-acts  { width: 20%; }

.supply-src-key-cell { }
.supply-src-key-text {
  font-family: monospace;
  font-size: 12px;
  color: #475569;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Supply Details Modal ──────────────────────────────────────── */

.supply-details-modal-card {
  width: 50vw;
  min-width: 320px;
  max-width: 900px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-lg, 12px);
  background: #fff;
  box-shadow: 0 8px 32px rgba(15,23,42,0.18);
  overflow: hidden;
}

.modal-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid #e2e8f0;
  background: #f8fafc;
  flex-shrink: 0;
}

.modal-close-btn {
  background: none;
  border: none;
  font-size: 18px;
  color: #94a3b8;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  line-height: 1;
  transition: color 0.12s, background 0.12s;
}
.modal-close-btn:hover { color: #334155; background: #f1f5f9; }

.supply-details-body {
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  flex: 1 1 auto;
}

.supply-detail-row {
  display: grid;
  grid-template-columns: 120px 1fr;
  align-items: center;
  gap: 12px;
}

.supply-detail-label {
  font-size: 13px;
  font-weight: 600;
  color: #64748b;
  white-space: nowrap;
}

.supply-detail-value {
  font-size: 14px;
  color: #1e293b;
  font-weight: 500;
}

.supply-detail-input {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 13px;
  color: #1e293b;
  background: #fff;
  transition: border-color 0.12s, box-shadow 0.12s;
  box-sizing: border-box;
}
.supply-detail-input:focus {
  outline: none;
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99,102,241,0.12);
}
.supply-detail-input::placeholder { color: #94a3b8; font-style: italic; }

.supply-details-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px 14px;
  border-top: 1px solid #e2e8f0;
  flex-shrink: 0;
  background: #fff;
}
.supply-details-footer .small { margin-left: 4px; }

/* Детали link button in table */
/* Supply action buttons in table */
.supply-detail-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  box-sizing: border-box;
  gap: 4px;
  background: #fff;
  border: 1px solid #c7d2fe;
  color: #4f46e5;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, color 0.12s, box-shadow 0.12s;
  line-height: 1.4;
}
.supply-detail-link:hover {
  background: #eef2ff;
  border-color: #818cf8;
  color: #3730a3;
  box-shadow: 0 1px 4px rgba(99,102,241,0.15);
}
.supply-detail-link:active {
  background: #e0e7ff;
  box-shadow: none;
}

.supplies-col-prod { width: 120px; }
.supply-prod-cell { color: #374151; }
.supply-prod-empty { color: #f59e0b; font-style: italic; font-size: 12px; }

/* ── Supplies main table overrides ────────────────────────────── */
.supplies-table-wrap {
  width: 100%;
  max-width: 100%;
  overflow: hidden; /* no horizontal scroll, ever */
}

/* Override global min-width that would cause overflow on narrow screens */
.supplies-table-wrap .supplies-main-table {
  min-width: 0 !important;
}

.supplies-main-table {
  width: 100%;
  max-width: 100%;
  table-layout: fixed !important;
  border-collapse: collapse;
  font-size: 15px;
}

.supplies-main-table th,
.supplies-main-table td {
  text-align: left;
  border-bottom: 1px solid rgba(147,175,224,0.25);
  padding: 8px 6px;
  vertical-align: middle;
  overflow: hidden;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: normal;
  max-width: 0; /* forces table-layout:fixed to respect col widths */
}

.supplies-main-table th {
  position: relative;
  color: #4a607f;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: rgba(239,246,255,0.5);
  white-space: nowrap;
  overflow: hidden;
}

.supplies-main-table tbody tr:hover { background: rgba(239,246,255,0.62); }

/* Column resize handle */
.col-resize-handle {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 6px;
  cursor: col-resize;
  background: transparent;
  z-index: 1;
}
.col-resize-handle:hover,
.col-resize-handle:active {
  background: rgba(99,102,241,0.35);
}

.supply-barcode-link {
  background: #ecfdf5 !important;
  border-color: #6ee7b7 !important;
  color: #047857 !important;
}
.supply-barcode-link:hover {
  background: #d1fae5 !important;
  border-color: #34d399 !important;
  color: #065f46 !important;
  box-shadow: 0 1px 4px rgba(16,185,129,0.15) !important;
}

.supply-packing-link {
  background: #fefce8 !important;
  border-color: #fde047 !important;
  color: #854d0e !important;
}
.supply-packing-link:hover {
  background: #fef9c3 !important;
  border-color: #facc15 !important;
  color: #713f12 !important;
  box-shadow: 0 1px 4px rgba(234,179,8,0.15) !important;
}

.edit-inline-input {
  width: 100%;
  height: 30px;
  padding: 0 8px;
  border: 1px solid #6366f1;
  border-radius: 5px;
  font-size: 13px;
  box-sizing: border-box;
}
.edit-inline-input:focus { outline: none; box-shadow: 0 0 0 2px rgba(99,102,241,0.2); }

.supply-legal-cell { color: #374151; font-size: 14px; }

.supply-links-col {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
}

/* ── Supplies table row distinction ───────────────────────────── */
.supplies-main-table tbody tr:nth-child(4n+1) td,
.supplies-main-table tbody tr:nth-child(4n+2) td {
  background: #f8fafc;
}
.supplies-main-table tbody tr:nth-child(4n+3) td,
.supplies-main-table tbody tr:nth-child(4n+4) td {
  background: #fff;
}
/* Goods rows inherit parent's background */
.supplies-main-table tbody tr.supply-goods-row td {
  background: #f1f5f9 !important;
}
/* Stronger hover */
.supplies-main-table tbody tr.supply-row:hover td {
  background: #eef2ff !important;
  transition: background 0.1s;
}
/* Slightly more visible row separator */
.supplies-main-table th,
.supplies-main-table td {
  border-bottom: 1px solid rgba(100, 116, 139, 0.18);
}
/* Group rows by pairs — thicker line every 2 data rows */
.supplies-main-table tbody tr.supply-row:nth-child(4n+1) td {
  border-top: 2px solid rgba(100, 116, 139, 0.15);
}

.supply-poa-link {
  background: #f5f3ff !important;
  border-color: #c4b5fd !important;
  color: #5b21b6 !important;
}
.supply-poa-link:hover {
  background: #ede9fe !important;
  border-color: #a78bfa !important;
  color: #3b0764 !important;
  box-shadow: 0 1px 4px rgba(139,92,246,0.15) !important;
}

/* Supplies date range panel */
.supplies-date-panel {
  display: none; /* hidden by default — only shown via JS */
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15,23,42,0.18);
  padding: 12px;
  z-index: 9999;
  min-width: 260px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.supplies-date-panel-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.supplies-date-panel-row label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: #374151;
}
.supplies-date-panel-row input[type="date"] { width: 130px; }

/* Settings tables (drivers/warehouses/legal) — no overflow */
#supplies-settings-pane-drivers .table-wrap,
#supplies-settings-pane-warehouses .table-wrap,
#supplies-settings-pane-legal .table-wrap {
  overflow: hidden;
}
#supplies-settings-pane-drivers .table-wrap .supply-sources-table,
#supplies-settings-pane-warehouses .table-wrap .supply-sources-table,
#supplies-settings-pane-legal .table-wrap .supply-sources-table {
  min-width: 0 !important;
  width: 100%;
}
/* Icon-only action cells don't overflow */
.supply-sources-table td:last-child,
.supply-sources-table th:last-child {
  width: 72px;
  min-width: 60px;
  text-align: center;
  overflow: visible;
}

/* ── Date range calendar ──────────────────────────────────────── */
.supplies-date-panel { min-width: 260px; }
.cal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-title { font-size: 14px; font-weight: 600; color: #1e293b; }
.cal-nav { background: none; border: none; cursor: pointer; font-size: 14px; color: #64748b;
  padding: 2px 6px; border-radius: 4px; transition: background 0.12s; }
.cal-nav:hover { background: #f1f5f9; color: #334155; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-cell { display: flex; align-items: center; justify-content: center;
  height: 30px; font-size: 13px; border-radius: 4px; user-select: none; }
.cal-dow { font-size: 11px; font-weight: 600; color: #94a3b8; height: 24px; }
.cal-day { cursor: pointer; color: #374151; transition: background 0.1s, color 0.1s; }
.cal-day:hover { background: #e0e7ff; color: #3730a3; }
.cal-today { font-weight: 700; color: #6366f1; }
.cal-selected { background: #6366f1 !important; color: #fff !important; border-radius: 50% !important; font-weight: 700; }
.cal-in-range { background: #e0e7ff; color: #3730a3; border-radius: 0; }
.cal-range-start { border-radius: 50% 0 0 50% !important; }
.cal-range-end { border-radius: 0 50% 50% 0 !important; }
.cal-range-label { text-align: center; font-size: 12px; color: #475569; margin: 6px 0 2px; font-weight: 500; }
.cal-footer { display: flex; justify-content: center; margin-top: 6px; }

.supply-ttn-link {
  background: #eff6ff !important;
  border-color: #93c5fd !important;
  color: #1d4ed8 !important;
}
.supply-ttn-link:hover {
  background: #dbeafe !important;
  border-color: #60a5fa !important;
  color: #1e40af !important;
  box-shadow: 0 1px 4px rgba(59,130,246,0.15) !important;
}
