/* ==========================================================================
   CodeHub — Design System
   Premium dark dev-tool theme. Hand-written CSS, no build step.
   ========================================================================== */

:root {
  --ch-bg: #0a0c11;
  --ch-bg-elevated: #10131a;
  --ch-bg-card: #141822;
  --ch-bg-card-hover: #181d2a;
  --ch-border: #232838;
  --ch-border-soft: #1a1f2c;
  --ch-text: #eef1f7;
  --ch-text-muted: #8d95ab;
  --ch-text-faint: #5c6479;

  --ch-primary: #a3e635;
  --ch-primary-soft: #d4f571;
  --ch-primary-dim: #3a5216;
  --ch-primary-glow: rgba(163, 230, 53, 0.35);
  --ch-accent-2: #5eead4;
  --ch-on-primary: #0e1608;

  --ch-success: #22c55e;
  --ch-danger: #ef4444;
  --ch-warning: #f5a524;
  --ch-info: #38bdf8;

  --ch-radius-sm: 0.4rem;
  --ch-radius: 0.65rem;
  --ch-radius-lg: 1rem;

  --ch-shadow-card: 0 1px 0 0 rgba(255, 255, 255, 0.03) inset, 0 8px 24px -12px rgba(0, 0, 0, 0.6);
  --ch-shadow-pop: 0 20px 60px -20px rgba(0, 0, 0, 0.7);

  --ch-font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --ch-font-mono: 'JetBrains Mono', 'Fira Code', SFMono-Regular, Consolas, monospace;

  color-scheme: dark;
}

html, body {
  background-color: var(--ch-bg);
  color: var(--ch-text);
  font-family: var(--ch-font);
  font-size: 15px;
}

body {
  min-height: 100vh;
  background-image:
    radial-gradient(circle at 15% -10%, rgba(163, 230, 53, 0.12), transparent 45%),
    radial-gradient(circle at 100% 0%, rgba(94, 234, 212, 0.08), transparent 40%);
  background-attachment: fixed;
}

::selection {
  background: var(--ch-primary-dim);
  color: #fff;
}

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--ch-border); border-radius: 10px; border: 2px solid var(--ch-bg); }
::-webkit-scrollbar-thumb:hover { background: var(--ch-text-faint); }

