/* Global resets and variables */
:root {
  --bg: #0f172a;       /* slate-900 */
  --bg-soft: #111827;  /* gray-900 */
  --text: #e5e7eb;     /* gray-200 */
  --muted: #9ca3af;    /* gray-400 */
  --brand: #6366f1;    /* indigo-500 */
  --brand-600: #5458e0;
  --surface: #111827;  /* panel */
  --border: #1f2937;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --shadow: 0 6px 20px rgba(0,0,0,0.35);
}

*,
*::before,
*::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(1200px 800px at 80% -10%, rgba(99,102,241,0.15), transparent 60%),
              radial-gradient(1000px 600px at 10% -20%, rgba(16,185,129,0.12), transparent 55%),
              var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Ensure room for fixed navbar */
body { padding-top: 64px; }

/* Container helpers */
.container {
  width: min(1200px, 92vw);
  margin: 0 auto;
}

.panel {
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01));
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0.02));
  color: var(--text);
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
  text-decoration: none;
  transition: transform .15s ease, background .2s ease, border-color .2s ease;
}
.btn:hover {
  transform: translateY(-1px);
  background: linear-gradient(180deg, rgba(255,255,255,0.1), rgba(255,255,255,0.03));
  border-color: #2a3448;
}
.btn-primary {
  background: linear-gradient(180deg, var(--brand), var(--brand-600));
  border-color: transparent;
  color: #fff;
}
.btn-primary:hover {
  transform: translateY(-1px);
  filter: brightness(1.03);
}
.btn-danger { background: linear-gradient(180deg, #ef4444, #dc2626); color: #fff; border-color: transparent; }
.btn-success { background: linear-gradient(180deg, #10b981, #059669); color: #fff; border-color: transparent; }

/* Shared top navbar */
.site-nav {
  position: fixed;
  inset: 0 0 auto 0;
  height: 64px;
  display: flex;
  align-items: center;
  z-index: 2000;
  backdrop-filter: saturate(180%) blur(10px);
  background: rgba(15,23,42,0.7);
  border-bottom: 1px solid var(--border);
}
.site-nav .nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
}
.brand .logo {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: conic-gradient(from 220deg at 50% 50%, var(--brand), #22d3ee, #10b981, var(--brand));
  box-shadow: 0 0 0 2px rgba(99,102,241,0.25), 0 8px 20px rgba(99,102,241,0.35);
}
.brand .title {
  font-weight: 700;
  letter-spacing: .2px;
  font-size: 16px;
}

.nav-links {
  display: flex;
  gap: 12px;
  align-items: center;
}
.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  opacity: .9;
  text-decoration: none;
  font-weight: 500;
  padding: 8px 10px;
  border-radius: 8px;
  transition: background .2s ease, opacity .2s ease, transform .15s ease;
}
.nav-link:hover { background: rgba(255,255,255,0.06); opacity: 1; transform: translateY(-1px); }
.nav-link.active { background: rgba(99,102,241,0.18); color: #fff; }

/* Page headings */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 18px 0 10px;
}
.page-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: .2px;
}

/* Cards/grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}
.card {
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01));
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow);
}

/* Tables */
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 8px;
}
.table thead th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
  padding: 8px 12px;
}
.table tbody tr {
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.table tbody td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
}
.table tbody tr:last-child td { border-bottom: none; }

/* Utilities */
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.text-muted { color: var(--muted); }

/* Responsive */
@media (max-width: 720px) {
  .nav-links { gap: 8px; }
  .brand .title { display: none; }
  body { padding-top: 58px; }
}

/* Toasts */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 3000;
}
.toast {
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity .2s ease, transform .2s ease;
  background: rgba(17,24,39,0.95); /* near slate-900 */
  color: #fff;
  border: 1px solid var(--border);
  border-left: 4px solid var(--brand);
  padding: 10px 14px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  max-width: 360px;
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
.toast.info { border-left-color: var(--brand); }

/* Forms and inputs */
label {
  display: block;
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 14px;
}

input, select, textarea {
  width: 100%;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
  transition: border-color .2s ease, box-shadow .2s ease, background .2s ease;
}
input::placeholder, textarea::placeholder { color: var(--muted); }
input:focus, select:focus, textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.25);
}

/* Accessibility helpers */
:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

/* Flex utilities */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }

/* Display/text utilities */
.hidden { display: none !important; }
.text-center { text-align: center; }

/* Auth / Login */
.login-container {
  min-height: calc(100vh - 64px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-box {
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01));
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  width: min(420px, 92vw);
  box-shadow: var(--shadow);
}
.login-box h1 {
  margin: 0 0 16px;
  color: var(--text);
  text-align: center;
  font-size: 22px;
  font-weight: 700;
}
.login-box .btn { width: 100%; margin-top: 8px; }
.error-message {
  background: rgba(239,68,68,0.1);
  color: #fecaca;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--danger);
}

/* Dashboard header (generic) */
.header {
  background: linear-gradient(180deg, rgba(99,102,241,0.18), rgba(99,102,241,0.08));
  color: var(--text);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.header h1 { margin: 0; font-size: 20px; }

/* Status indicators */
.status-indicator { display: inline-flex; align-items: center; gap: 8px; }
.status-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 2px rgba(16,185,129,0.3);
}
.status-dot.busy {
  background: var(--danger);
  box-shadow: 0 0 0 2px rgba(239,68,68,0.3);
}

/* Cards for stats */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 16px; }
.stat-card {
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01));
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  box-shadow: var(--shadow);
}
.stat-card h3 {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  margin: 0 0 8px;
  text-transform: none;
}
.stat-card .value {
  font-size: 28px;
  font-weight: 800;
  color: var(--brand);
}

