/* ============================================================
   AIsendr — App-specific styles (sidebar shell + screens)
   Extends styles.css design tokens
   ============================================================ */

/* ============ APP SHELL ============ */
/* Sidebar is position:fixed, so main simply offsets by the sidebar width and
   fills ALL remaining space. Avoids grid-column miscalculations that left the
   content stuck at ~half width on large screens. */
.app-shell {
  min-height: 100vh;
  background: var(--surface);
}
.app-sidebar {
  background: var(--bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 30;
  width: 240px;
}
.app-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  margin-left: 240px;       /* clear the fixed sidebar */
  width: calc(100% - 240px); /* fill the rest of the viewport */
  min-height: 100vh;
}

/* Mobile: full-width layout, sidebar becomes drawer overlay */
@media (max-width: 768px) {
  .app-main {
    margin-left: 0;
    width: 100%;
  }
  .app-sidebar {
    width: 260px;
    transform: translateX(-100%);
    box-shadow: 4px 0 20px rgba(0,0,0,0.12);
  }
}

/* sidebar internals */
.sb-top {
  padding: 16px 16px 8px;
}
.sb-logo {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.025em;
  color: var(--text-1);
  margin-bottom: 12px;
}
.sb-logo .logo-mark {
  width: 24px; height: 24px;
  border-radius: 6px;
}
.sb-logo .logo-mark svg { width: 13px; height: 13px; }

.sb-search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12.5px;
  color: var(--text-3);
  margin-bottom: 8px;
  cursor: text;
  transition: border-color 160ms ease;
}
.sb-search:hover { border-color: var(--border-strong); }
.sb-search svg { color: var(--text-3); }
.sb-search kbd {
  margin-left: auto;
  font-family: 'Geist Mono', monospace;
  font-size: 10px;
  background: var(--bg-warm);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--text-3);
}

.sb-ws {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 140ms ease;
}
.sb-ws:hover { background: var(--surface-2); }
.sb-ws-mark {
  width: 30px; height: 30px;
  background: var(--primary);
  color: #fff;
  border-radius: 7px;
  display: grid; place-items: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}
.sb-ws-info { flex: 1; min-width: 0; }
.sb-ws-name {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-1);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sb-ws-plan {
  font-size: 11.5px;
  color: var(--text-3);
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 1px;
}
.sb-ws-plan .dot { width: 5px; height: 5px; background: var(--accent); border-radius: 50%; }
.sb-ws-chev {
  width: 16px; height: 16px;
  color: var(--text-3);
  flex-shrink: 0;
}

