:root {
  --sidebar-bg: #0f1424;
  --sidebar-text: #97a2c4;
  --sidebar-text-active: #ffffff;
  --sidebar-active-bg: #1c2440;
  --sidebar-border: #1f2740;

  --bg: #f4f5fa;
  --card-bg: #ffffff;
  --text: #14162b;
  --muted: #6b7186;
  --border: #e7e8f1;

  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef0fe;

  --success: #16a34a;
  --success-bg: #e7f8ed;
  --danger: #dc2626;
  --danger-bg: #fdecec;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--accent); }

/* ---------- App shell (logged in) ---------- */

.app-shell {
  display: flex;
  min-height: 100vh;
  align-items: stretch;
}

.app-shell.no-sidebar {
  display: block;
  min-height: 100vh;
}

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 22px;
  color: #fff;
  font-weight: 700;
  font-size: 1.05rem;
}

.sidebar-brand svg { flex-shrink: 0; }

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.92rem;
  transition: background 0.12s, color 0.12s;
}

.nav-item svg { flex-shrink: 0; opacity: 0.85; }

.nav-item:hover {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-text-active);
}

.nav-item.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-text-active);
  font-weight: 600;
}

.sidebar-footer {
  border-top: 1px solid var(--sidebar-border);
  padding-top: 12px;
  margin-top: 12px;
}

.main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topheader {
  padding: 22px 32px 0;
}

.page-title {
  font-size: 1.35rem;
  margin: 0;
}

.content {
  flex: 1;
  padding: 20px 32px 40px;
  max-width: 840px;
}

.content.auth-content {
  max-width: none;
  padding: 0;
}

/* ---------- Cards & components ---------- */

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px 24px;
  margin-bottom: 18px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}

.auth-shell-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-card {
  max-width: 380px;
  width: 100%;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  font-weight: 700;
  font-size: 1.15rem;
  margin-bottom: 22px;
}

h1 { font-size: 1.3rem; margin-top: 0; }
h2 { font-size: 1.02rem; margin: 0 0 4px; }

.muted { color: var(--muted); font-size: 0.9rem; }

form { display: flex; flex-direction: column; gap: 6px; }

label { font-size: 0.83rem; color: var(--muted); margin-top: 10px; font-weight: 600; }

input, textarea, select {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}

textarea { resize: vertical; }

.btn-primary {
  margin-top: 18px;
  background: var(--accent);
  color: white;
  border: none;
  padding: 11px 18px;
  border-radius: 8px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  align-self: flex-start;
}

.btn-primary:hover { background: var(--accent-hover); }

.token-block {
  background: #0f1424;
  color: #d9deff;
  padding: 14px 16px;
  border-radius: 10px;
  font-size: 0.85rem;
  overflow-x: auto;
  direction: ltr;
  text-align: left;
  margin: 10px 0;
  line-height: 1.6;
}

code {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 2px 7px;
  border-radius: 5px;
  direction: ltr;
  display: inline-block;
  font-size: 0.85rem;
}

.copy-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.btn-copy {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  padding: 6px 12px;
  border-radius: 7px;
  font-size: 0.82rem;
  cursor: pointer;
}

.btn-copy:hover { background: var(--bg); }

.flash {
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 0.9rem;
}

.flash-error {
  background: var(--danger-bg);
  color: var(--danger);
}

/* ---------- Badges & stat tiles ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}

.badge-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.badge-active { background: var(--success-bg); color: var(--success); }
.badge-active .badge-dot { background: var(--success); }

.badge-inactive { background: var(--danger-bg); color: var(--danger); }
.badge-inactive .badge-dot { background: var(--danger); }

.stat-row {
  display: flex;
  gap: 14px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.stat-tile {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 20px;
  flex: 1;
  min-width: 130px;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 2px;
}

/* ---------- Lists (tools / conversations) ---------- */

.item-card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.item-card-body { flex: 1; min-width: 200px; }

.row-actions {
  display: flex;
  gap: 8px;
}

.row-actions form { flex-direction: row; }

.btn-secondary, .btn-danger {
  border: 1px solid var(--border);
  background: #fff;
  padding: 7px 13px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.82rem;
}

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

.empty-state {
  text-align: center;
  padding: 30px 10px;
  color: var(--muted);
}

.turn {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.turn:last-child { border-bottom: none; }

.turn-caller { color: var(--muted); font-size: 0.88rem; margin-bottom: 4px; }
.turn-bot { font-size: 0.95rem; }

@media (max-width: 720px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; padding: 10px 14px; }
  .sidebar-brand { padding: 0; margin-inline-end: 10px; }
  .sidebar-nav { flex-direction: row; flex: 1; overflow-x: auto; }
  .sidebar-footer { display: none; }
  .topheader, .content { padding-inline: 16px; }
}
