/* ── Reset & Base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --navy:    #0a2540;
  --blue:    #1a6fb5;
  --blue-lt: #e8f2fb;
  --green:   #22c55e;
  --red:     #ef4444;
  --orange:  #f59e0b;
  --gray-50: #f8fafc;
  --gray-100:#f1f5f9;
  --gray-200:#e2e8f0;
  --gray-400:#94a3b8;
  --gray-600:#475569;
  --gray-800:#1e293b;
  --white:   #ffffff;
  --radius:  8px;
  --shadow:  0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
  --shadow-lg: 0 10px 25px rgba(0,0,0,.15);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  color: var(--gray-800);
  background: var(--gray-50);
  height: 100vh;
  overflow: hidden;
}

/* ── Screens ──────────────────────────────────────────────────────────────── */
.screen { display: flex; height: 100vh; }
.hidden { display: none !important; }

/* ── Login ────────────────────────────────────────────────────────────────── */
#login-screen {
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--navy) 0%, #1a4a7a 100%);
}

.login-card {
  background: var(--white);
  border-radius: 16px;
  padding: 40px;
  width: 380px;
  box-shadow: var(--shadow-lg);
}

.brand {
  text-align: center;
  margin-bottom: 32px;
}

.brand-icon {
  width: 56px; height: 56px;
  border-radius: 14px;
  background: var(--blue);
  color: var(--white);
  font-weight: 800;
  font-size: 20px;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 12px;
}

.brand-icon.sm {
  width: 32px; height: 32px;
  border-radius: 8px;
  font-size: 13px;
  margin: 0;
  flex-shrink: 0;
}

.brand h1 { font-size: 22px; color: var(--navy); }
.brand p  { color: var(--gray-400); font-size: 13px; margin-top: 4px; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--gray-600); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .5px; }

input[type="text"], input[type="password"], input[type="email"], input[type="number"], select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--gray-800);
  background: var(--white);
  transition: border-color .15s;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(26,111,181,.12);
}

textarea { resize: vertical; min-height: 80px; }

.login-hint { text-align: center; margin-top: 20px; font-size: 12px; color: var(--gray-400); }
.login-hint code { background: var(--gray-100); padding: 2px 5px; border-radius: 4px; font-size: 11px; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  padding: 9px 18px;
  border-radius: var(--radius);
  border: none;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary  { background: var(--blue); color: var(--white); }
.btn-primary:hover:not(:disabled) { background: #155fa0; }
.btn-ghost    { background: transparent; color: var(--gray-600); }
.btn-ghost:hover { background: var(--gray-100); }
.btn-danger   { background: var(--red); color: var(--white); }
.btn-full     { width: 100%; }
.btn-sm       { padding: 5px 12px; font-size: 12px; }

/* ── App Layout ───────────────────────────────────────────────────────────── */
#app-screen {
  flex-direction: row;
  overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  width: 220px;
  background: var(--navy);
  color: var(--white);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  padding: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px;
  font-weight: 700;
  font-size: 16px;
  border-bottom: 1px solid rgba(255,255,255,.1);
}

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: none;
  background: transparent;
  color: rgba(255,255,255,.65);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background .15s, color .15s;
}

.nav-item:hover { background: rgba(255,255,255,.08); color: var(--white); }
.nav-item.active { background: rgba(255,255,255,.15); color: var(--white); }
.nav-icon { font-size: 16px; }

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,.1);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.agent-info { display: flex; align-items: center; gap: 10px; min-width: 0; }
.agent-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--blue);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}
.agent-name { font-size: 13px; font-weight: 600; color: var(--white); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.agent-role { font-size: 11px; color: rgba(255,255,255,.5); text-transform: capitalize; }

/* ── Main Content ─────────────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px;
  background: var(--gray-50);
}

.view-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}

.view-header h2 { font-size: 22px; font-weight: 700; color: var(--navy); }
.subtitle { font-size: 13px; color: var(--gray-400); margin-left: auto; }

/* ── Stats Grid ───────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--blue);
}

.stat-label { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--gray-400); font-weight: 600; margin-bottom: 8px; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--navy); }

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.card-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--gray-400);
  margin-bottom: 12px;
}

/* ── Detail Grid ──────────────────────────────────────────────────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 0;
}

/* ── Info rows ────────────────────────────────────────────────────────────── */
.info-row {
  display: flex;
  justify-content: space-between;
  padding: 7px 0;
  border-bottom: 1px solid var(--gray-100);
  font-size: 13px;
}
.info-row:last-child { border-bottom: none; }
.info-label { color: var(--gray-400); font-weight: 500; }
.info-value { color: var(--gray-800); font-weight: 600; text-align: right; max-width: 60%; word-break: break-word; }

/* ── Account Items ────────────────────────────────────────────────────────── */
.account-item {
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.account-item:hover { border-color: var(--blue); background: var(--blue-lt); }
.account-item.selected { border-color: var(--blue); background: var(--blue-lt); }

.account-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.account-type { font-weight: 700; font-size: 13px; text-transform: capitalize; }
.account-number { font-size: 11px; color: var(--gray-400); font-family: monospace; }
.account-balance { font-size: 20px; font-weight: 700; color: var(--navy); }
.account-available { font-size: 11px; color: var(--gray-400); margin-top: 2px; }

/* ── Status badges ────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .3px;
}
.badge-active, .badge-open     { background: #dcfce7; color: #15803d; }
.badge-frozen                   { background: #fef9c3; color: #854d0e; }
.badge-closed                   { background: var(--gray-100); color: var(--gray-400); }
.badge-in_progress              { background: #dbeafe; color: #1d4ed8; }
.badge-resolved                 { background: #f0fdf4; color: #16a34a; }
.badge-low                      { background: var(--gray-100); color: var(--gray-600); }
.badge-medium                   { background: #fef3c7; color: #92400e; }
.badge-high                     { background: #fee2e2; color: #991b1b; }
.badge-urgent                   { background: #fce7f3; color: #9d174d; }

/* ── Search / Filter ──────────────────────────────────────────────────────── */
.search-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}
.search-bar input { flex: 1; }

.filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}
.filter-bar label { font-size: 13px; font-weight: 600; color: var(--gray-600); }
.filter-bar select { width: auto; }