.sb-nav {
  flex: 1;
  padding: 4px 12px;
  overflow-y: auto;
}
.sb-section {
  margin-top: 14px;
}
.sb-section-title {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
  padding: 0 10px 6px;
}
.sb-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  font-size: 13px;
  font-weight: 450;
  color: var(--text-2);
  border-radius: 6px;
  margin-bottom: 1px;
  text-decoration: none;
  transition: background 120ms ease, color 120ms ease;
}
.sb-nav-item:hover { background: var(--surface-2); color: var(--text-1); }
.sb-nav-item svg { width: 15px; height: 15px; color: var(--text-3); flex-shrink: 0; }
.sb-nav-item:hover svg { color: var(--text-2); }
.sb-nav-item.active {
  background: var(--surface);
  color: var(--text-1);
  font-weight: 500;
  box-shadow: var(--shadow-sm);
}
.sb-nav-item.active svg { color: var(--primary); }
.sb-pill {
  margin-left: auto;
  background: var(--primary-tint);
  color: var(--primary);
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 999px;
}
.sb-tag-new {
  margin-left: auto;
  background: var(--accent);
  color: var(--text-1);
  font-size: 9px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 3px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.sb-foot {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding: 10px 12px;
}
.sb-user {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 8px;
  border-radius: 8px;
  cursor: pointer;
}
.sb-user:hover { background: var(--surface-2); }
.sb-user-av {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #25D366, #128C7E);
  color: #fff;
  display: grid; place-items: center;
  font-size: 11.5px;
  font-weight: 600;
  flex-shrink: 0;
}
.sb-user-info { flex: 1; min-width: 0; }
.sb-user-name { font-size: 13px; font-weight: 500; color: var(--text-1); }
.sb-user-email {
  font-size: 11px;
  color: var(--text-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============ PAGE HEADER ============ */
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: 24px 32px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 5;
}
.page-head h1 {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.025em;
  margin: 0;
}
.page-head .page-sub {
  font-size: 13.5px;
  color: var(--text-2);
  margin-top: 4px;
}
.page-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.page-body {
  padding: 24px 32px 80px;
  flex: 1;
  background: var(--bg);
}
@media (max-width: 768px) {
  .page-head {
    padding: 14px 16px;
    flex-direction: column;
    gap: 12px;
    top: 52px; /* below mobile topbar */
  }
  .page-head h1 { font-size: 19px; }
  .page-actions { width: 100%; }
  .page-actions .btn-app { flex: 1; justify-content: center; min-height: 40px; }
  .page-body { padding: 16px 16px 80px; }
}

/* ============ SHARED UI ============ */

/* generic card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.card-head h3 {
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
}
.card-head a {
  font-size: 12.5px;
  color: var(--text-2);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.card-head a:hover { color: var(--primary); }

/* pills/badges */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-2);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.pill .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--text-3); }
.pill.success { background: var(--primary-tint); color: var(--primary); border-color: transparent; }
.pill.success .dot { background: var(--primary); }
.pill.warn { background: rgba(232,163,61,0.13); color: #B57613; border-color: transparent; }
.pill.warn .dot { background: #E8A33D; }
.pill.danger { background: rgba(214,69,69,0.10); color: var(--danger); border-color: transparent; }
.pill.danger .dot { background: var(--danger); }
.pill.live .dot {
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,211,102,0.22);
  animation: pulse-soft 1.8s infinite;
}
.pill.live { background: rgba(37,211,102,0.12); color: #0a7d3a; border-color: transparent; }

/* tag chips (for table cells, etc.) */
.tag {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 500;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--bg-warm);
  color: var(--text-2);
  border: 1px solid var(--border);
}
.tag.tag-vip { background: rgba(232,163,61,0.13); color: #B57613; border-color: transparent; }
.tag.tag-new { background: var(--primary-tint); color: var(--primary); border-color: transparent; }
.tag.tag-cold { background: var(--surface-2); color: var(--text-3); }

/* table */
.dt {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.dt thead th {
  text-align: left;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
  padding: 10px 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
}
.dt tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-1);
  vertical-align: middle;
}
.dt tbody tr:hover { background: var(--bg); }
.dt tbody tr:last-child td { border-bottom: none; }
.dt .checkbox {
  appearance: none;
  width: 14px; height: 14px;
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  background: var(--surface);
  cursor: pointer;
  position: relative;
  vertical-align: middle;
}
.dt .checkbox:checked {
  background: var(--primary);
  border-color: var(--primary);
}
.dt .checkbox:checked::after {
  content: ''; position: absolute;
  left: 3px; top: 0;
  width: 4px; height: 8px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.row-id {
  display: flex;
  align-items: center;
  gap: 10px;
}
.row-av {
  width: 28px; height: 28px;
  border-radius: 50%;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  display: grid; place-items: center;
  flex-shrink: 0;
}
.row-name { font-size: 13px; font-weight: 500; color: var(--text-1); }
.row-meta { font-size: 11.5px; color: var(--text-3); margin-top: 1px; }

.icon-btn {
  width: 28px; height: 28px;
  border-radius: 6px;
  background: transparent;
  color: var(--text-2);
  border: 1px solid transparent;
  display: inline-grid; place-items: center;
  cursor: pointer;
  transition: all 140ms ease;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text-1); border-color: var(--border); }

/* toolbar (search + filters) */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.search-input {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 0 12px;
  height: 34px;
  flex: 1;
  min-width: 220px;
  max-width: 340px;
}
.search-input input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-size: 13px;
  color: var(--text-1);
}
.search-input input::placeholder { color: var(--text-3); }
.search-input svg { color: var(--text-3); }
.filter-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 500;
  padding: 6px 12px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  color: var(--text-2);
  cursor: pointer;
  transition: all 140ms ease;
  white-space: nowrap;
}
.filter-pill:hover { color: var(--text-1); border-color: var(--text-3); }
.filter-pill.active {
  background: var(--primary-tint);
  color: var(--primary);
  border-color: var(--primary);
}
.filter-pill svg { color: var(--text-3); }

.btn-app {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  height: 34px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-1);
  cursor: pointer;
  transition: all 140ms ease;
}
.btn-app:hover { border-color: var(--text-3); }
.btn-app.primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-app.primary:hover { background: var(--primary-hover); }

