/* ── Arcane palette ────────────────────────────────── */
:root {
  --bg-deep:     #080412;
  --bg-panel:    #110820;
  --bg-card:     #180d2e;
  --border:      #3b1a5c;
  --border-glow: #7c3aed;
  --text:        #c8b0e0;
  --text-dim:    #6b4a8a;
  --text-bright: #ede0ff;
  --green:       #00e87a;
  --green-dim:   #00704a;
  --amber:       #ffb800;
  --amber-dim:   #7a5800;
  --red:         #ff4455;
  --red-dim:     #7a1a22;
  --blue:        #ff7a2a;   /* orange replaces blue as the primary accent */
  --orange:      #ff7a2a;
  --purple:      #a855f7;
  --font:        'JetBrains Mono', 'Courier New', monospace;
  --header-h:    52px;

  /* ── Aliases for templates that use semantic names ── */
  --bg-primary:    var(--bg-deep);
  --bg-secondary:  var(--bg-panel);
  --bg-tertiary:   var(--bg-card);
  --text-primary:  var(--text-bright);
  --text-secondary: var(--text);
  --text-muted:    var(--text-dim);
  --accent:        var(--orange);
  --accent-dim:    #b35500;
  --success:       var(--green);
  --warning:       var(--amber);
  --danger:        var(--red);
  --info:          var(--purple);

  /* ── Radius & spacing tokens ── */
  --radius-sm:  4px;
  --radius-md:  8px;
  --radius-lg:  14px;
  --radius-xl:  20px;

  /* ── Shadow tokens ── */
  --shadow-sm:  0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md:  0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg:  0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-glow-purple: 0 0 20px rgba(124, 58, 237, 0.15);
  --shadow-glow-orange: 0 0 20px rgba(249, 115, 22, 0.12);

  /* ── Transition tokens ── */
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-out-back: cubic-bezier(0.34, 1.56, 0.64, 1);
  --transition-fast: 0.15s var(--ease-out-expo);
  --transition-med:  0.25s var(--ease-out-expo);
  --transition-slow: 0.4s var(--ease-out-expo);

  /* ── Glass effect ── */
  --glass-bg:    rgba(17, 8, 32, 0.72);
  --glass-blur:  16px;
  --glass-border: rgba(124, 58, 237, 0.18);

  /* Bootstrap dark-mode overrides */
  --bs-body-bg:            var(--bg-deep);
  --bs-body-color:         var(--text);
  --bs-body-font-family:   var(--font);
  --bs-body-font-size:     13px;
  --bs-card-bg:            var(--bg-panel);
  --bs-card-border-color:  var(--border);
  --bs-card-cap-bg:        var(--bg-card);
  --bs-card-cap-color:     var(--text-dim);
  --bs-border-color:       var(--border);
  --bs-form-control-bg:    var(--bg-deep);
  --bs-form-control-color: var(--text-bright);
}

/* ── Reset & base ─────────────────────────────────── */
* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background-color: var(--bg-deep);
  background-image: url('/static/bg.svg');
  background-size: cover;
  background-position: center top;
  background-attachment: fixed;
  color: var(--text);
  font-size: 13px;
  min-height: 100dvh;
  overflow-x: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Vivid magical background animation layer ─────── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 600px 400px at 20% 30%, rgba(124, 58, 237, 0.18) 0%, transparent 70%),
    radial-gradient(ellipse 500px 500px at 80% 70%, rgba(249, 115, 22, 0.12) 0%, transparent 70%),
    radial-gradient(ellipse 400px 300px at 60% 20%, rgba(168, 85, 247, 0.10) 0%, transparent 70%);
  animation: auroraShift 20s ease-in-out infinite alternate;
}
body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 350px 350px at 40% 60%, rgba(124, 58, 237, 0.12) 0%, transparent 70%),
    radial-gradient(ellipse 450px 300px at 75% 35%, rgba(192, 132, 252, 0.08) 0%, transparent 70%);
  animation: auroraShift2 25s ease-in-out infinite alternate;
}