/* ── Results list ─────────────────────────────────────────────────────────── */
.results-list { display: flex; flex-direction: column; gap: 6px; }

.result-item {
  background: var(--white);
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 12px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: border-color .15s, background .15s;
}
.result-item:hover { border-color: var(--blue); background: var(--blue-lt); }
.result-name { font-weight: 700; font-size: 14px; }
.result-meta { font-size: 12px; color: var(--gray-400); margin-top: 2px; }

/* ── Ticket list ──────────────────────────────────────────────────────────── */
.ticket-list { display: flex; flex-direction: column; gap: 8px; }

.ticket-item {
  background: var(--white);
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color .15s;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.ticket-item:hover { border-color: var(--blue); }
.ticket-subject { font-weight: 700; font-size: 13px; margin-bottom: 4px; }
.ticket-meta    { font-size: 12px; color: var(--gray-400); }
.ticket-badges  { display: flex; gap: 6px; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }

/* ── Transaction table ────────────────────────────────────────────────────── */
.txn-table { width: 100%; border-collapse: collapse; }
.txn-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--gray-400);
  padding: 6px 10px;
  border-bottom: 2px solid var(--gray-200);
}
.txn-table td {
  padding: 10px;
  border-bottom: 1px solid var(--gray-100);
  font-size: 13px;
}
.txn-table tr:last-child td { border-bottom: none; }
.txn-amount.credit { color: var(--green); font-weight: 700; }
.txn-amount.debit  { color: var(--red);   font-weight: 700; }

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}

.modal {
  background: var(--white);
  border-radius: 12px;
  width: 560px;
  max-width: 95vw;
  max-height: 85vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--gray-200);
}
.modal-header h3 { font-size: 16px; font-weight: 700; color: var(--navy); }
.modal-body { padding: 20px 24px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--gray-200);
  display: flex; justify-content: flex-end; gap: 10px;
}