a { color: var(--ch-primary-soft); text-decoration: none; }
a:hover { color: #fff; }

h1, h2, h3, h4, h5, h6 { font-weight: 650; letter-spacing: -0.02em; color: #fff; }

code, .font-mono { font-family: var(--ch-font-mono); }

.text-muted-ch { color: var(--ch-text-muted) !important; }
.text-faint-ch { color: var(--ch-text-faint) !important; }

/* ==========================================================================
   Bootstrap overrides (dark, no build step — plain CSS variable remap)
   ========================================================================== */

.btn {
  border-radius: var(--ch-radius-sm);
  font-weight: 550;
  letter-spacing: -0.01em;
  transition: all 0.15s ease;
}

.btn-primary {
  background: var(--ch-primary);
  border-color: var(--ch-primary);
  color: var(--ch-on-primary);
  box-shadow: 0 0 0 0 var(--ch-primary-glow);
}
.btn-primary:hover, .btn-primary:focus, .btn-primary:focus-visible,
.btn-primary:active, .btn-primary.active,
.btn-primary:not(:disabled):not(.disabled):active,
.btn-primary:not(:disabled):not(.disabled).active {
  background: var(--ch-primary-soft) !important;
  border-color: var(--ch-primary-soft) !important;
  color: var(--ch-on-primary) !important;
  box-shadow: 0 0 24px 0 var(--ch-primary-glow) !important;
}

/* Bootstrap's own focus ring defaults to blue regardless of our overrides
   above — reset it globally so no control ever flashes blue on click. */
.btn:focus, .form-control:focus, .form-select:focus, .form-check-input:focus {
  box-shadow: 0 0 0 3px var(--ch-primary-glow) !important;
}

.btn-outline-light {
  border-color: var(--ch-border);
  color: var(--ch-text);
}
.btn-outline-light:hover {
  background: var(--ch-bg-card-hover);
  border-color: var(--ch-text-faint);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  border: 1px solid transparent;
  color: var(--ch-text-muted);
}
.btn-ghost:hover { color: #fff; background: var(--ch-bg-card-hover); }

.form-control, .form-select {
  background-color: var(--ch-bg-elevated);
  border: 1px solid var(--ch-border);
  color: var(--ch-text);
  border-radius: var(--ch-radius-sm);
}
.form-control:focus, .form-select:focus {
  background-color: var(--ch-bg-elevated);
  border-color: var(--ch-primary);
  color: var(--ch-text);
  box-shadow: 0 0 0 3px var(--ch-primary-glow);
}
.form-control::placeholder { color: var(--ch-text-faint); }
.form-label { color: var(--ch-text-muted); font-size: 0.85rem; font-weight: 550; margin-bottom: 0.4rem; }

.dropdown-menu {
  background-color: var(--ch-bg-card);
  border: 1px solid var(--ch-border);
  border-radius: var(--ch-radius);
  box-shadow: var(--ch-shadow-pop);
  padding: 0.4rem;
}
.dropdown-item { color: var(--ch-text-muted); border-radius: var(--ch-radius-sm); font-size: 0.9rem; padding: 0.5rem 0.75rem; }
.dropdown-item:hover, .dropdown-item:focus { background: var(--ch-bg-card-hover); color: #fff; }
.dropdown-item.active, .dropdown-item:active {
  background: var(--ch-primary-dim);
  color: var(--ch-primary-soft);
}
.dropdown-divider { border-color: var(--ch-border); }

.modal-content {
  background-color: var(--ch-bg-card);
  border: 1px solid var(--ch-border);
  border-radius: var(--ch-radius-lg);
}
.modal-header, .modal-footer { border-color: var(--ch-border); }

.alert {
  border: 1px solid var(--ch-border);
  border-radius: var(--ch-radius-sm);
  background: var(--ch-bg-elevated);
}
.alert-success { border-color: rgba(34, 197, 94, 0.35); color: #4ade80; background: rgba(34, 197, 94, 0.08); }
.alert-danger { border-color: rgba(239, 68, 68, 0.35); color: #f87171; background: rgba(239, 68, 68, 0.08); }

.form-check-input {
  background-color: var(--ch-bg-elevated);
  border-color: var(--ch-border);
}
.form-check-input:checked { background-color: var(--ch-primary); border-color: var(--ch-primary); }

.invalid-feedback { color: var(--ch-danger); font-size: 0.8rem; }
.is-invalid { border-color: var(--ch-danger) !important; }

.table { color: var(--ch-text); --bs-table-bg: transparent; }
.table > :not(caption) > * > * { border-bottom-color: var(--ch-border); }
.table-hover > tbody > tr:hover > * { background-color: var(--ch-bg-card-hover); color: #fff; }

.badge { font-weight: 550; letter-spacing: 0.01em; border-radius: 999px; padding: 0.35em 0.7em; }

/* ==========================================================================
   Layout shell
   ========================================================================== */

.ch-navbar {
  background: rgba(10, 12, 17, 0.85);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--ch-border-soft);
  min-height: 64px;
}

@media (max-width: 991.98px) {
  .ch-navbar .navbar-collapse {
    background: var(--ch-bg-elevated);
    border: 1px solid var(--ch-border);
    border-radius: var(--ch-radius-lg);
    box-shadow: var(--ch-shadow-pop);
    padding: 1rem;
    margin-top: 0.75rem;
    margin-bottom: 0.75rem;
  }
  .ch-navbar .navbar-nav {
    margin: 0 0 0.75rem !important;
  }
}

.ch-navbar .navbar-brand {
  font-weight: 700;
  letter-spacing: -0.03em;
  font-size: 1.15rem;
  color: #fff;
}
.ch-logo-mark {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 20px 0 var(--ch-primary-glow);
  margin-right: 0.55rem;
  flex-shrink: 0;
  overflow: hidden;
}
.ch-logo-mark img { width: 100%; height: 100%; object-fit: contain; display: block; }

.ch-nav-link {
  color: var(--ch-text-muted);
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.5rem 0.9rem !important;
  border-radius: var(--ch-radius-sm);
  transition: all 0.15s ease;
}
.ch-nav-link:hover, .ch-nav-link.active { color: #fff; background: var(--ch-bg-card-hover); }

/* Sidebar (dashboard) */
.ch-shell { display: flex; min-height: 100vh; }

[x-cloak] { display: none !important; }

.ch-sidebar {
  width: 248px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--ch-bg-elevated);
  border-right: 1px solid var(--ch-border-soft);
  padding: 1rem 0.75rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  transition: width 0.18s ease;
}
.ch-sidebar.collapsed { width: 76px; }
.ch-sidebar.collapsed .ch-sidebar-label,
.ch-sidebar.collapsed .ch-sidebar-section-title { display: none; }
.ch-sidebar.collapsed .ch-sidebar-link { justify-content: center; }

.ch-sidebar-section-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ch-text-faint);
  padding: 0.9rem 0.6rem 0.4rem;
}

.ch-sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.65rem;
  border-radius: var(--ch-radius-sm);
  color: var(--ch-text-muted);
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 0.15rem;
}
.ch-sidebar-link i { font-size: 1.05rem; width: 1.1rem; text-align: center; flex-shrink: 0; }
.ch-sidebar-link:hover { background: var(--ch-bg-card-hover); color: #fff; }
.ch-sidebar-link.active {
  background: linear-gradient(90deg, var(--ch-primary-dim), transparent);
  color: #fff;
  box-shadow: inset 2px 0 0 0 var(--ch-primary);
}

.ch-main { flex: 1; min-width: 0; }
.ch-content { padding: 1.75rem; max-width: 1400px; margin: 0 auto; }

@media (max-width: 991.98px) {
  .ch-sidebar { position: fixed; z-index: 1050; left: -260px; top: 0; height: 100vh; transition: left 0.2s ease; }
  .ch-sidebar.mobile-open { left: 0; box-shadow: var(--ch-shadow-pop); }
  .ch-sidebar-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 1040; }
  .ch-content { padding: 1.1rem; }
}

/* ==========================================================================
   Cards & surfaces
   ========================================================================== */

.ch-card {
  background: var(--ch-bg-card);
  border: 1px solid var(--ch-border);
  border-radius: var(--ch-radius-lg);
  box-shadow: var(--ch-shadow-card);
}

.ch-card-hover { transition: border-color 0.15s ease, transform 0.15s ease; }
.ch-card-hover:hover { border-color: var(--ch-text-faint); transform: translateY(-2px); }

.ch-glass {
  background: rgba(20, 24, 34, 0.6);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--ch-border);
}

.ch-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.ch-status-dot.online { background: var(--ch-success); box-shadow: 0 0 8px 1px rgba(34, 197, 94, 0.6); }
.ch-status-dot.offline { background: var(--ch-text-faint); }
.ch-status-dot.error { background: var(--ch-danger); box-shadow: 0 0 8px 1px rgba(239, 68, 68, 0.6); }

.ch-kbd {
  font-family: var(--ch-font-mono);
  font-size: 0.75rem;
  background: var(--ch-bg-elevated);
  border: 1px solid var(--ch-border);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 0.1rem 0.4rem;
  color: var(--ch-text-muted);
}

/* Hero / marketing
   The grid pattern + fade mask live on a ::before layer BEHIND the content,
   never on the element itself — masking the element directly would also
   clip/fade its real children (headings, buttons, cards). */
.ch-hero-grid { position: relative; }
.ch-hero-grid::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image:
    linear-gradient(to right, rgba(255,255,255,0.035) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255,255,255,0.035) 1px, transparent 1px);
  background-size: 44px 44px;
  -webkit-mask-image: radial-gradient(ellipse 70% 60% at 50% 0%, #000 40%, transparent 100%);
  mask-image: radial-gradient(ellipse 70% 60% at 50% 0%, #000 40%, transparent 100%);
}
.ch-hero-grid > * { position: relative; z-index: 1; }

.ch-gradient-text {
  background: linear-gradient(90deg, #fff 20%, var(--ch-primary-soft) 60%, var(--ch-accent-2) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.ch-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid var(--ch-border);
  background: var(--ch-bg-card);
  border-radius: 999px;
  padding: 0.3rem 0.8rem;
  font-size: 0.8rem;
  color: var(--ch-text-muted);
}

/* Footer */
.ch-footer { border-top: 1px solid var(--ch-border-soft); background: var(--ch-bg-elevated); }

/* Chat / console (used later, kept here so tokens stay consistent) */
.ch-chat-bubble { border-radius: var(--ch-radius-lg); padding: 0.85rem 1.1rem; max-width: 78%; }
.ch-chat-bubble.user { background: var(--ch-primary); color: var(--ch-on-primary); margin-left: auto; border-bottom-right-radius: 0.25rem; }
.ch-chat-bubble.agent { background: var(--ch-bg-card); border: 1px solid var(--ch-border); border-bottom-left-radius: 0.25rem; }

.ch-tool-bubble {
  border-left: 3px solid var(--ch-primary) !important;
  max-width: 90%;
}
.ch-tool-bubble[data-tool-status="completed"] { border-left-color: var(--ch-success) !important; }
.ch-tool-bubble[data-tool-status="error"] { border-left-color: var(--ch-danger) !important; }

.ch-toolbar-scroll { overflow-x: auto; overflow-y: hidden; }
.ch-toolbar-scroll::-webkit-scrollbar { height: 6px; }

.ch-tool-images a img,
.ch-lightbox-trigger img { cursor: zoom-in; }

.ch-lightbox {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(6, 8, 5, .92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  cursor: zoom-out;
}

.ch-lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--ch-radius-sm);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
  cursor: default;
}

.ch-lightbox-close,
.ch-lightbox-open {
  position: absolute;
  top: 1rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--ch-border);
  background: var(--ch-bg-card);
  color: var(--ch-text);
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  cursor: pointer;
}

.ch-lightbox-close { right: 1rem; }
.ch-lightbox-open { right: 4.25rem; }
.ch-lightbox-close:hover,
.ch-lightbox-open:hover { background: var(--ch-bg-card-hover); color: var(--ch-text); }

.ch-tool-status-badge { background: var(--ch-bg-elevated); color: var(--ch-text-muted); text-transform: capitalize; }
.ch-tool-bubble[data-tool-status="completed"] .ch-tool-status-badge { background: rgba(34,197,94,.15); color: #4ade80; }
.ch-tool-bubble[data-tool-status="error"] .ch-tool-status-badge { background: rgba(239,68,68,.15); color: #f87171; }

.ch-tool-io {
  font-family: var(--ch-font-mono);
  font-size: 0.75rem;
  background: var(--ch-bg-elevated);
  border: 1px solid var(--ch-border);
  border-radius: var(--ch-radius-sm);
  padding: 0.5rem;
  margin: 0.4rem 0 0;
  white-space: pre-wrap;
  word-break: break-word;
}

@keyframes ch-spin { to { transform: rotate(360deg); } }
.ch-spin { display: inline-block; animation: ch-spin 1s linear infinite; color: var(--ch-primary); }

/* Markdown content inside chat bubbles */
.ch-markdown { line-height: 1.6; word-break: break-word; }
.ch-markdown > *:first-child { margin-top: 0; }
.ch-markdown > *:last-child { margin-bottom: 0; }
.ch-markdown h1, .ch-markdown h2, .ch-markdown h3, .ch-markdown h4 { font-size: 1rem; font-weight: 650; margin: 0.9rem 0 0.4rem; }
.ch-markdown h1 { font-size: 1.15rem; }
.ch-markdown p { margin: 0 0 0.6rem; }
.ch-markdown ul, .ch-markdown ol { margin: 0 0 0.6rem; padding-left: 1.3rem; }
.ch-markdown li { margin-bottom: 0.2rem; }
.ch-markdown a { color: var(--ch-primary-soft); text-decoration: underline; }
.ch-chat-bubble.user .ch-markdown a { color: var(--ch-on-primary); text-decoration-color: rgba(14,22,8,.5); }
.ch-markdown strong { font-weight: 650; color: #fff; }
.ch-chat-bubble.user .ch-markdown strong { color: var(--ch-on-primary); }
.ch-markdown code { font-family: var(--ch-font-mono); font-size: 0.85em; background: rgba(255,255,255,.08); padding: 0.1rem 0.35rem; border-radius: 0.3rem; }
/* Plain (no language hint) code fences — Prism.js styles any block with a
   language-xxx class instead (see partials pushed by console/index.blade.php). */
.ch-markdown pre:not([class*="language-"]) { background: var(--ch-bg-elevated); border: 1px solid var(--ch-border); border-radius: var(--ch-radius-sm); padding: 0.7rem; overflow-x: auto; margin: 0 0 0.6rem; }
.ch-markdown pre:not([class*="language-"]) code { background: none; padding: 0; font-size: 0.8rem; }

/* Prism.js code blocks — align its theme with our design tokens */
.ch-markdown pre[class*="language-"] {
  border: 1px solid var(--ch-border);
  border-radius: var(--ch-radius-sm);
  margin: 0 0 0.6rem;
  font-size: 0.8rem;
}
.ch-markdown div.code-toolbar > .toolbar { top: 0.3rem; right: 0.3rem; }
.ch-markdown div.code-toolbar > .toolbar .toolbar-item > button {
  background: var(--ch-bg-card-hover);
  color: var(--ch-text-muted);
  border: 1px solid var(--ch-border);
  border-radius: var(--ch-radius-sm);
  font-size: 0.7rem;
  padding: 0.2rem 0.5rem;
}
.ch-markdown div.code-toolbar > .toolbar .toolbar-item > button:hover { color: #fff; border-color: var(--ch-primary); }
.ch-markdown blockquote { border-left: 3px solid var(--ch-border); margin: 0 0 0.6rem; padding: 0.1rem 0 0.1rem 0.8rem; color: var(--ch-text-muted); }
.ch-markdown hr { border-color: var(--ch-border); margin: 0.8rem 0; }
.ch-markdown table { width: 100%; border-collapse: collapse; margin: 0 0 0.6rem; font-size: 0.85rem; overflow-x: auto; display: block; }
.ch-markdown th, .ch-markdown td { border: 1px solid var(--ch-border); padding: 0.4rem 0.6rem; text-align: left; }
.ch-markdown th { background: var(--ch-bg-elevated); font-weight: 600; }

/* Tool-call image/gif attachments */
.ch-tool-images { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.ch-tool-images img {
  max-width: 220px;
  max-height: 160px;
  border-radius: var(--ch-radius-sm);
  border: 1px solid var(--ch-border);
  object-fit: cover;
  display: block;
  transition: transform 0.15s ease;
}
.ch-tool-images a:hover img { transform: scale(1.02); border-color: var(--ch-primary); }

/* Composer */
.ch-chat-textarea {
  resize: none;
  min-height: 2.5rem;
  max-height: 220px;
  overflow-y: auto;
  border: none;
  background: transparent !important;
  padding: 0.4rem 0.5rem;
}
.ch-chat-textarea:focus { box-shadow: none; }

/* Conversation list */
.ch-conv-item { transition: background 0.15s ease; }
.ch-conv-item:hover { background: var(--ch-bg-card-hover); }
.ch-conv-item.active { background: var(--ch-bg-card-hover); box-shadow: inset 2px 0 0 0 var(--ch-primary); }
.ch-conv-delete { opacity: 0; transition: opacity 0.15s ease; }
.ch-conv-item:hover .ch-conv-delete { opacity: 1; }
.ch-conv-delete:hover { color: var(--ch-danger) !important; }

/* Utility */
.ch-divider { height: 1px; background: var(--ch-border-soft); border: 0; }
.cursor-pointer { cursor: pointer; }

@media (min-width: 992px) {
  .py-lg-6 { padding-top: 6rem !important; padding-bottom: 6rem !important; }
  .pt-lg-6 { padding-top: 6rem !important; }
}

@keyframes ch-blink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }
.cursor-blink { animation: ch-blink 1s step-start infinite; }

/* Recommended prompts gallery */
.ch-prompt-card {
  background: var(--ch-bg-card);
  border: 1px solid var(--ch-border);
  border-radius: var(--ch-radius);
  padding: 1rem;
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.ch-prompt-card:hover { border-color: var(--ch-primary); transform: translateY(-2px); }

.ch-prompt-card-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--ch-radius-sm);
  background: var(--ch-primary-dim);
  color: var(--ch-primary-soft);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  margin-bottom: 0.6rem;
}

.ch-prompt-card-cover {
  width: calc(100% + 2rem);
  height: 96px;
  object-fit: cover;
  margin: -1rem -1rem 0.6rem -1rem;
  border-radius: var(--ch-radius) var(--ch-radius) 0 0;
  display: block;
}

/* Chat attachments */
.ch-file-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--ch-bg-elevated);
  border: 1px solid var(--ch-border);
  border-radius: var(--ch-radius-sm);
  padding: 0.3rem 0.6rem;
  font-size: 0.78rem;
  color: var(--ch-text-muted);
  text-decoration: none;
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ch-file-chip:hover { color: #fff; border-color: var(--ch-primary); }

.ch-pending-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--ch-bg-elevated);
  border: 1px solid var(--ch-border);
  border-radius: var(--ch-radius-sm);
  padding: 0.3rem 0.4rem 0.3rem 0.6rem;
  font-size: 0.78rem;
  color: var(--ch-text-muted);
  max-width: 200px;
}
.ch-pending-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-pending-chip button {
  background: none;
  border: none;
  color: var(--ch-text-faint);
  padding: 0 0.2rem;
  line-height: 1;
  flex-shrink: 0;
}
.ch-pending-chip button:hover { color: var(--ch-danger); }
.ch-pending-chip img { width: 18px; height: 18px; object-fit: cover; border-radius: 3px; flex-shrink: 0; }