@keyframes auroraShift {
  0%   { transform: translate(0, 0) scale(1); opacity: 0.7; }
  33%  { transform: translate(3%, -2%) scale(1.05); opacity: 1; }
  66%  { transform: translate(-2%, 3%) scale(0.97); opacity: 0.8; }
  100% { transform: translate(1%, -1%) scale(1.02); opacity: 0.9; }
}
@keyframes auroraShift2 {
  0%   { transform: translate(0, 0) scale(1) rotate(0deg); opacity: 0.5; }
  50%  { transform: translate(-3%, 2%) scale(1.08) rotate(1deg); opacity: 0.9; }
  100% { transform: translate(2%, -3%) scale(0.95) rotate(-1deg); opacity: 0.6; }
}

/* Ensure all content sits above the animated background */
.mc-header, .mc-main, .mc-mobile-overlay, .mc-mobile-menu,
.mc-toast-container { position: relative; z-index: 1; }

/* ── Magical particle canvas ─────────────────────── */
#magic-particles {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.85;
}
@media (prefers-reduced-motion: reduce) {
  body::before, body::after, #magic-particles { display: none !important; }
}

a { color: var(--purple); transition: color var(--transition-fast); }
a:hover { color: var(--orange); }

/* Smooth page transitions */
.mc-main { animation: fadeUp 0.4s var(--ease-out-expo); }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Header ─────────────────────────────────────── */
.mc-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 24px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: rgba(8, 4, 18, 0.82);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  border-bottom: 1px solid rgba(124, 58, 237, 0.12);
  box-shadow: 0 1px 24px rgba(124, 58, 237, 0.08), 0 1px 0 rgba(124, 58, 237, 0.06);
  position: sticky;
  top: 0;
  z-index: 100;
}
.mc-header-left { display: flex; align-items: baseline; gap: 0; }
.mc-header-right { display: flex; align-items: center; gap: 16px; }
.mc-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-bright);
  letter-spacing: 0.15em;
  text-shadow: 0 0 18px rgba(168, 85, 247, 0.55), 0 0 40px rgba(168, 85, 247, 0.25);
  text-decoration: none;
  animation: titleGlow 4s ease-in-out infinite alternate;
}
.mc-title:hover { color: var(--text-bright); text-decoration: none; }
@keyframes titleGlow {
  0%   { text-shadow: 0 0 18px rgba(168, 85, 247, 0.55), 0 0 40px rgba(168, 85, 247, 0.25); }
  100% { text-shadow: 0 0 24px rgba(168, 85, 247, 0.75), 0 0 60px rgba(168, 85, 247, 0.35), 0 0 80px rgba(124, 58, 237, 0.15); }
}
.mc-subtitle {
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.2em;
  margin-left: 16px;
}
.mc-time {
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  color: var(--orange);
  letter-spacing: 0.1em;
  text-shadow: 0 0 10px rgba(249, 115, 22, 0.4);
  animation: clockPulse 2s ease-in-out infinite alternate;
}
@keyframes clockPulse {
  0%   { text-shadow: 0 0 10px rgba(249, 115, 22, 0.4); }
  100% { text-shadow: 0 0 16px rgba(249, 115, 22, 0.6), 0 0 30px rgba(249, 115, 22, 0.2); }
}
.mc-test-link {
  font-size: 9px;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: 0.2em;
  text-decoration: none;
  border: 1px solid rgba(59, 26, 92, 0.4);
  border-radius: 3px;
  padding: 4px 10px;
  transition: border-color var(--transition-fast), color var(--transition-fast),
              background var(--transition-fast), box-shadow var(--transition-fast);
  touch-action: manipulation;
}
.mc-test-link:hover {
  border-color: var(--purple);
  color: var(--purple);
  background: rgba(168, 85, 247, 0.06);
  box-shadow: 0 0 8px rgba(168, 85, 247, 0.1);
}

