:root {
  --bg: #0a0a0a;
  --bg-card: #111111;
  --bg-card-hover: #1a1a1a;
  --bg-sidebar: #0d0d0d;
  --border: #222;
  --text: #e0e0e0;
  --text-dim: #666;
  --text-bright: #fff;
  --accent: #00ff88;
  --accent-dim: #00cc6a;
  --accent-glow: rgba(0,255,136,0.15);
  --danger: #ff4444;
  --warning: #ffaa00;
  --blue: #4488ff;
  --font-mono: 'JetBrains Mono', monospace;
  --font-body: 'Space Grotesk', sans-serif;
  --radius: 6px;
  --sidebar-w: 260px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  background: var(--bg); color: var(--text);
  font-family: var(--font-body); font-size: 14px;
  min-height: 100vh; -webkit-font-smoothing: antialiased;
}

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

.sidebar {
  width: var(--sidebar-w); background: var(--bg-sidebar);
  border-right: 1px solid var(--border); position: fixed;
  height: 100vh; overflow-y: auto; display: flex; flex-direction: column;
}
.sidebar-logo {
  padding: 16px 20px; font-family: var(--font-mono); font-weight: 700;
  font-size: 15px; color: var(--accent); letter-spacing: 2px;
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 8px var(--accent);
}

.sidebar-section { padding: 12px 0; }
.sidebar-section-title {
  padding: 0 20px 8px; font-family: var(--font-mono); font-size: 10px;
  font-weight: 600; color: var(--text-dim); text-transform: uppercase;
  letter-spacing: 1.5px;
}