/* ============ DASHBOARD ============ */
.banner-status {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  background: var(--primary-tint);
  border: 1px solid var(--primary-tint-2);
  border-radius: var(--r-lg);
  margin-bottom: 22px;
}
.banner-status .bs-icon {
  width: 36px; height: 36px;
  background: var(--primary);
  color: #fff;
  border-radius: 9px;
  display: grid; place-items: center;
  flex-shrink: 0;
}
.bs-num { font-size: 15px; font-weight: 600; color: var(--text-1); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.bs-num .pill { background: var(--surface); border-color: var(--primary-tint-2); }
.bs-sub { font-size: 12.5px; color: var(--primary); margin-top: 2px; display: flex; gap: 10px; flex-wrap: wrap; }
.bs-sub b { color: var(--text-1); font-weight: 500; }
.banner-status .bs-actions { margin-left: auto; flex-shrink: 0; }

@media (max-width: 600px) {
  .banner-status { flex-wrap: wrap; }
  .banner-status .bs-actions { margin-left: 0; width: 100%; }
  .banner-status .bs-actions .btn-app { width: 100%; justify-content: center; }
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 22px;
}
@media (max-width: 980px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px) { .kpi-grid { grid-template-columns: 1fr; } }
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px;
}
.kpi-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.kpi-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-top: 8px;
  gap: 12px;
}
.kpi-val {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.05;
  color: var(--text-1);
}
.kpi-delta {
  font-size: 11.5px;
  font-weight: 500;
  padding: 1px 6px 1px 4px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-top: 6px;
}
.kpi-delta.up { color: var(--primary); background: var(--primary-tint); }
.kpi-delta.down { color: var(--danger); background: rgba(214,69,69,0.10); }
.kpi-spark { width: 80px; height: 32px; }

.split-2 {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 14px;
  margin-bottom: 22px;
}
@media (max-width: 980px) { .split-2 { grid-template-columns: 1fr; } }

/* mini campaign rows */
.mini-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  align-items: center;
  font-size: 13px;
}
.mini-row:last-child { border-bottom: none; padding-bottom: 0; }
.mini-row:first-child { padding-top: 0; }
.mini-row .mr-name { font-weight: 500; color: var(--text-1); }
.mini-row .mr-meta { font-size: 11.5px; color: var(--text-3); margin-top: 1px; }
.mini-row .mr-stat { font-size: 12.5px; color: var(--text-2); text-align: right; }
.mini-row .mr-stat b { color: var(--text-1); font-weight: 600; }

