:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #818cf8;
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-input: #334155;
  --border: #475569;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --radius: 10px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ========== Layout ========== */

.app-container { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  padding: 20px 0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 10;
}

.sidebar .logo {
  padding: 0 20px 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.sidebar .logo h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary-light);
  letter-spacing: -0.3px;
}

.sidebar .logo span {
  font-size: 11px;
  color: var(--text-muted);
}

.nav-items { flex: 1; padding: 0 10px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s;
  margin-bottom: 2px;
}

.nav-item:hover { background: var(--bg-input); color: var(--text); }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item .icon { font-size: 18px; width: 22px; text-align: center; }
.nav-item.admin-only, .nav-item.super-admin-only { display: none; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-badge .avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
}

.user-badge .info { flex: 1; min-width: 0; }
.user-badge .info .name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-badge .info .role { font-size: 11px; color: var(--text-muted); text-transform: capitalize; }

.btn-logout {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 18px;
  padding: 4px;
}

.main-content {
  margin-left: 240px;
  flex: 1;
  padding: 28px 32px;
  min-height: 100vh;
}

/* ========== Auth Pages ========== */

.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 440px;
}

.auth-card h1 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--primary-light);
}

.auth-card .subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 28px;
}

/* ========== Forms ========== */

.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }

input, select, textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border 0.15s;
}

