/* =========================================================
   MARKETING HUB – Design tokens & components
   ========================================================= */
:root {
  --navy-900: #0b1533;
  --navy-800: #111d45;
  --navy-700: #1a2757;
  --indigo: #4f46e5;
  --indigo-600: #4338ca;
  --indigo-50: #eef2ff;
  --indigo-100: #e0e7ff;
  --bg: #f4f6fb;
  --card: #ffffff;
  --border: #e5e8f0;
  --border-strong: #d5dae6;
  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;
  --muted-2: #94a3b8;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --info: #0284c7;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 3px rgba(15, 23, 42, .04);
  --shadow: 0 4px 16px rgba(15, 23, 42, .06);
  --shadow-lg: 0 20px 48px rgba(15, 23, 42, .18);
  --hd-h: 64px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
svg.lucide { width: 18px; height: 18px; stroke-width: 2; flex-shrink: 0; display: inline-block; vertical-align: middle; }
.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.link { color: var(--indigo); font-weight: 500; cursor: pointer; }
.link:hover { text-decoration: underline; }

/* ---------------- Layout ---------------- */
.app { --sb-w: 248px; display: flex; min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sb-w);
  background: var(--navy-900); color: #cbd5e1;
  display: flex; flex-direction: column; z-index: 50;
  transition: width .2s ease, transform .22s ease;
}
.main-wrap { flex: 1; margin-left: var(--sb-w); min-width: 0; transition: margin .2s ease; }
.page { padding: 24px 28px 48px; max-width: 1640px; margin: 0 auto; }

