@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700&display=swap');

/* ── Tokens ───────────────────────────────────────────────────────────────── */
:root {
  --sidebar-bg:   #0f172a;
  --sidebar-w:    220px;
  --accent:       #6366f1;
  --accent-h:     #4f46e5;
  --accent-soft:  #eef2ff;
  --topbar-h:     54px;
  --radius:       8px;
  --shadow:       0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:    0 4px 12px rgba(0,0,0,.10);
  --border:       #e5e7eb;
  --text:         #111827;
  --muted:        #6b7280;
  --bg:           #f3f4f6;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  font-family: 'Montserrat', system-ui, sans-serif;
  font-size: 14px;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ───────────────────────────────────────────────────────────────── */
#layout { display: flex; min-height: 100vh; }

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 300;
  overflow-y: auto;
  transition: transform .22s cubic-bezier(.4,0,.2,1);
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.15) transparent;
}
#sidebar::-webkit-scrollbar       { width: 4px; }
#sidebar::-webkit-scrollbar-track { background: transparent; }
#sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 4px; }
#sidebar::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.28); }

.sidebar-brand {
  padding: 22px 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,.07);
  flex-shrink: 0;
}
.sidebar-brand-text {
  font-family: 'Montserrat', sans-serif;
  font-weight: 700;
  font-size: 1rem;
  color: #fff;
  letter-spacing: .5px;
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}
.sidebar-brand-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  box-shadow: 0 0 0 3px rgba(99,102,241,.25);
}

.sidebar-section-label {
  padding: 16px 20px 6px;
  font-size: .68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: rgba(255,255,255,.25);
}