/* ── Named link colors ───────────────────────────── */
.mc-link-thinking { color: #c084fc; }
.mc-link-bugs { color: #ff6b6b; }
.mc-link-grok { color: #00ff88; }

/* ── Desktop "More" dropdown ─────────────────────── */
.mc-nav-dropdown { position: relative; }
.mc-dropdown-toggle {
  background: none;
  cursor: pointer;
}
.mc-dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: rgba(12, 6, 24, 0.96);
  backdrop-filter: blur(24px) saturate(1.3);
  -webkit-backdrop-filter: blur(24px) saturate(1.3);
  border: 1px solid rgba(124, 58, 237, 0.15);
  border-radius: 6px;
  padding: 6px 0;
  min-width: 160px;
  z-index: 150;
  max-height: 70vh;
  overflow-y: auto;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(124, 58, 237, 0.06);
  /* Animated fade + slide */
  display: flex;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
}
.mc-nav-dropdown:hover .mc-dropdown-menu,
.mc-nav-dropdown.open .mc-dropdown-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}
.mc-dropdown-menu .mc-test-link {
  display: block;
  padding: 6px 14px;
  border: none;
  border-radius: 0;
  white-space: nowrap;
}
.mc-dropdown-menu .mc-test-link:hover {
  background: rgba(124, 58, 237, 0.12);
}
.mc-dropdown-menu .mc-test-link.active {
  color: var(--orange);
  border-left: 3px solid var(--orange);
  background: rgba(124, 58, 237, 0.08);
}

/* ── Mobile section labels ───────────────────────── */
.mc-mobile-section-label {
  font-size: 9px;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: 0.2em;
  padding: 12px 20px 4px;
  text-transform: uppercase;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

/* ── Hamburger (mobile only) ───────────────────── */
.mc-hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  width: 44px;
  height: 44px;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.mc-hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text);
  border-radius: 1px;
  transition: transform 0.3s ease, opacity 0.2s ease;
}
.mc-hamburger.open span:nth-child(1) { transform: rotate(45deg) translate(5px, 5px); }
.mc-hamburger.open span:nth-child(2) { opacity: 0; }
.mc-hamburger.open span:nth-child(3) { transform: rotate(-45deg) translate(5px, -5px); }

/* ── Mobile slide-out menu ─────────────────────── */
.mc-mobile-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 199;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.mc-mobile-overlay.open { display: block; opacity: 1; }

.mc-mobile-menu {
  position: fixed;
  top: 0;
  right: -280px;
  width: 280px;
  height: 100%;
  background: rgba(12, 6, 24, 0.96);
  backdrop-filter: blur(28px) saturate(1.4);
  -webkit-backdrop-filter: blur(28px) saturate(1.4);
  border-left: 1px solid rgba(124, 58, 237, 0.12);
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.5);
  z-index: 200;
  transition: right 0.35s var(--ease-out-expo);
  display: flex;
  flex-direction: column;
  padding-top: max(12px, env(safe-area-inset-top));
  overflow-y: auto;
  overscroll-behavior: contain;
}
.mc-mobile-menu.open { right: 0; }

.mc-mobile-menu-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.mc-mobile-menu-title {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: 0.2em;
}

.mc-mobile-link {
  display: block;
  padding: 14px 20px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.12em;
  text-decoration: none;
  border-bottom: 1px solid rgba(59, 26, 92, 0.3);
  transition: background 0.15s, color 0.15s, padding-left 0.2s;
}
.mc-mobile-link:hover,
.mc-mobile-link.active {
  background: rgba(124, 58, 237, 0.1);
  color: var(--text-bright);
  padding-left: 28px;
}
.mc-mobile-link.active {
  border-left: 3px solid var(--orange);
  color: var(--orange);
}
.mc-mobile-menu-footer {
  margin-top: auto;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}

/* ── Main layout ─────────────────────────────────── */
.mc-main {
  padding: 16px;
  height: calc(100dvh - var(--header-h));
  overflow: hidden;
}
.mc-content {
  height: 100%;
}
.mc-content > .row {
  height: 100%;
  flex-wrap: nowrap;
}