.sb-brand { height: var(--hd-h); display: flex; align-items: center; gap: 11px; padding: 0 18px; border-bottom: 1px solid rgba(255,255,255,.06); flex-shrink: 0; }
.sb-logo { width: 36px; height: 36px; border-radius: 10px; background: var(--indigo); display: grid; place-items: center; color: #fff; flex-shrink: 0; }
.sb-logo svg { width: 20px; height: 20px; }
.sb-title { font-weight: 800; color: #fff; letter-spacing: .06em; font-size: 14px; white-space: nowrap; }
.sb-sub { font-size: 11px; color: #8b97b8; white-space: nowrap; }
.sb-nav { flex: 1; overflow-y: auto; padding: 8px 12px 12px; scrollbar-width: thin; scrollbar-color: #24315e transparent; }
.sb-group { font-size: 10.5px; font-weight: 600; letter-spacing: .09em; color: #5f6b8c; padding: 16px 10px 6px; text-transform: uppercase; white-space: nowrap; }
.sb-item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 9px 12px; border-radius: 8px; color: #b3bdd8; font-weight: 500; font-size: 13.5px;
  margin-bottom: 2px; cursor: pointer; border: 0; background: none; text-align: left; white-space: nowrap;
  transition: background .15s, color .15s;
}
.sb-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.sb-item.active { background: var(--indigo); color: #fff; box-shadow: 0 6px 14px rgba(79,70,229,.35); }
.sb-count { margin-left: auto; background: #ef4444; color: #fff; font-size: 11px; font-weight: 700; border-radius: 10px; padding: 1px 7px; line-height: 16px; }
.sb-foot { padding: 10px 12px; border-top: 1px solid rgba(255,255,255,.06); }
.sb-backdrop { display: none; }

@media (min-width: 1024px) {
  .app.collapsed { --sb-w: 72px; }
  .app.collapsed .sb-text, .app.collapsed .sb-count { display: none; }
  .app.collapsed .sb-group { font-size: 0; padding: 10px 0 6px; }
  .app.collapsed .sb-group::after { content: ''; display: block; height: 1px; background: rgba(255,255,255,.08); margin: 0 8px; }
  .app.collapsed .sb-item { justify-content: center; padding: 10px 0; position: relative; }
  .app.collapsed .sb-item .sb-dot { position: absolute; top: 6px; right: 14px; width: 8px; height: 8px; background: #ef4444; border-radius: 50%; }
  .app.collapsed .sb-brand { padding: 0 18px; }
  .app.collapsed .sb-collapse svg { transform: rotate(180deg); }
  .lg-hide { display: none !important; }
}
.sb-dot { display: none; }
.app.collapsed .sb-dot { display: block; }

@media (max-width: 1023px) {
  .sidebar { transform: translateX(-100%); width: 260px; box-shadow: var(--shadow-lg); }
  .app.mobile-open .sidebar { transform: none; }
  .app.mobile-open .sb-backdrop { display: block; position: fixed; inset: 0; background: rgba(11,21,51,.45); z-index: 45; }
  .main-wrap { margin-left: 0; }
  .sb-collapse { display: none; }
  .page { padding: 18px 16px 40px; }
}

/* ---------------- Topbar ---------------- */
.topbar {
  position: sticky; top: 0; height: var(--hd-h); z-index: 30;
  background: rgba(255,255,255,.94); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px; padding: 0 20px 0 24px;
}
.topbar-spacer { flex: 1; }
.breadcrumb { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); min-width: 0; white-space: nowrap; overflow: hidden; }
.breadcrumb a:hover { color: var(--indigo); }
.breadcrumb .bc-current { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.breadcrumb svg { width: 14px; height: 14px; color: var(--muted-2); }

.search-box { position: relative; display: flex; align-items: center; gap: 8px; background: #f1f4f9; border: 1px solid transparent; border-radius: 10px; padding: 0 12px; height: 38px; width: 320px; transition: all .15s; }
.search-box:focus-within { background: #fff; border-color: var(--indigo); box-shadow: 0 0 0 3px rgba(79,70,229,.12); }
.search-box > svg { width: 16px; height: 16px; color: var(--muted); }
.search-box input { border: 0; outline: 0; background: transparent; flex: 1; font-size: 13px; font-family: inherit; min-width: 0; }
@media (max-width: 1279px) { .search-box { width: 220px; } }
@media (max-width: 767px) { .search-box { display: none; } .user-meta { display: none !important; } }

.icon-btn { width: 38px; height: 38px; display: inline-grid; place-items: center; border-radius: 10px; border: 0; background: transparent; color: var(--text-2); cursor: pointer; position: relative; transition: background .15s; }
.icon-btn:hover { background: #eef1f7; }
.icon-btn.sm { width: 30px; height: 30px; border-radius: 8px; }
.icon-btn.sm svg { width: 16px; height: 16px; }
.icon-btn.danger:hover { background: #fef2f2; color: var(--danger); }
.notif-dot { position: absolute; top: 6px; right: 6px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px; background: #ef4444; color: #fff; font-size: 10px; font-weight: 700; display: grid; place-items: center; border: 2px solid #fff; }
.notif-dot:empty { display: none; }

.user-btn { display: flex; align-items: center; gap: 10px; border: 0; background: transparent; padding: 4px 8px 4px 4px; border-radius: 10px; cursor: pointer; }
.user-btn:hover { background: #eef1f7; }
.user-meta { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.2; }
.user-name { font-size: 13px; font-weight: 600; }
.user-role { font-size: 11.5px; color: var(--muted); }

.scope-banner { background: #fff7ed; border-bottom: 1px solid #fed7aa; color: #9a3412; font-size: 12.5px; padding: 7px 28px; display: flex; align-items: center; gap: 8px; }
.scope-banner svg { width: 15px; height: 15px; }

/* ---------------- Dropdowns ---------------- */
.relative { position: relative; }
.dropdown { position: absolute; top: calc(100% + 8px); right: 0; background: #fff; border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); z-index: 60; display: none; overflow: hidden; }
.dropdown.open { display: block; animation: dd .14s ease-out; }
@keyframes dd { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.search-results { left: 0; right: auto; width: 420px; max-height: 440px; overflow-y: auto; }
.sr-group { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted-2); padding: 10px 14px 4px; }
.sr-item { display: flex; align-items: center; gap: 10px; padding: 8px 14px; cursor: pointer; }
.sr-item:hover, .sr-item.hl { background: var(--indigo-50); }
.sr-item svg { width: 16px; height: 16px; color: var(--muted); }
.sr-item .sr-title { font-size: 13px; font-weight: 500; }
.sr-item .sr-sub { font-size: 11.5px; color: var(--muted); }
.notif-menu { width: 380px; }
.dd-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); font-weight: 600; }
.notif-item { display: flex; gap: 12px; padding: 12px 16px; border-bottom: 1px solid #f1f3f8; cursor: pointer; }
.notif-item:hover { background: #f8fafc; }
.notif-item.unread { background: #f7f8ff; }
.notif-item .ni-icon { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; flex-shrink: 0; }
.notif-item .ni-title { font-size: 13px; font-weight: 600; }
.notif-item .ni-text { font-size: 12.5px; color: var(--muted); }
.notif-item .ni-time { font-size: 11px; color: var(--muted-2); margin-top: 2px; }
.notif-list { max-height: 400px; overflow-y: auto; }
.user-menu { width: 300px; }
.role-opt { display: flex; align-items: center; gap: 10px; padding: 9px 16px; cursor: pointer; font-size: 13px; }
.role-opt:hover { background: #f8fafc; }
.role-opt.active { background: var(--indigo-50); color: var(--indigo-600); font-weight: 600; }
.role-opt svg { width: 16px; height: 16px; }
.range-menu { width: 260px; padding: 6px; }
.range-opt { padding: 8px 12px; border-radius: 8px; cursor: pointer; font-size: 13px; display: flex; justify-content: space-between; align-items: center; }
.range-opt:hover { background: #f4f6fb; }
.range-opt.active { background: var(--indigo-50); color: var(--indigo-600); font-weight: 600; }
.range-custom { padding: 8px 12px 10px; border-top: 1px solid var(--border); margin-top: 4px; display: grid; gap: 8px; }

/* ---------------- Page header ---------------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; font-weight: 700; margin: 0; letter-spacing: -.01em; }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: 13.5px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------------- Cards ---------------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 20px 0; }
.card-head h3 { font-size: 15px; font-weight: 600; margin: 0; }
.card-head .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.card-body { padding: 16px 20px 20px; }
.card-pad { padding: 18px 20px; }
.chart-box { position: relative; height: 280px; }
.chart-box.sm { height: 220px; }
.chart-box.lg { height: 330px; }

.kpi { padding: 16px 18px; display: flex; flex-direction: column; gap: 8px; position: relative; overflow: hidden; }
.kpi-top { display: flex; align-items: center; justify-content: space-between; }
.kpi-label { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.kpi-icon { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; background: var(--indigo-50); color: var(--indigo); }
.kpi-icon svg { width: 17px; height: 17px; }
.kpi-value { font-size: 22px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi-foot { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.delta { display: inline-flex; align-items: center; gap: 2px; font-weight: 600; font-size: 12px; padding: 1px 6px; border-radius: 6px; }
.delta svg { width: 13px; height: 13px; }
.delta.up { color: #15803d; background: #dcfce7; }
.delta.down { color: #b91c1c; background: #fee2e2; }
.delta.flat { color: var(--muted); background: #f1f5f9; }

.tone-green .kpi-icon { background: #dcfce7; color: #15803d; }
.tone-amber .kpi-icon { background: #fef3c7; color: #b45309; }
.tone-red .kpi-icon { background: #fee2e2; color: #b91c1c; }
.tone-sky .kpi-icon { background: #e0f2fe; color: #0369a1; }
.tone-slate .kpi-icon { background: #f1f5f9; color: #334155; }
.tone-violet .kpi-icon { background: #f3e8ff; color: #7e22ce; }

.grid-kpi { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 1279px) { .grid-kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) { .grid-kpi { grid-template-columns: 1fr; } }

/* ---------------- Buttons ---------------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 38px; padding: 0 15px; border-radius: 9px; font-size: 13.5px; font-weight: 600; font-family: inherit; border: 1px solid transparent; cursor: pointer; white-space: nowrap; transition: all .15s; }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--indigo); color: #fff; box-shadow: 0 1px 2px rgba(79,70,229,.3); }
.btn-primary:hover { background: var(--indigo-600); }
.btn-outline { background: #fff; border-color: var(--border-strong); color: var(--text-2); }
.btn-outline:hover { background: #f8fafc; border-color: #c3c9d8; }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: #eef1f7; }
.btn-success { background: #16a34a; color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-danger { background: #dc2626; color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-soft-danger { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.btn-soft-danger:hover { background: #fee2e2; }
.btn-soft { background: var(--indigo-50); color: var(--indigo-600); }
.btn-soft:hover { background: var(--indigo-100); }
.btn-sm { height: 32px; padding: 0 11px; font-size: 12.5px; border-radius: 8px; }
.btn-xs { height: 27px; padding: 0 9px; font-size: 12px; border-radius: 7px; gap: 5px; }
.btn-xs svg { width: 14px; height: 14px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.spin { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- Forms ---------------- */
.input, .select, .textarea {
  width: 100%; height: 38px; border: 1px solid var(--border-strong); border-radius: 9px; padding: 0 12px;
  font-size: 13.5px; font-family: inherit; color: var(--text); background: #fff; outline: none; transition: border .15s, box-shadow .15s;
}
.textarea { height: auto; min-height: 84px; padding: 9px 12px; resize: vertical; }
.select { appearance: none; padding-right: 32px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2364748b' stroke-width='2' viewBox='0 0 24 24'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--indigo); box-shadow: 0 0 0 3px rgba(79,70,229,.12); }
.input-sm, .select.input-sm { height: 34px; font-size: 13px; }
.field.invalid .input, .field.invalid .select, .field.invalid .textarea, .field.invalid .check-grid, .field.invalid .pf-alloc { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(220,38,38,.08); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
.field label.lbl { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.field .req { color: var(--danger); margin-left: 2px; }
.field-error { color: var(--danger); font-size: 12px; margin-top: 5px; display: none; }
.field.invalid .field-error { display: block; }
.field-help { color: var(--muted); font-size: 12px; margin-top: 5px; }
.form-section { grid-column: 1 / -1; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; padding-top: 6px; border-top: 1px dashed var(--border); margin-top: 4px; }
.check-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 12px; border: 1px solid var(--border-strong); border-radius: 9px; padding: 10px 12px; max-height: 200px; overflow-y: auto; }
.check-grid .cg-group { grid-column: 1 / -1; font-size: 11px; font-weight: 700; color: var(--muted-2); text-transform: uppercase; letter-spacing: .06em; margin-top: 4px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--indigo); }

.pf-alloc { border: 1px solid var(--border-strong); border-radius: 10px; overflow: hidden; }
.pf-row { display: grid; grid-template-columns: 170px 1fr 170px; gap: 10px; align-items: center; padding: 10px 12px; border-bottom: 1px solid #eef1f6; }
.pf-row.off { background: #fafbfd; }
.pf-row.off .select, .pf-row.off .input { opacity: .5; pointer-events: none; }
.pf-total { display: flex; justify-content: space-between; padding: 10px 12px; background: #f8fafc; font-size: 13px; }
@media (max-width: 640px) { .pf-row { grid-template-columns: 1fr; } }

/* toggle switch */
.switch { position: relative; width: 36px; height: 20px; display: inline-block; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #cbd5e1; border-radius: 20px; cursor: pointer; transition: .2s; }
.switch span::before { content: ''; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--indigo); }
.switch input:checked + span::before { transform: translateX(16px); }
.switch input:disabled + span { opacity: .5; cursor: not-allowed; }

/* ---------------- Toolbar / filters ---------------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.toolbar .input, .toolbar .select { height: 36px; font-size: 13px; width: auto; min-width: 150px; }
.toolbar .tb-search { position: relative; flex: 1; min-width: 200px; max-width: 320px; }
.toolbar .tb-search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); }
.toolbar .tb-search .input { padding-left: 34px; width: 100%; }
.toolbar .tb-right { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.seg { display: inline-flex; background: #eef1f7; border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; font-size: 12.5px; font-weight: 600; color: var(--muted); cursor: pointer; font-family: inherit; white-space: nowrap; }
.seg button:hover { color: var(--text); }
.seg button.active { background: #fff; color: var(--indigo-600); box-shadow: var(--shadow-sm); }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs button { border: 0; background: none; padding: 12px 14px; font-size: 13.5px; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; font-family: inherit; display: inline-flex; align-items: center; gap: 7px; }
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--indigo-600); border-bottom-color: var(--indigo); }
.tabs .tab-count { background: #eef1f7; color: var(--muted); font-size: 11px; padding: 1px 7px; border-radius: 10px; }
.tabs button.active .tab-count { background: var(--indigo-50); color: var(--indigo-600); }

/* ---------------- Badges ---------------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 600; white-space: nowrap; line-height: 18px; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.badge.nodot::before { display: none; }
.badge-gray { background: #f1f5f9; color: #475569; }
.badge-amber { background: #fef3c7; color: #b45309; }
.badge-sky { background: #e0f2fe; color: #0369a1; }
.badge-green { background: #dcfce7; color: #15803d; }
.badge-orange { background: #ffedd5; color: #c2410c; }
.badge-indigo { background: #e0e7ff; color: #4338ca; }
.badge-red { background: #fee2e2; color: #b91c1c; }
.badge-violet { background: #f3e8ff; color: #7e22ce; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 500; background: #f1f5f9; color: var(--text-2); white-space: nowrap; }
.chip .dot { width: 8px; height: 8px; border-radius: 3px; }

.pf { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 6px; color: #fff; font-weight: 800; font-size: 12px; font-family: Arial, sans-serif; flex-shrink: 0; }
.pf.lg { width: 40px; height: 40px; border-radius: 11px; font-size: 20px; }
.pf.md { width: 30px; height: 30px; border-radius: 8px; font-size: 15px; }
.pf-facebook { background: #1877F2; }
.pf-google { background: #fff; color: #4285F4; border: 1px solid #dfe3ea; }
.pf-tiktok { background: #111827; box-shadow: inset -2px 0 0 #FE2C55, inset 2px 0 0 #25F4EE; }
.pf-stack { display: inline-flex; gap: 4px; }

.avatar { display: inline-grid; place-items: center; border-radius: 50%; color: #fff; font-weight: 600; flex-shrink: 0; font-size: 12px; width: 32px; height: 32px; }
.avatar.xs { width: 24px; height: 24px; font-size: 10px; }
.avatar.sm { width: 28px; height: 28px; font-size: 11px; }
.avatar.lg { width: 44px; height: 44px; font-size: 15px; }
.avatar.xl { width: 56px; height: 56px; font-size: 18px; }
.avatar-stack { display: inline-flex; }
.avatar-stack .avatar { border: 2px solid #fff; margin-left: -7px; }
.avatar-stack .avatar:first-child { margin-left: 0; }

.progress { height: 7px; background: #eef1f6; border-radius: 10px; overflow: hidden; min-width: 60px; }
.progress > span { display: block; height: 100%; border-radius: 10px; background: var(--indigo); transition: width .4s ease; }
.progress.green > span { background: #16a34a; }
.progress.amber > span { background: #f59e0b; }
.progress.red > span { background: #dc2626; }
.progress-cell { display: flex; align-items: center; gap: 8px; min-width: 120px; }
.progress-cell .progress { flex: 1; }
.progress-cell small { font-size: 11.5px; color: var(--muted); width: 38px; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------------- Table ---------------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; font-weight: 600; font-size: 11.5px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); background: #f8fafc; padding: 11px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; user-select: none; }
.tbl th.sortable { cursor: pointer; }
.tbl th.sortable:hover { color: var(--text); }
.tbl th .sort-ic { display: inline-block; margin-left: 4px; opacity: .35; font-size: 10px; }
.tbl th.sorted .sort-ic { opacity: 1; color: var(--indigo); }
.tbl td { padding: 11px 12px; border-bottom: 1px solid #f0f2f7; vertical-align: middle; }
.tbl tbody tr { transition: background .1s; }
.tbl tbody tr:hover { background: #fafbff; }
.tbl tbody tr.clickable { cursor: pointer; }
.tbl tbody tr.row-warn { background: #fffbeb; }
.tbl tbody tr.row-danger { background: #fef6f6; }
.tbl .right { text-align: right; }
.tbl .center { text-align: center; }
.tbl tfoot td { font-weight: 700; background: #f8fafc; border-top: 1px solid var(--border); }
.cell-title { font-weight: 600; color: var(--text); }
.cell-sub { font-size: 12px; color: var(--muted); margin-top: 1px; }
.row-actions { display: inline-flex; gap: 2px; justify-content: flex-end; }
.pager { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; font-size: 12.5px; color: var(--muted); gap: 10px; flex-wrap: wrap; }
.pager-btns { display: flex; gap: 4px; }
.pager-btns button { min-width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--border); background: #fff; cursor: pointer; font-size: 12.5px; font-weight: 600; color: var(--text-2); display: grid; place-items: center; padding: 0 8px; font-family: inherit; }
.pager-btns button:hover:not([disabled]) { border-color: var(--indigo); color: var(--indigo); }
.pager-btns button.active { background: var(--indigo); border-color: var(--indigo); color: #fff; }
.pager-btns button[disabled] { opacity: .4; cursor: not-allowed; }
.pager-btns svg { width: 15px; height: 15px; }

/* ---------------- Empty / skeleton ---------------- */
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty-ic { width: 56px; height: 56px; border-radius: 16px; background: #f1f4f9; display: grid; place-items: center; margin: 0 auto 14px; color: var(--muted-2); }
.empty-ic svg { width: 26px; height: 26px; }
.empty h4 { margin: 0 0 4px; color: var(--text); font-size: 15px; }
.empty p { margin: 0 auto 14px; font-size: 13px; max-width: 360px; }
.skel { background: linear-gradient(90deg, #eceff5 25%, #f6f7fb 37%, #eceff5 63%); background-size: 400% 100%; animation: skel 1.3s ease infinite; border-radius: 8px; }
@keyframes skel { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ---------------- Modal / Drawer ---------------- */
.overlay { position: fixed; inset: 0; background: rgba(11,21,51,.45); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 20px; opacity: 0; transition: opacity .18s; }
.overlay.show { opacity: 1; }
.modal { background: #fff; border-radius: 14px; box-shadow: var(--shadow-lg); width: 100%; max-height: calc(100vh - 40px); display: flex; flex-direction: column; transform: translateY(10px) scale(.98); transition: transform .18s; }
.overlay.show .modal { transform: none; }
.modal-sm { max-width: 420px; }
.modal-md { max-width: 580px; }
.modal-lg { max-width: 760px; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 22px 14px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 17px; font-weight: 700; }
.modal-head p { margin: 3px 0 0; font-size: 13px; color: var(--muted); }
.modal-body { padding: 18px 22px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 22px; border-top: 1px solid var(--border); background: #fafbfd; border-radius: 0 0 14px 14px; }
.overlay.drawer-ov { justify-content: flex-end; padding: 0; align-items: stretch; }
.drawer { background: #fff; width: 100%; max-width: 560px; height: 100%; display: flex; flex-direction: column; box-shadow: var(--shadow-lg); transform: translateX(30px); transition: transform .2s; }
.overlay.show .drawer { transform: none; }
.drawer .modal-body { flex: 1; }
.confirm-ic { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; margin-bottom: 12px; }
.confirm-ic.danger { background: #fee2e2; color: #dc2626; }
.confirm-ic.info { background: var(--indigo-50); color: var(--indigo); }

/* ---------------- Toast / Tooltip ---------------- */
.toast-root { position: fixed; right: 20px; bottom: 20px; z-index: 200; display: flex; flex-direction: column; gap: 10px; align-items: flex-end; }
.toast { display: flex; gap: 12px; align-items: flex-start; background: #fff; border: 1px solid var(--border); border-left: 4px solid var(--indigo); border-radius: 10px; padding: 12px 14px; box-shadow: var(--shadow-lg); min-width: 300px; max-width: 400px; animation: toastIn .25s ease-out; }
.toast.out { animation: toastOut .2s ease-in forwards; }
.toast.success { border-left-color: #16a34a; } .toast.success .t-ic { color: #16a34a; }
.toast.error { border-left-color: #dc2626; } .toast.error .t-ic { color: #dc2626; }
.toast.warning { border-left-color: #d97706; } .toast.warning .t-ic { color: #d97706; }
.toast.info .t-ic { color: var(--indigo); }
.toast .t-title { font-weight: 600; font-size: 13.5px; }
.toast .t-msg { font-size: 12.5px; color: var(--muted); }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateX(20px); } }
.tooltip { position: fixed; z-index: 300; background: #0f172a; color: #fff; font-size: 12px; font-weight: 500; padding: 5px 9px; border-radius: 6px; pointer-events: none; opacity: 0; transition: opacity .12s; max-width: 260px; white-space: normal; }
.tooltip.show { opacity: 1; }

/* ---------------- Lists ---------------- */
.li-row { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid #f0f2f7; }
.li-row:last-child { border-bottom: 0; }
.activity { display: flex; gap: 12px; padding: 10px 0; position: relative; }
.activity:not(:last-child)::before { content: ''; position: absolute; left: 15px; top: 42px; bottom: -4px; width: 2px; background: #eef1f6; }
.activity .a-text { font-size: 13px; color: var(--text-2); }
.activity .a-text b { color: var(--text); font-weight: 600; }
.activity .a-time { font-size: 11.5px; color: var(--muted-2); margin-top: 2px; }
.alert-row { display: flex; gap: 12px; padding: 12px; border-radius: 10px; border: 1px solid var(--border); margin-bottom: 10px; align-items: center; cursor: pointer; transition: border .15s; }
.alert-row:hover { border-color: var(--indigo); }
.callout { display: flex; gap: 12px; padding: 14px 16px; border-radius: 10px; background: var(--indigo-50); color: #312e81; font-size: 13px; border: 1px solid var(--indigo-100); }
.callout svg { color: var(--indigo); margin-top: 1px; }
.callout.amber { background: #fffbeb; border-color: #fde68a; color: #78350f; }
.callout.amber svg { color: #d97706; }

.stat-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; font-size: 13px; border-bottom: 1px dashed #eceff5; }
.stat-row:last-child { border-bottom: 0; }
.stat-row .k { color: var(--muted); }
.stat-row .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.info-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 20px; }
.info-grid .k { font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.info-grid .v { font-weight: 600; font-size: 13.5px; }

/* demo flow */
.flow { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.flow-step { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px; border-radius: 30px; background: #fff; border: 1px solid var(--indigo-100); font-size: 12.5px; font-weight: 600; color: var(--text-2); cursor: pointer; transition: all .15s; }
.flow-step:hover { border-color: var(--indigo); color: var(--indigo); }
.flow-step .n { width: 22px; height: 22px; border-radius: 50%; background: var(--indigo); color: #fff; display: grid; place-items: center; font-size: 11px; }
.flow-arrow { color: var(--muted-2); }
.flow-arrow svg { width: 14px; height: 14px; }

/* ---------------- Org chart ---------------- */
.org { display: flex; flex-direction: column; align-items: center; align-items: safe center; gap: 0; overflow-x: auto; padding: 10px 0 20px; }
.org-node { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow-sm); display: flex; align-items: center; gap: 10px; min-width: 220px; }
.org-node.root { background: var(--navy-900); color: #fff; border-color: var(--navy-900); }
.org-node.root .cell-sub { color: #a5b0cf; }
.org-v { width: 2px; height: 24px; background: #d5dae6; }
.org-level { display: flex; gap: 18px; position: relative; padding-top: 24px; justify-content: center; }
.org-level::before { content: ''; position: absolute; top: 0; left: var(--l, 10%); right: var(--r, 10%); height: 2px; background: #d5dae6; }
.org-branch { display: flex; flex-direction: column; align-items: center; position: relative; }
.org-branch::before { content: ''; position: absolute; top: -24px; width: 2px; height: 24px; background: #d5dae6; }
.org-team { width: 250px; background: #fff; border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-sm); overflow: hidden; cursor: pointer; transition: border .15s, box-shadow .15s; }
.org-team:hover { border-color: var(--indigo); box-shadow: var(--shadow); }
.org-team-head { padding: 12px 14px; border-top: 4px solid var(--c, var(--indigo)); border-bottom: 1px solid var(--border); }
.org-member { display: flex; align-items: center; gap: 9px; padding: 7px 14px; font-size: 12.5px; }
.org-member:nth-child(odd) { background: #fafbfd; }

/* ---------------- Kanban ---------------- */
.kanban { display: grid; grid-template-columns: repeat(4, minmax(260px, 1fr)); gap: 16px; overflow-x: auto; padding-bottom: 8px; align-items: start; }
.k-col { background: #eef1f7; border-radius: 12px; padding: 10px; min-height: 420px; transition: background .15s, box-shadow .15s; }
.k-col.drag-over { background: #e0e7ff; box-shadow: inset 0 0 0 2px var(--indigo); }
.k-col-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 10px; font-weight: 600; font-size: 13px; }
.k-col-head .k-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 8px; }
.k-card { background: #fff; border-radius: 10px; padding: 12px; margin-bottom: 10px; box-shadow: var(--shadow-sm); border: 1px solid #e6e9f2; cursor: grab; transition: box-shadow .15s, transform .15s; }
.k-card:hover { box-shadow: var(--shadow); }
.k-card.dragging { opacity: .45; transform: rotate(1.5deg); }
.k-card .k-title { font-weight: 600; font-size: 13px; margin: 6px 0 8px; line-height: 1.35; }
.k-card .k-meta { display: flex; align-items: center; justify-content: space-between; gap: 6px; font-size: 11.5px; color: var(--muted); }
.k-card .k-overdue { color: var(--danger); font-weight: 600; }
.k-empty { border: 2px dashed #d5dae6; border-radius: 10px; padding: 24px 10px; text-align: center; font-size: 12.5px; color: var(--muted-2); }

/* ---------------- Account cards ---------------- */
.acc-card { padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; }
.acc-card.disconnected { background: #fcfcfd; }
.acc-head { display: flex; gap: 12px; align-items: flex-start; }
.acc-name { font-weight: 600; font-size: 14px; line-height: 1.3; }
.acc-id { font-size: 12px; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.acc-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; background: #f8fafc; border-radius: 9px; padding: 10px; }
.acc-stats .k { font-size: 11px; color: var(--muted); }
.acc-stats .v { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.acc-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); }

.connect-pf { display: flex; align-items: center; gap: 12px; padding: 14px; border: 1px solid var(--border-strong); border-radius: 12px; cursor: pointer; transition: all .15s; }
.connect-pf:hover { border-color: var(--indigo); background: #fafaff; }
.connect-pf.selected { border-color: var(--indigo); box-shadow: 0 0 0 3px rgba(79,70,229,.12); background: #fafaff; }

/* perm matrix */
.perm-tbl td, .perm-tbl th { text-align: center; }
.perm-tbl td:first-child, .perm-tbl th:first-child { text-align: left; }

/* ---------------- Responsive grid helpers ---------------- */
.grid-12 { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 16px; }
.c-12 { grid-column: span 12; } .c-8 { grid-column: span 8; } .c-7 { grid-column: span 7; } .c-6 { grid-column: span 6; } .c-5 { grid-column: span 5; } .c-4 { grid-column: span 4; } .c-3 { grid-column: span 3; }
@media (max-width: 1279px) { .c-8, .c-7, .c-6, .c-5, .c-4 { grid-column: span 12; } .c-3 { grid-column: span 6; } .c-4.keep { grid-column: span 6; } }
@media (max-width: 640px) { .c-3, .c-4.keep { grid-column: span 12; } }
.stack > * + * { margin-top: 16px; }
.mb-4x { margin-bottom: 16px; }

/* ---------------- Print ---------------- */
@media print {
  .sidebar, .topbar, .sb-backdrop, .page-actions, .no-print, .toast-root, .scope-banner, .toolbar, .pager { display: none !important; }
  .main-wrap { margin: 0 !important; }
  .page { padding: 0; max-width: none; }
  body { background: #fff; }
  .card { box-shadow: none; break-inside: avoid; }
  .print-only { display: block !important; }
}
.print-only { display: none; }