.sidebar-nav { flex: 1; padding-top: 6px; padding-bottom: 8px; }

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 20px;
  color: rgba(255,255,255,.5);
  text-decoration: none;
  font-size: .855rem;
  font-weight: 500;
  transition: all .15s;
  border-left: 2px solid transparent;
  margin: 1px 0;
}
.sidebar-nav a i { font-size: .95rem; width: 16px; text-align: center; flex-shrink: 0; }
.sidebar-nav a:hover  { color: rgba(255,255,255,.85); background: rgba(255,255,255,.06); }
.sidebar-nav a.active {
  color: #fff;
  background: rgba(99,102,241,.18);
  border-left-color: var(--accent);
}
.sidebar-nav a.dev-link { color: rgba(251,191,36,.6); }
.sidebar-nav a.dev-link:hover { color: rgba(251,191,36,.9); background: rgba(251,191,36,.07); }
.sidebar-nav a.dev-link.active { color: #fbbf24; background: rgba(251,191,36,.12); border-left-color: #fbbf24; }

.sidebar-footer {
  padding: 14px 20px;
  border-top: 1px solid rgba(255,255,255,.07);
  flex-shrink: 0;
}
.sidebar-footer a {
  color: rgba(255,255,255,.3);
  text-decoration: none;
  font-size: .82rem;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: color .15s;
}
.sidebar-footer a:hover { color: #ef4444; }

/* ── Sidebar bot selector ─────────────────────────────────────────────────── */
.sidebar-bot-selector {
  position: relative;
  margin: 0 -20px 4px;
}
.sidebar-bot-current {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 20px;
  cursor: pointer;
  color: rgba(255,255,255,.5);
  font-size: .855rem;
  font-weight: 500;
  transition: background .15s, color .15s;
  user-select: none;
  border-left: 2px solid transparent;
}
.sidebar-bot-current:hover {
  background: rgba(255,255,255,.06);
  color: rgba(255,255,255,.85);
}
.sidebar-bot-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-bot-chevron { font-size: .65rem; flex-shrink: 0; transition: transform .2s; }
.sidebar-bot-selector.open .sidebar-bot-chevron { transform: rotate(180deg); }

.sidebar-bot-menu {
  display: none;
  flex-direction: column;
  gap: 1px;
  padding: 6px 0 8px;
  /* visual design */
  background: #141e35;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,.55), 0 2px 8px rgba(0,0,0,.35);
  /* escape sidebar overflow clipping via JS-positioned fixed */
  position: fixed;
  width: max-content;
  min-width: 220px;
  max-width: min(480px, calc(100vw - 16px));
  z-index: 9999;
  /* entry animation */
  opacity: 0;
  transform: translateY(6px);
  transition: opacity .15s ease, transform .15s ease;
  pointer-events: none;
}
.sidebar-bot-selector.open .sidebar-bot-menu {
  display: flex;
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* label at top of popup */
.sidebar-bot-menu-label {
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: rgba(255,255,255,.25);
  padding: 2px 16px 6px;
}
/* thin divider between main bot and lite bots */
.sidebar-bot-menu-divider {
  height: 1px;
  background: rgba(255,255,255,.07);
  margin: 4px 0;
}

.sidebar-bot-menu form { margin: 0; }
.sidebar-bot-option {
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: rgba(255,255,255,.55);
  font-size: .8rem;
  font-weight: 500;
  padding: 7px 16px;
  border-radius: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 9px;
  transition: background .1s, color .1s;
  white-space: nowrap;
}
.sidebar-bot-option i { font-size: .85rem; width: 14px; text-align: center; flex-shrink: 0; opacity: .7; }
.sidebar-bot-option:hover {
  background: rgba(255,255,255,.07);
  color: rgba(255,255,255,.95);
}
.sidebar-bot-option:hover i { opacity: 1; }
.sidebar-bot-option.active {
  color: #93c5fd;
  font-weight: 600;
}
.sidebar-bot-option.active i { opacity: 1; color: #93c5fd; }
.sidebar-bot-empty { font-size: .75rem; color: rgba(255,255,255,.28); padding: 6px 16px; }

@media (max-width: 640px) {
  .sidebar-bot-menu {
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    top: auto !important;
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 12px 12px 0 0;
    padding-bottom: env(safe-area-inset-bottom, 8px);
  }
}

.sidebar-divider {
  border-color: rgba(255,255,255,.1);
  margin: 8px -20px;
}

/* ── Main ─────────────────────────────────────────────────────────────────── */
#main {
  flex: 1;
  min-width: 0;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
}

/* ── Topbar ───────────────────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 200;
  flex-shrink: 0;
}
.topbar-title {
  font-size: .95rem;
  font-weight: 600;
  color: var(--text);
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: .8rem;
  color: var(--muted);
}
.topbar-right a { color: var(--muted); text-decoration: none; transition: color .15s; }
.topbar-right a:hover { color: #ef4444; }

.burger-btn {
  display: none;
  background: none;
  border: none;
  font-size: 1.3rem;
  color: var(--text);
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

/* ── Content ──────────────────────────────────────────────────────────────── */
.content { padding: 24px; flex: 1; min-width: 0; }

/* ── Stat cards ───────────────────────────────────────────────────────────── */
.stat-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 44px 16px 14px 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  text-decoration: none;
  color: inherit;
  border: 1px solid var(--border);
  transition: box-shadow .18s, border-color .18s;
  height: 100%;
  position: relative;
}
a.stat-card:hover {
  box-shadow: var(--shadow-md);
  border-color: #d1d5db;
  color: inherit;
}

.stat-icon {
  position: absolute;
  top: -14px;
  left: 16px;
  width: 44px; height: 44px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
  border: 3px solid #fff;
  box-shadow: 0 1px 6px rgba(0,0,0,.10);
}

@media (max-width: 1279px) {
  .stat-icon  { width: 36px; height: 36px; font-size: 1rem; top: -12px; }
  .stat-value { font-size: 1.2rem; }
  .stat-row   { margin-top: 20px; }
}

@media (min-width: 1280px) {
  .stat-card {
    flex-direction: row;
    align-items: center;
    gap: 14px;
    padding: 18px 20px;
  }
  .stat-icon {
    position: static;
    top: auto;
    left: auto;
    border: none;
    box-shadow: none;
  }
}
.si-blue   { background: #eff6ff; color: #3b82f6; }
.si-green  { background: #f0fdf4; color: #22c55e; }
.si-purple { background: #f5f3ff; color: #8b5cf6; }
.si-orange { background: #fff7ed; color: #f97316; }
.si-teal   { background: #f0fdfa; color: #14b8a6; }
.si-red    { background: #fef2f2; color: #ef4444; }
.si-indigo { background: var(--accent-soft); color: var(--accent); }
.si-amber  { background: #fffbeb; color: #f59e0b; }

.stat-value { font-size: 1.5rem; font-weight: 700; color: var(--text); line-height: 1; }
.stat-label { font-size: .75rem; color: var(--muted); margin-top: 3px; }

/* ── Section titles ──────────────────────────────────────────────────────── */
.section-title {
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: .5rem;
}

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-header {
  background: none;
  border-bottom: 1px solid var(--border);
  padding: 14px 18px;
  font-weight: 600;
  font-size: .875rem;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-header i { color: var(--muted); }
.card-body { padding: 18px; }

/* ── Tables ───────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table      { margin: 0; min-width: 560px; border-collapse: collapse; }

.table thead th {
  background: #f9fafb;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
  padding: 9px 16px;
  white-space: nowrap;
}
.table tbody td {
  padding: 10px 16px;
  vertical-align: middle;
  font-size: .845rem;
  border-bottom: 1px solid #f3f4f6;
  color: var(--text);
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td      { background: #fafafa; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f5f3ff !important; }

/* ── Badges ───────────────────────────────────────────────────────────────── */
.plan-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 600;
  white-space: nowrap;
}
.plan-free    { background: #f3f4f6; color: #6b7280; }
.plan-start   { background: #f0fdf4; color: #15803d; }
.plan-pro     { background: #eff6ff; color: #2563eb; }
.plan-premium { background: #fefce8; color: #a16207; }

.type-text       { background: #eff6ff; color: #2563eb; }
.type-vision     { background: #f0fdfa; color: #0f766e; }
.type-classifier { background: #f5f3ff; color: #7c3aed; }
.type-image      { background: #fffbeb; color: #b45309; }
.type-video      { background: #fff1f2; color: #be123c; }
.type-file       { background: #ecfeff; color: #0e7490; }
.type-search     { background: #f0fdf4; color: #15803d; }
.type-audio      { background: #f0f9ff; color: #0369a1; }

/* ── Audience chart toggles ──────────────────────────────────────────────── */
.audience-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 500;
  border: 1px solid var(--border);
  background: #f9fafb;
  color: #9ca3af;
  cursor: pointer;
  user-select: none;
  transition: background .13s, color .13s, border-color .13s;
}
.audience-toggle input[type=checkbox] { display: none; }
.audience-toggle.active { background: #f9fafb; color: #111; border-color: var(--tc, #6366f1); }
.audience-toggle:not(.active) { opacity: .55; }
.audience-toggle:hover  { opacity: 1; border-color: var(--tc, #d1d5db); }
.tgl-dot {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--tc, #6366f1);
  flex-shrink: 0;
  transition: opacity .15s;
}
.audience-toggle:not(.active) .tgl-dot { opacity: .35; }

/* ── Plan distribution bar widget ────────────────────────────────────────── */
.plan-dist-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 2px;
}
.plan-dist-count {
  font-size: .88rem;
  font-weight: 600;
  color: #374151;
  flex-shrink: 0;
  min-width: 2.5rem;
  text-align: right;
}
.plan-dist-track {
  height: 7px;
  background: rgba(0,0,0,.07);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 10px;
}
.plan-dist-bar {
  height: 100%;
  border-radius: 4px;
  transition: width .45s cubic-bezier(.4,0,.2,1);
}
.plan-dist-bar.bar-free    { background: #9ca3af; }
.plan-dist-bar.bar-start   { background: #22c55e; }
.plan-dist-bar.bar-pro     { background: #3b82f6; }
.plan-dist-bar.bar-premium { background: #f59e0b; }
.plan-dist-bar.bar-default { background: #6366f1; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn-primary       { background: var(--accent);   border-color: var(--accent); font-weight: 500; }
.btn-primary:hover { background: var(--accent-h); border-color: var(--accent-h); }
.btn-xs { padding: 2px 8px; font-size: .72rem; border-radius: 4px; }

/* ── Form controls ───────────────────────────────────────────────────────── */
.form-control:focus, .form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}

/* ── Login ────────────────────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0f172a;
  padding: 16px;
}
.login-card {
  background: #fff;
  border-radius: 12px;
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 25px 60px rgba(0,0,0,.5);
}
.login-brand {
  font-family: 'Montserrat', sans-serif;
  font-weight: 700;
  font-size: 1.5rem;
  color: var(--accent);
  text-align: center;
  margin-bottom: 4px;
  letter-spacing: .5px;
}
.login-sub { text-align: center; color: var(--muted); font-size: .84rem; margin-bottom: 28px; }

/* ── Log viewer ───────────────────────────────────────────────────────────── */
.log-box {
  background: #0f172a;
  color: #94a3b8;
  font-family: 'Consolas', 'JetBrains Mono', monospace;
  font-size: .75rem;
  line-height: 1.65;
  padding: 14px;
  border-radius: 6px;
  max-height: 500px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}
.log-error   { color: #f87171; }
.log-warning { color: #fbbf24; }
.log-info    { color: #60a5fa; }

/* ── Search ───────────────────────────────────────────────────────────────── */
.search-form { display: flex; gap: 8px; flex-wrap: wrap; }
.search-form input { max-width: 260px; min-width: 140px; }

/* ── Pagination ───────────────────────────────────────────────────────────── */
.pagination { gap: 3px; }
.pagination .page-link {
  border-radius: 6px !important;
  font-size: .8rem;
  padding: 4px 10px;
  color: var(--accent);
  border-color: var(--border);
}
.pagination .page-item.active .page-link {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── Detail grid ─────────────────────────────────────────────────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0;
}
.detail-grid dt {
  padding: 10px 16px;
  font-size: .73rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  border-bottom: 1px solid #f3f4f6;
  white-space: nowrap;
  background: #fafafa;
}
.detail-grid dd {
  padding: 10px 16px;
  font-size: .855rem;
  color: var(--text);
  margin: 0;
  border-bottom: 1px solid #f3f4f6;
  word-break: break-word;
}
.detail-grid dt:last-of-type,
.detail-grid dd:last-of-type { border-bottom: none; }

/* ── Sidebar overlay ─────────────────────────────────────────────────────── */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 299;
  backdrop-filter: blur(2px);
}

/* ── Dev page ─────────────────────────────────────────────────────────────── */
.dev-action-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.dev-action-card h6 {
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
  margin-bottom: 12px;
}
.dev-badge {
  background: #fffbeb;
  border: 1px solid #fcd34d;
  color: #92400e;
  font-size: .72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* ── Platform switcher ───────────────────────────────────────────────────── */
.platform-switcher {
  display: flex;
  gap: 6px;
  padding: 8px 20px 10px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.platform-btn {
  flex: 1;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.12);
  color: rgba(255,255,255,.6);
  border-radius: 6px;
  padding: 5px 6px;
  font-size: .73rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.platform-btn:hover { background: rgba(255,255,255,.14); color: #fff; }
.platform-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── Breadcrumb ──────────────────────────────────────────────────────────── */
.breadcrumb { font-size: .8rem; }
.breadcrumb-item a { color: var(--accent); text-decoration: none; }
.breadcrumb-item a:hover { text-decoration: underline; }

/* ── Mobile ───────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  #sidebar            { transform: translateX(-100%); }
  #sidebar.open       { transform: translateX(0); }
  #sidebar-overlay.open { display: block; }
  #main               { margin-left: 0; }
  .burger-btn         { display: block; }
  .content            { padding: 16px; }
  .topbar             { padding: 0 16px; }
  .stat-value         { font-size: 1.3rem; }
  .detail-grid        { grid-template-columns: 1fr; }
  .detail-grid dt     { border-bottom: none; padding-bottom: 2px; background: none; }
  .detail-grid dd     { padding-top: 2px; }
  .topbar-right span.d-none { display: none !important; }
}

@media (max-width: 480px) {
  .login-card { padding: 28px 20px; }
  .content    { padding: 12px; }
}