.sidebar-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 20px; cursor: pointer; transition: all 0.1s;
  border-left: 3px solid transparent;
}
.sidebar-item:hover { background: rgba(255,255,255,0.03); }
.sidebar-item.active { background: var(--accent-glow); border-left-color: var(--accent); }
.sidebar-item .dot-online { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 6px var(--accent); flex-shrink: 0; }
.sidebar-item .dot-offline { width: 6px; height: 6px; border-radius: 50%; background: var(--text-dim); flex-shrink: 0; }
.sidebar-item-name { font-size: 13px; font-weight: 500; color: var(--text-bright); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-item-meta { font-family: var(--font-mono); font-size: 10px; color: var(--text-dim); flex-shrink: 0; }
.sidebar-item-badge {
  font-family: var(--font-mono); font-size: 9px; padding: 1px 5px;
  border-radius: 3px; flex-shrink: 0;
}
.badge-admin { background: var(--accent-glow); color: var(--accent); }
.badge-user { background: rgba(255,255,255,0.05); color: var(--text-dim); }
.badge-head { background: var(--accent-glow); color: var(--accent); }

.sidebar-bottom {
  margin-top: auto; border-top: 1px solid var(--border); padding: 8px 0;
}

.content { margin-left: var(--sidebar-w); flex: 1; min-height: 100vh; min-width: 0; overflow-x: hidden; }

/* ── Content Header ───────────── */
.content-header {
  padding: 16px 32px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.content-header h2 { font-size: 18px; font-weight: 600; color: var(--text-bright); }

/* ── Tabs (inside content) ────── */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); padding: 0 32px; }
.tab {
  padding: 10px 16px; font-family: var(--font-mono); font-size: 12px;
  font-weight: 600; color: var(--text-dim); background: none; border: none;
  border-bottom: 2px solid transparent; cursor: pointer; transition: all 0.1s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-content { padding: 24px 32px; overflow-wrap: break-word; word-break: break-word; }

/* ── Buttons ──────────────────── */
.btn {
  font-family: var(--font-mono); font-size: 12px; font-weight: 500;
  padding: 8px 16px; border-radius: var(--radius); cursor: pointer;
  border: 1px solid var(--border); background: var(--bg-card);
  color: var(--text); transition: all 0.1s; letter-spacing: 0.5px;
}
.btn:hover { border-color: var(--text-dim); color: var(--text-bright); }
.btn-primary { background: var(--accent); color: #000; border-color: var(--accent); font-weight: 600; }
.btn-primary:hover { background: var(--accent-dim); }
.btn-danger { color: var(--danger); border-color: transparent; background: none; }
.btn-danger:hover { border-color: var(--danger); }
.btn-sm { padding: 4px 10px; font-size: 11px; }
.btn.loading { opacity: 0.6; pointer-events: none; }
.btn.loading::after {
  content: ''; width: 12px; height: 12px;
  border: 2px solid currentColor; border-top-color: transparent;
  border-radius: 50%; animation: spin 0.6s linear infinite;
  display: inline-block; margin-left: 6px; vertical-align: middle;
}

/* ── Cards ────────────────────── */
.library-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.lib-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; transition: all 0.1s; cursor: pointer;
}
.lib-card:hover { border-color: var(--accent); }
.lib-card-title { font-weight: 600; font-size: 14px; color: var(--text-bright); margin-bottom: 4px; }
.lib-card-desc { font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.lib-card-meta { font-family: var(--font-mono); font-size: 11px; color: var(--text-dim); }

/* ── Section ──────────────────── */
.section { margin-bottom: 28px; }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.section-title {
  font-family: var(--font-mono); font-size: 11px; font-weight: 600;
  color: var(--text-dim); text-transform: uppercase; letter-spacing: 1.5px;
}

.block {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}

.empty-state {
  text-align: center; padding: 32px; color: var(--text-dim);
  font-size: 13px; font-family: var(--font-mono);
}

/* ── Activity Feed ────────────── */
.feed-item {
  padding: 12px 0; border-bottom: 1px solid rgba(255,255,255,0.03);
}
.feed-header { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.feed-agent { font-weight: 600; font-size: 12px; color: var(--accent); }
.feed-arrow { color: var(--text-dim); font-size: 11px; }
.feed-user { font-weight: 500; font-size: 12px; color: var(--blue); }
.feed-time { font-family: var(--font-mono); font-size: 10px; color: var(--text-dim); margin-left: auto; }
.feed-text { font-size: 13px; color: var(--text); line-height: 1.5; word-break: break-word; overflow-wrap: break-word; }

/* ── Table ────────────────────── */
.table { width: 100%; border-collapse: collapse; }
.table th {
  font-family: var(--font-mono); font-size: 11px; font-weight: 600;
  color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px;
  padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border);
}
.table td { padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
.table tr { cursor: pointer; transition: background 0.1s; }
.table tr:hover td { background: rgba(255,255,255,0.02); }

/* ── Item List ────────────────── */
.item-list { list-style: none; }
.item-list li {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.item-list li:last-child { border-bottom: none; }
.item-name { font-weight: 500; font-size: 13px; color: var(--text-bright); }
.item-desc { font-size: 12px; color: var(--text-dim); }

/* ── Tags ─────────────────────── */
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  font-family: var(--font-mono); font-size: 11px; padding: 2px 8px;
  border-radius: 3px; border: 1px solid var(--border); color: var(--text-dim);
}
.tag-skill { border-color: #335; color: var(--blue); }
.tag-conn { border-color: #353; color: var(--accent); }

/* ── Tooltip ──────────────────── */
[data-tooltip] { position: relative; cursor: default; }
[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute; bottom: calc(100% + 6px); left: 0;
  background: #1a1a1a; color: var(--text); border: 1px solid var(--border);
  font-family: var(--font-body); font-size: 11px; font-weight: 400;
  padding: 6px 10px; border-radius: 4px;
  white-space: normal; max-width: 280px; width: max-content;
  z-index: 100; pointer-events: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

/* ── Forms ────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group:last-child { margin-bottom: 0; }
.form-label {
  display: block; font-family: var(--font-mono); font-size: 11px;
  font-weight: 600; color: var(--text-dim); text-transform: uppercase;
  letter-spacing: 1px; margin-bottom: 6px;
}
.form-input, .form-select, .form-textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-family: var(--font-mono);
  font-size: 13px; padding: 10px 12px; outline: none; transition: border-color 0.15s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--accent); }
.form-textarea { resize: vertical; min-height: 120px; }
.form-textarea.tall { min-height: 300px; }
.form-hint { font-size: 11px; color: var(--text-dim); margin-top: 4px; font-family: var(--font-mono); }
.form-input.invalid, .form-textarea.invalid { border-color: var(--danger) !important; }
.form-error { font-size: 11px; color: var(--danger); margin-top: 4px; font-family: var(--font-mono); }

textarea.code-editor {
  width: 100%; min-height: 300px; background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--accent); font-family: var(--font-mono); font-size: 13px;
  padding: 16px; resize: vertical; outline: none;
}
textarea.code-editor:focus { border-color: var(--accent); }

/* ── Modal ────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  z-index: 1000; display: flex; align-items: center; justify-content: center;
  opacity: 0; visibility: hidden; transition: all 0.15s; backdrop-filter: blur(4px);
}
.modal-overlay.active { opacity: 1; visibility: visible; }
.modal-overlay.active .modal { transform: translateY(0) scale(1); opacity: 1; }
.modal {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 8px; width: 90%; max-width: 600px; max-height: 85vh;
  overflow-y: auto; transform: translateY(16px) scale(0.98); opacity: 0;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.modal-wide { max-width: 720px; }
.modal-header {
  padding: 20px 24px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; background: var(--bg-card); z-index: 1;
}
.modal-header h3 { font-size: 16px; font-weight: 600; color: var(--text-bright); }
.modal-close {
  background: none; border: none; color: var(--text-dim); font-size: 20px;
  cursor: pointer; padding: 4px 8px; line-height: 1;
}
.modal-close:hover { color: var(--text-bright); }
.modal-body { padding: 20px 24px; }
.modal-footer {
  padding: 16px 24px; border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: flex-end; gap: 8px;
  position: sticky; bottom: 0; background: var(--bg-card); z-index: 1;
}

/* ── Toast ────────────────────── */
.toast-container {
  position: fixed; bottom: 24px; right: 24px; z-index: 2000;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 20px;
  color: var(--text); box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  transform: translateX(120%); transition: transform 0.25s ease;
  pointer-events: auto; display: flex; align-items: center; gap: 10px;
  font-family: var(--font-mono); font-size: 12px;
}
.toast.show { transform: translateX(0); }
.toast-success { border-left: 3px solid var(--accent); }
.toast-error { border-left: 3px solid var(--danger); }
.toast-info { border-left: 3px solid var(--blue); }

/* ── Loading ──────────────────── */
.loading-overlay {
  position: fixed; inset: 0; background: var(--bg);
  z-index: 9999; display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 16px; transition: opacity 0.3s;
}
.loading-overlay.hidden { opacity: 0; pointer-events: none; }
.loading-spinner {
  width: 32px; height: 32px; border: 3px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-family: var(--font-mono); font-size: 12px; color: var(--text-dim); }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }
