/* ═══════════════════════════════════════════════════════════════
   css/main.css — Apana Vyapar App Styles
   Covers: design tokens, layout, sidebar, topbar, cards,
           forms, tables, badges, buttons, toast, dialogs
═══════════════════════════════════════════════════════════════ */

/* ── Design Tokens ──────────────────────────────────────────── */
:root {
  --ink:          #0d0d14;
  --surface:      #f7f6f2;
  --card:         #ffffff;
  --border:       #e8e4dc;
  --primary:      #2563eb;
  --primary-light:#dbeafe;
  --primary-dark: #1d4ed8;
  --saffron:      #f97316;
  --saffron-light:#fff7ed;
  --green:        #16a34a;
  --green-light:  #dcfce7;
  --red:          #dc2626;
  --red-light:    #fee2e2;
  --amber:        #d97706;
  --amber-light:  #fef3c7;
  --purple:       #7c3aed;
  --purple-light: #ede9fe;
  --muted:        #6b7280;
  --muted-light:  #f3f4f6;
  --sidebar-w:    230px;
  --topbar-h:     58px;
  --r:            10px;
  --r-sm:         6px;
  --shadow:       0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  --shadow-lg:    0 4px 24px rgba(0,0,0,.12);
}

/* ── Reset ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  font-family: 'Sora', system-ui, sans-serif;
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

/* ── App Layout ──────────────────────────────────────────────── */
/* .active required — index.php's generic .screen{display:none}/.screen.active{display:flex}
   toggle must still control visibility; this only fixes layout once active. */