/* ── Sidebar ─────────────────────────────────────── */
.mc-sidebar {
  overflow-y: auto;
  min-height: 0;
  max-height: 100%;
}

/* ── Chat column ─────────────────────────────────── */
.mc-chat-panel {
  min-height: 0;
  max-height: 100%;
}
.mc-chat-panel > .card {
  height: 100%;
  min-height: 0;            /* flex child: allow shrink below content */
  margin-bottom: 0;         /* override Bootstrap .card margin that breaks flex sizing */
  overflow: hidden;
}

/* ── Panel / Card overrides ──────────────────────── */
.mc-panel {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur)) saturate(1.2);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(1.2);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md), var(--shadow-glow-purple);
  transition: border-color var(--transition-med), box-shadow var(--transition-med),
              transform var(--transition-fast);
}
.mc-panel:hover {
  border-color: rgba(124, 58, 237, 0.32);
  box-shadow: var(--shadow-lg), 0 0 28px rgba(124, 58, 237, 0.12);
}
.mc-panel-header {
  background: rgba(24, 10, 45, 0.90);
  border-bottom: 1px solid rgba(59, 26, 92, 0.4);
  font-size: 10px;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  padding: 8px 14px;
}

/* ── Agent Card ──────────────────────────────────── */
.mc-agent-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  background: rgba(24, 10, 45, 0.82);
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition-med), transform var(--transition-fast),
              box-shadow var(--transition-med);
}
.mc-agent-card:hover {
  border-color: rgba(124, 58, 237, 0.25);
  box-shadow: var(--shadow-md), 0 0 16px rgba(124, 58, 237, 0.08);
}
.mc-agent-card:active {
  transform: scale(0.98);
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-block;
}
.status-dot.green { background: var(--green); box-shadow: 0 0 6px var(--green); animation: dotPulse 2s ease-in-out infinite; }
.status-dot.amber { background: var(--amber); box-shadow: 0 0 6px var(--amber); animation: dotPulseAmber 2s ease-in-out infinite; }
.status-dot.red   { background: var(--red);   box-shadow: 0 0 6px var(--red); animation: dotPulseRed 1.5s ease-in-out infinite; }

@keyframes dotPulse {
  0%, 100% { box-shadow: 0 0 6px var(--green); }
  50%      { box-shadow: 0 0 12px var(--green), 0 0 20px rgba(0, 232, 122, 0.3); }
}
@keyframes dotPulseAmber {
  0%, 100% { box-shadow: 0 0 6px var(--amber); }
  50%      { box-shadow: 0 0 12px var(--amber), 0 0 20px rgba(255, 184, 0, 0.3); }
}
@keyframes dotPulseRed {
  0%, 100% { box-shadow: 0 0 6px var(--red); }
  50%      { box-shadow: 0 0 12px var(--red), 0 0 20px rgba(255, 68, 85, 0.3); }
}

.agent-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-bright);
  letter-spacing: 0.1em;
}
.agent-meta { font-size: 11px; line-height: 2; }
.meta-key   { color: var(--text-dim); display: inline-block; width: 60px; }
.meta-val   { color: var(--text); }

/* ── Generic agent card (used by mobile, marketplace, swarm) ── */
.agent-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--glass-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition-med), transform var(--transition-fast),
              box-shadow var(--transition-med);
}
.agent-card:hover {
  border-color: rgba(124, 58, 237, 0.28);
  box-shadow: var(--shadow-md), 0 0 16px rgba(124, 58, 237, 0.08);
}
.agent-card:active { transform: scale(0.98); }
.agent-avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--purple), var(--orange));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  color: white;
  flex-shrink: 0;
  box-shadow: 0 0 12px rgba(168, 85, 247, 0.25);
}
.agent-info { flex: 1; min-width: 0; }
.agent-info .agent-name {
  font-size: 13px;
  margin-bottom: 2px;
}
.agent-info .agent-meta {
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.6;
}

