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

:root {
  --sidebar-w: 220px;
  --purple: #7F77DD;
  --purple-dark: #534AB7;
  --green: #3B6D11;
  --amber: #854F0B;
  --red: #A32D2D;
  --bg: #ffffff;
  --bg2: #f6f5f2;
  --bg3: #efede8;
  --text: #1a1a1a;
  --text2: #5f5e5a;
  --text3: #9a9892;
  --border: rgba(0,0,0,0.12);
  --border2: rgba(0,0,0,0.22);
  --radius: 8px;
  --radius-lg: 12px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg2);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

a { text-decoration: none; color: inherit; }
code { font-family: monospace; background: var(--bg3); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* ── Layout ─────────────────────────────────────────────────── */
#sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--bg);
  border-right: 0.5px solid var(--border);
  overflow-y: auto;
  z-index: 100;
  transition: transform .25s ease;
  display: flex; flex-direction: column;
}

#sidebar.closed { transform: translateX(calc(-1 * var(--sidebar-w))); }

#main {
  margin-left: var(--sidebar-w);
  padding: 1.25rem 1.5rem;
  min-height: 100vh;
  transition: margin .25s ease;
}

#main.expanded { margin-left: 0; }

/* ── Logo ───────────────────────────────────────────────────── */
.logo {
  display: flex; align-items: center; gap: 10px;
  padding: .875rem 1rem 1rem;
  border-bottom: 0.5px solid var(--border);
}
.logo-icon { font-size: 22px; color: var(--purple); flex-shrink: 0; }
.logo-title { font-size: 13px; font-weight: 500; }
.logo-sub { font-size: 11px; color: var(--text3); }

/* ── Nav ────────────────────────────────────────────────────── */
.nav-section { padding: .5rem 0; }
.nav-label {
  font-size: 10px; font-weight: 500; color: var(--text3);
  text-transform: uppercase; letter-spacing: .08em;
  padding: .5rem 1rem .2rem;
}
.nav-item {
  display: flex; align-items: center; gap: 8px;
  padding: .42rem 1rem; font-size: 13px;
  color: var(--text2); cursor: pointer;
  transition: background .12s, color .12s;
  border-left: 2px solid transparent;
}
.nav-item:hover { background: var(--bg2); color: var(--text); }
.nav-item.active { background: var(--bg2); color: var(--text); font-weight: 500; border-left-color: var(--purple); }
.nav-item i { font-size: 15px; flex-shrink: 0; }
.nav-item.sub { padding-left: 2rem; font-size: 12px; }

/* ── Topbar ─────────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 1.25rem;
}
.topbar-title { font-size: 18px; font-weight: 500; flex: 1; }
.topbar-actions { display: flex; gap: 8px; }

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: .38rem .8rem; font-size: 13px;
  border: 0.5px solid var(--border2);
  border-radius: var(--radius);
  background: var(--bg); color: var(--text);
  cursor: pointer; transition: background .12s;
  white-space: nowrap;
}
.btn:hover { background: var(--bg2); }
.btn-primary { background: var(--purple); border-color: var(--purple); color: #fff; }
.btn-primary:hover { background: var(--purple-dark); border-color: var(--purple-dark); }
.icon-btn {
  width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
  border: 0.5px solid var(--border); border-radius: var(--radius);
  background: var(--bg); cursor: pointer; font-size: 16px;
  transition: background .12s;
}
.icon-btn:hover { background: var(--bg2); }
.full-btn { width: 100%; justify-content: center; }
.ml-auto { margin-left: auto; }

/* ── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.card-header {
  display: flex; align-items: center; gap: 8px;
  padding: .7rem 1rem;
  border-bottom: 0.5px solid var(--border);
  font-size: 13px; font-weight: 500;
}
.card-header i { font-size: 15px; color: var(--purple); }
.pad { padding: .875rem 1rem; }

/* ── Stat cards ─────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px; margin-bottom: 1.25rem;
}
.stat-card {
  background: var(--bg); border: 0.5px solid var(--border);
  border-radius: var(--radius); padding: 1rem;
}
.stat-label { font-size: 11px; color: var(--text2); margin-bottom: .2rem; font-weight: 500; text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-size: 26px; font-weight: 500; }
.stat-sub { font-size: 11px; color: var(--text3); margin-top: .15rem; }

/* ── Two column layout ──────────────────────────────────────── */
.two-col {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 1rem;
}
.col-stack { display: flex; flex-direction: column; gap: 1rem; }