input:focus, select:focus, textarea:focus { border-color: var(--primary); }
textarea { resize: vertical; min-height: 80px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-success { background: var(--success); color: #fff; }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--bg-input); }
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.link-btn {
  background: none;
  border: none;
  color: var(--primary-light);
  cursor: pointer;
  font-size: 14px;
  text-decoration: underline;
}

/* ========== Page Headers ========== */

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-header h1 { font-size: 22px; font-weight: 700; }

/* ========== Cards ========== */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.stat-card .label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.stat-card .value { font-size: 28px; font-weight: 700; margin-top: 4px; }

/* ========== Table ========== */

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }

th, td {
  padding: 12px 16px;
  text-align: left;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}

th { color: var(--text-muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
tr:hover td { background: rgba(99,102,241,0.04); }

/* ========== Chat ========== */

.chat-layout { display: flex; gap: 20px; height: calc(100vh - 120px); }

.chat-sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-sidebar-header h3 { font-size: 15px; font-weight: 600; }

.session-list { flex: 1; overflow-y: auto; padding: 8px; }

.session-item {
  padding: 12px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 4px;
  transition: background 0.15s;
}

.session-item:hover { background: var(--bg-input); }
.session-item.active { background: var(--primary); }
.session-item .title { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-item .meta { font-size: 11px; color: var(--text-muted); margin-top: 4px; display: flex; gap: 8px; }
.session-item.active .meta { color: rgba(255,255,255,0.7); }

.chat-main {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-header .session-info h3 { font-size: 15px; font-weight: 600; }
.chat-header .session-info .badges { display: flex; gap: 8px; margin-top: 4px; }

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.badge-intake { background: rgba(59,130,246,0.15); color: var(--info); }
.badge-assessment { background: rgba(245,158,11,0.15); color: var(--warning); }
.badge-decision { background: rgba(168,85,247,0.15); color: #a855f7; }
.badge-closure { background: rgba(34,197,94,0.15); color: var(--success); }
.badge-active { background: rgba(34,197,94,0.15); color: var(--success); }
.badge-closed { background: rgba(239,68,68,0.15); color: var(--danger); }
.badge-reassure { background: rgba(34,197,94,0.15); color: var(--success); }
.badge-monitor { background: rgba(245,158,11,0.15); color: var(--warning); }
.badge-escalate { background: rgba(239,68,68,0.15); color: var(--danger); }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
}

.message.user {
  align-self: flex-end;
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.message.assistant {
  align-self: flex-start;
  background: var(--bg-input);
  border-bottom-left-radius: 4px;
}

.message.assistant p { margin-bottom: 8px; }
.message.assistant p:last-child { margin-bottom: 0; }
.message.assistant ul, .message.assistant ol { padding-left: 20px; margin-bottom: 8px; }
.message.assistant strong { color: var(--primary-light); }

.chat-input-area {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
}

.chat-input-area input {
  flex: 1;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  text-align: center;
  padding: 40px;
}

.empty-state .icon { font-size: 48px; margin-bottom: 16px; opacity: 0.5; }
.empty-state h3 { font-size: 18px; margin-bottom: 8px; color: var(--text); }
.empty-state p { font-size: 14px; max-width: 320px; }

/* ========== Message Feedback ========== */

.msg-feedback {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.fb-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 2px 8px;
  cursor: pointer;
  font-size: 16px;
  opacity: 0.4;
  transition: all 0.15s;
}

.fb-btn:hover { opacity: 0.8; }
.fb-btn.active { opacity: 1; border-color: var(--primary); background: rgba(99,102,241,0.15); }

/* ========== Decision Card (standalone below messages) ========== */

.decision-card {
  align-self: stretch;
  border-radius: 12px;
  padding: 16px 20px;
  border-left: 4px solid;
}

.decision-card .decision-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  margin-bottom: 8px;
}

.decision-card .decision-text {
  font-size: 14px;
  line-height: 1.6;
}

.decision-reassure {
  background: rgba(34,197,94,0.08);
  border-color: var(--success);
}
.decision-reassure .decision-label { color: var(--success); }
.decision-reassure .dc-badge { background: rgba(34,197,94,0.15); color: var(--success); }

.decision-monitor {
  background: rgba(245,158,11,0.08);
  border-color: var(--warning);
}
.decision-monitor .decision-label { color: var(--warning); }
.decision-monitor .dc-badge { background: rgba(245,158,11,0.15); color: var(--warning); }

.decision-escalate {
  background: rgba(239,68,68,0.08);
  border-color: var(--danger);
}
.decision-escalate .decision-label { color: var(--danger); }
.decision-escalate .dc-badge { background: rgba(239,68,68,0.15); color: var(--danger); }

/* ========== Inline Decision Card (inside chat messages) ========== */

.decision-card-inline {
  margin-top: 12px;
  border-radius: 10px;
  padding: 14px 16px;
  border-left: 4px solid;
}

.dc-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.dc-badge {
  display: inline-block;
  padding: 3px 12px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
}

.dc-badge-escalate { background: rgba(239,68,68,0.15); color: var(--danger); }
.dc-badge-monitor { background: rgba(245,158,11,0.15); color: var(--warning); }
.dc-badge-reassure { background: rgba(34,197,94,0.15); color: var(--success); }

.dc-risk {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  padding: 2px 10px;
  border-radius: 20px;
}

.dc-risk-high { background: rgba(239,68,68,0.12); color: var(--danger); }
.dc-risk-moderate { background: rgba(245,158,11,0.12); color: var(--warning); }
.dc-risk-low { background: rgba(34,197,94,0.12); color: var(--success); }

.dc-summary {
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 6px;
}

.dc-symptom {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ========== Session Actions ========== */

.session-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: rgba(99,102,241,0.04);
}

/* ========== Follow-ups ========== */

.followup-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.followup-card .concern { font-weight: 600; font-size: 15px; margin-bottom: 6px; }
.followup-card .instructions { font-size: 13px; color: var(--text-muted); margin-bottom: 8px; }
.followup-card .meta-row { display: flex; gap: 16px; font-size: 12px; color: var(--text-muted); }
.followup-card .actions { display: flex; gap: 8px; flex-shrink: 0; }

.overdue { border-left: 3px solid var(--danger); }

/* ========== Health State ========== */

.hs-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.issue-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 12px;
  transition: border-color 0.15s;
}

.issue-card:hover { border-color: var(--primary); }

.issue-card.overdue { border-left: 3px solid var(--danger); }

.issue-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.issue-id {
  font-family: monospace;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-input);
  padding: 2px 8px;
  border-radius: 4px;
}

.issue-label {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 10px;
  text-transform: capitalize;
}

.issue-meta {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.issue-actions {
  display: flex;
  gap: 8px;
}

/* ========== Campaign ========== */

.campaign-form textarea { min-height: 200px; font-family: monospace; font-size: 13px; }

/* ========== Toast ========== */

.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  animation: slideIn 0.2s ease;
  min-width: 280px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

.toast-success { background: var(--success); color: #fff; }
.toast-error { background: var(--danger); color: #fff; }
.toast-info { background: var(--info); color: #fff; }

@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ========== Loading Spinner ========== */

.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ========== Responsive ========== */

@media (max-width: 768px) {
  .sidebar { display: none; }
  .main-content { margin-left: 0; }
  .chat-layout { flex-direction: column; height: auto; }
  .chat-sidebar { width: 100%; height: 200px; }
  .form-row { flex-direction: column; gap: 0; }
}