#screen-app.active { height: 100vh; overflow: hidden; display: flex; flex-direction: column; }
.app-inner  { display: flex; flex: 1; overflow: hidden; }

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--ink);
  display: flex; flex-direction: column; overflow: hidden;
  transition: transform .3s;
}
.brand { padding: 18px 16px 14px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand-name { font-size: 17px; font-weight: 800; color: #fff; letter-spacing: -.3px; }
.brand-name span { color: var(--saffron); }
.brand-sub  { font-size: 10px; color: rgba(255,255,255,.35); margin-top: 2px; letter-spacing: .08em; text-transform: uppercase; }

.nav { flex: 1; overflow-y: auto; padding: 10px 8px; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav-section { font-size: 9.5px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: rgba(255,255,255,.28); padding: 12px 8px 5px; }
.nav-item {
  display: flex; align-items: center; gap: 9px; padding: 9px 10px;
  border-radius: 7px; cursor: pointer; font-size: 13px; font-weight: 500;
  color: rgba(255,255,255,.6); transition: all .18s; margin-bottom: 1px;
}
.nav-item .ni-icon { font-size: 15px; width: 20px; text-align: center; flex-shrink: 0; }
.nav-item:hover  { background: rgba(255,255,255,.07); color: rgba(255,255,255,.9); }
.nav-item.active { background: var(--primary); color: #fff; font-weight: 600; }
.nav-admin-only  { display: none; }
body.role-admin .nav-admin-only { display: flex; }

.sidebar-user {
  padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.08);
  display: flex; align-items: center; gap: 10px;
}
.sidebar-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg, var(--saffron), #f59e0b);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 800; color: #fff; flex-shrink: 0;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name { font-size: 12px; font-weight: 700; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-sub  { font-size: 10px; color: rgba(255,255,255,.35); }

.sidebar-ref-box {
  margin: 0 10px 10px; background: rgba(255,255,255,.07);
  border-radius: 8px; padding: 8px 10px; display: none;
}
.sidebar-ref-label { font-size: 9px; font-weight: 700; color: rgba(255,255,255,.4); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 4px; }
.sidebar-ref-code  { font-size: 14px; font-weight: 900; color: #a78bfa; letter-spacing: 3px; font-family: monospace; }
.sidebar-ref-count { font-size: 9px; color: rgba(255,255,255,.3); margin-top: 3px; }

/* ── Mobile-only header (shown at @media max-width:768px below) ─ */
.mobile-header { display: none; }

/* ── App Top Bar — desktop hidden (sidebar already shows the same
   branding); shown on mobile where its menu button is the only way
   to open the off-canvas sidebar (see @media max-width:768px) ──── */
.topbar {
  display: none;
  align-items: center;
  gap: 10px;
  position: sticky; top: 0; z-index: 200;
  background: #111827;
  padding: 0 16px;
  height: 52px;
  box-shadow: 0 2px 12px rgba(0,0,0,.35);
  flex-shrink: 0;
}
.topbar-menu-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,.1);
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: 20px;
  width: 38px; height: 38px;
  flex-shrink: 0;
  cursor: pointer;
  transition: background .15s;
  -webkit-tap-highlight-color: transparent;
}
.topbar-menu-btn:hover { background: rgba(255,255,255,.18); }
.topbar-logo-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
  flex-shrink: 0;
}
.topbar-logo-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}
.tl-v {
  font-size: 13px;
  font-weight: 900;
  color: #fff;
  letter-spacing: .1em;
  font-family: 'Sora', sans-serif;
}
.tl-l {
  font-size: 9.5px;
  font-weight: 700;
  color: rgba(255,255,255,.5);
  letter-spacing: .18em;
  font-family: 'Sora', sans-serif;
}
.topbar-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  font-family: 'Sora', sans-serif;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Lang switcher in topbar */
.lang-btn-app {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--muted-light);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  font-family: 'Sora', sans-serif;
  white-space: nowrap;
  transition: background .15s;
}
.lang-btn-app:hover { background: #e5e7eb; }
.topbar-avatar { width: 26px; height: 26px; border-radius: 50%; background: linear-gradient(135deg,var(--primary),#7c3aed); display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 800; color: #fff; }
.topbar-username { font-size: 12px; font-weight: 700; color: var(--ink); }
.topbar-company  { font-size: 10px; color: var(--muted); }
#topbar-trial-badge { display: none; font-size: 11px; font-weight: 700; padding: 3px 10px; border-radius: 20px; background: var(--amber-light); color: var(--amber); border: 1px solid #fcd34d; white-space: nowrap; }

/* ── Main / Content ──────────────────────────────────────────── */
.main    { flex: 1; display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.content { flex: 1; overflow-y: auto; padding: 18px; }
.tab     { display: none; }
.tab.active { display: block; animation: slideUp .22s ease; }
@keyframes slideUp { from{opacity:0;transform:translateY(8px)} to{opacity:1;transform:translateY(0)} }

/* ── Page Header ─────────────────────────────────────────────── */
.ph { margin-bottom: 18px; }
.ph h2 { font-size: 20px; font-weight: 800; color: var(--ink); letter-spacing: -.3px; }
.ph p  { font-size: 12px; color: var(--muted); margin-top: 3px; }

/* ── Cards ───────────────────────────────────────────────────── */
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); border: 1px solid var(--border); margin-bottom: 16px; overflow: hidden; }
.card-header { padding: 13px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; background: #fafaf8; }
.card-header h3 { font-size: 13px; font-weight: 700; color: var(--ink); }
.card-body      { padding: 18px; }
.card-body.tight{ padding: 14px; }

/* ── KPIs ────────────────────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { border-radius: var(--r); padding: 16px 18px; display: flex; flex-direction: column; gap: 5px; position: relative; overflow: hidden; }
.kpi::before { content: ''; position: absolute; top: -20px; right: -20px; width: 80px; height: 80px; border-radius: 50%; background: rgba(255,255,255,.1); }
.kpi-label { font-size: 10.5px; font-weight: 600; opacity: .85; text-transform: uppercase; letter-spacing: .06em; }
.kpi-value { font-size: 22px; font-weight: 800; font-family: 'JetBrains Mono', monospace; letter-spacing: -1px; }
.kpi-sub   { font-size: 10px; opacity: .7; }

/* ── Forms ───────────────────────────────────────────────────── */
.form-grid { display: grid; gap: 12px; margin-bottom: 12px; }
.fg { display: flex; flex-direction: column; gap: 4px; }
.fg label { font-size: 10.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.fg input, .fg select, .fg textarea {
  width: 100%; padding: 8px 11px; border: 1.5px solid var(--border);
  border-radius: var(--r-sm); font-size: 13px; font-family: 'Sora', sans-serif;
  color: var(--ink); background: #fff; outline: none;
  transition: border-color .18s, box-shadow .18s;
}
.fg select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath fill='%236b7280' d='M1 1l5 5 5-5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; appearance: none; -webkit-appearance: none; }
.fg input:focus, .fg select:focus, .fg textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.fg textarea { resize: vertical; min-height: 60px; }
.fg input.err, .fg select.err { border-color: var(--red); }
.cols-2 { grid-template-columns: 1fr 1fr; }
.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.cols-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }
.col-full { grid-column: 1 / -1; }

.field-chip-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.field-chip { display: inline-flex; align-items: center; gap: 6px; background: var(--primary-light); color: var(--primary-dark); border-radius: 20px; padding: 5px 6px 5px 12px; font-size: 12px; font-weight: 600; }
.field-chip-type { font-weight: 400; opacity: .75; font-size: 10px; text-transform: uppercase; margin-left: 2px; }
.field-chip button { background: none; border: none; color: inherit; cursor: pointer; font-size: 12px; line-height: 1; padding: 2px 4px; opacity: .7; }
.field-chip button:hover { opacity: 1; }

.segment-condition-row { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 8px; }
.segment-condition-row .fg { margin-bottom: 0; }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn { border: none; border-radius: var(--r-sm); padding: 8px 16px; cursor: pointer; font-size: 13px; font-weight: 600; font-family: 'Sora', sans-serif; transition: all .18s; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-saffron { background: var(--saffron); color: #fff; }
.btn-saffron:hover { opacity: .9; }
.btn-success { background: var(--green); color: #fff; }
.btn-success:hover { opacity: .9; }
.btn-danger  { background: var(--red); color: #fff; }
.btn-danger:hover  { opacity: .9; }
.btn-ghost   { background: var(--muted-light); color: var(--ink); border: 1px solid var(--border); }
.btn-ghost:hover   { background: var(--border); }
.btn-outline { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-outline:hover { background: var(--primary-light); }
.btn-logout  { background: none; border: 1.5px solid var(--border); color: var(--red); font-weight: 600; }
.btn-logout:hover { background: var(--red-light); border-color: #fca5a5; }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 5px; }
.btn-xs { padding: 3px 7px; font-size: 11px; border-radius: 4px; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.share-opt { display:flex; align-items:center; gap:9px; padding:9px 14px; border-radius:7px; text-decoration:none; color:#111827; font-size:13px; font-weight:600; transition:background .15s; white-space:nowrap; }
.share-opt:hover { background:#f3f4f6; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ── Tables ──────────────────────────────────────────────────── */
.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.tbl thead tr { background: var(--muted-light); }
.tbl th { padding: 9px 12px; text-align: left; font-size: 10.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; border-bottom: 2px solid var(--border); white-space: nowrap; }
.tbl td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tbody tr:hover { background: #fafaf8; }
.tbl tbody tr:last-child td { border-bottom: none; }
.mono, .tbl .mono { font-family: 'JetBrains Mono', monospace; }
.tbl .bold { font-weight: 700; }
.tbl .r    { text-align: right; }
.tbl .c    { text-align: center; }
.small { font-size: 11px; }
.muted { color: var(--muted); }
.team-role-select { border: 1.5px solid var(--border); border-radius: 8px; padding: 5px 8px; font-size: 12px; font-family: 'Sora', sans-serif; background: var(--card); color: var(--ink); }
.team-role-select:disabled { opacity: .6; cursor: not-allowed; }
.text-red   { color: var(--red); }
.text-green { color: var(--green); }

/* ── Badges ──────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 20px; font-size: 10.5px; font-weight: 700; white-space: nowrap; }
.badge-green  { background: var(--green-light);   color: var(--green); }
.badge-red    { background: var(--red-light);     color: var(--red); }
.badge-amber  { background: var(--amber-light);   color: var(--amber); }
.badge-blue   { background: var(--primary-light); color: var(--primary); }
.badge-purple { background: var(--purple-light);  color: var(--purple); }

/* ── Info Box ────────────────────────────────────────────────── */
.info-box { background: var(--primary-light); border-left: 3px solid var(--primary); border-radius: var(--r-sm); padding: 9px 13px; font-size: 12px; color: var(--primary-dark); margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }

/* ── Section Title ───────────────────────────────────────────── */
.sec-title { font-size: 10px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--primary); margin: 18px 0 10px; display: flex; align-items: center; gap: 8px; }
.sec-title::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ── Sale Item Rows ──────────────────────────────────────────── */
.items-header { display: grid; grid-template-columns: 2.2fr 70px 80px 85px 60px 95px 30px; gap: 5px; padding: 8px 10px; background: var(--ink); border-radius: 7px 7px 0 0; color: rgba(255,255,255,.8); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.item-row     { display: grid; grid-template-columns: 2.2fr 70px 80px 85px 60px 95px 30px; gap: 5px; padding: 6px 10px; border: 1px solid var(--border); border-top: none; background: #fff; align-items: center; }
.item-row:last-child { border-radius: 0 0 7px 7px; }
.item-row input, .item-row select { border: 1px solid var(--border); border-radius: 5px; padding: 6px 8px; font-size: 12px; font-family: 'Sora', sans-serif; width: 100%; outline: none; transition: border-color .15s; }
.item-row input:focus, .item-row select:focus { border-color: var(--primary); }
.item-row .ro { background: var(--muted-light); color: var(--muted); font-family: 'JetBrains Mono', monospace; }
.btn-del-row  { background: none; border: none; cursor: pointer; color: #d1d5db; font-size: 15px; padding: 4px; border-radius: 4px; transition: all .15s; display: flex; align-items: center; justify-content: center; }
.btn-del-row:hover { color: var(--red); background: var(--red-light); }
.add-row-btn  { width: 100%; margin-top: 5px; background: var(--primary-light); color: var(--primary); border: 2px dashed var(--primary); border-radius: 7px; padding: 8px; font-size: 13px; font-weight: 700; cursor: pointer; font-family: 'Sora', sans-serif; transition: all .15s; }
.add-row-btn:hover { background: #bfdbfe; }

/* ── Grand Total Bar ─────────────────────────────────────────── */
.grand-bar { display: flex; align-items: center; justify-content: space-between; background: var(--ink); color: #fff; border-radius: 8px; padding: 12px 18px; margin-top: 10px; }
.grand-bar .label  { font-size: 12px; font-weight: 600; opacity: .7; }
.grand-bar .amount { font-family: 'JetBrains Mono', monospace; font-size: 22px; font-weight: 700; color: var(--saffron); }

/* ── Password Strength Bar ───────────────────────────────────── */
.pw-bar-wrap { height: 3px; background: var(--border); border-radius: 4px; margin-top: 5px; overflow: hidden; }
.pw-bar      { height: 100%; width: 0; border-radius: 4px; transition: width .3s, background .3s; }

/* ── Toast ───────────────────────────────────────────────────── */
.toast { position: fixed; bottom: 20px; right: 20px; z-index: 9999; padding: 11px 18px; border-radius: 8px; font-size: 13px; font-weight: 600; color: #fff; box-shadow: var(--shadow-lg); animation: slideUp .3s ease; display: flex; align-items: center; gap: 8px; }

/* ── Empty State ─────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 32px; color: var(--muted); }
.empty-state .e-icon { font-size: 36px; margin-bottom: 8px; }
.empty-state p { font-size: 13px; }

/* ── Overlay & Dialog ────────────────────────────────────────── */
.overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 2000; align-items: center; justify-content: center; backdrop-filter: blur(4px); }
.overlay.show { display: flex; }
.dialog { background: #fff; border-radius: 14px; padding: 28px 24px; width: 100%; max-width: 400px; box-shadow: var(--shadow-lg); animation: dialogIn .22s ease; margin: 20px; }
@keyframes dialogIn { from{opacity:0;transform:scale(.92)} to{opacity:1;transform:scale(1)} }
.dialog-icon { font-size: 36px; text-align: center; margin-bottom: 10px; }
.dialog h3   { font-size: 18px; font-weight: 800; text-align: center; margin-bottom: 6px; }
.dialog p    { font-size: 12.5px; color: var(--muted); text-align: center; margin-bottom: 20px; line-height: 1.6; }
.dialog-btns { display: flex; gap: 8px; }
.dialog-btns .btn { flex: 1; justify-content: center; }

/* ── Mobile Sidebar Overlay ──────────────────────────────────── */
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 199; }

/* ── Low Stock Row ───────────────────────────────────────────── */
.low-stock-row  { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 12px; }
.low-name       { flex: 1; font-weight: 600; }
.low-qty        { font-family: 'JetBrains Mono', monospace; font-weight: 700; }
.low-qty.zero   { color: var(--red); }
.low-qty.low    { color: var(--amber); }
.low-min        { color: var(--muted); font-size: 11px; }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Show mobile header */
  .mobile-header { display: flex; }
  /* Topbar: only needed on mobile, for its sidebar-open menu button */
  .topbar { display: flex; }
  /* Sidebar: slide in from left */
  #screen-app .sidebar { position: fixed; top: 0; left: 0; bottom: 0; z-index: 200; transform: translateX(-100%); width: 270px; transition: transform .25s ease; }
  #screen-app .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.show { display: block; }
  /* Grids: single column */
  .cols-2, .cols-3, .cols-4 { grid-template-columns: 1fr !important; }
  .form-grid[style] { grid-template-columns: 1fr !important; }
  /* KPI: 2 columns */
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  /* Tables: horizontal scroll */
  .tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  /* Inputs: prevent iOS zoom, larger touch targets */
  .fg input, .fg select, .fg textarea { font-size: 16px !important; min-height: 44px; }
  .fg label { font-size: 12px; }
  /* Buttons: bigger touch targets */
  .btn { min-height: 44px; padding: 10px 16px; font-size: 13px; }
  .btn-group { flex-wrap: wrap; gap: 8px; }
  /* Item rows: compressed columns */
  .items-header, .item-row { grid-template-columns: 2fr 60px 80px 60px 90px 30px; font-size: 11px; }
  /* Purchase item rows: stack on mobile */
  .pur-row { grid-template-columns: 1fr 1fr !important; }
  .pur-row > div:last-of-type { grid-column: 1 / -1; }
  #pur-items-wrap { overflow-x: auto; }
  /* Typography */
  .ph h2 { font-size: 18px; }
  .ph p  { font-size: 12px; }
  .card-header h3 { font-size: 14px; }
  .card-header { flex-wrap: wrap; gap: 8px; }
  /* Quotation layout: single column */
  #app-qt-layout { grid-template-columns: 1fr !important; }
  .sidebar-user { flex-wrap: wrap; gap: 6px; }
  /* Content padding */
  .content { padding: 12px !important; }
  .card-body { padding: 12px !important; }
}
@media (max-width: 480px) {
  /* Item rows: hide unit & disc columns */
  .items-header, .item-row { grid-template-columns: 2fr 55px 75px 80px 28px; font-size: 10.5px; }
  .items-header .ih-unit, .item-row .ir-unit,
  .items-header .ih-disc, .item-row .ir-disc { display: none; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  /* Item row inputs: taller */
  .item-row input, .item-row select { min-height: 38px; font-size: 14px !important; padding: 4px 6px; }
}
@media (max-width: 420px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .mob-title { font-size: 14px; }
  .items-header, .item-row { grid-template-columns: 2fr 50px 70px 75px 26px; font-size: 10px; }
}

/* ═══════════════════════════════════════════════════════════════
   WhatsApp module additions — status pills + chat inbox
   Not present in Vyaparlekha's original main.css; added here rather
   than a separate stylesheet so the WA screens keep inheriting one
   design system.
═══════════════════════════════════════════════════════════════ */

/* ── Status pills (contacts / campaigns) ─────────────────────── */
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 20px; font-size: 10.5px; font-weight: 700; white-space: nowrap; }
.pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-optin  { background: var(--green-light); color: var(--green); }
.pill-optout { background: var(--red-light);   color: var(--red); }
.pill-pending{ background: var(--amber-light); color: var(--amber); }

/* ── Chat inbox: two-pane layout ─────────────────────────────── */
.inbox-layout { display: flex; height: calc(100vh - var(--topbar-h) - 140px); min-height: 420px; border: 1px solid var(--border); border-radius: var(--r); overflow: hidden; background: var(--card); box-shadow: var(--shadow); }

.inbox-list { width: 300px; flex-shrink: 0; border-right: 1px solid var(--border); overflow-y: auto; background: var(--card); }
.inbox-list-item { display: flex; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background .12s; }
.inbox-list-item:hover { background: #fafaf8; }
.inbox-list-item.active { background: var(--primary-light); }
.inbox-avatar { width: 38px; height: 38px; border-radius: 50%; background: linear-gradient(135deg, var(--primary), #7c3aed); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 14px; flex-shrink: 0; }
.inbox-list-body { flex: 1; min-width: 0; }
.inbox-list-top { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.inbox-list-name { font-size: 13px; font-weight: 700; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inbox-list-time { font-size: 10px; color: var(--muted); flex-shrink: 0; }
.inbox-list-preview { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.inbox-unread-badge { background: var(--primary); color: #fff; font-size: 10px; font-weight: 800; min-width: 18px; height: 18px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; padding: 0 5px; flex-shrink: 0; }

.inbox-thread { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--surface); }
.inbox-thread-header { padding: 12px 18px; border-bottom: 1px solid var(--border); background: var(--card); font-weight: 700; font-size: 14px; flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.inbox-thread-header-actions { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.inbox-thread-header-actions select { border: 1.5px solid var(--border); border-radius: 8px; padding: 5px 8px; font-size: 12px; font-family: 'Sora', sans-serif; background: var(--card); color: var(--ink); max-width: 140px; }
.inbox-thread-body { flex: 1; display: flex; min-height: 0; }
.inbox-thread-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.inbox-empty { margin: auto; text-align: center; color: var(--muted); padding: 20px; }

.inbox-notes-panel { width: 260px; flex-shrink: 0; border-left: 1px solid var(--border); background: var(--card); display: flex; flex-direction: column; }
.inbox-notes-list { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.note-item { background: var(--amber-light); border-radius: 8px; padding: 8px 10px; font-size: 12px; line-height: 1.5; }
.note-item-meta { font-size: 10px; font-weight: 700; color: var(--muted); margin-top: 4px; }
.inbox-notes-composer { padding: 10px; border-top: 1px solid var(--border); flex-shrink: 0; }
.inbox-notes-composer textarea { width: 100%; min-height: 60px; resize: vertical; padding: 8px 10px; border: 1.5px solid var(--border); border-radius: 8px; font-size: 12px; font-family: 'Sora', sans-serif; outline: none; margin-bottom: 6px; }
.inbox-notes-composer textarea:focus { border-color: var(--primary); }

.canned-item { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 12px; line-height: 1.5; cursor: pointer; }
.canned-item:hover { border-color: var(--primary); background: var(--amber-light); }
.canned-item-title { font-weight: 700; margin-bottom: 2px; }
.canned-item-body { color: var(--muted); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

.subtab-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.bubble { max-width: 68%; padding: 8px 12px; border-radius: 14px; font-size: 13px; line-height: 1.5; position: relative; }
.bubble-in  { align-self: flex-start; background: #fff; border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.bubble-out { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.bubble-tag { display: inline-block; font-size: 9.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; opacity: .75; margin-bottom: 3px; }
.bubble-time { font-size: 9.5px; opacity: .65; margin-top: 3px; text-align: right; }

.inbox-composer { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border); background: var(--card); flex-shrink: 0; }
.inbox-composer input { flex: 1; padding: 10px 14px; border: 1.5px solid var(--border); border-radius: 20px; font-size: 13px; font-family: 'Sora', sans-serif; outline: none; }
.inbox-composer input:focus { border-color: var(--primary); }
.inbox-composer button { border-radius: 20px; }

.inbox-attach-panel { display: flex; gap: 8px; padding: 10px 12px 0; border-top: 1px solid var(--border); background: var(--card); flex-shrink: 0; }
.inbox-attach-panel select { border: 1.5px solid var(--border); border-radius: 8px; padding: 6px 8px; font-size: 12px; font-family: 'Sora', sans-serif; }
.inbox-attach-panel input { flex: 1; padding: 6px 10px; border: 1.5px solid var(--border); border-radius: 8px; font-size: 12px; font-family: 'Sora', sans-serif; outline: none; }
.inbox-attach-panel input:focus { border-color: var(--primary); }

.bubble-media-img, .bubble-media-video { max-width: 100%; border-radius: 8px; display: block; margin-bottom: 4px; }
.bubble-media-audio { width: 220px; display: block; margin-bottom: 4px; }

.media-upload-row { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.media-upload-row label.btn { cursor: pointer; margin: 0; }

@media (max-width: 768px) {
  .inbox-layout { flex-direction: column; height: auto; }
  .inbox-list { width: 100%; max-height: 240px; border-right: none; border-bottom: 1px solid var(--border); }
  .inbox-thread { min-height: 360px; }
  .inbox-thread-body { flex-direction: column; }
  .inbox-notes-panel { width: 100%; max-height: 220px; border-left: none; border-top: 1px solid var(--border); }
}

/* ── "+ Add Step" popup menu ─────────────────────────────────── */
.add-step-wrap { position: relative; }
.add-step-menu {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 50;
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow-lg); width: 240px; max-height: 400px; overflow-y: auto; padding: 6px;
}
.add-step-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: none; border: none; border-radius: 7px; padding: 9px 10px;
  font-size: 12.5px; font-weight: 600; color: var(--ink); cursor: pointer;
  font-family: 'Sora', sans-serif; transition: background .12s;
}
.add-step-item:hover { background: var(--muted-light); }
.add-step-icon { font-size: 15px; width: 18px; text-align: center; flex-shrink: 0; }

/* ── Preview bot — phone mockup + canvas lock ────────────────── */
.flow-canvas-area { position: relative; flex: 1; display: flex; margin: 10px 20px 20px; min-height: 0; }
.flow-canvas-area .flow-canvas-wrap { flex: 1; margin: 0; height: auto; }
.flow-canvas-area.locked .flow-canvas-wrap { pointer-events: none; filter: saturate(.5) brightness(.97); }

.flow-lock-banner {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 40;
  background: var(--primary-light); color: var(--primary-dark); border: 1px solid var(--primary);
  border-radius: 20px; padding: 7px 16px; font-size: 12px; font-weight: 700; box-shadow: var(--shadow);
}

.preview-phone {
  width: 300px; flex-shrink: 0; margin-left: 16px; border-radius: 28px; background: #0b0d11;
  padding: 10px; box-shadow: var(--shadow-lg); display: flex; flex-direction: column;
}
.preview-phone-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 10px 10px; color: #fff; font-size: 11.5px; font-weight: 700; letter-spacing: .03em; }
.preview-phone-close { background: rgba(255,255,255,.12); border: none; color: #fff; width: 22px; height: 22px; border-radius: 50%; cursor: pointer; font-size: 12px; line-height: 1; }
.preview-phone-body { flex: 1; background: #e8eaf0; border-radius: 16px; padding: 12px; overflow-y: auto; min-height: 380px; max-height: 500px; display: flex; flex-direction: column; gap: 8px; }
.preview-bubble { max-width: 85%; padding: 8px 11px; border-radius: 13px; font-size: 12.5px; line-height: 1.5; background: #fff; box-shadow: 0 1px 1px rgba(0,0,0,.06); align-self: flex-start; border-bottom-left-radius: 3px; }
.preview-bubble.user { align-self: flex-end; background: var(--saffron-light); border-bottom-left-radius: 13px; border-bottom-right-radius: 3px; }
.preview-bubble.system { align-self: center; background: rgba(0,0,0,.06); color: var(--muted); font-size: 10.5px; padding: 4px 10px; border-radius: 20px; }
.preview-options { display: flex; flex-direction: column; gap: 5px; margin-top: 6px; }
.preview-option-btn { background: #fff; border: 1px solid var(--border); color: var(--primary); font-size: 12px; font-weight: 700; padding: 7px 10px; border-radius: 8px; cursor: pointer; text-align: center; }
.preview-option-btn:hover { background: var(--primary-light); }
.preview-phone-composer { display: flex; gap: 6px; padding: 8px 4px 2px; }
.preview-phone-composer input { flex: 1; background: #1a1d24; border: none; border-radius: 16px; padding: 8px 12px; font-size: 12px; color: #fff; outline: none; }

/* ── Pipeline kanban board ────────────────────────────────────── */
.kanban-wrap { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 10px; align-items: flex-start; }
.kanban-col { flex: 0 0 260px; background: var(--muted-light); border: 1px solid var(--border); border-radius: 10px; display: flex; flex-direction: column; max-height: calc(100vh - 260px); }
.kanban-col-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; font-weight: 700; font-size: 13px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.kanban-col-body { padding: 10px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; }
.kanban-empty { color: var(--muted); font-size: 12px; text-align: center; padding: 16px 8px; }
.kanban-card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 10px 11px; box-shadow: var(--shadow); }
.kanban-card-title { font-weight: 700; font-size: 13px; margin-bottom: 3px; }
.kanban-card-contact { font-size: 11.5px; color: var(--muted); margin-bottom: 4px; }
.kanban-card-value { font-family: 'JetBrains Mono', monospace; font-size: 12px; font-weight: 700; color: var(--green); margin-bottom: 6px; }
.kanban-move { width: 100%; font-size: 11.5px; padding: 5px 6px; margin-top: 4px; }
.kanban-col-add { display: flex; align-items: center; justify-content: center; background: none; border: 2px dashed var(--border); min-height: 60px; }

/* ── Chatbot bot editor — full-screen overlay ────────────────── */
.flow-overlay { position: fixed; inset: 0; z-index: 500; background: var(--card); display: flex; flex-direction: column; }
.flow-overlay-titlebar { display: flex; align-items: center; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.flow-overlay-name { flex: 1; border: none; outline: none; font-size: 18px; font-weight: 800; font-family: 'Sora', sans-serif; color: var(--ink); padding: 4px 6px; border-radius: 6px; }
.flow-overlay-name:focus { background: var(--muted-light); }
.flow-overlay-actions { display: flex; gap: 8px; flex-shrink: 0; }
.flow-overlay-trigger-bar { display: flex; align-items: center; gap: 10px; padding: 10px 20px; border-bottom: 1px solid var(--border); background: #fafaf8; flex-wrap: wrap; flex-shrink: 0; }
.flow-overlay-trigger-bar input, .flow-overlay-trigger-bar select { padding: 6px 10px; font-size: 12.5px; }
.flow-overlay .flow-connect-banner { margin: 10px 20px 0; }
/* .flow-canvas-wrap's flex/height/margin now come from .flow-canvas-area
   (below) — it wraps canvas + preview phone side by side. */
.flow-overlay .flow-canvas-wrap { border-radius: var(--r); }

/* ── Chatbot flow canvas ──────────────────────────────────────── */
.flow-connect-banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--primary-light); color: var(--primary-dark); border: 1px solid var(--primary); border-radius: var(--r-sm); padding: 8px 14px; font-size: 12.5px; font-weight: 600; margin-bottom: 10px; }

.flow-canvas-wrap { position: relative; width: 100%; height: 560px; overflow: auto; border: 1px solid var(--border); border-radius: var(--r); background: var(--surface); background-image: radial-gradient(circle, #d8d4c8 1px, transparent 1px); background-size: 18px 18px; }
.flow-canvas-svg { position: absolute; top: 0; left: 0; width: 2400px; height: 1600px; pointer-events: none; overflow: visible; }
.flow-canvas-layer { position: relative; width: 2400px; height: 1600px; }

.flow-node { position: absolute; top: 0; left: 0; width: 240px; background: var(--card); border: 1.5px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); }
.flow-node.entry { border-color: var(--saffron); }
.flow-node-header { display: flex; align-items: center; gap: 6px; padding: 7px 8px; background: var(--ink); border-radius: 8px 8px 0 0; cursor: grab; }
.flow-node-header:active { cursor: grabbing; }
.flow-node-num { color: #fff; font-size: 11px; font-weight: 700; flex-shrink: 0; }
.flow-node-header select { flex: 1; min-width: 0; font-size: 10.5px; padding: 3px 4px; border-radius: 4px; border: none; }
.flow-node-del { background: none; border: none; color: rgba(255,255,255,.6); cursor: pointer; font-size: 12px; padding: 2px 4px; flex-shrink: 0; }
.flow-node-del:hover { color: #fff; }
.flow-node-body { padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.flow-node-body .fg label { font-size: 9px; }
.flow-node-body textarea, .flow-node-body input, .flow-node-body select { font-size: 11.5px; padding: 6px 8px; }
.flow-node-badge { position: absolute; top: -10px; left: 10px; background: var(--saffron); color: #fff; font-size: 9px; font-weight: 800; letter-spacing: .05em; padding: 2px 8px; border-radius: 10px; }
.flow-node-makeentry { position: absolute; top: -10px; left: 10px; background: var(--card); border: 1px solid var(--border); color: var(--muted); font-size: 9px; font-weight: 700; padding: 2px 8px; border-radius: 10px; cursor: pointer; opacity: 0; transition: opacity .15s; }
.flow-node:hover .flow-node-makeentry { opacity: 1; }
.flow-node-dropzone { position: absolute; inset: -6px; background: rgba(37,99,235,.08); border: 2px dashed var(--primary); border-radius: 12px; color: var(--primary-dark); font-size: 11px; font-weight: 800; display: flex; align-items: center; justify-content: center; cursor: pointer; z-index: 5; }

.flow-branch-row { display: flex; align-items: center; gap: 5px; }
.flow-branch-input { flex: 1; min-width: 0; }
.flow-branch-special { justify-content: space-between; padding-top: 4px; border-top: 1px dashed var(--border); }
.flow-port { flex-shrink: 0; border: 1.5px solid var(--border); background: var(--muted-light); color: var(--muted); border-radius: 12px; font-size: 10px; font-weight: 700; padding: 3px 8px; cursor: pointer; white-space: nowrap; }
.flow-port:hover { border-color: var(--primary); color: var(--primary); }
.flow-port.linked { background: var(--primary-light); border-color: var(--primary); color: var(--primary-dark); }
.flow-port.connecting { background: var(--saffron); border-color: var(--saffron); color: #fff; animation: pulsePort 1s infinite; }
@keyframes pulsePort { 50% { opacity: .55; } }
