:root {
  --bg: #f5f6fb; --surface: #ffffff; --surface-2: #f2f3f9; --surface-3: #e9ebf4; --border: #e4e6ef;
  --text: #141a2e; --text-2: #3d4560; --muted: #6b7290;
  --primary: #5b4bdb; --primary-600: #4a3bc6; --primary-50: #efedff; --primary-100: #e0dcff;
  --accent: #e07a3f; --accent-50: #fdf0e7;
  --green: #15803d; --green-50: #e7f6ec; --red: #d92d2d; --red-50: #fdecec; --amber: #b45309; --amber-50: #fdf3e1; --blue: #0369a1; --blue-50: #e5f3fb;
  --wa: #1fa855; --wa-50: #e5f7ec;
  --shadow-sm: 0 1px 2px rgba(20, 26, 46, .06);
  --shadow: 0 1px 2px rgba(20, 26, 46, .05), 0 6px 20px -8px rgba(20, 26, 46, .12);
  --shadow-lg: 0 24px 60px -12px rgba(20, 26, 46, .35);
  --r: 14px; --r-sm: 10px;
  --side: 256px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0d1020; --surface: #151a2e; --surface-2: #1b2138; --surface-3: #242b47; --border: #2a3150;
  --text: #eef0fa; --text-2: #c5cae0; --muted: #8e95b4;
  --primary: #8b7dff; --primary-600: #7a6bf5; --primary-50: #231f4a; --primary-100: #2e2963;
  --accent: #f0955f; --accent-50: #3a2418;
  --green: #4ade80; --green-50: #12301f; --red: #f87171; --red-50: #3a1717; --amber: #fbbf24; --amber-50: #382a0f; --blue: #38bdf8; --blue-50: #0f2a3a;
  --wa: #34d399; --wa-50: #0f2e22;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px -8px rgba(0, 0, 0, .5);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: 'Plus Jakarta Sans', system-ui, -apple-system, Segoe UI, Roboto, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; letter-spacing: -.01em; }
h1 { font-size: 24px; font-weight: 800; }
h2 { font-size: 16px; font-weight: 700; }
h3 { font-size: 14px; font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ic.sm { width: 15px; height: 15px; }
.ic.lg { width: 22px; height: 22px; }

/* ---------- layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar { width: var(--side); flex: none; background: var(--surface); border-right: 1px solid var(--border); position: fixed; inset: 0 auto 0 0; display: flex; flex-direction: column; z-index: 40; transition: transform .25s ease; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; }
.brand-logo { width: 36px; height: 36px; border-radius: 11px; background: linear-gradient(135deg, var(--primary), #8f5cf6 60%, var(--accent)); display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 17px; box-shadow: 0 6px 16px -6px var(--primary); }
.brand b { font-size: 16px; display: block; }
.brand span { font-size: 11.5px; color: var(--muted); }
.agency-switch { margin: 0 12px 8px; padding: 9px 11px; border: 1px solid var(--border); border-radius: 11px; display: flex; align-items: center; gap: 9px; background: var(--surface-2); }
.agency-switch .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px var(--green-50); }
.nav { flex: 1; overflow-y: auto; padding: 4px 10px 12px; }
.nav-group { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; padding: 14px 10px 6px; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 8.5px 10px; border-radius: 10px; color: var(--text-2); font-weight: 600; font-size: 13.5px; position: relative; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--primary-50); color: var(--primary); }
.nav a.active::before { content: ''; position: absolute; left: -10px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--primary); }
.nav a .badge { margin-left: auto; }
.nav a.locked { opacity: .45; }
.nav a.value-link { background: linear-gradient(135deg, var(--primary-50), var(--accent-50)); color: var(--primary); margin-top: 6px; }
.side-foot { padding: 12px; border-top: 1px solid var(--border); }
.me-card { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 11px; }
.me-card .nm { font-weight: 700; font-size: 13px; }
.me-card .rl { font-size: 11.5px; color: var(--muted); }
.main { flex: 1; margin-left: var(--side); min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 30; background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; padding: 10px 24px; }
.view { padding: 22px 24px 60px; max-width: 1480px; width: 100%; margin: 0 auto; }
.icon-btn.menu-btn { display: none; }
.search { position: relative; flex: 1; max-width: 420px; }
.search input { width: 100%; padding: 9px 12px 9px 36px; border: 1px solid var(--border); background: var(--surface); border-radius: 11px; outline: none; }
.search input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-50); }
.search .ic-holder .ic { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search-results { position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 6px; max-height: 380px; overflow: auto; display: none; }
.search-results.open { display: block; }
.sr-item { display: flex; gap: 10px; align-items: center; padding: 8px; border-radius: 9px; cursor: pointer; }
.sr-item:hover { background: var(--surface-2); }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.role-switch { display: flex; align-items: center; gap: 8px; padding: 4px 6px 4px 10px; border: 1px dashed var(--primary); border-radius: 11px; background: var(--primary-50); }
.role-switch label { font-size: 11px; font-weight: 700; color: var(--primary); text-transform: uppercase; letter-spacing: .05em; }
.role-switch select { border: 0; background: transparent; font-weight: 700; outline: none; cursor: pointer; max-width: 210px; }
.icon-btn { width: 38px; height: 38px; border-radius: 11px; border: 1px solid var(--border); background: var(--surface); display: grid; place-items: center; cursor: pointer; position: relative; color: var(--text-2); }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn .dot { position: absolute; top: 6px; right: 6px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 9px; background: var(--red); color: #fff; font-size: 10px; font-weight: 800; display: grid; place-items: center; border: 2px solid var(--surface); }
.bottomnav { display: none; }
.overlay { display: none; }

/* ---------- common ---------- */
.btn { display: inline-flex; align-items: center; gap: 7px; padding: 8.5px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); font-weight: 650; font-size: 13.5px; cursor: pointer; white-space: nowrap; color: var(--text); transition: background .15s, transform .05s; }
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 4px 12px -4px var(--primary); }
.btn.primary:hover { background: var(--primary-600); }
.btn.wa { background: var(--wa); border-color: var(--wa); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--red); }
.btn.sm { padding: 6px 10px; font-size: 12.5px; border-radius: 8px; }
.btn.xs { padding: 4px 8px; font-size: 12px; border-radius: 7px; gap: 5px; }
.btn.block { width: 100%; justify-content: center; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow-sm); padding: 18px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head p { margin: 2px 0 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 14px; margin-bottom: 16px; }
.kpis.k4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpis.k5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 15px 16px; position: relative; overflow: hidden; box-shadow: var(--shadow-sm); }
.kpi .lbl { padding-right: 38px; font-size: 12px; color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 7px; }
.kpi .lbl .ic { width: 15px; height: 15px; }
.kpi .val { font-size: 22px; font-weight: 800; margin-top: 8px; letter-spacing: -.02em; }
.kpi .val small { font-size: 12px; font-weight: 700; color: var(--muted); margin-left: 3px; }
.kpi .sub { font-size: 12px; margin-top: 4px; color: var(--muted); }
.kpi .ico { position: absolute; right: 14px; top: 14px; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; }
.up { color: var(--green); font-weight: 700; }
.down { color: var(--red); font-weight: 700; }
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 99px; font-size: 11.5px; font-weight: 700; background: var(--surface-3); color: var(--text-2); white-space: nowrap; }
.pill.green { background: var(--green-50); color: var(--green); }
.pill.red { background: var(--red-50); color: var(--red); }
.pill.amber { background: var(--amber-50); color: var(--amber); }
.pill.blue { background: var(--blue-50); color: var(--blue); }
.pill.violet { background: var(--primary-50); color: var(--primary); }
.pill.orange { background: var(--accent-50); color: var(--accent); }
.pill.wa { background: var(--wa-50); color: var(--wa); }
.badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--primary); color: #fff; font-size: 11px; font-weight: 800; display: inline-grid; place-items: center; }
.badge.red { background: var(--red); }
.av { --c: #64748b; width: 32px; height: 32px; border-radius: 50%; background: color-mix(in srgb, var(--c) 16%, var(--surface)); color: var(--c); display: inline-grid; place-items: center; font-weight: 800; font-size: 12px; flex: none; border: 1.5px solid color-mix(in srgb, var(--c) 35%, transparent); }
.av.sm { width: 24px; height: 24px; font-size: 10px; }
.av.lg { width: 52px; height: 52px; font-size: 18px; }
.av-stack { display: flex; }
.av-stack .av { margin-left: -6px; border: 2px solid var(--surface); }
.status-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.status-dot.online { background: #22c55e; } .status-dot.away { background: #f59e0b; } .status-dot.offline { background: #9ca3af; }
.progress { height: 7px; border-radius: 9px; background: var(--surface-3); overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: 9px; background: var(--primary); }
.progress.green > i { background: var(--green); }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.stack > * + * { margin-top: 10px; }
.hr { height: 1px; background: var(--border); margin: 14px 0; }
.empty { text-align: center; padding: 30px 10px; color: var(--muted); }
.tabs { display: flex; gap: 4px; padding: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; overflow-x: auto; scrollbar-width: none; }
.tabs button { border: 0; background: transparent; padding: 7px 13px; border-radius: 9px; font-weight: 650; font-size: 13px; cursor: pointer; color: var(--muted); white-space: nowrap; display: inline-flex; gap: 6px; align-items: center; }
.tabs button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: var(--surface); padding: 6px 12px; border-radius: 99px; font-size: 12.5px; font-weight: 650; cursor: pointer; color: var(--text-2); }
.chip.on { background: var(--text); color: var(--surface); border-color: var(--text); }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.input, .select, textarea.input { width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); outline: none; }
.input:focus, .select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-50); }
.toolbar .input, .toolbar .select { width: auto; min-width: 160px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; font-weight: 700; color: var(--text-2); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }
.switch { position: relative; width: 38px; height: 22px; flex: none; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--surface-3); border-radius: 22px; cursor: pointer; transition: .2s; }
.switch span::after { content: ''; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(16px); }

