/* Futuristic AI theme (60% white, 20% purple, 20% black) */
:root {
  /* Core palette */
  --bg: #f7f7fb;                  /* light backdrop */
  --panel: #ffffff;               /* white cards/inputs */
  --border: rgba(106, 0, 255, 0.18); /* subtle purple border */
  --fg: #0b0b12;                  /* near-black text */
  --muted: #5a5f73;               /* muted text */
  --strong: #6a00ff;              /* strong purple text */
  --accent: #7c3aed;              /* primary purple */
  --accent-2: #a855f7;            /* secondary purple */
  --accent-grad: linear-gradient(135deg, #7c3aed 0%, #a855f7 50%, #7c3aed 100%);

  /* Glow */
  --glow: 0 0 0 1px rgba(124,58,237,.18), 0 0 24px rgba(106,0,255,.18);
}

html, body { height: 100%; }

body {
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  margin: 0;
  color: var(--fg);
  background:
    radial-gradient(1200px 600px at 120% -20%, rgba(106,0,255,.10), transparent 60%),
    radial-gradient(900px 500px at -20% 120%, rgba(168,85,247,.10), transparent 60%),
    repeating-linear-gradient(
      0deg,
      rgba(0,0,0,0.04) 0px,
      rgba(0,0,0,0.04) 1px,
      transparent 1px,
      transparent 24px
    ),
    linear-gradient(180deg, #ffffff 0%, var(--bg) 100%);
  background-attachment: fixed;
}

/* Content container for centered layouts */
.container {
  max-width: 980px;
  margin: 32px auto 48px;
  padding: 0 12px;
}

/* Top header */
.header {
  position: relative;
  display: block;
  text-align: center;
  margin-bottom: 18px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: 0.4px;
  font-size: 3rem; /* 3x bigger */
}
.brand .logo-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent-grad);
  box-shadow: var(--glow);
}
.badge-beta {
  display: inline-block;
  font-size: 0.9rem;
  color: var(--fg);
  border: 1px solid var(--border);
  background: rgba(168,85,247,0.08);
  padding: 3px 10px;
  border-radius: 999px;
  margin-left: 6px;
}
.title-row { text-align: center; margin-top: 6px; }
.title-row h2 { margin: 0; font-size: 1.45rem; font-weight: 700; display: inline-block; }
.title-row .user { float: none; }

/* Keep user controls at top-right while logo stays centered */
.header .user {
  position: absolute;
  right: 0;
  top: 0;
  float: none;
}

/* Buttons */
.btn,
button {
  background-image: var(--accent-grad);
  color: #ffffff;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: transform .15s ease, box-shadow .3s ease, background-size .6s ease;
  border-radius: 10px;
  padding: 12px 14px;
  background-size: 120% auto;
  box-shadow: var(--glow);
}
.btn:hover,
button:hover { background-size: 200% auto; transform: translateY(-1px); }
.btn:active,
button:active { transform: translateY(0); }

/* Outline button variant */
.btn.outline,
button.outline {
  background: rgba(124,58,237,0.06);
  background-image: none;
  border: 1px solid var(--border);
  color: var(--fg);
  box-shadow: none;
}
.btn.outline:hover,
button.outline:hover { background: rgba(124,58,237,0.12); }

/* Inputs */
input, select, textarea {
  background-color: var(--panel);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 10px;
  outline: none;
  transition: box-shadow .2s ease, border-color .2s ease, background-color .2s ease;
}
input, select { padding: 10px 12px; }
textarea { padding: 12px; }
input:focus, select:focus, textarea:focus {
  border-color: rgba(124,58,237,.45);
  box-shadow: var(--glow);
}

/* Forms */
label { font-weight: 600; display: block; margin: 6px 0 4px; }
fieldset {
  border: 1px solid var(--border);
  background: transparent;
  padding: 12px;
  margin-bottom: 16px;
  border-radius: 8px;
}
legend { padding: 0 6px; color: var(--muted); }