/* ── Health ──────────────────────────────────────── */
.health-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.health-row:last-child { border-bottom: none; }
.health-label { color: var(--text-dim); letter-spacing: 0.08em; }

/* Status badges */
.mc-badge-up    { background: var(--green-dim) !important; color: var(--green) !important; font-size: 10px; letter-spacing: 0.12em; border-radius: 2px; }
.mc-badge-down  { background: var(--red-dim)   !important; color: var(--red)   !important; font-size: 10px; letter-spacing: 0.12em; border-radius: 2px; }
.mc-badge-ready { background: var(--amber-dim) !important; color: var(--amber) !important; font-size: 10px; letter-spacing: 0.12em; border-radius: 2px; }

/* Generic badges (used across pages) */
.badge-success { background: var(--green-dim) !important; color: var(--green) !important; }
.badge-warning { background: var(--amber-dim) !important; color: var(--amber) !important; }
.badge-danger  { background: var(--red-dim)   !important; color: var(--red)   !important; }
.badge-secondary { background: rgba(59, 26, 92, 0.5) !important; color: var(--text-dim) !important; }
.badge-info    { background: rgba(168, 85, 247, 0.2) !important; color: var(--purple) !important; }

/* ── Chat ────────────────────────────────────────── */
.chat-log {
  flex: 1;
  min-height: 0;            /* allow flex child to shrink below content height */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.chat-message { margin-bottom: 16px; }
.msg-meta {
  font-size: 10px;
  color: var(--text-dim);
  margin-bottom: 4px;
  letter-spacing: 0.12em;
}
.chat-message.user      .msg-meta { color: var(--orange); }
.chat-message.agent     .msg-meta { color: var(--purple); }
.chat-message.error-msg .msg-meta { color: var(--red); }

.msg-body {
  background: rgba(24, 10, 45, 0.80);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: var(--shadow-sm);
  animation: msgAppear 0.3s var(--ease-out-expo);
}
@keyframes msgAppear {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.chat-message.user      .msg-body { border-color: rgba(124, 58, 237, 0.35); box-shadow: var(--shadow-sm), 0 0 12px rgba(124, 58, 237, 0.06); }
.chat-message.agent     .msg-body { border-left: 3px solid var(--purple); }
.chat-message.error-msg .msg-body { border-left: 3px solid var(--red); color: var(--red); }

/* ── Markdown rendering in agent chat ─────────────────── */
.agent-md { white-space: normal; }
.agent-md p { margin: 0 0 0.5em; }
.agent-md p:last-child { margin-bottom: 0; }
.agent-md pre {
  background: #0d0620;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  overflow-x: auto;
  margin: 0.5em 0;
  white-space: pre;
}
.agent-md code {
  font-family: var(--font);
  font-size: 0.9em;
}
.agent-md :not(pre) > code {
  background: rgba(168, 85, 247, 0.15);
  padding: 2px 5px;
  border-radius: 3px;
  color: var(--text-bright);
}
.agent-md ul, .agent-md ol { padding-left: 1.5em; margin: 0.4em 0; }
.agent-md blockquote {
  border-left: 3px solid var(--purple);
  padding-left: 10px;
  color: var(--text-dim);
  margin: 0.5em 0;
}
.agent-md h1, .agent-md h2, .agent-md h3 {
  color: var(--text-bright);
  margin: 0.6em 0 0.3em;
  font-size: 1em;
  font-weight: 700;
}
.agent-md a { color: var(--purple); }

/* Mobile chat classes (used by mobile.html) */
.chat-container {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
}
.chat-message .chat-meta {
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.1em;
  margin-bottom: 4px;
}
.chat-message.user .chat-meta { color: var(--orange); }
.chat-message.agent .chat-meta { color: var(--purple); }
.chat-message.agent > div:last-child {
  color: var(--text);
  line-height: 1.6;
}

/* ── Chat input footer ───────────────────────────── */
.mc-chat-footer {
  padding: 12px 14px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: rgba(24, 10, 45, 0.90);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.mc-btn-clear {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 2px;
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 9px;
  font-weight: 700;
  padding: 3px 8px;
  letter-spacing: 0.12em;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
  touch-action: manipulation;
}
.mc-btn-clear:hover { border-color: var(--red); color: var(--red); }

/* Bootstrap form-control overrides */
.mc-input {
  background: rgba(8, 4, 18, 0.75) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-md) !important;
  color: var(--text-bright) !important;
  font-family: var(--font) !important;
  font-size: 13px !important;
  transition: border-color var(--transition-fast), box-shadow var(--transition-med) !important;
  min-height: 48px;
  padding: 12px 14px !important;
}
.mc-input:focus {
  border-color: var(--border-glow) !important;
  box-shadow: 0 0 0 1px var(--border-glow), 0 0 14px rgba(124, 58, 237, 0.2), 0 0 30px rgba(124, 58, 237, 0.06) !important;
}
.mc-input::placeholder { color: var(--text-dim) !important; }

/* Larger touch-friendly input on tablets / stylus devices */
@media (pointer: coarse), (hover: none) {
  .mc-input, .mobile-chat-input input, .local-chat-input input {
    min-height: 56px;
    font-size: 16px !important;
    padding: 14px 16px !important;
  }
}

.mc-btn-send {
  background: linear-gradient(135deg, var(--border-glow), #9333ea);
  border: none;
  border-radius: var(--radius-md);
  color: var(--text-bright);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 700;
  padding: 8px 18px;
  letter-spacing: 0.12em;
  transition: background var(--transition-fast), color var(--transition-fast),
              box-shadow var(--transition-med), transform 0.1s;
  touch-action: manipulation;
  white-space: nowrap;
  box-shadow: 0 0 12px rgba(124, 58, 237, 0.2);
}
.mc-btn-send:hover {
  background: linear-gradient(135deg, var(--orange), #f59e0b);
  color: #080412;
  box-shadow: 0 0 20px rgba(249, 115, 22, 0.45), 0 0 40px rgba(249, 115, 22, 0.15);
}
.mc-btn-send:active { transform: scale(0.96); }

/* ── Buttons (generic) ──────────────────────────── */
.btn-primary {
  background: linear-gradient(135deg, var(--border-glow), #9333ea) !important;
  border-color: transparent !important;
  color: var(--text-bright) !important;
  font-family: var(--font);
  font-weight: 600;
  letter-spacing: 0.06em;
  border-radius: var(--radius-md);
  transition: background var(--transition-fast), box-shadow var(--transition-med), transform 0.1s;
  box-shadow: 0 0 10px rgba(124, 58, 237, 0.15);
}
.btn-primary:hover {
  background: linear-gradient(135deg, var(--purple), #7c3aed) !important;
  box-shadow: 0 0 20px rgba(168, 85, 247, 0.35), 0 4px 12px rgba(0, 0, 0, 0.3);
}
.btn-primary:active { transform: scale(0.97); }

.btn-secondary {
  background: rgba(59, 26, 92, 0.25) !important;
  border-color: rgba(59, 26, 92, 0.5) !important;
  color: var(--text) !important;
  font-family: var(--font);
  font-weight: 600;
  letter-spacing: 0.06em;
  border-radius: var(--radius-md);
  transition: background var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-med);
}
.btn-secondary:hover {
  background: rgba(59, 26, 92, 0.45) !important;
  border-color: var(--purple) !important;
  box-shadow: 0 0 12px rgba(168, 85, 247, 0.12);
}

/* ── Grid utilities (used across pages) ────────── */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }

/* ── Stat cards ─────────────────────────────────── */
.stat {
  background: var(--glass-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  text-align: center;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition-med), box-shadow var(--transition-med),
              transform var(--transition-fast);
}
.stat:hover {
  border-color: rgba(124, 58, 237, 0.28);
  box-shadow: var(--shadow-md), var(--shadow-glow-purple);
  transform: translateY(-1px);
}
.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text-bright);
  font-family: var(--font);
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}
.stat-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-top: 4px;
}

/* ── Form elements ──────────────────────────────── */
.form-group {
  margin-bottom: 16px;
}
.form-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  background: rgba(8, 4, 18, 0.75);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-bright);
  font-family: var(--font);
  font-size: 13px;
  padding: 10px 12px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--border-glow);
  box-shadow: 0 0 0 1px var(--border-glow), 0 0 10px rgba(124, 58, 237, 0.2);
}
.form-group input::placeholder,
.form-group textarea::placeholder {
  color: var(--text-dim);
}
.form-group small {
  display: block;
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 4px;
}