/* activity feed */
.feed { display: flex; flex-direction: column; }
.feed-item {
  display: flex;
  gap: 11px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.feed-item:last-child { border-bottom: none; }
.feed-icon {
  width: 26px; height: 26px;
  border-radius: 50%;
  display: grid; place-items: center;
  flex-shrink: 0;
}
.feed-icon.in { background: var(--primary-tint); color: var(--primary); }
.feed-icon.bot { background: rgba(91,108,255,0.13); color: #5B6CFF; }
.feed-icon.alert { background: rgba(232,163,61,0.13); color: #B57613; }
.feed-text { flex: 1; min-width: 0; }
.feed-text b { font-weight: 600; }
.feed-time { font-size: 11px; color: var(--text-3); margin-top: 2px; }

/* quick actions grid */
.qa-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
@media (max-width: 900px) { .qa-grid { grid-template-columns: repeat(2, 1fr); } }
.qa {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px;
  cursor: pointer;
  transition: all 160ms ease;
  display: flex;
  gap: 12px;
  align-items: center;
}
.qa:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.qa-icon {
  width: 36px; height: 36px;
  border-radius: 9px;
  background: var(--primary-tint);
  color: var(--primary);
  display: grid; place-items: center;
  flex-shrink: 0;
}
.qa h4 { font-size: 13.5px; font-weight: 600; margin: 0; color: var(--text-1); }
.qa p { font-size: 11.5px; color: var(--text-2); margin-top: 1px; }

/* ============ TEMPLATES grid ============ */
.tpl-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}
@media (max-width: 960px) { .tpl-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px) { .tpl-grid { grid-template-columns: 1fr; } }

.tpl-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color 160ms ease, transform 160ms ease;
}
.tpl-card:hover { border-color: var(--border-strong); transform: translateY(-2px); }
.tpl-preview {
  background: #ECE5DD;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  min-height: 180px;
}
.tpl-bubble {
  background: #fff;
  border-radius: 8px;
  border-top-left-radius: 2px;
  padding: 0;
  overflow: hidden;
  font-size: 11.5px;
  line-height: 1.4;
  color: #111;
  box-shadow: 0 1px 0.5px rgba(0,0,0,0.06);
  max-width: 88%;
}
.tpl-media {
  background: linear-gradient(135deg, #128C7E, #25D366);
  color: #fff;
  padding: 14px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.tpl-body { padding: 9px 11px; }
.tpl-btn {
  border-top: 1px solid #eee;
  padding: 7px;
  text-align: center;
  color: #128C7E;
  font-weight: 500;
  font-size: 11px;
}
.tpl-meta {
  padding: 12px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.tpl-meta h4 { font-size: 13px; font-weight: 600; margin: 0; }
.tpl-meta .row-meta { font-size: 11.5px; color: var(--text-3); }
.tpl-status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 14px 10px;
  border-top: 1px solid var(--border);
  margin-top: auto;
}

/* ============ CAMPAIGNS list ============ */
.cmp-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px 18px;
  display: grid;
  grid-template-columns: 1.4fr 1fr 1.3fr auto;
  gap: 16px;
  align-items: center;
  margin-bottom: 8px;
  transition: border-color 140ms ease;
}
.cmp-row:hover { border-color: var(--border-strong); }
@media (max-width: 880px) { .cmp-row { grid-template-columns: 1fr; } }

.cmp-head h4 { font-size: 14px; font-weight: 600; margin: 0 0 4px; }
.cmp-head .pill + .pill { margin-left: 6px; }
.cmp-meta { font-size: 12px; color: var(--text-3); }

.cmp-aud { font-size: 12.5px; color: var(--text-2); }
.cmp-aud b { color: var(--text-1); font-weight: 600; font-size: 14px; }

.cmp-bars { display: flex; flex-direction: column; gap: 6px; }
.cmp-bar-row { display: flex; align-items: center; gap: 10px; font-size: 11px; color: var(--text-3); }
.cmp-bar-row .lbl { width: 56px; flex-shrink: 0; }
.cmp-bar-row .bar { flex: 1; height: 5px; background: var(--bg-warm); border-radius: 3px; overflow: hidden; }
.cmp-bar-row .bar > div { height: 100%; background: var(--primary); border-radius: 3px; }
.cmp-bar-row .val { font-weight: 600; color: var(--text-1); font-size: 11.5px; min-width: 38px; text-align: right; }

/* ============ INBOX ============ */
.inbox-shell {
  display: grid;
  grid-template-columns: 280px 1fr 300px;
  height: calc(100vh - 64px);
  background: var(--surface);
  border-top: 1px solid var(--border);
}
@media (max-width: 1100px) {
  .inbox-shell { grid-template-columns: 260px 1fr; }
  .ib-details { display: none; }
}
@media (max-width: 768px) {
  .inbox-shell {
    grid-template-columns: 1fr;
    height: calc(100vh - 52px); /* account for mobile topbar */
  }
  /* Default: show list, hide chat */
  .ib-chat { display: none; }
  .ib-list { display: flex; }
  /* When a conversation is selected */
  .inbox-shell.show-chat .ib-list { display: none; }
  .inbox-shell.show-chat .ib-chat { display: flex; }
}

.ib-col {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.ib-list { border-right: 1px solid var(--border); }
.ib-details { border-left: 1px solid var(--border); background: var(--bg); }

.ib-list-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.ib-list-tabs {
  display: flex;
  gap: 4px;
  margin-top: 10px;
  font-size: 12px;
}
.ib-list-tabs span {
  padding: 4px 10px;
  border-radius: 999px;
  color: var(--text-3);
  cursor: pointer;
}
.ib-list-tabs span.on { background: var(--primary-tint); color: var(--primary); font-weight: 500; }

.ib-threads { flex: 1; overflow-y: auto; }
.ib-thread {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  border-left: 2px solid transparent;
}
.ib-thread:hover { background: var(--bg); }
.ib-thread.on {
  background: var(--primary-tint);
  border-left-color: var(--primary);
}
.ib-th-body { flex: 1; min-width: 0; }
.ib-th-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font-size: 13px;
}
.ib-th-row b { font-weight: 600; color: var(--text-1); }
.ib-th-row span { font-size: 11px; color: var(--text-3); flex-shrink: 0; }
.ib-th-prev {
  font-size: 12px;
  color: var(--text-2);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
}
.ib-th-tags { display: flex; gap: 5px; margin-top: 6px; }
.ib-unread {
  background: var(--primary);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  padding: 0 5px;
  display: grid; place-items: center;
  flex-shrink: 0;
}

/* chat panel */
.ib-chat-head {
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
}
.ib-chat-actions { display: flex; gap: 6px; margin-left: auto; }
.ib-chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #ECE5DD;
  background-image:
    radial-gradient(circle at 10% 10%, rgba(0,0,0,0.02) 1px, transparent 1px),
    radial-gradient(circle at 80% 60%, rgba(0,0,0,0.02) 1px, transparent 1px);
  background-size: 28px 28px;
}
.ib-day {
  align-self: center;
  background: rgba(225, 245, 254, 0.92);
  color: #54656F;
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 6px;
  margin: 6px 0;
}
.ib-bubble {
  max-width: 60%;
  padding: 8px 12px 6px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.45;
  color: #111;
  box-shadow: 0 1px 0.5px rgba(0,0,0,0.06);
  position: relative;
}
.ib-bubble.in { background: #fff; align-self: flex-start; border-top-left-radius: 2px; }
.ib-bubble.out { background: #D9FDD3; align-self: flex-end; border-top-right-radius: 2px; }
.ib-bubble .ib-time {
  display: inline-block;
  font-size: 10px;
  color: #667781;
  margin-left: 6px;
  vertical-align: bottom;
}
.ib-bubble .ib-check { color: #53BDEB; }

.ib-composer {
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.ib-composer-tools {
  display: flex;
  gap: 4px;
  margin-bottom: 10px;
}
.ib-tool {
  width: 26px; height: 26px;
  border-radius: 6px;
  background: transparent;
  color: var(--text-3);
  display: grid; place-items: center;
  cursor: pointer;
}
.ib-tool:hover { background: var(--surface-2); color: var(--text-1); }
.ib-composer-input {
  display: flex;
  gap: 10px;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}
.ib-composer-input input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-size: 13.5px;
  color: var(--text-1);
}
.ib-send {
  width: 32px; height: 32px;
  background: var(--primary);
  color: #fff;
  border-radius: 8px;
  display: grid; place-items: center;
  cursor: pointer;
}

/* contact details */
.ib-det-head {
  padding: 24px 20px 16px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.ib-det-av {
  width: 64px; height: 64px;
  border-radius: 50%;
  margin: 0 auto 10px;
  background: linear-gradient(135deg, #25D366, #128C7E);
  color: #fff;
  display: grid; place-items: center;
  font-size: 22px;
  font-weight: 600;
}
.ib-det-name { font-size: 15px; font-weight: 600; }
.ib-det-meta { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.ib-det-actions { display: flex; gap: 6px; justify-content: center; margin-top: 12px; }
.ib-det-actions .icon-btn { width: 32px; height: 32px; border-color: var(--border); }

.ib-det-section { padding: 16px 20px; border-bottom: 1px solid var(--border); }
.ib-det-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  margin-bottom: 10px;
}
.ib-det-prop {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  padding: 4px 0;
}
.ib-det-prop .k { color: var(--text-3); }
.ib-det-prop .v { color: var(--text-1); font-weight: 500; text-align: right; max-width: 60%; }
.ib-det-tags { display: flex; flex-wrap: wrap; gap: 6px; }

/* ============ AUTOMATIONS ============ */
.auto-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
@media (max-width: 880px) { .auto-grid { grid-template-columns: 1fr; } }
.auto-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px;
}
.auto-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 14px;
  gap: 12px;
}
.auto-icon {
  width: 36px; height: 36px;
  border-radius: 9px;
  background: var(--primary-tint);
  color: var(--primary);
  display: grid; place-items: center;
  flex-shrink: 0;
}
.auto-card h3 { font-size: 14.5px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
.auto-card .auto-desc { font-size: 12.5px; color: var(--text-2); margin-top: 4px; }

.auto-flow {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
  font-size: 11.5px;
  color: var(--text-2);
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.auto-step {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  white-space: nowrap;
}
.auto-step.trigger { background: var(--primary-tint); color: var(--primary); border-color: transparent; }
.auto-arrow { color: var(--text-3); }

.auto-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.auto-stat-mini { padding: 6px 0; border-right: 1px solid var(--border); padding-right: 12px; }
.auto-stat-mini:last-child { border-right: none; }
.auto-stat-mini .v { font-size: 17px; font-weight: 600; letter-spacing: -0.02em; }
.auto-stat-mini .k { font-size: 11px; color: var(--text-3); }

/* ============ ANALYTICS ============ */
.an-chart {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 22px;
  margin-bottom: 14px;
}
.an-chart svg { width: 100%; height: 260px; display: block; }
.an-legend {
  display: flex;
  gap: 18px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.an-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-2);
}
.an-legend-item .sw {
  width: 10px; height: 10px;
  border-radius: 3px;
}

.an-heatmap {
  display: grid;
  grid-template-columns: 44px repeat(24, 1fr);
  gap: 2px;
}
.an-heat-label {
  font-size: 10px;
  color: var(--text-3);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 6px;
}
.an-heat-cell {
  height: 18px;
  border-radius: 2px;
  background: var(--primary-tint);
  position: relative;
}

/* ============ STUB SCREEN ============ */
.stub-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  max-width: 480px;
  margin: 60px auto;
}
.stub-icon {
  width: 56px; height: 56px;
  border-radius: 14px;
  background: var(--primary-tint);
  color: var(--primary);
  display: grid; place-items: center;
  margin-bottom: 16px;
}
.stub-empty h2 { font-size: 22px; font-weight: 600; letter-spacing: -0.025em; margin: 0 0 8px; }
.stub-empty p { font-size: 14px; color: var(--text-2); line-height: 1.55; }
.stub-empty .btn-app { margin-top: 18px; }

/* table containers */
.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.table-card .dt-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
@media (max-width: 640px) {
  .dt thead th, .dt tbody td { padding: 10px 12px; }
  .dt { min-width: 520px; }
}
.table-foot {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-3);
}
.table-foot .pages {
  display: flex;
  gap: 4px;
}
.table-foot .pages button {
  width: 28px; height: 28px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-2);
  font-size: 12px;
  cursor: pointer;
}
.table-foot .pages button.on {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* screen visibility */
.screen { display: none; }
.screen.active { display: block; }
.inbox-shell.screen { display: none; }
.inbox-shell.screen.active { display: grid; }

/* Mobile topbar: add back button for inbox chat */
.ib-back-btn {
  display: none;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--text-2);
  font-size: 13px;
  cursor: pointer;
  padding: 4px 0;
  margin-right: 4px;
}
@media (max-width: 768px) {
  .ib-back-btn { display: inline-flex; }
}

/* Touch target minimum sizes */
@media (max-width: 768px) {
  .btn-app { min-height: 44px; padding: 0 14px; }
  .filter-pill { min-height: 40px; }
  .icon-btn { width: 40px; height: 40px; }
  .ib-send { width: 40px; height: 40px; }
  .sb-nav-item { min-height: 44px; }
  /* Inbox chat header: keep actions compact */
  .ib-chat-head { padding: 10px 14px; gap: 8px; }
  .ib-chat-actions { gap: 4px; }
  .ib-chat-actions .btn-app { padding: 0 10px; font-size: 12px; min-height: 36px; }
  .ib-bubble { max-width: 80%; }
  .ib-chat-body { padding: 14px 12px; }
}

/* Campaigns row stacking on mobile */
@media (max-width: 600px) {
  .cmp-row { padding: 14px 16px; gap: 12px; }
  .cmp-row > *:not(:first-child) { padding-top: 8px; border-top: 1px solid var(--border); }
}

/* Mini rows on mobile */
@media (max-width: 480px) {
  .mini-row { grid-template-columns: 1fr auto; gap: 8px; }
  .mini-row .mr-stat:not(:last-child) { display: none; }
}

/* Quick actions: 2 cols on mobile */
@media (max-width: 480px) {
  .qa-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .qa { padding: 12px; flex-direction: column; gap: 8px; }
  .qa p { display: none; }
}

/* KPI grid: always 2 cols on small, 1 on very small */
@media (max-width: 380px) {
  .kpi-grid { grid-template-columns: 1fr; }
}

/* Analytics heatmap: scrollable on mobile */
@media (max-width: 640px) {
  .an-heatmap-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .an-heatmap { min-width: 500px; }
}

/* Toolbar wraps properly */
@media (max-width: 480px) {
  .toolbar { gap: 8px; }
  .search-input { max-width: 100%; min-width: 0; }
}

/* Two-column grids: stack on mobile */
@media (max-width: 480px) {
  .two-col-grid { grid-template-columns: 1fr !important; }
}

/* Forms: full-width inputs on mobile */
@media (max-width: 600px) {
  .input { font-size: 16px !important; } /* prevent iOS zoom */
}