/* tables */
.table-wrap { overflow-x: auto; margin: 0 -18px -18px; }
table.t { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.t th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
.t td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.t tr:last-child td { border-bottom: 0; }
.t tbody tr { cursor: pointer; transition: background .1s; }
.t tbody tr:hover { background: var(--surface-2); }
.t .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.t .nm { font-weight: 700; }
.cell-user { display: flex; align-items: center; gap: 10px; min-width: 180px; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px dashed var(--border); }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .t1 { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .t2 { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ico-box { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; flex: none; }
.bg-violet { background: var(--primary-50); color: var(--primary); } .bg-green { background: var(--green-50); color: var(--green); } .bg-red { background: var(--red-50); color: var(--red); } .bg-amber { background: var(--amber-50); color: var(--amber); } .bg-blue { background: var(--blue-50); color: var(--blue); } .bg-orange { background: var(--accent-50); color: var(--accent); } .bg-wa { background: var(--wa-50); color: var(--wa); }

/* dashboard */
.g-dash { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.insights { background: linear-gradient(160deg, var(--primary-50), var(--surface) 55%); border-color: var(--primary-100); }
.insight { display: flex; gap: 11px; padding: 11px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); margin-bottom: 9px; }
.insight .grow { flex: 1; min-width: 0; }
.insight p { margin: 0 0 7px; font-size: 13px; color: var(--text-2); }
.insight b { color: var(--text); }
.ai-tag { display: inline-flex; gap: 5px; align-items: center; font-size: 11px; font-weight: 800; color: var(--primary); background: var(--surface); border: 1px solid var(--primary-100); padding: 3px 8px; border-radius: 99px; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart .grid-line { stroke: var(--border); stroke-dasharray: 3 4; }
.chart .bar { fill: var(--primary); opacity: .9; transition: opacity .15s; }
.chart .bar:hover { opacity: 1; }
.chart .bar2 { fill: var(--accent); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); font-weight: 600; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.donut-wrap { display: flex; align-items: center; gap: 18px; }
.donut-wrap svg { width: 140px; height: 140px; flex: none; }
.donut-legend { flex: 1; display: flex; flex-direction: column; gap: 7px; font-size: 12.5px; min-width: 0; }
.donut-legend div { display: flex; align-items: center; gap: 8px; }
.donut-legend b { margin-left: auto; }
.hbar { display: grid; grid-template-columns: 120px 1fr 80px; gap: 10px; align-items: center; margin-bottom: 9px; font-size: 12.5px; }
.hbar .bar-bg { height: 10px; background: var(--surface-3); border-radius: 6px; overflow: hidden; }
.hbar .bar-bg i { display: block; height: 100%; border-radius: 6px; background: var(--primary); }
.hbar .v { text-align: right; font-weight: 700; }

/* kanban */
.kanban { display: grid; grid-template-columns: repeat(5, minmax(240px, 1fr)); gap: 12px; overflow-x: auto; padding-bottom: 10px; align-items: start; }
.kanban.k3 { grid-template-columns: repeat(3, minmax(260px, 1fr)); }
.col { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r); padding: 10px; min-height: 200px; transition: background .15s, border-color .15s; }
.col.drag-over { background: var(--primary-50); border-color: var(--primary); border-style: dashed; }
.col-head { display: flex; align-items: center; gap: 8px; padding: 4px 4px 10px; font-weight: 800; font-size: 13px; }
.col-head .cnt { color: var(--muted); font-weight: 700; }
.col-head .sum { margin-left: auto; font-size: 11.5px; color: var(--muted); font-weight: 700; }
.col-head .bullet { width: 9px; height: 9px; border-radius: 50%; }
.kcard { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px; margin-bottom: 9px; cursor: grab; box-shadow: var(--shadow-sm); transition: box-shadow .15s, transform .15s; }
.kcard:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.kcard.dragging { opacity: .5; }
.kcard .nm { font-weight: 750; font-size: 13.5px; }
.kcard .meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.kcard .foot { display: flex; align-items: center; gap: 6px; margin-top: 10px; padding-top: 9px; border-top: 1px dashed var(--border); }
.kcard .foot .time { font-size: 11.5px; color: var(--muted); margin-right: auto; }
.sla { margin-top: 8px; font-size: 11.5px; font-weight: 700; color: var(--red); background: var(--red-50); padding: 4px 8px; border-radius: 7px; display: inline-flex; gap: 5px; align-items: center; }
.mini-btn { width: 28px; height: 28px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); display: grid; place-items: center; cursor: pointer; color: var(--text-2); }
.mini-btn:hover { background: var(--surface-2); }
.mini-btn.wa { color: var(--wa); }
.mini-btn .ic { width: 14px; height: 14px; }

/* inbox */
.inbox { display: grid; grid-template-columns: 320px 1fr 280px; height: calc(100vh - 150px); min-height: 520px; padding: 0; overflow: hidden; }
.inbox-list { border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.inbox-list .tabs { margin: 12px; }
.conv-list { overflow-y: auto; flex: 1; }
.conv { display: flex; gap: 10px; padding: 12px 14px; cursor: pointer; border-bottom: 1px solid var(--border); position: relative; }
.conv:hover { background: var(--surface-2); }
.conv.on { background: var(--primary-50); }
.conv .grow { flex: 1; min-width: 0; }
.conv .t1 { font-weight: 700; display: flex; gap: 6px; align-items: center; }
.conv .t1 span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .t2 { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.conv .when { font-size: 11px; color: var(--muted); margin-left: auto; white-space: nowrap; }
.ch-ico { width: 18px; height: 18px; border-radius: 6px; display: inline-grid; place-items: center; flex: none; }
.ch-ico .ic { width: 11px; height: 11px; }
.thread { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.thread-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.msgs { flex: 1; overflow-y: auto; padding: 18px; background: var(--bg); background-image: radial-gradient(var(--surface-3) 1px, transparent 1px); background-size: 18px 18px; }
.msg { max-width: 72%; padding: 9px 12px; border-radius: 14px; margin-bottom: 8px; font-size: 13.5px; box-shadow: var(--shadow-sm); white-space: pre-wrap; word-wrap: break-word; }
.msg.them { background: var(--surface); border-bottom-left-radius: 4px; }
.msg.me { background: var(--primary); color: #fff; margin-left: auto; border-bottom-right-radius: 4px; }
.msg.me.whatsapp { background: #d9fdd3; color: #102a12; }
:root[data-theme="dark"] .msg.me.whatsapp { background: #144d37; color: #e7fff0; }
.msg .mt { font-size: 10.5px; opacity: .65; margin-top: 4px; text-align: right; }
.msg.sys { background: var(--amber-50); color: var(--amber); margin: 0 auto 8px; text-align: center; font-weight: 600; font-size: 12.5px; max-width: 90%; }
.composer { border-top: 1px solid var(--border); padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; background: var(--surface); }
.composer .row textarea { flex: 1; resize: none; height: 44px; }
.inbox-side { border-left: 1px solid var(--border); padding: 16px; overflow-y: auto; }
.back-btn { display: none; }

/* chat */
.chat-layout { display: grid; grid-template-columns: 230px 1fr; height: calc(100vh - 150px); min-height: 480px; padding: 0; overflow: hidden; }
.chan { display: flex; align-items: center; gap: 8px; padding: 9px 12px; border-radius: 9px; cursor: pointer; font-weight: 650; color: var(--text-2); }
.chan.on { background: var(--primary-50); color: var(--primary); }
.chat-msg { display: flex; gap: 10px; margin-bottom: 14px; }
.chat-msg .bd { background: var(--surface); padding: 9px 12px; border-radius: 12px; border: 1px solid var(--border); max-width: 640px; }

/* drawer & modal */
.modal-bg { position: fixed; inset: 0; background: rgba(10, 12, 28, .45); backdrop-filter: blur(3px); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px; animation: fade .15s; }
.modal { background: var(--surface); border-radius: 18px; width: 100%; max-width: 560px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: var(--shadow-lg); animation: pop .18s ease; }
.modal.wide { max-width: 860px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); gap: 10px; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.drawer-bg { position: fixed; inset: 0; background: rgba(10, 12, 28, .35); z-index: 90; animation: fade .15s; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%); background: var(--surface); z-index: 91; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; animation: slide .22s ease; }
.drawer-head { padding: 18px 20px; border-bottom: 1px solid var(--border); }
.drawer-body { flex: 1; overflow-y: auto; padding: 18px 20px 40px; }
.drawer .sec { margin-bottom: 20px; }
.drawer .sec > h3 { margin-bottom: 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kv div { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.kv span { display: block; font-size: 11.5px; color: var(--muted); font-weight: 600; }
.kv b { font-size: 14px; }
.check-item { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px dashed var(--border); cursor: pointer; }
.check-item .box { width: 20px; height: 20px; border-radius: 6px; border: 2px solid var(--border); display: grid; place-items: center; flex: none; }
.check-item.done .box { background: var(--green); border-color: var(--green); color: #fff; }
.check-item.done .tx { text-decoration: line-through; color: var(--muted); }
.timeline { border-left: 2px solid var(--border); margin-left: 6px; padding-left: 16px; }
.timeline .ev { position: relative; margin-bottom: 12px; font-size: 13px; }
.timeline .ev::before { content: ''; position: absolute; left: -22px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); border: 2px solid var(--surface); }
.toasts { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.toast { background: var(--text); color: var(--surface); padding: 11px 15px; border-radius: 12px; font-weight: 600; font-size: 13.5px; box-shadow: var(--shadow-lg); display: flex; gap: 9px; align-items: center; animation: pop .2s ease; max-width: 380px; }
.toast .ic { color: #4ade80; }
.dropdown { position: absolute; top: calc(100% + 8px); right: 0; width: 360px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg); z-index: 60; display: none; }
.dropdown.open { display: block; animation: pop .15s; }
.notif { display: flex; gap: 10px; padding: 11px 14px; border-bottom: 1px solid var(--border); font-size: 13px; }
.notif.unread { background: var(--primary-50); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.97) translateY(4px); } }
@keyframes slide { from { transform: translateX(40px); opacity: 0; } }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 7px 12px; cursor: pointer; font-weight: 650; font-size: 12.5px; display: inline-flex; gap: 6px; align-items: center; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--primary-50); color: var(--primary); }

/* website builder */
.wb { display: grid; grid-template-columns: minmax(380px, 1fr) minmax(0, 1.2fr); gap: 16px; align-items: start; }
.preview-card { position: sticky; top: 76px; padding: 0; overflow: hidden; }
.preview-bar { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.preview-bar .url { flex: 1; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 5px 10px; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dots i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; }
.preview-frame-wrap { background: var(--surface-3); display: flex; justify-content: center; height: calc(100vh - 200px); min-height: 520px; }
.preview-frame-wrap iframe { width: 100%; height: 100%; border: 0; background: #fff; transition: width .25s; }
.preview-frame-wrap.mobile { padding: 16px 0; }
.preview-frame-wrap.mobile iframe { width: 375px; border-radius: 24px; box-shadow: var(--shadow-lg); border: 6px solid #111; }
.offer-row { display: flex; gap: 12px; align-items: center; padding: 10px; border: 1px solid var(--border); border-radius: 12px; margin-bottom: 8px; background: var(--surface); }
.offer-thumb { width: 64px; height: 52px; border-radius: 10px; display: grid; place-items: center; font-size: 26px; flex: none; }
.offer-row .grow { flex: 1; min-width: 0; }
.offer-row .t1 { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.offer-row.off { opacity: .55; }

/* value page */
.hero-value { border-radius: 22px; padding: 34px; color: #fff; background: radial-gradient(1200px 400px at 90% -20%, rgba(255, 255, 255, .18), transparent), linear-gradient(135deg, #3b2db8, #5b4bdb 45%, #c2410c); position: relative; overflow: hidden; margin-bottom: 18px; }
.hero-value h1 { font-size: 34px; line-height: 1.1; max-width: 720px; }
.hero-value p { font-size: 16px; opacity: .9; max-width: 640px; }
.hero-value .zellige { position: absolute; right: -40px; bottom: -40px; width: 300px; opacity: .14; }
.hero-stats { display: flex; gap: 28px; flex-wrap: wrap; margin-top: 22px; }
.hero-stats b { font-size: 28px; display: block; }
.hero-stats span { opacity: .85; font-size: 13px; }
.feature { padding: 18px; }
.feature .ico-box { margin-bottom: 12px; width: 42px; height: 42px; }
.feature p { color: var(--muted); margin: 6px 0 0; font-size: 13px; }
.ba { display: grid; grid-template-columns: 1fr 1fr; gap: 0; border-radius: var(--r); overflow: hidden; border: 1px solid var(--border); }
.ba > div { padding: 18px; }
.ba .before { background: var(--red-50); }
.ba .after { background: var(--green-50); }
.ba ul { margin: 8px 0 0; padding-left: 18px; }
.ba li { margin-bottom: 6px; }
.plan { padding: 22px; display: flex; flex-direction: column; }
.plan.pop { border: 2px solid var(--primary); box-shadow: 0 20px 40px -20px var(--primary); }
.plan .price { font-size: 30px; font-weight: 800; margin: 10px 0 2px; }
.plan ul { list-style: none; padding: 0; margin: 14px 0 18px; flex: 1; }
.plan li { display: flex; gap: 8px; margin-bottom: 8px; font-size: 13.5px; }
.plan li .ic { color: var(--green); width: 16px; height: 16px; margin-top: 2px; }
.roi-out { background: var(--surface-2); border-radius: 12px; padding: 14px; }
.roi-out .big { font-size: 28px; font-weight: 800; color: var(--green); }
input[type=range] { width: 100%; accent-color: var(--primary); }

/* invoice */
.invoice { font-size: 13px; }
.invoice .inv-head { display: flex; justify-content: space-between; gap: 20px; border-bottom: 2px solid var(--text); padding-bottom: 14px; margin-bottom: 14px; flex-wrap: wrap; }
.invoice table { width: 100%; border-collapse: collapse; margin: 12px 0; }
.invoice th, .invoice td { padding: 8px; border-bottom: 1px solid var(--border); text-align: left; }
.invoice .r { text-align: right; }
.perm-table td, .perm-table th { text-align: center; }
.perm-table td:first-child, .perm-table th:first-child { text-align: left; }
.perm-table tbody tr { cursor: default; }
.perm-table input { width: 17px; height: 17px; accent-color: var(--primary); cursor: pointer; }

@media print {
  body * { visibility: hidden; }
  .invoice, .invoice * { visibility: visible; }
  .invoice { position: absolute; left: 0; top: 0; width: 100%; padding: 20px; color: #000; }
}

/* ---------- responsive ---------- */
@media (max-width: 1280px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .inbox { grid-template-columns: 300px 1fr; }
  .inbox-side { display: none; }
}
@media (max-width: 1100px) {
  .g-dash { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g-dash .span-2 { grid-column: span 2; }
  .wb { grid-template-columns: 1fr; }
  .preview-card { position: static; }
  .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpis.k5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  :root { --side: 280px; }
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .app.side-open .sidebar { transform: none; }
  .app.side-open .overlay { display: block; position: fixed; inset: 0; background: rgba(10, 12, 28, .4); z-index: 35; }
  .main { margin-left: 0; }
  .icon-btn.menu-btn { display: grid; }
  .topbar { padding: 10px 16px; }
  .view { padding: 16px 16px 96px; }
  .role-switch label { display: none; }
  .role-switch select { max-width: 120px; }
  .hide-md { display: none !important; }
  .bottomnav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface); border-top: 1px solid var(--border); z-index: 30; padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); justify-content: space-around; }
  .bottomnav a { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 10.5px; font-weight: 700; color: var(--muted); padding: 4px 8px; border-radius: 10px; position: relative; flex: 1; }
  .bottomnav a.active { color: var(--primary); }
  .bottomnav a .badge { position: absolute; top: -2px; right: calc(50% - 22px); min-width: 17px; height: 17px; font-size: 10px; }
  .toasts { bottom: 84px; right: 12px; left: 12px; align-items: stretch; }
  .inbox { grid-template-columns: 1fr; height: calc(100vh - 190px); }
  .inbox .thread { display: none; }
  .inbox.show-thread .inbox-list { display: none; }
  .inbox.show-thread .thread { display: flex; }
  .back-btn { display: grid; }
  .chat-layout { grid-template-columns: 1fr; height: auto; }
  .chat-layout .chans { display: flex; gap: 6px; overflow-x: auto; border-bottom: 1px solid var(--border); padding: 10px !important; }
  .chat-layout .chans h3 { display: none; }
  .chat-msgs { height: calc(100vh - 330px); }
}
@media (max-width: 700px) {
  h1 { font-size: 21px; }
  .kpis, .kpis.k4, .kpis.k5 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 13px; }
  .kpi .val { font-size: 18px; }
  .kpi .ico { display: none; }
  .g2, .g3, .g-dash { grid-template-columns: 1fr; }
  .span-2, .span-3, .g-dash .span-2 { grid-column: auto; }
  .search { display: none; }
  .search.mobile-open { display: block; position: absolute; left: 12px; right: 12px; top: 8px; max-width: none; z-index: 5; }
  .form-grid { grid-template-columns: 1fr; }
  .page-head { align-items: stretch; }
  .page-head .btn-row { width: 100%; }
  .page-head .btn-row .btn { flex: 1; justify-content: center; }
  .hide-sm { display: none !important; }
  .card { padding: 14px; }
  .table-wrap { margin: 0 -14px -14px; }
  /* responsive tables become cards */
  table.rt thead { display: none; }
  table.rt, table.rt tbody, table.rt tr, table.rt td { display: block; width: 100%; }
  table.rt tr { padding: 12px 14px; border-bottom: 1px solid var(--border); }
  table.rt td { border: 0; padding: 3px 0; display: flex; justify-content: space-between; gap: 10px; text-align: right; }
  table.rt td::before { content: attr(data-l); color: var(--muted); font-size: 12px; font-weight: 600; text-align: left; }
  table.rt td.first { padding-bottom: 8px; }
  table.rt td.first::before { display: none; }
  table.rt .num { text-align: right; }
  .hero-value { padding: 24px; }
  .hero-value h1 { font-size: 25px; }
  .ba { grid-template-columns: 1fr; }
  .dropdown { position: fixed; left: 12px; right: 12px; width: auto; top: 60px; }
  .donut-wrap { flex-direction: column; align-items: stretch; }
  .donut-wrap svg { margin: 0 auto; }
  .hbar { grid-template-columns: 90px 1fr 64px; }
  .kanban { grid-template-columns: repeat(5, 82vw); scroll-snap-type: x mandatory; }
  .kanban.k3 { grid-template-columns: repeat(3, 82vw); }
  .kanban .col { scroll-snap-align: start; }
  .msg { max-width: 86%; }
  .preview-frame-wrap { height: 560px; }
  .modal-bg { align-items: flex-end; padding: 0; }
  .modal { border-radius: 18px 18px 0 0; max-height: 92vh; }
  .top-actions .icon-btn.hide-xs { display: none; }
}

/* ---------- language switcher & Arabic (RTL) ---------- */
.lang-switch { height: 38px; border: 1px solid var(--border); background: var(--surface); border-radius: 11px; padding: 0 10px; font-weight: 700; font-size: 12.5px; cursor: pointer; color: var(--text); outline: none; }
:root[lang="ar"] body { font-family: 'Cairo', 'Plus Jakarta Sans', system-ui, sans-serif; }
[dir="rtl"] .sidebar { inset: 0 0 0 auto; border-right: 0; border-left: 1px solid var(--border); }
[dir="rtl"] .main { margin-left: 0; margin-right: var(--side); }
[dir="rtl"] .nav a.active::before { left: auto; right: -10px; border-radius: 3px 0 0 3px; }
[dir="rtl"] .nav a .badge, [dir="rtl"] .top-actions { margin-left: 0; margin-right: auto; }
[dir="rtl"] .search .ic-holder .ic { left: auto; right: 11px; }
[dir="rtl"] .search input { padding: 9px 36px 9px 12px; }
[dir="rtl"] .search-results, [dir="rtl"] .dropdown { right: auto; left: 0; }
[dir="rtl"] .kpi .ico { right: auto; left: 14px; }
[dir="rtl"] .kpi .lbl { padding-right: 0; padding-left: 38px; }
[dir="rtl"] .t th, [dir="rtl"] .t td { text-align: right; }
[dir="rtl"] .t .num { text-align: left; }
[dir="rtl"] .col-head .sum, [dir="rtl"] .kcard .foot .time, [dir="rtl"] .conv .when, [dir="rtl"] .donut-legend b { margin-left: 0; margin-right: auto; }
[dir="rtl"] .kcard .foot .time { margin-right: 0; margin-left: auto; }
[dir="rtl"] .msg.me { margin-left: 0; margin-right: auto; }
[dir="rtl"] .msg.them { margin-left: auto; }
[dir="rtl"] .msg.me { border-bottom-right-radius: 14px; border-bottom-left-radius: 4px; }
[dir="rtl"] .msg.them { border-bottom-left-radius: 14px; border-bottom-right-radius: 4px; }
[dir="rtl"] .inbox-list { border-right: 0; border-left: 1px solid var(--border); }
[dir="rtl"] .inbox-side { border-left: 0; border-right: 1px solid var(--border); }
[dir="rtl"] .chat-layout .chans { border-right: 0 !important; border-left: 1px solid var(--border); }
[dir="rtl"] .drawer { right: auto; left: 0; animation-name: slideL; }
[dir="rtl"] .toasts { right: auto; left: 20px; }
[dir="rtl"] .timeline { border-left: 0; border-right: 2px solid var(--border); margin-left: 0; margin-right: 6px; padding-left: 0; padding-right: 16px; }
[dir="rtl"] .timeline .ev::before { left: auto; right: -22px; }
[dir="rtl"] .hero-value .zellige { right: auto; left: -40px; }
[dir="rtl"] .ba ul, [dir="rtl"] .plan ul { padding-left: 0; padding-right: 18px; }
[dir="rtl"] .switch span::after { left: auto; right: 3px; }
[dir="rtl"] .switch input:checked + span::after { transform: translateX(-16px); }
[dir="rtl"] .ic[viewBox] { }
[dir="rtl"] .back-btn svg, [dir="rtl"] [data-act] .ic polyline[points="12 5 19 12 12 19"] { transform-origin: center; }
[dir="rtl"] .hbar .v { text-align: left; }
@keyframes slideL { from { transform: translateX(-40px); opacity: 0; } }
@media (max-width: 900px) {
  [dir="rtl"] .sidebar { transform: translateX(100%); }
  [dir="rtl"] .app.side-open .sidebar { transform: none; }
  [dir="rtl"] .main { margin-right: 0; }
  [dir="rtl"] .toasts { left: 12px; right: 12px; }
  .lang-switch { width: 84px; padding: 0 6px; }
}
/* user-written content (messages, notes, names) picks its own direction inside the Arabic UI */
[dir="rtl"] .msg, [dir="rtl"] .chat-msg .bd, [dir="rtl"] .conv .t2, [dir="rtl"] .timeline .ev div, [dir="rtl"] input, [dir="rtl"] textarea { unicode-bidi: plaintext; text-align: start; }
[dir="rtl"] .invoice { direction: ltr; text-align: left; }