/* ── Card enhancements (Bootstrap cards in theme) ── */
.card {
  background: var(--glass-bg) !important;
  backdrop-filter: blur(var(--glass-blur)) saturate(1.2);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(1.2);
  border: 1px solid var(--glass-border) !important;
  border-radius: var(--radius-md) !important;
  margin-bottom: 16px;
  box-shadow: var(--shadow-md);
  transition: border-color var(--transition-med), box-shadow var(--transition-med);
}
.card:hover {
  border-color: rgba(124, 58, 237, 0.25) !important;
}
.card-header {
  background: rgba(24, 10, 45, 0.90) !important;
  border-bottom: 1px solid rgba(59, 26, 92, 0.4) !important;
  padding: 14px 16px;
}
.card-title {
  color: var(--text-bright);
  font-family: var(--font);
  font-size: 16px;
  letter-spacing: 0.06em;
  margin-bottom: 0;
}
.card-body {
  padding: 16px;
}

/* ── HTMX Loading ────────────────────────────────── */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  display: inline-block;
  color: var(--amber);
  animation: shimmerLoad 1.2s ease-in-out infinite;
}
@keyframes shimmerLoad {
  0%   { opacity: 1; text-shadow: 0 0 4px rgba(255, 184, 0, 0.3); }
  50%  { opacity: 0.3; text-shadow: 0 0 8px rgba(255, 184, 0, 0.6); }
  100% { opacity: 1; text-shadow: 0 0 4px rgba(255, 184, 0, 0.3); }
}

