/* ═══════════════════════════════════════════════════════════════
   AMI — Agentic Management Intelligence
   Light Mode · Minimal · Corporate
═══════════════════════════════════════════════════════════════ */

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

/* ── Tokens ────────────────────────────────────────────────── */
:root {
  --bg:        #f1f4f8;
  --surface:   #ffffff;
  --surface-2: #f8f9fb;
  --border:    #e2e8f0;

  --accent:    #2563eb;
  --accent-bg: #eff6ff;

  --green:     #16a34a;
  --green-bg:  #f0fdf4;
  --red:       #dc2626;
  --red-bg:    #fef2f2;

  --t1: #0f172a;
  --t2: #475569;
  --t3: #94a3b8;

  --r4:  4px;
  --r8:  8px;
  --r12: 12px;

  --ease: 0.15s ease;
  --font: 'Inter', system-ui, sans-serif;
}

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--t1);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

#app {
  height: 100%;
}

/* ── Scrollbar ─────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

/* ═══════════════════════════════════════════════════════════════
   UTILITIES
═══════════════════════════════════════════════════════════════ */

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid transparent;
  border-radius: var(--r8);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  outline: none;
  transition: background var(--ease), border-color var(--ease), box-shadow var(--ease);
  white-space: nowrap;
  text-decoration: none;
}
.btn:focus-visible { box-shadow: 0 0 0 3px rgba(37,99,235,0.2); }
.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover { background: #1d4ed8; border-color: #1d4ed8; }

.btn-ghost {
  background: var(--surface);
  color: var(--t2);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--t1); }

.btn-danger {
  background: var(--red-bg);
  color: var(--red);
  border-color: #fca5a5;
}
.btn-danger:hover { background: #fee2e2; }

.btn-sm   { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 0; width: 30px; height: 30px; border-radius: var(--r8); }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 500;
  line-height: 18px;
}
.badge-blue  { background: var(--accent-bg); color: var(--accent); }
.badge-green { background: var(--green-bg);  color: var(--green); }

/* Chips */
.chip-group { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--t2);
  transition: var(--ease);
  user-select: none;
}
.chip:hover, .chip.selected {
  background: var(--accent-bg);
  border-color: #93c5fd;
  color: var(--accent);
}

/* Form */
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-label { font-size: 12px; font-weight: 500; color: var(--t2); }
.form-input {
  width: 100%;
  padding: 8px 11px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r8);
  color: var(--t1);
  font-family: var(--font);
  font-size: 14px;
  outline: none;
  transition: border-color var(--ease), box-shadow var(--ease);
}
.form-input::placeholder { color: var(--t3); }
.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}

/* Toast */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 9999;
}
.toast {
  padding: 9px 14px;
  border-radius: var(--r8);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid;
  animation: tIn .2s ease, tOut .3s ease 2.7s forwards;
}
.toast-success { background: var(--green-bg); border-color: #bbf7d0; color: var(--green); }
.toast-error   { background: var(--red-bg);   border-color: #fca5a5; color: var(--red);   }
.toast-info    { background: var(--accent-bg); border-color: #93c5fd; color: var(--accent);}
@keyframes tIn  { from { opacity:0; transform:translateX(10px); } to { opacity:1; transform:translateX(0); } }
@keyframes tOut { to { opacity:0; } }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
  overflow-y: auto;
  animation: mIn .15s ease;
}
@keyframes mIn { from { opacity:0; } to { opacity:1; } }

.modal {
  width: 100%;
  max-width: 460px;
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r12);
  box-shadow: 0 20px 40px rgba(0,0,0,0.12);
  animation: mScale .18s ease;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 40px);
}
@keyframes mScale { from { opacity:0; transform:scale(0.97); } to { opacity:1; transform:scale(1); } }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 0;
  flex-shrink: 0;
}
.modal-title { font-size: 15px; font-weight: 600; }

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface);
  border-radius: 0 0 var(--r12) var(--r12);
}

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  padding: 10px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--t3);
  text-transform: uppercase;
  letter-spacing: .06em;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