/* ── Tables ─────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; padding: .55rem 1rem;
  font-size: 11px; font-weight: 500; color: var(--text2);
  text-transform: uppercase; letter-spacing: .05em;
  background: var(--bg2); border-bottom: 0.5px solid var(--border);
  white-space: nowrap;
}
td { padding: .55rem 1rem; border-bottom: 0.5px solid var(--border); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg2); }

/* ── Badges ─────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 11px; font-weight: 500; padding: 2px 8px; border-radius: 20px;
}
.badge-active   { background: #EAF3DE; color: #3B6D11; }
.badge-pending  { background: #FAEEDA; color: #854F0B; }
.badge-inactive { background: #F1EFE8; color: #5F5E5A; }
.badge-flag     { background: #FCEBEB; color: #A32D2D; }

/* ── Avatar ─────────────────────────────────────────────────── */
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: #EEEDFE; color: #534AB7;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 500; flex-shrink: 0;
}
.member-name { display: flex; align-items: center; gap: 8px; }

/* ── Toolbar ────────────────────────────────────────────────── */
.toolbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: .7rem 1rem; background: var(--bg2);
  border-bottom: 0.5px solid var(--border);
}
.toolbar input, .toolbar select {
  border: 0.5px solid var(--border2); border-radius: var(--radius);
  padding: .35rem .65rem; font-size: 13px;
  background: var(--bg); color: var(--text);
}
.toolbar input { min-width: 200px; }
.count-label { font-size: 12px; color: var(--text3); }