/* ── Scrollbar ───────────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(59, 26, 92, 0.6); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-glow); box-shadow: 0 0 4px rgba(124, 58, 237, 0.3); }

/* ── Nav tabs (Bootstrap override) ───────────────── */
.nav-tabs {
  border-bottom-color: var(--border) !important;
}
.nav-tabs .nav-link {
  color: var(--text-dim) !important;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  border-color: transparent !important;
  padding: 8px 16px;
  transition: color 0.15s, border-color 0.15s;
}
.nav-tabs .nav-link:hover {
  color: var(--text) !important;
  border-color: transparent transparent var(--border) !important;
}
.nav-tabs .nav-link.active {
  color: var(--orange) !important;
  background: transparent !important;
  border-color: var(--border) var(--border) var(--bg-deep) !important;
}


/* ════════════════════════════════════════════════════
   TABLET  (max-width: 1024px) — iPad / Apple Pencil
   ════════════════════════════════════════════════════ */
@media (max-width: 1024px) {
  /* Larger touch targets for nav dropdown toggles */
  .mc-test-link {
    font-size: 10px;
    padding: 6px 12px;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
  }
  .mc-dropdown-menu .mc-test-link {
    padding: 10px 16px;
    min-height: 40px;
  }

  /* Prevent iPad floating toolbar from obscuring chat input */
  .mc-chat-footer {
    padding-bottom: max(10px, env(safe-area-inset-bottom, 10px));
  }

  /* Ensure chat input is above iPad keyboard toolbar */
  .mc-main {
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
}

/* ════════════════════════════════════════════════════
   MOBILE  (max-width: 768px) — iPhone optimized
   ════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  :root { --header-h: 48px; }

  /* ── Header: hide desktop nav, show hamburger ── */
  .mc-header  {
    padding: 0 12px;
    padding-top: max(0px, env(safe-area-inset-top));
    height: var(--header-h);
    gap: 8px;
  }
  .mc-desktop-nav { display: none !important; }
  .mc-hamburger   { display: flex; }
  .mc-title   { font-size: 14px; letter-spacing: 0.1em; }
  .mc-subtitle { display: none; }

  /* ── Main layout becomes scrollable column stack ── */
  .mc-main {
    height: auto;
    overflow: visible;
    padding: 10px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }
  .mc-content { height: auto; }
  .mc-content > .row { height: auto; flex-wrap: wrap !important; }

  /* ── Sidebar becomes a horizontal scroll strip ── */
  .mc-sidebar {
    flex-direction: row !important;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
  }
  .mc-sidebar::-webkit-scrollbar { display: none; }
  .mc-sidebar .mc-panel {
    min-width: 220px;
    flex-shrink: 0;
  }

  /* ── Chat fills remaining space ── */
  .mc-chat-panel { min-height: 60dvh; }
  .mc-chat-panel > .card { height: 60dvh; }

  /* ── Tighter chat ── */
  .chat-log { padding: 10px !important; }
  .msg-body { padding: 8px 10px; font-size: 13px; }
  .chat-message { margin-bottom: 12px; }

  /* ── Touch-friendly inputs ── */
  .mc-chat-footer {
    padding: 8px 10px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
  .mc-input {
    font-size: 16px !important;
    min-height: 44px;
    border-radius: var(--radius-md) !important;
  }
  .mc-btn-send {
    min-height: 44px;
    min-width: 64px;
    font-size: 12px;
    padding: 0 14px;
    border-radius: var(--radius-md);
  }
  .mc-btn-clear {
    min-height: 36px;
    padding: 6px 10px;
    font-size: 10px;
    display: flex;
    align-items: center;
  }

  /* ── Agent cards ── */
  .mc-agent-card { padding: 10px; }

  /* ── Grids collapse ── */
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .stat-value { font-size: 1.3rem; }

  /* ── Bootstrap columns stack ── */
  .col-md-3, .col-md-4, .col-md-6, .col-md-9 {
    flex: 0 0 100%;
    max-width: 100%;
  }
  .col-lg-4 {
    flex: 0 0 100%;
    max-width: 100%;
  }

  /* ── Form elements ── */
  .form-group input,
  .form-group textarea,
  .form-group select {
    font-size: 16px;
    min-height: 44px;
    border-radius: var(--radius-md);
  }

  /* ── Cards ── */
  .card {
    border-radius: var(--radius-md) !important;
    margin-bottom: 12px;
  }
  .card-header {
    padding: 12px 14px;
  }
  .card-title {
    font-size: 14px;
  }

  /* ── Tab nav scrollable ── */
  .nav-tabs {
    flex-wrap: nowrap !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .nav-tabs::-webkit-scrollbar { display: none; }
  .nav-tabs .nav-link {
    white-space: nowrap;
    padding: 8px 14px;
    font-size: 11px;
  }

  /* ── touch-button (used by mobile.html) ── */
  .touch-button {
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    transition: transform 0.1s, box-shadow 0.2s;
  }
  .touch-button:active { transform: scale(0.96); }

  /* ── Display utilities ── */
  .display-6 { font-size: 1.2rem !important; }

  /* ── Container-fluid tight ── */
  .container-fluid { padding-left: 10px; padding-right: 10px; }
}


/* ════════════════════════════════════════════════════
   SMALL MOBILE (max-width: 390px) — iPhone SE / mini
   ════════════════════════════════════════════════════ */
@media (max-width: 390px) {
  .mc-title { font-size: 12px; }
  .mc-sidebar .mc-panel { min-width: 180px; }
  .mc-btn-send { min-width: 54px; padding: 0 10px; }
  .stat-value { font-size: 1.1rem; }
}
