/* DoctorBX IA — SaaS light theme (teal / slate) */
:root {
  --bg: #f3f6f8;
  --bg-elevated: #ffffff;
  --sidebar: #0f2a32;
  --sidebar-2: #14363f;
  --sidebar-text: #c5d5da;
  --sidebar-active: #1a9b8e;
  --primary: #0d9488;
  --primary-dark: #0f766e;
  --primary-soft: rgba(13, 148, 136, 0.12);
  --slate: #334155;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --amber: #d97706;
  --rose: #e11d48;
  --radius: 14px;
  --shadow: 0 8px 24px rgba(15, 42, 50, 0.06);
  --shadow-sm: 0 2px 8px rgba(15, 42, 50, 0.04);
  --font: "DM Sans", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --sidebar-w: 268px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button, .btn { font-family: inherit; }

/* Shell */
.app-shell { display: flex; min-height: 100vh; }
.app-shell:has(.chat-page) { height: 100vh; overflow: hidden; }
.app-main { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.app-content { padding: 1.25rem 1.5rem 2rem; flex: 1; min-height: 0; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--sidebar) 0%, #0b2228 100%);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 100;
  transition: transform .25s ease;
}
.sidebar-brand {
  display: flex; align-items: center; gap: .85rem;
  padding: 1.25rem 1.2rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.brand-mark {
  width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #14b8a6, #0d9488);
  color: #fff; font-size: 1.15rem;
  box-shadow: 0 8px 20px rgba(13,148,136,.35);
}
.brand-mark.lg { width: 56px; height: 56px; font-size: 1.5rem; border-radius: 16px; }
.brand-name { color: #fff; font-weight: 700; letter-spacing: -.02em; }
.brand-sub { font-size: .75rem; opacity: .65; }
.sidebar-nav { padding: .75rem .75rem; overflow-y: auto; flex: 1; }
.nav-section {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .08em;
  opacity: .45; padding: .85rem .75rem .35rem; font-weight: 600;
}
.sidebar .nav-link {
  display: flex; align-items: center; gap: .7rem;
  padding: .65rem .85rem; border-radius: 10px;
  color: var(--sidebar-text); margin-bottom: .15rem;
  transition: background .2s, color .2s, transform .15s;
}
.sidebar .nav-link i { font-size: 1.1rem; opacity: .85; width: 1.25rem; text-align: center; }
.sidebar .nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar .nav-link.active {
  background: rgba(20,184,166,.18); color: #5eead4;
  box-shadow: inset 3px 0 0 var(--sidebar-active);
}
.sidebar-footer { padding: .85rem; border-top: 1px solid rgba(255,255,255,.06); }
.user-chip {
  display: flex; align-items: center; gap: .65rem;
  padding: .55rem .65rem; border-radius: 12px; background: rgba(255,255,255,.04);
}
.user-meta { flex: 1; min-width: 0; }
.user-meta strong { display: block; color: #fff; font-size: .85rem; }
.user-meta small { opacity: .55; text-transform: capitalize; }
.logout-btn { color: var(--sidebar-text); opacity: .7; }
.logout-btn:hover { color: #fff; opacity: 1; }
.sidebar-overlay {
  display: none; position: fixed; inset: 0; background: rgba(15,42,50,.45); z-index: 90;
}

/* Topbar */
.topbar {
  display: flex; align-items: center; gap: 1rem;
  padding: .9rem 1.5rem; background: rgba(255,255,255,.82);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.topbar-title h1 { font-size: 1.15rem; margin: 0; font-weight: 700; letter-spacing: -.02em; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: .75rem; }
.btn-icon { border: 1px solid var(--border); background: #fff; width: 40px; height: 40px; border-radius: 10px; }
.status-pill {
  display: inline-flex; align-items: center; gap: .4rem;
  background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0;
  font-size: .78rem; font-weight: 600; padding: .35rem .7rem; border-radius: 999px;
}
.status-pill .dot {
  width: 7px; height: 7px; border-radius: 50%; background: #10b981;
  box-shadow: 0 0 0 0 rgba(16,185,129,.5); animation: pulse 2s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(16,185,129,.45); }
  70% { box-shadow: 0 0 0 8px rgba(16,185,129,0); }
  100% { box-shadow: 0 0 0 0 rgba(16,185,129,0); }
}

/* Buttons */
.btn-primary {
  --bs-btn-bg: var(--primary);
  --bs-btn-border-color: var(--primary);
  --bs-btn-hover-bg: var(--primary-dark);
  --bs-btn-hover-border-color: var(--primary-dark);
  --bs-btn-active-bg: var(--primary-dark);
  --bs-btn-active-border-color: var(--primary-dark);
  box-shadow: 0 6px 16px rgba(13,148,136,.25);
}
.btn-outline-primary {
  --bs-btn-color: var(--primary);
  --bs-btn-border-color: #99f6e4;
  --bs-btn-hover-bg: var(--primary);
  --bs-btn-hover-border-color: var(--primary);
}

/* Cards / panels */
.page-fade { animation: fadeUp .35s ease; }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
.page-toolbar {
  display: flex; justify-content: space-between; align-items: center;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem;
}
.page-desc { color: var(--muted); }
.filter-bar { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

.stat-card {
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.1rem 1.15rem;
  display: flex; gap: .9rem; align-items: center;
  box-shadow: var(--shadow-sm); transition: transform .2s, box-shadow .2s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat-icon {
  width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; font-size: 1.2rem;
}
.stat-icon.teal { background: var(--primary-soft); color: var(--primary); }
.stat-icon.slate { background: #e2e8f0; color: #475569; }
.stat-icon.amber { background: #fff7ed; color: var(--amber); }
.stat-icon.rose { background: #fff1f2; color: var(--rose); }
.stat-label { color: var(--muted); font-size: .8rem; font-weight: 500; }
.stat-value { font-size: 1.55rem; font-weight: 700; letter-spacing: -.03em; line-height: 1.1; }
.text-teal { color: var(--primary); }

.panel {
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden;
}
.panel-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: .95rem 1.15rem; border-bottom: 1px solid var(--border);
}
.panel-header h2 { font-size: .95rem; margin: 0; font-weight: 700; }
.panel-body { padding: 1.15rem; }
.panel-footer { padding: .9rem 1.15rem; border-top: 1px solid var(--border); background: #fafbfc; }

.list-row {
  display: flex; align-items: center; gap: .85rem;
  padding: .85rem 1.15rem; border-bottom: 1px solid var(--border);
}
.list-row:last-child { border-bottom: 0; }
.list-row-link:hover { background: #f8fafc; }
.rank {
  width: 26px; height: 26px; border-radius: 8px; background: var(--primary-soft);
  color: var(--primary); display: grid; place-items: center; font-size: .75rem; font-weight: 700;
}
.metric-row {
  display: flex; justify-content: space-between; padding: .55rem 0;
  border-bottom: 1px dashed var(--border);
}
.progress-soft {
  height: 7px; background: #eef2f6; border-radius: 999px; overflow: hidden;
}
.progress-soft .bar {
  height: 100%; background: linear-gradient(90deg, #14b8a6, #0d9488);
  border-radius: 999px; transition: width .5s ease;
}

.avatar {
  width: 38px; height: 38px; border-radius: 11px;
  background: linear-gradient(135deg, #99f6e4, #5eead4);
  color: #115e59; display: grid; place-items: center;
  font-weight: 700; font-size: .8rem; flex-shrink: 0;
}
.avatar.sm { width: 30px; height: 30px; font-size: .7rem; border-radius: 8px; }
.avatar.lg { width: 56px; height: 56px; font-size: 1.1rem; border-radius: 16px; }

/* Badges */
.badge-soft-primary { background: var(--primary-soft); color: #0f766e; }
.badge-soft-success { background: #ecfdf5; color: #047857; }
.badge-soft-warning { background: #fffbeb; color: #b45309; }
.badge-soft-danger { background: #fff1f2; color: #be123c; }
.badge-soft-info { background: #ecfeff; color: #0e7490; }
.badge-soft-secondary { background: #f1f5f9; color: #475569; }

/* Tables */
.table { --bs-table-bg: transparent; }
.table thead th {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); font-weight: 600; border-bottom-width: 1px;
  background: #f8fafc;
}
.form-control, .form-select {
  border-color: var(--border); border-radius: 10px;
  padding: .6rem .85rem;
}
.form-control:focus, .form-select:focus {
  border-color: #5eead4; box-shadow: 0 0 0 .2rem rgba(13,148,136,.15);
}

/* Products */
.product-card {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; height: 100%; box-shadow: var(--shadow-sm);
  transition: transform .2s, box-shadow .2s;
}
.product-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.product-cover {
  height: 120px; background:
    radial-gradient(circle at 20% 20%, rgba(94,234,212,.35), transparent 45%),
    linear-gradient(135deg, #0f2a32, #134e4a);
  display: flex; align-items: flex-end; justify-content: space-between;
  padding: 1rem; color: #99f6e4; font-size: 2rem; position: relative;
}
.product-cover .badge { position: absolute; top: .75rem; right: .75rem; }
.product-body { padding: 1rem 1.1rem 1.15rem; }
.product-body h3 { font-size: 1.05rem; margin: 0 0 .35rem; font-weight: 700; }
.product-body p { margin: 0; color: var(--muted); font-size: .9rem; }

.media-tile, .library-card {
  display: flex; gap: .75rem; align-items: center;
  border: 1px solid var(--border); border-radius: 12px; padding: .85rem; background: #fff;
}
.media-icon, .library-thumb {
  width: 44px; height: 44px; border-radius: 10px; display: grid; place-items: center;
  background: var(--primary-soft); color: var(--primary); font-size: 1.2rem;
}
.library-card { flex-direction: column; align-items: stretch; height: 100%; }
.library-thumb { width: 100%; height: 90px; border-radius: 10px 10px 0 0; font-size: 1.6rem; }
.library-body { padding: .25rem; }
.score-bar { height: 6px; background: #eef2f6; border-radius: 99px; overflow: hidden; width: 70px; display: inline-block; vertical-align: middle; margin-right: .35rem; }
.score-bar > div { height: 100%; background: linear-gradient(90deg, #14b8a6, #0d9488); }

/* Chat WhatsApp-like */
.app-main:has(.chat-page) {
  height: 100vh;
  overflow: hidden;
}
.app-content:has(.chat-page) {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  padding-bottom: 1rem;
}
.chat-page {
  flex: 1;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-shell {
  display: grid;
  grid-template-columns: 340px 1fr;
  flex: 1;
  min-height: 0;
  height: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
  box-shadow: var(--shadow-sm);
}
.chat-list-pane {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background: #fbfcfd;
}
.chat-list-header {
  padding: .9rem 1rem; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center; gap: .5rem; flex-wrap: wrap;
  flex-shrink: 0;
}
.chat-list { overflow-y: auto; flex: 1; min-height: 0; }
.chat-item {
  display: flex; gap: .75rem; padding: .85rem 1rem;
  border-bottom: 1px solid var(--border); transition: background .15s;
}
.chat-item:hover, .chat-item.active { background: #f0fdfa; }
.chat-item.active { box-shadow: inset 3px 0 0 var(--primary); }
.chat-item-body { min-width: 0; flex: 1; }
.chat-item .preview { color: var(--muted); font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .meta { display: flex; gap: .35rem; align-items: center; margin-top: .25rem; flex-wrap: wrap; }
.unread {
  background: var(--primary); color: #fff; border-radius: 999px;
  font-size: .68rem; font-weight: 700; min-width: 18px; height: 18px;
  display: inline-grid; place-items: center; padding: 0 .35rem;
}
.chat-thread-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
}
.chat-thread-header {
  padding: .9rem 1.1rem; background: #fff; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; flex-wrap: wrap;
  flex-shrink: 0;
}
.chat-thread-header h2 { font-size: 1rem; margin: 0; }
.chat-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: .65rem;
  overscroll-behavior: contain;
}
.chat-empty { flex: 1; display: grid; place-items: center; color: var(--muted); text-align: center; min-height: 0; }
.chat-empty i { font-size: 2.5rem; opacity: .4; display: block; margin-bottom: .5rem; }
.bubble-wrap { display: flex; flex-direction: column; max-width: min(78%, 520px); flex-shrink: 0; }
.bubble-wrap.in { align-self: flex-start; }
.bubble-wrap.out { align-self: flex-end; }
.bubble-wrap.system { align-self: center; max-width: 90%; }
.bubble {
  padding: .7rem .9rem; border-radius: 14px; background: #fff;
  border: 1px solid var(--border); box-shadow: var(--shadow-sm);
}
.bubble-wrap.out .bubble {
  background: linear-gradient(135deg, #0d9488, #0f766e); color: #fff; border: 0;
}
.bubble-wrap.system .bubble { background: #fffbeb; color: #92400e; border-color: #fde68a; font-size: .85rem; }
.bubble-meta { font-size: .7rem; opacity: .75; margin-bottom: .2rem; font-weight: 600; }
.bubble-foot { display: flex; gap: .5rem; justify-content: flex-end; align-items: center; margin-top: .35rem; font-size: .7rem; opacity: .7; }
.intent-chip {
  background: rgba(15,42,50,.08); padding: .1rem .4rem; border-radius: 6px; font-family: var(--mono); font-size: .65rem;
}
.bubble-wrap.out .intent-chip { background: rgba(255,255,255,.18); }
.ai-context {
  margin-top: .35rem; font-size: .78rem; color: var(--muted);
}
.ai-context pre {
  background: #0f2a32; color: #99f6e4; padding: .75rem; border-radius: 10px;
  white-space: pre-wrap; font-family: var(--mono); font-size: .72rem; margin: .4rem 0 0;
}
.chat-composer {
  display: flex;
  gap: .5rem;
  padding: .85rem 1rem;
  background: #fff;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
  z-index: 2;
}
.chat-composer .form-control { border-radius: 999px; padding-left: 1rem; }
.chat-composer .btn { border-radius: 999px; width: 46px; height: 46px; display: grid; place-items: center; padding: 0; }

.sim-bubble {
  background: linear-gradient(135deg, #0d9488, #0f766e); color: #fff;
  padding: 1rem 1.15rem; border-radius: 14px; line-height: 1.5;
}
.sim-result { min-height: 180px; }

/* Auth */
.auth-body { min-height: 100vh; }
.auth-wrap {
  min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr;
}
.auth-visual {
  background:
    radial-gradient(circle at 15% 20%, rgba(20,184,166,.25), transparent 40%),
    radial-gradient(circle at 80% 80%, rgba(45,212,191,.12), transparent 35%),
    linear-gradient(160deg, #0b2228 0%, #134e4a 55%, #0f766e 100%);
  color: #e2e8f0; display: flex; align-items: center; padding: 3rem;
}
.auth-visual-inner { max-width: 460px; }
.auth-visual h1 { color: #fff; font-weight: 700; letter-spacing: -.03em; font-size: 2.4rem; margin: 1rem 0 .5rem; }
.auth-visual p { opacity: .8; line-height: 1.6; }
.auth-features { list-style: none; padding: 0; margin: 2rem 0 0; }
.auth-features li { display: flex; gap: .6rem; align-items: center; margin-bottom: .65rem; color: #99f6e4; }
.auth-form-side { display: grid; place-items: center; padding: 2rem; background:
  linear-gradient(180deg, #f8fafc, #eef2f6); }
.auth-card {
  width: 100%; max-width: 420px; background: #fff; border: 1px solid var(--border);
  border-radius: 18px; padding: 2rem; box-shadow: var(--shadow);
}
.auth-card h2 { font-weight: 700; letter-spacing: -.02em; }

/* Editor */
.editor-toolbar { display: flex; gap: .35rem; margin-bottom: .5rem; }
.rich-editor {
  min-height: 180px; border: 1px solid var(--border); border-radius: 10px;
  padding: .85rem 1rem; background: #fff;
}
.rich-editor:focus { outline: 2px solid rgba(13,148,136,.2); border-color: #5eead4; }
.content-body { line-height: 1.6; }
.settings-tabs .nav-link {
  border-radius: 999px; color: var(--muted); font-weight: 600;
}
.settings-tabs .nav-link.active { background: var(--primary); color: #fff; }

/* WhatsApp QR */
.wa-qr-wrap {
  min-height: 280px; display: grid; place-items: center;
  background: #f8fafc; border: 1px dashed var(--border); border-radius: 16px; padding: 1rem;
}
.wa-qr-image { width: 260px; height: 260px; border-radius: 12px; box-shadow: var(--shadow-sm); }
.wa-qr-placeholder, .wa-connected-state {
  color: var(--muted); display: grid; place-items: center; gap: .35rem; padding: 1.5rem;
}
.wa-qr-placeholder i, .wa-connected-state i { font-size: 2.5rem; color: var(--primary); }
.wa-connected-state i { color: #25d366; font-size: 3rem; }
.wa-steps { font-size: .85rem; color: var(--muted); padding-left: 1.1rem; }
.wa-steps li { margin-bottom: .35rem; }
.wa-steps code { font-size: .78rem; }

/* Responsive */
@media (max-width: 991.98px) {
  .sidebar {
    position: fixed; left: 0; top: 0; transform: translateX(-100%);
  }
  .sidebar.open { transform: none; }
  .sidebar-overlay.show { display: block; }
  .chat-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(180px, 32vh) 1fr;
    height: 100%;
    min-height: 0;
  }
  .chat-list-pane { max-height: none; min-height: 0; }
  .chat-page { height: 100%; }
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-visual { display: none; }
}