/* Queue panel */
.queue-stats {
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01));
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.queue-stats h2 { margin: 0 0 12px; }
.queue-item {
  padding: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.queue-item:first-child { border-top: none; }
.queue-name { font-weight: 600; }
.queue-metrics { display: flex; gap: 16px; color: var(--muted); font-size: 14px; }

/* Active / incoming call */
@keyframes slideIn {
  from { transform: translateX(400px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
.incoming-call {
  position: fixed;
  top: 100px; right: 30px;
  background: var(--surface);
  padding: 20px;
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  z-index: 1000;
  display: none;
  animation: slideIn .3s ease-out;
}
.incoming-call.show { display: block; }
.incoming-call h3 { color: var(--brand); margin: 0 0 10px; }
.call-info p { margin: 4px 0; color: var(--muted); }
.call-info strong { color: var(--text); }

.active-call {
  background: linear-gradient(180deg, rgba(99,102,241,0.25), rgba(99,102,241,0.12));
  color: var(--text);
  padding: 18px;
  border-radius: 12px;
  border: 1px solid var(--border);
  margin-bottom: 20px;
  display: none;
}
.active-call.show { display: block; }
.call-timer { font-size: 22px; font-weight: 800; margin: 8px 0; }

/* Responsive tweaks */
@media (max-width: 768px) {
  .incoming-call { right: 20px; left: 20px; }
}

/* Layout: Sidebar app */
.app-container { display: flex; min-height: calc(100vh - 64px); }
.sidebar {
  position: fixed; top: 64px; bottom: 0; left: 0;
  width: 260px;
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01));
  border-right: 1px solid var(--border);
  padding: 16px 0;
  overflow-y: auto;
  z-index: 1500;
}
.sidebar-header { padding: 0 20px 16px; border-bottom: 1px solid var(--border); }
.sidebar-header h2 { font-size: 16px; margin: 0 0 6px; }
.sidebar-header .agent-name { color: var(--muted); font-size: 14px; }
.sidebar-header .agent-role {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  background: rgba(99,102,241,0.35);
  border-radius: 999px;
  margin-top: 6px;
}
.nav-menu { margin-top: 12px; }
.nav-item {
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  opacity: .9;
  cursor: pointer;
  transition: background .2s ease, opacity .2s ease, transform .15s ease;
}
.nav-item:hover { background: rgba(255,255,255,0.06); opacity: 1; transform: translateY(-1px); }
.nav-item.active { background: rgba(99,102,241,0.18); color: #fff; }
.logout-btn { display: block; width: 100%; margin-top: 10px; }

.status-section { padding: 16px 20px; border-top: 1px solid var(--border); margin-top: auto; }
.status-toggle {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px; background: rgba(255,255,255,0.04);
  border: 1px solid var(--border); border-radius: 10px; cursor: pointer;
}
.status-menu {
  display: none;
  position: fixed;
  left: 20px;
  width: 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 1600;
}
.status-menu.show { display: block; }
.status-option { padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.status-option:last-child { border-bottom: none; }
.status-option:hover { background: rgba(255,255,255,0.04); }

.main-content { flex: 1; margin-left: 260px; padding: 20px 30px; }

/* Content cards */
.content-card {
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01));
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.table-container { overflow-x: auto; }

/* Buttons (extensions) */
.btn-secondary {
  background: linear-gradient(180deg, rgba(255,255,255,0.16), rgba(255,255,255,0.08));
  color: var(--text);
  border-color: var(--border);
}
.btn-sm { padding: 6px 10px; font-size: 12px; border-radius: 8px; }

/* Badges */
.badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
}
.badge-success {
  color: var(--success);
  border-color: rgba(16,185,129,0.45);
  background: rgba(16,185,129,0.12);
}
.badge-danger {
  color: var(--danger);
  border-color: rgba(239,68,68,0.45);
  background: rgba(239,68,68,0.12);
}
.badge-warning {
  color: var(--warning);
  border-color: rgba(245,158,11,0.45);
  background: rgba(245,158,11,0.12);
}
.badge-info {
  color: var(--brand);
  border-color: rgba(99,102,241,0.45);
  background: rgba(99,102,241,0.12);
}

/* Modals */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 3000;
  align-items: center;
  justify-content: center;
}
.modal.show { display: flex; }
.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: min(600px, 92vw);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.modal-header h2 { margin: 0; font-size: 20px; }
.close-btn { background: none; border: none; font-size: 22px; color: var(--muted); cursor: pointer; }

/* Page visibility helpers */
.page { display: none; }
.page.active { display: block; }

/* Extra utilities */
.w-full { width: 100%; }
.p-3 { padding: 12px; }
.p-4 { padding: 16px; }
.p-5 { padding: 20px; }
.p-6 { padding: 24px; }
.py-6 { padding-top: 24px; padding-bottom: 24px; }
.py-10 { padding-top: 40px; padding-bottom: 40px; }
.px-4 { padding-left: 16px; padding-right: 16px; }

/* Responsive sidebar collapse */
@media (max-width: 960px) {
  .sidebar { transform: translateX(-100%); transition: transform .3s ease; }
  .sidebar.show { transform: translateX(0); }
  .main-content { margin-left: 0; }
}

/* Page-specific layout helpers for Knowledge Base (generic enough for reuse) */
.kb-layout { display: grid; grid-template-columns: 260px 1fr; gap: 16px; }

/* Header actions */
.header-actions { display: flex; gap: 10px; align-items: center; }

/* Search bar */
.search-bar { display: flex; gap: 10px; }
.search-input { flex: 1; }

/* Category tree */
.category-tree { list-style: none; padding: 0; margin: 0; }
.category-item {
  padding: 10px 12px;
  margin: 6px 0;
  border-radius: 10px;
  cursor: pointer;
  color: var(--muted);
  transition: background .2s ease, color .2s ease, transform .15s ease;
}
.category-item:hover { background: rgba(255,255,255,0.06); color: var(--text); transform: translateY(-1px); }
.category-item.active { background: rgba(99,102,241,0.18); color: #fff; }
.category-item.subcategory { margin-left: 16px; font-size: 14px; }

/* Script meta + tags row */
.script-meta { display: flex; gap: 12px; flex-wrap: wrap; margin: 8px 0; color: var(--muted); font-size: 14px; }
.meta-item { display: inline-flex; align-items: center; gap: 6px; }

/* Content display blocks */
.script-content-display {
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.6;
}

/* Objections */
.objections-section { margin-top: 16px; }
.objections-section h3 { margin: 0 0 10px; }
.objection-card {
  background: rgba(99,102,241,0.08);
  border-left: 3px solid var(--brand);
  padding: 12px;
  border-radius: 10px;
  margin: 10px 0;
}
.objection-text { color: #fca5a5; font-style: italic; margin: 6px 0; }
.objection-response {
  color: #86efac;
  padding-left: 10px;
  border-left: 2px solid #22c55e;
}

/* Empty/loading states */
.loading, .empty-state { text-align: center; color: var(--muted); padding: 28px 12px; }
.empty-state i, .loading i { font-size: 28px; opacity: .6; display: block; margin-bottom: 8px; }