/* ── Pagination ─────────────────────────────────────────────── */
.pagination {
  display: flex; align-items: center; gap: 4px;
  padding: .65rem 1rem; border-top: 0.5px solid var(--border);
}
.pag-btn {
  min-width: 30px; height: 30px; display: flex; align-items: center; justify-content: center;
  border: 0.5px solid var(--border); border-radius: var(--radius);
  background: var(--bg); font-size: 12px; cursor: pointer;
  color: var(--text2); transition: background .12s;
}
.pag-btn:hover { background: var(--bg2); }
.pag-btn.active { background: var(--purple); color: #fff; border-color: var(--purple); }
.pag-info { font-size: 12px; color: var(--text3); margin-right: auto; }

/* ── Progress bar ───────────────────────────────────────────── */
.progress-bar { height: 4px; background: var(--bg3); border-radius: 2px; margin-top: .5rem; overflow: hidden; }
.progress-fill { height: 4px; background: var(--purple); border-radius: 2px; width: 0%; transition: width .3s; }

/* ── Domain bars ────────────────────────────────────────────── */
.domain-row { margin-bottom: .65rem; }
.domain-row-header { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 3px; }
.domain-label { color: var(--text2); }
.domain-count { font-weight: 500; }

/* ── Drop zone ──────────────────────────────────────────────── */
.drop-zone {
  border: 1.5px dashed var(--border2); border-radius: var(--radius-lg);
  padding: 2rem; text-align: center; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.drop-zone:hover { border-color: var(--purple); background: #EEEDFE20; }
.drop-icon { font-size: 36px; color: var(--text3); display: block; margin-bottom: .5rem; }
.drop-text { font-size: 13px; font-weight: 500; }
.drop-sub { font-size: 11px; color: var(--text2); margin-top: .25rem; }
.import-status { font-size: 13px; margin-top: .75rem; color: var(--green); }
.hint { font-size: 12px; color: var(--text3); }

/* ── AI Agents ──────────────────────────────────────────────── */
.agents-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}
.agent-card {
  background: var(--bg); border: 0.5px solid var(--border);
  border-radius: var(--radius-lg); padding: 1rem;
  display: flex; flex-direction: column; gap: .5rem;
}
.agent-icon {
  width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; font-size: 20px;
}
.agent-name { font-size: 14px; font-weight: 500; }
.agent-desc { font-size: 12px; color: var(--text2); flex: 1; }
.agent-status { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--green); }
.agent-status.running { color: var(--amber); }
.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.agent-output-body { white-space: pre-wrap; font-size: 13px; line-height: 1.7; color: var(--text2); max-height: 400px; overflow-y: auto; }

/* ── AI output ──────────────────────────────────────────────── */
.ai-output {
  margin-top: .75rem; padding: .75rem; border-radius: var(--radius);
  background: var(--bg2); border: 0.5px solid var(--border);
  font-size: 13px; line-height: 1.7; color: var(--text2);
  white-space: pre-wrap; max-height: 300px; overflow-y: auto;
}

/* ── Quick AI chips ─────────────────────────────────────────── */
.quick-ai { display: flex; flex-direction: column; gap: .5rem; }
.ai-chip {
  display: flex; align-items: center; gap: 7px; padding: .5rem .75rem;
  background: var(--bg2); border: 0.5px solid var(--border);
  border-radius: var(--radius); font-size: 13px; cursor: pointer;
  transition: background .12s; width: 100%;
}
.ai-chip:hover { background: #EEEDFE; border-color: var(--purple); color: var(--purple-dark); }
.ai-chip i { font-size: 15px; }

/* ── Chat ───────────────────────────────────────────────────── */
.chat-messages {
  padding: .75rem 1rem; max-height: 360px; overflow-y: auto;
  display: flex; flex-direction: column; gap: .65rem;
}
.chat-msg { display: flex; gap: 8px; }
.chat-msg.user { flex-direction: row-reverse; }
.chat-bubble {
  padding: .5rem .75rem; border-radius: 12px; max-width: 75%;
  font-size: 13px; line-height: 1.5;
}
.chat-msg.bot .chat-bubble { background: var(--bg2); border: 0.5px solid var(--border); }
.chat-msg.user .chat-bubble { background: var(--purple); color: #fff; }
.chat-input-row {
  display: flex; gap: 8px; padding: .65rem 1rem;
  border-top: 0.5px solid var(--border);
}
.chat-input-row input { flex: 1; }

/* ── Segment cards ──────────────────────────────────────────── */
.segment-card { background: var(--bg); border: 0.5px solid var(--border); border-radius: var(--radius); padding: 1rem; }

/* ── Settings ───────────────────────────────────────────────── */
.settings-card { max-width: 540px; }
.field-group { margin-bottom: .75rem; }
.field-group label { display: block; font-size: 12px; color: var(--text2); margin-bottom: .25rem; }
.field-group input, .field-group select, .field-group textarea {
  width: 100%; border: 0.5px solid var(--border2); border-radius: var(--radius);
  padding: .4rem .65rem; font-size: 13px;
  background: var(--bg); color: var(--text);
}

/* ── Map table ──────────────────────────────────────────────── */
.map-table td, .map-table th { padding: .4rem .5rem; }
.map-table select { width: auto; }

/* ── Export form ────────────────────────────────────────────── */
.export-form { display: flex; flex-direction: column; gap: .75rem; }

/* ── Page sections ──────────────────────────────────────────── */
.page { display: none; }
.page.active { display: block; }

/* ── Toast ──────────────────────────────────────────────────── */
#toast-el {
  position: fixed; bottom: 1.25rem; right: 1.25rem;
  background: #3C3489; color: #fff;
  padding: .55rem 1rem; border-radius: var(--radius);
  font-size: 13px; max-width: 320px;
  z-index: 999; display: none;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}

/* ── Spinner ────────────────────────────────────────────────── */
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid #fff4; border-top-color: #fff; border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 900px) {
  .two-col { grid-template-columns: 1fr; }
  .agents-grid { grid-template-columns: 1fr 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
  #sidebar { transform: translateX(calc(-1 * var(--sidebar-w))); }
  #main { margin-left: 0; padding: 1rem; }
  .agents-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr; }
}