/* ── Misc ─────────────────────────────────────────────────────────────────── */
.error-msg  { background: #fee2e2; color: #991b1b; padding: 10px 14px; border-radius: var(--radius); font-size: 13px; margin-bottom: 12px; }
.empty-msg  { text-align: center; color: var(--gray-400); padding: 32px; font-size: 13px; }
.loading    { text-align: center; padding: 24px; color: var(--gray-400); font-size: 13px; }

/* ── Ticket Detail Page ───────────────────────────────────────────────────── */
.ticket-detail-heading {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.td-badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.ticket-detail-grid {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 20px;
  align-items: start;
}

.ticket-detail-left,
.ticket-detail-right {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.td-description-body {
  font-size: 14px;
  line-height: 1.65;
  color: var(--gray-800);
  white-space: pre-wrap;
  min-height: 60px;
}

/* ── Account tabs (ticket detail transactions) ────────────────────────────── */
.account-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.account-tab {
  padding: 4px 10px;
  border-radius: 20px;
  border: 1.5px solid var(--gray-200);
  background: var(--white);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  color: var(--gray-600);
  text-transform: capitalize;
  transition: border-color .15s, background .15s, color .15s;
}

.account-tab:hover  { border-color: var(--blue); color: var(--blue); }
.account-tab.active { border-color: var(--blue); background: var(--blue); color: var(--white); }

.td-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 4px;
}

.td-save-feedback {
  font-size: 13px;
  font-weight: 600;
  color: var(--green);
  opacity: 0;
  transition: opacity .3s;
}

.td-save-feedback.visible {
  opacity: 1;
}

@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .detail-grid { grid-template-columns: 1fr; }
  .ticket-detail-grid { grid-template-columns: 1fr; }
}

/* ── Admin panel ───────────────────────────────────────────────────────────── */
.admin-warning {
  color: #4b5563;
  font-size: 14px;
  line-height: 1.5;
  margin: 8px 0 16px;
}
.admin-warning.subtle {
  color: #6b7280;
  font-size: 13px;
}
.admin-results {
  margin-top: 18px;
}
.admin-stream {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 14px;
}
.admin-phase {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 10px;
  color: #1f2937;
}
.persona-list {
  max-height: 420px;
  overflow-y: auto;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.7;
}
.persona-line {
  padding: 2px 6px;
  border-radius: 4px;
  animation: persona-fade-in 250ms ease-out;
}
.persona-line.bucket-overdraft  { color: #b91c1c; }
.persona-line.bucket-average    { color: #1f2937; }
.persona-line.bucket-better_off { color: #047857; }
.persona-line.persona-error     { color: #b91c1c; background: #fef2f2; }

@keyframes persona-fade-in {
  from { opacity: 0; transform: translateY(-2px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Credit account: balance shown as amount owed, in red. */
.account-balance.account-owed {
  color: #b91c1c;
}

/* ── AI Advisor — snapshot, recommendations, drawer, fab ──────────────────── */
.advisor-snapshot-card {
  background: linear-gradient(135deg, #f3f4f6 0%, #e0e7ff 100%);
  border-left: 3px solid #4f46e5;
}
.advisor-snapshot-body {
  font-size: 14px;
  line-height: 1.55;
  color: #1f2937;
  margin: 6px 0 8px;
  white-space: pre-wrap;
}
.advisor-snapshot-meta {
  font-size: 11px;
  color: #6b7280;
}

#recommendations-list { display: flex; flex-direction: column; gap: 8px; }
.rec-item {
  border: 1px solid #e5e7eb;
  border-left: 4px solid #6b7280;
  border-radius: 6px;
  padding: 10px 14px;
  background: var(--white);
}
.rec-item.rec-status-relayed   { border-left-color: var(--green); background: #f0fdf4; }
.rec-item.rec-status-dismissed { border-left-color: #9ca3af; background: #f9fafb; opacity: 0.7; }
.rec-item.rec-status-pending   { border-left-color: #4f46e5; }

.rec-header {
  display: flex; align-items: center; gap: 10px;
  font-size: 12px; margin-bottom: 6px;
}
.rec-cat { text-transform: uppercase; font-weight: 600; }
.rec-impact { color: var(--green); font-weight: 600; }
.rec-status { color: #6b7280; text-transform: uppercase; font-size: 11px; margin-left: auto; }
.rec-text { font-size: 14px; line-height: 1.5; color: #1f2937; }
.rec-meta { font-size: 11px; color: #6b7280; margin-top: 4px; }
.rec-notes { font-size: 12px; color: #374151; margin-top: 6px; padding: 6px 8px; background: #f9fafb; border-radius: 4px; }
.rec-actions { display: flex; gap: 8px; margin-top: 8px; }

/* Floating button */
.advisor-fab {
  position: fixed; right: 24px; bottom: 24px; z-index: 50;
  background: #4f46e5; color: white;
  border: none; border-radius: 999px;
  padding: 12px 18px; font-size: 14px; font-weight: 600;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(79, 70, 229, 0.4);
  transition: transform 0.15s, box-shadow 0.15s;
}
.advisor-fab:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(79, 70, 229, 0.5); }

/* Drawer */
.advisor-drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 460px; max-width: 90vw;
  background: white;
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.15);
  z-index: 60;
  display: flex; flex-direction: column;
  transition: transform 0.25s;
}
.advisor-drawer.hidden { transform: translateX(100%); display: flex; }
.advisor-drawer-inner { display: flex; flex-direction: column; height: 100%; }
.advisor-drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid #e5e7eb;
  background: #f9fafb;
}
.advisor-chat-log {
  flex: 1; overflow-y: auto; padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.advisor-input-row {
  border-top: 1px solid #e5e7eb;
  padding: 10px 14px;
  display: flex; gap: 8px; align-items: flex-end;
}
.advisor-input-row textarea {
  flex: 1; resize: none; padding: 8px;
  border: 1px solid #d1d5db; border-radius: 6px;
  font-family: inherit; font-size: 13px;
}

.chat-bubble {
  max-width: 90%; padding: 10px 14px;
  border-radius: 12px; font-size: 13px; line-height: 1.5;
  word-wrap: break-word;
}
.chat-user { align-self: flex-end; background: #4f46e5; color: white; }
.chat-bot  { align-self: flex-start; background: #f3f4f6; color: #1f2937; }
.chat-bubble-error { background: #fef2f2; color: #b91c1c; }
.bubble-tools { display: flex; flex-direction: column; gap: 2px; margin-bottom: 4px; }
.tool-chip {
  font-size: 11px; color: #6b7280; font-style: italic;
}
.bubble-text { white-space: pre-wrap; }
