/* aiNGo Client Hub — Phase 2A Standalone Responsive Stylesheet (Desktop 1440px + Mobile 390px, Light & Dark) */
:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-2: #f0f4f9;
  --border: #dce4ee;
  --text: #0f172a;
  --text-muted: #526075;
  --brand: #0d9488;
  --brand-strong: #0f766e;
  --brand-soft: #ccfbf1;
  --brand-ink: #115e59;
  --navy: #0f1f38;
  --ok-bg: #dcfce7;
  --ok-ink: #166534;
  --warn-bg: #fef3c7;
  --warn-ink: #92400e;
  --danger-bg: #fee2e2;
  --danger-ink: #991b1b;
  --info-bg: #e0f2fe;
  --info-ink: #075985;
  --purple-bg: #f3e8ff;
  --purple-ink: #6b21a8;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.05);
  --radius: 14px;
  --radius-sm: 10px;
}

html[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #111b2e;
  --surface-2: #17233a;
  --border: #24334f;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --brand: #14b8a6;
  --brand-strong: #2dd4bf;
  --brand-soft: rgba(20, 184, 166, 0.16);
  --brand-ink: #5eead4;
  --navy: #09101d;
  --ok-bg: rgba(34, 197, 94, 0.16);
  --ok-ink: #86efac;
  --warn-bg: rgba(245, 158, 11, 0.16);
  --warn-ink: #fcd34d;
  --danger-bg: rgba(239, 68, 68, 0.16);
  --danger-ink: #fca5a5;
  --info-bg: rgba(56, 189, 248, 0.16);
  --info-ink: #7dd3fc;
  --purple-bg: rgba(168, 85, 247, 0.18);
  --purple-ink: #d8b4fe;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
}

*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  max-width: 100%;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* Auth Screen */
.auth-shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background: radial-gradient(circle at top right, var(--brand-soft), transparent 45%), var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
}
.brand-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.brand-mark { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.05rem; letter-spacing: -0.02em; }
.brand-dot {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, var(--brand), var(--brand-strong));
  color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 0.9rem; flex-shrink: 0;
}
.auth-title { margin: 0 0 6px; font-size: 1.38rem; letter-spacing: -0.02em; }
.auth-sub { margin: 0 0 20px; color: var(--text-muted); font-size: 0.92rem; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 0.82rem; font-weight: 600; margin-bottom: 6px; color: var(--text-muted); }
.input, .select, .textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.93rem;
}
.textarea { min-height: 88px; resize: vertical; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 15px; border-radius: var(--radius-sm);
  border: 1px solid transparent; font-weight: 600; font-size: 0.88rem;
  transition: transform 0.12s ease, opacity 0.12s ease, background 0.12s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-strong); }
.btn-secondary { background: var(--surface-2); border-color: var(--border); color: var(--text); }
.btn-secondary:hover { background: var(--border); }
.btn-ghost { background: transparent; color: var(--text-muted); padding: 7px 10px; }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger-bg); color: var(--danger-ink); border-color: transparent; }
.btn-sm { padding: 6px 11px; font-size: 0.8rem; }
.btn-block { width: 100%; }
.divider { display: flex; align-items: center; gap: 10px; margin: 16px 0; color: var(--text-muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* App Shell */
.shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100dvh; }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: sticky;
  top: 0;
  height: 100dvh;
  overflow-y: auto;
}
.nav-section {
  font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-muted); padding: 10px 10px 4px;
}
.nav-btn {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 11px; border-radius: 10px; border: 0; background: transparent;
  color: var(--text-muted); font-weight: 600; font-size: 0.88rem; text-align: left;
}
.nav-btn-left { display: inline-flex; align-items: center; gap: 9px; min-width: 0; }
.nav-btn-left span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-btn:hover { background: var(--surface-2); color: var(--text); }
.nav-btn.active { background: var(--brand-soft); color: var(--brand-ink); }
.nav-count {
  font-size: 0.72rem; font-weight: 700; padding: 1px 7px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-muted);
}
.nav-btn.active .nav-count { background: var(--brand); color: #fff; }

.main-col { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 25;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 10px 20px; display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 8px; min-width: 0; flex-wrap: nowrap; }
.tenant-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 0.78rem; font-weight: 600; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.icon-btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 10px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font-size: 0.82rem; font-weight: 600;
}
.icon-btn:hover { border-color: var(--brand); }
.unread-dot {
  position: absolute; top: 4px; right: 4px; width: 8px; height: 8px; border-radius: 50%;
  background: #ef4444; box-shadow: 0 0 0 2px var(--surface);
}
.ask-pill {
  background: linear-gradient(135deg, var(--brand), var(--brand-strong));
  color: #fff; border: 0; padding: 7px 12px; border-radius: 999px;
  font-size: 0.82rem; font-weight: 700; display: inline-flex; align-items: center; gap: 6px;
}

.content {
  padding: 20px 22px 44px;
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
}

/* Banners & Badges */
.banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 11px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  margin-bottom: 18px; font-size: 0.86rem;
}
.banner-safe { background: var(--warn-bg); color: var(--warn-ink); border-color: transparent; }
.banner-info { background: var(--info-bg); color: var(--info-ink); border-color: transparent; }
.banner-ok { background: var(--ok-bg); color: var(--ok-ink); border-color: transparent; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 999px; font-size: 0.74rem; font-weight: 700; white-space: nowrap;
}
.badge-ok { background: var(--ok-bg); color: var(--ok-ink); }
.badge-warn { background: var(--warn-bg); color: var(--warn-ink); }
.badge-danger { background: var(--danger-bg); color: var(--danger-ink); }
.badge-info { background: var(--info-bg); color: var(--info-ink); }
.badge-purple { background: var(--purple-bg); color: var(--purple-ink); }
.badge-muted { background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }

/* Headings & Cards */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-title { margin: 0; font-size: 1.45rem; letter-spacing: -0.02em; }
.page-sub { margin: 3px 0 0; color: var(--text-muted); font-size: 0.9rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card + .card { margin-top: 14px; }
.card-title { margin: 0 0 12px; font-size: 1rem; font-weight: 700; display: flex; align-items: center; justify-content: space-between; gap: 8px; }

/* Tile Home Grid */
.tile-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: var(--shadow);
  transition: transform 0.14s ease, border-color 0.14s ease, box-shadow 0.14s ease;
  min-width: 0;
}
.tile:hover {
  transform: translateY(-2px);
  border-color: var(--brand);
}
.tile-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tile-icon {
  width: 38px; height: 38px; border-radius: 11px;
  background: var(--brand-soft); color: var(--brand-ink);
  display: grid; place-items: center; flex-shrink: 0;
}
.tile-title { font-weight: 700; font-size: 0.98rem; color: var(--text); }
.tile-desc { font-size: 0.82rem; color: var(--text-muted); line-height: 1.4; }

/* Roadmap strip */
.roadmap-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
  margin-top: 10px;
}
.roadmap-item {
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
}
.roadmap-item strong { display: block; font-size: 0.86rem; margin-bottom: 3px; }
.roadmap-item span { font-size: 0.78rem; color: var(--text-muted); }

/* KPI Grid */
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 15px; box-shadow: var(--shadow); }
.kpi-label { font-size: 0.78rem; color: var(--text-muted); font-weight: 600; }
.kpi-val { font-size: 1.65rem; font-weight: 800; margin: 4px 0; letter-spacing: -0.03em; }
.kpi-sub { font-size: 0.78rem; color: var(--text-muted); }

/* Filters & Lists */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .input { flex: 1 1 200px; min-width: 0; }
.toolbar .select { flex: 0 1 180px; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.list-stack { display: flex; flex-direction: column; gap: 10px; }
.item-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  min-width: 0;
}
.item-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.item-title { font-weight: 700; font-size: 0.96rem; margin: 0; }
.item-meta { font-size: 0.81rem; color: var(--text-muted); margin-top: 3px; }
.item-body { margin: 9px 0 0; font-size: 0.89rem; color: var(--text); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

/* Table wrapper */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 0.87rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }

/* Toggle Switch */
.switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 11px 0; border-bottom: 1px solid var(--border);
}
.switch-row:last-child { border-bottom: 0; }
.switch-row strong { display: block; font-size: 0.9rem; }
.switch-row small { color: var(--text-muted); font-size: 0.8rem; }

/* Slide-over Drawers & Modals */
.drawer-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(15, 23, 42, 0.45);
  display: flex; justify-content: flex-end;
}
.drawer {
  width: 100%; max-width: 440px; height: 100dvh;
  background: var(--surface); border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  box-shadow: -8px 0 30px rgba(0, 0, 0, 0.22);
}
.drawer-head {
  padding: 16px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.drawer-body { padding: 16px 18px; overflow-y: auto; flex: 1; }
.drawer-foot { padding: 12px 18px; border-top: 1px solid var(--border); background: var(--surface-2); }

/* Chat Bubbles (Ask Aingo & Texts) */
.chat-log { display: flex; flex-direction: column; gap: 10px; }
.bubble {
  max-width: 88%; padding: 10px 13px; border-radius: 13px; font-size: 0.88rem; line-height: 1.45;
}
.bubble-in { background: var(--surface-2); color: var(--text); align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble-out { background: var(--brand); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }

/* Toast */
.toast {
  position: fixed; right: 18px; bottom: 82px; z-index: 80;
  background: var(--navy); color: #fff; padding: 10px 15px; border-radius: 10px;
  font-size: 0.86rem; font-weight: 600; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

/* Mobile Bottom Nav & More Sheet */
.mobile-nav { display: none; }
.more-sheet-backdrop {
  position: fixed; inset: 0; z-index: 55; background: rgba(15, 23, 42, 0.45);
  display: flex; align-items: flex-end;
}
.more-sheet {
  width: 100%; background: var(--surface); border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(18px + env(safe-area-inset-bottom));
  max-height: 82dvh; overflow-y: auto;
}
.more-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 12px; }

@media (max-width: 1080px) {
  .tile-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .topbar { padding: 10px 12px; }
  .tenant-pill { display: none; }
  .content { padding: 14px 12px 92px; }
  .tile-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .grid-2 { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .mobile-nav {
    display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .mobile-nav button {
    border: 0; background: transparent; color: var(--text-muted);
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 4px 2px; font-size: 0.69rem; font-weight: 600;
  }
  .mobile-nav button.active { color: var(--brand); }
}

/* Phase 2B Live-Ops UI utilities */
.progress-track {
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: var(--surface-2, rgba(148, 163, 184, 0.2));
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--brand, #2563eb), #10b981);
  transition: width 0.25s ease;
}
.progress-fill.warn {
  background: linear-gradient(90deg, #f59e0b, #ef4444);
}
.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}
.bh-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 8px;
}
.bh-pill {
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2, rgba(148, 163, 184, 0.08));
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 0.82rem;
}
.bh-pill.active {
  border-color: var(--brand, #2563eb);
}
.list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2, rgba(148, 163, 184, 0.06));
  flex-wrap: wrap;
}
.list-item-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}
.list-item-main small {
  color: var(--muted);
  font-size: 0.82rem;
}
.banner-warn {
  border-color: rgba(245, 158, 11, 0.45);
  background: rgba(245, 158, 11, 0.1);
}
.badge-brand {
  background: rgba(37, 99, 235, 0.14);
  color: var(--brand, #2563eb);
}