/* Layout helpers */
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.muted { color: var(--muted); font-size: 12px; }
.success { color: #6ee7b7; }
.error { color: #f87171; }

/* Tables and links */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px; border-bottom: 1px solid var(--border); }
thead th { color: var(--muted); font-weight: 600; }
tbody tr:hover { background: rgba(106,0,255,0.04); }
a { color: #7c3aed; text-decoration: none; }
a:hover { text-decoration: underline; }

/* Utility */
.neon { color: var(--strong); text-shadow: 0 0 14px rgba(124,58,237,.24); }

/* Modern file upload */
#media { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.file-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.file-trigger { display: inline-flex; align-items: center; gap: 8px; padding: 12px 18px; }
.file-trigger svg { width: 16px; height: 16px; fill: currentColor; }

/* Prompt view specific */
#run-form textarea,
#run-form button {
  box-sizing: border-box;
  resize: vertical;
  width: 100%;
  margin-top: 10px;
  font-size: 16px;
}

.user { float: right; font-size: 14px; color: #667085; }

.chat-wrapper { padding-bottom: 160px; }
.chat-response {
  margin: 14px 0 28px;
  padding: 22px 24px;
  background-color: rgba(255,255,255,0.85);
  border: 1px solid var(--border);
  box-shadow: var(--glow);
  transition: border-color .2s ease, box-shadow .2s ease;
  color: var(--fg);
  white-space: pre-wrap; /* preserve user newlines */
  overflow-wrap: anywhere; /* break long words/URLs */
  word-break: break-word;
  line-height: 1.7;
  border-radius: 14px;
  backdrop-filter: blur(8px);
}
.chat-response:hover { box-shadow: 0 0 0 1px rgba(124,58,237,.2), 0 0 36px rgba(106,0,255,.18); }
.chat-response strong { color: var(--strong); font-style: normal; }
.chat-response em { color: var(--muted); font-style: normal; }
.chat-response pre { background: #f4f5fb; border: 1px solid #e6e0ff; padding: 12px; border-radius: 10px; overflow: auto; white-space: pre-wrap; }
.chat-response code { color: #6a00ff; }
.chat-response table { border: 1px solid #e6e0ff; border-radius: 8px; overflow: hidden; }
.chat-response thead th { background: #f4f5fb; }
/* Ensure nested elements wrap appropriately */
.chat-response * { overflow-wrap: anywhere; word-break: break-word; }
.chat-response img { max-width: 100%; height: auto; }
/* Render fenced HTML blocks with normal whitespace behavior */
.chat-response .languge-html { white-space: normal; }

#run-form-wrapper {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: rgba(255,255,255,0.85);
  padding: 16px;
  border-top: 1px solid var(--border);
  z-index: 10;
  backdrop-filter: blur(8px);
}
#run-form { max-width: 980px; margin: auto; }

#loading-bar {
  margin: 6px auto 0;
  height: 4px; width: 100%;
  background: var(--accent-grad) no-repeat;
  animation: loading 5s ease-out infinite;
  border-radius: 999px;
  box-shadow: var(--glow);
  z-index: 9999;
}
@keyframes loading { 0% { background-size: 0% 50%; } 100% { background-size: 100% 50%; } }

/* Responsive */
@media (max-width: 768px) {
  body { font-size: 15px; }
  .container { margin: 16px auto 24px; padding: 0 10px; }
  .brand { font-size: 2rem; }
  .badge-beta { font-size: 0.8rem; }
  #run-form textarea, #run-form button { font-size: 14px; }
  #run-form-wrapper { padding: 10px; }
  .chat-response { padding: 16px; font-size: 14px; line-height: 1.55; }
  h2, h3 { font-size: 1.2rem; }
  .row { grid-template-columns: 1fr; }
}

/* Intro mode: center form, hide response */
body.intro-mode .chat-wrapper { display: none; }
body.intro-mode #run-form-wrapper {
  position: static;
  background: transparent;
  border-top: none;
  box-shadow: none;
  padding-top: 6vh;
  backdrop-filter: none;
}
body.intro-mode #run-form {
  max-width: 680px;
  margin: 10vh auto 8vh;
}

#media-field-group { display: flex; align-items: center; gap: 12px; flex-wrap: nowrap; }
#media-field-group > label { display: inline-flex; margin: 0; white-space: nowrap; }

/* Drawer for prompt list (page-scoped) */
#menu-toggle { position: absolute; left: 0; top: 0; transform: translateY(-2px); font-size: 24px; line-height: 1; }
/* When drawer is hidden, show a floating toggle pinned to left */
body:not(.drawer-open) #menu-toggle { position: fixed; left: 12px; top: 12px; z-index: 30; transform: none; }
/* Hide toggle when drawer is open */
body.drawer-open #menu-toggle { display: none; }
.drawer { position: fixed; inset: 0 auto 0 0; width: 260px; background: rgba(255,255,255,0.92); border-right: 1px solid var(--border); box-shadow: 0 0 0 1px rgba(124,58,237,.08), 0 0 36px rgba(106,0,255,.12); padding: 14px; z-index: 20; backdrop-filter: blur(8px); transform: translateX(-100%); transition: transform .25s ease; }
.drawer.open { transform: translateX(0); }
.drawer h4 { margin: 6px 0 10px; color: var(--muted); font-weight: 600; }
.prompt-list { list-style: none; margin: 0; padding: 0; }
.prompt-item { margin-bottom: 6px; }
.prompt-btn { width: 100%; text-align: left; padding: 10px 12px; border: 1px solid var(--border); background: transparent; color: var(--fg); border-radius: 10px; cursor: pointer; }
.prompt-btn.active { border-color: rgba(168,85,247,.55); box-shadow: var(--glow); background: rgba(124,58,237,0.10); color: var(--strong); font-weight: 700; }
/* Drawer close button: borderless */
#drawer-close { border: none !important; box-shadow: none; background: transparent; font-size: 24px; }
@media (max-width: 768px) { .drawer { width: 80%; } }
/* Shift a dedicated wrapper instead of body */
#page { transition: margin .25s ease; }
#run-form-wrapper { transition: left .25s ease; }
@media (min-width: 1024px) {
  body.drawer-open #page { margin-left: 260px; }
  body.drawer-open #run-form-wrapper { left: 260px; right: 0; }
}