tbody tr { border-bottom: 1px solid var(--border); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
td { padding: 11px 16px; vertical-align: middle; }
.td-actions { display: flex; align-items: center; gap: 6px; }

/* ═══════════════════════════════════════════════════════════════
   LOGIN
═══════════════════════════════════════════════════════════════ */
.login-page {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r12);
  padding: 32px;
  box-shadow: 0 4px 16px rgba(0,0,0,.06);
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}
.logo-mark {
  width: 34px;
  height: 34px;
  background: var(--accent);
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.logo-text {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.03em;
}
.login-brand-name {
  font-size: 12px;
  color: var(--t2);
  margin-bottom: 2px;
}
.login-brand-sub {
  font-size: 11px;
  color: var(--t3);
  margin-bottom: 20px;
}
.login-divider {
  height: 1px;
  background: var(--border);
  margin-bottom: 20px;
}
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-btn  { width: 100%; padding: 9px; font-size: 14px; margin-top: 2px; }
.login-error {
  display: none;
  padding: 9px 12px;
  background: var(--red-bg);
  border: 1px solid #fca5a5;
  border-radius: var(--r8);
  color: var(--red);
  font-size: 13px;
}
.login-error.show { display: block; }

/* ═══════════════════════════════════════════════════════════════
   APP SHELL — full viewport, fixed layout
═══════════════════════════════════════════════════════════════ */
.app-shell {
  display: grid;
  grid-template-rows: 52px 41px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-left { display: flex; align-items: center; gap: 8px; }
.topbar-logo-mark {
  width: 24px; height: 24px;
  background: var(--accent);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.topbar-logo {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -.02em;
  display: flex;
  align-items: baseline;
  gap: 5px;
}
.topbar-sub { font-size: 10px; font-weight: 400; color: var(--t3); }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.topbar-user {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px 4px 4px;
  border: 1px solid var(--border);
  border-radius: 99px;
  cursor: pointer;
  background: var(--surface);
  transition: var(--ease);
}
.topbar-user:hover { background: var(--surface-2); }
.user-avatar {
  width: 24px; height: 24px;
  background: var(--accent);
  border-radius: 99px;
  display: flex; align-items: center; justify-content: center;
  font-size: 9px; font-weight: 700; color: white;
  flex-shrink: 0;
}
.user-name { font-size: 13px; font-weight: 500; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Nav tabs */
.nav-tabs {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  overflow-x: auto;
}
.nav-tab {
  padding: 0 14px;
  height: 40px;
  line-height: 40px;
  font-size: 13px;
  font-weight: 500;
  color: var(--t3);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color var(--ease), border-color var(--ease);
  user-select: none;
}
.nav-tab:hover  { color: var(--t2); }
.nav-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Content area fills remaining grid row */
.app-content {
  display: flex;
  overflow: hidden;
  min-height: 0;
}
.page { display: none; width: 100%; overflow: hidden; }
.page.active { display: flex; flex-direction: column; }

/* ═══════════════════════════════════════════════════════════════
   ADMIN PAGES (Users / Roles)
═══════════════════════════════════════════════════════════════ */
.admin-page {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.page-title { font-size: 16px; font-weight: 600; }
.page-sub   { font-size: 13px; color: var(--t3); margin-top: 2px; }

.data-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r12);
  overflow: hidden;
}
.empty-state { padding: 48px; text-align: center; color: var(--t3); font-size: 13px; }

/* ═══════════════════════════════════════════════════════════════
   CHAT PAGE
═══════════════════════════════════════════════════════════════ */

/* chat-page takes full height of .app-content */
.chat-page {
  display: flex;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* ── Sidebar ────────────────────────────────────────── */
.chat-sidebar {
  width: 210px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

.sb-section {
  padding: 12px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sb-section:last-child { border-bottom: none; }

.sb-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.sb-title {
  font-size: 10px;
  font-weight: 600;
  color: var(--t3);
  text-transform: uppercase;
  letter-spacing: .08em;
}
.btn-new-room {
  width: 20px; height: 20px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--t2);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: var(--ease);
  flex-shrink: 0;
}
.btn-new-room:hover { background: var(--accent-bg); border-color: #93c5fd; color: var(--accent); }

/* Room list */
.room-list { display: flex; flex-direction: column; gap: 2px; }
.room-item {
  display: flex;
  align-items: center;
  gap: 0;
  border-radius: var(--r8);
  cursor: pointer;
  transition: var(--ease);
  group: true;
  overflow: hidden;
}
.room-item:hover { background: var(--surface-2); }
.room-item.active { background: var(--accent-bg); }
.room-item-name {
  flex: 1;
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--t2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.room-item.active .room-item-name { color: var(--accent); }
.room-delete-btn {
  flex-shrink: 0;
  width: 24px; height: 24px;
  border: none;
  background: transparent;
  color: var(--t3);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  border-radius: var(--r4);
  display: flex; align-items: center; justify-content: center;
  opacity: 0;
  transition: var(--ease);
  margin-right: 4px;
}
.room-item:hover .room-delete-btn { opacity: 1; }
.room-delete-btn:hover { background: var(--red-bg); color: var(--red); }

/* Role selector */
.role-list { display: flex; flex-direction: column; gap: 4px; }
.role-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 8px;
  border-radius: var(--r8);
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 13px;
  color: var(--t2);
  cursor: pointer;
  transition: var(--ease);
  user-select: none;
}
.role-item:hover  { border-color: #93c5fd; color: var(--accent); background: var(--accent-bg); }
.role-item.active { border-color: #93c5fd; color: var(--accent); background: var(--accent-bg); }
.role-dot {
  width: 6px; height: 6px;
  border-radius: 99px;
  background: var(--border);
  flex-shrink: 0;
  transition: background var(--ease);
}
.role-item.active .role-dot { background: var(--accent); }

/* Agent list */
.agent-list { display: flex; flex-direction: column; gap: 4px; }
.agent-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: var(--r8);
  background: var(--surface-2);
  border: 1px solid var(--border);
  transition: var(--ease);
}
.agent-item.active { background: var(--green-bg); border-color: #bbf7d0; }

.agent-dot {
  width: 7px; height: 7px;
  border-radius: 99px;
  background: var(--border);
  flex-shrink: 0;
  transition: background var(--ease);
}
.agent-item.active .agent-dot {
  background: var(--green);
  animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse { 0%,100%{ opacity:1; } 50%{ opacity:.4; } }

.agent-info { min-width: 0; }
.agent-name  { font-size: 12px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent-status { font-size: 11px; color: var(--t3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent-item.active .agent-name { color: var(--green); }

/* ── Chat Main ──────────────────────────────────────── */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  background: var(--bg);
}

/* Messages */
.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Welcome */
.chat-welcome {
  margin: auto;
  text-align: center;
  padding: 32px 20px;
  max-width: 320px;
}
.chat-welcome-icon {
  width: 44px; height: 44px;
  border-radius: 11px;
  background: var(--accent-bg);
  border: 1px solid #bfdbfe;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 14px;
}
.chat-welcome h2 { font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.chat-welcome p  { font-size: 13px; color: var(--t3); line-height: 1.6; }

/* Message rows */
.msg-row {
  display: flex;
  gap: 8px;
  max-width: 78%;
  animation: msgIn .18s ease;
}
@keyframes msgIn { from { opacity:0; transform:translateY(5px); } to { opacity:1; transform:translateY(0); } }

.msg-row.user { align-self: flex-end; flex-direction: row-reverse; }
.msg-row.bot  { align-self: flex-start; }
.msg-row.error .msg-bubble { background: var(--red-bg); border-color: #fca5a5; color: var(--red); }

.msg-avatar {
  width: 28px; height: 28px;
  border-radius: 99px;
  display: flex; align-items: center; justify-content: center;
  font-size: 9px; font-weight: 700;
  flex-shrink: 0;
  margin-top: 2px;
  letter-spacing: .03em;
}
.msg-row.user .msg-avatar { background: var(--accent); color: white; }
.msg-row.bot  .msg-avatar { background: var(--surface); border: 1px solid var(--border); color: var(--t3); }

.msg-bubble {
  padding: 9px 13px;
  border-radius: var(--r8);
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
}
.msg-row.user .msg-bubble {
  background: var(--accent);
  color: white;
  border-radius: var(--r8) 3px var(--r8) var(--r8);
}
.msg-row.bot .msg-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--t1);
  border-radius: 3px var(--r8) var(--r8) var(--r8);
}
.msg-bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 13px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r8);
  overflow: hidden;
}
.msg-bubble th {
  background: var(--border);
  color: var(--t1);
  font-weight: 600;
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.msg-bubble td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--t2);
}
.msg-bubble tr:last-child td {
  border-bottom: none;
}
.msg-bubble ul, .msg-bubble ol {
  margin-left: 20px;
  margin-top: 6px;
  margin-bottom: 6px;
}
.msg-bubble li {
  margin-bottom: 4px;
}


/* Typing */
.typing-dots {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 11px 13px;
}
.typing-dots span {
  width: 5px; height: 5px;
  border-radius: 99px;
  background: var(--t3);
  animation: blink 1.2s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: .2s; }
.typing-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,60%,100%{ opacity:.3; transform:translateY(0); } 30%{ opacity:1; transform:translateY(-3px); } }

/* Input bar */
.chat-input-bar {
  flex-shrink: 0;
  padding: 12px 20px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.chat-textarea {
  flex: 1;
  min-height: 40px;
  max-height: 120px;
  padding: 9px 11px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r8);
  color: var(--t1);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  outline: none;
  overflow-y: auto;
  transition: border-color var(--ease), box-shadow var(--ease);
}
.chat-textarea::placeholder { color: var(--t3); }
.chat-textarea:focus {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
.send-btn {
  width: 40px; height: 40px;
  flex-shrink: 0;
  background: var(--accent);
  border: none;
  border-radius: var(--r8);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--ease), transform var(--ease);
}
.send-btn:hover    { background: #1d4ed8; }
.send-btn:active   { transform: scale(0.95); }
.send-btn:disabled { background: var(--border); cursor: not-allowed; }
.send-btn svg { width: 16px; height: 16px; fill: white; }
.chat-hint { font-size: 11px; color: var(--t3); text-align: center; margin-top: 7px; }

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE
═══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .chat-sidebar { width: 180px; }
  .chat-messages { padding: 14px; }
  .msg-row { max-width: 90%; }
  .admin-page { padding: 16px; }
}

@media (max-width: 580px) {
  .chat-page      { flex-direction: column; }
  .chat-sidebar   {
    width: 100%;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    border-right: none;
    border-bottom: 1px solid var(--border);
    height: auto;
    max-height: none;
    flex-shrink: 0;
  }
  .sb-section {
    border-bottom: none;
    border-right: 1px solid var(--border);
    padding: 10px 12px;
    flex-shrink: 0;
  }
  .sb-section:last-child { border-right: none; }
  .role-list  { flex-direction: row; }
  .agent-list { flex-direction: row; }
  .agent-item { min-width: 120px; }

  .msg-row { max-width: 95%; }
  .topbar  { padding: 0 14px; }
  .login-card { padding: 24px 20px; }
  .chat-messages { padding: 12px; }
  .chat-input-bar { padding: 10px 14px; }
}
