:root {
  --primary: #0d6efd;
  --primary-dark: #0b5ed7;
  --page: #f6f7fb;          /* Solid page background fixes the "column" */
  --card-bg: #ffffff;
  --radius: 16px;
  --transition: 0.25s ease;
}

/* Reset & base */
* { box-sizing: border-box; }
html { height: 100%; }
body {
  min-height: 100svh;
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--page);
  display: grid;
  place-items: center;       /* centers the card */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ---------- Card ---------- */
.card {
  width: 100%;
  max-width: 420px;
  padding: 32px 28px 36px;
  background: var(--card-bg);       /* solid white, no frosted blur */
  border-radius: var(--radius);
  box-shadow: 0 12px 30px rgba(16, 24, 40, 0.08);
  text-align: center;
  animation: fade-in 0.45s ease both;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.logo {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--primary);
}

.subtitle {
  font-size: 0.95rem;
  color: #6b7280;
  margin-bottom: 24px;
}

/* ---------- Form ---------- */
.field { position: relative; margin-bottom: 14px; }

.field input {
  width: 100%;
  padding: 14px 44px 14px 14px;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  background: #f9fafb;
  font-size: 0.95rem;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

.field input:focus {
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(13, 110, 253, 0.12);
}

.toggle-password {
  position: absolute;
  top: 50%;
  right: 12px;
  transform: translateY(-50%);
  border: none;
  background: none;
  cursor: pointer;
  font-size: 1rem;
  color: #9ca3af;
  padding: 2px 6px;
  border-radius: 8px;
}

.toggle-password:hover { color: var(--primary); }

/* ---------- Button ---------- */
.btn {
  width: 100%;
  padding: 14px;
  margin-top: 6px;
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  background: var(--primary);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: background var(--transition), transform 0.05s ease;
}

.btn:hover,
.btn:focus-visible { background: var(--primary-dark); }
.btn:active { transform: translateY(1px); }

/* ---------- Messages ---------- */
#message {
  margin-top: 14px;
  font-size: 0.93rem;
  font-weight: 500;
  min-height: 1.2em;
}

.error { color: #d52731; }
.success { color: #269f53; }

/* ---------- Logout button ---------- */
/* Tiny logout icon (top-left) */
/* Tiny logout icon inside the chat card */
#chatCard .logout-icon {
  position: absolute;
  top: 8px;
  left: 10px;
  width: 26px;
  height: 26px;
  padding: 0;
  border: none;
  border-radius: 9999px;
  display: grid;
  place-items: center;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(16, 24, 40, 0.12);
  transition: background var(--transition), transform 0.05s ease;
  z-index: 2;
}
#chatCard .logout-icon i { font-size: 12px; line-height: 1; }
#chatCard .logout-icon:hover { background: var(--primary-dark); }
#chatCard .logout-icon:active { transform: translateY(1px); }



/* ---------- Answer panel ---------- */
.answer {
  position: relative;

  text-align: left;
  margin-top: 20px;
  padding: 18px 20px;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
min-height: 240px;     /* keep a nice minimum */
height: auto;          /* let the box grow with the content */
overflow: visible;     /* no inner scrollbar */

}


.answer-title {
  font-weight: 700;
  color: #111827;
  margin-bottom: 8px;
}

.answer-body {
  white-space: normal;        /* we now build real HTML, not raw text */
  line-height: 1.7;
  font-size: 1rem;
  min-height: 120px;
  overflow-wrap: anywhere;    /* long words/URLs won’t overflow */
}

/* Basic typography inside the answer */
.answer-body p { margin: 0 0 0.8rem; }
.answer-body h1,
.answer-body h2,
.answer-body h3 {
  margin: 1rem 0 0.5rem;
  line-height: 1.3;
}
.answer-body ul,
.answer-body ol {
  margin: 0.5rem 0 0.9rem;
  padding-left: 1.25rem;
}
.answer-body li { margin: 0.2rem 0; }

.answer-body a { text-decoration: underline; }

.answer-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.95em;
  padding: 2px 4px;
  background: #f3f4f6;
  border-radius: 6px;
}
.answer-body pre {
  margin: 0.8rem 0;
  padding: 12px 14px;
  background: #0b1220;
  color: #e5e7eb;
  border-radius: 10px;
  overflow: auto;
}

/* Markdown table styling */
.answer-body .md-table-wrapper { overflow-x: auto; }
.answer-body table { border-collapse: collapse; width: 100%; margin: 0.75rem 0; }
.answer-body th, .answer-body td {
  border: 1px solid #e5e7eb;
  padding: 8px 10px;
  vertical-align: top;
}
.answer-body th { background: #f3f4f6; font-weight: 700; }
.answer-body tr:nth-child(even) td { background: #fafafa; }


/* ---------- Select ---------- */
.field select {
  width: 100%;
  padding: 14px;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  background: #f9fafb;
  font-size: 0.95rem;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}
.field select:focus {
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(13,110,253,0.12);
}


/* --- Chat UI upgrades --- */
#chatCard.card {
  position: relative;
max-width: 2000px;
width: min(calc(100vw - 32px), 2000px); /* ~16px gutter on each side */

  text-align: left;
  /* tighter padding: top/right/bottom/left */
  padding: 16px 24px 24px 24px;
}


#chatCard .logo { 
  margin-bottom: 6px;     /* slightly tighter under the heading */
}


#chatCard .logo,
#chatCard .subtitle {
  text-align: center; /* keep header centered */
}

/* Multiline input */
.field textarea {
  width: 100%;
  padding: 14px 56px 56px 14px; /* extra bottom space for toggle + send button */
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  background: #f9fafb;
  font-size: 1rem;
  line-height: 1.5;
  outline: none;
  min-height: 350px;  
  resize: vertical;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
  overflow: hidden;

}


.field textarea:focus {
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(13,110,253,0.12);
}

/* Hint text under the textarea */
.hint {
  margin-top: 6px;
  font-size: 0.85rem;
  color: #6b7280;
}

/* Dropdown + Send in one row */
.controls {
  display: flex;
  gap: 12px;
  align-items: stretch;
  margin-top: 10px;
}
.controls .field {
  flex: 1;
  margin: 0; /* remove extra bottom-space from .field */
}
.controls .btn {
  flex: 1;
  height: 48px;
  align-self: stretch;
  font-size: 1rem;
}


/* put the model toggle at the bottom-left inside the textarea field */
.field .model-toggle {
  position: absolute;
  bottom: 10px;
  left: 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.model-toggle .toggle-label {
  font-size: 0.9rem;
  color: #374151;
  user-select: none;
}


.switch {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  inset: 0;
  background: #e5e7eb;
  border-radius: 999px;
  cursor: pointer;
  transition: background var(--transition);
}

.slider::before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
  transition: transform var(--transition);
}

.switch input:checked + .slider {
  background: var(--primary);
}
.switch input:checked + .slider::before {
  transform: translateX(18px);
}


/* --- Floating send button inside textarea --- */
.send-fab {
  position: absolute;
  bottom: 10px;
  right: 10px;
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(16, 24, 40, 0.12);
  transition: background var(--transition), transform 0.05s ease;
}

.send-fab:hover,
.send-fab:focus-visible { background: var(--primary-dark); }

.send-fab:active { transform: translateY(1px); }


/* ----- Loading overlay over the answer panel ----- */
.loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.75);
  backdrop-filter: blur(2px);
  border-radius: inherit;
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.loading-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.loading-overlay .loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: #111827;
}

.loading-overlay .spinner {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 4px solid #e5e7eb;
  border-top-color: var(--primary);
  animation: spin 1s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }


/* --- Add (+) button at the top-right of the textarea --- */
.add-fab {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 9999px;
  background: var(--primary);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(16, 24, 40, 0.12);
  transition: background var(--transition, .2s), transform 0.05s ease;
  z-index: 2;
}
.add-fab:hover, .add-fab:focus-visible { background: var(--primary-dark); }
.add-fab:active { transform: translateY(1px); }

/* --- Modal shell --- */
.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(17, 24, 39, 0.45);
  backdrop-filter: blur(2px);
  z-index: 50;
}
.modal[hidden] { display: none; }

.modal-dialog {
  /* fill most of the viewport with a small margin */
  width: min(96vw, 1800px);
  height: 94vh;            /* use most of the height */
  max-height: none;        /* remove previous cap */
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 30px 80px rgba(16, 24, 40, 0.35);
  display: flex;
  flex-direction: column;
}

.modal-header, .modal-footer { padding: 14px 18px; }
.modal-header {
  border-bottom: 1px solid #e5e7eb;
  display: flex; align-items: center; justify-content: space-between;
  background: linear-gradient(180deg, #ffffff, #f8fbff);
}
.modal-footer {
  border-top: 1px solid #e5e7eb;
  display: flex; justify-content: center;
  background: linear-gradient(0deg, #ffffff, #f8fafc);
}
.modal-body { padding: 16px 18px; overflow: auto; }

.modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: #6b7280; }
.modal-close:hover { color: #111827; }

/* Layout: categories left, sub-prompts right */
.lib-layout {
  display: grid;
  grid-template-columns: 320px 1fr;  /* wider sidebar in big modal */
  gap: 20px;
}
.lib-cats, .lib-items { min-height: 360px; }
.lib-toolbar { display: flex; gap: 8px; margin-bottom: 10px; }

/* Make toolbar buttons compact, not full width */
.lib-toolbar .btn { width: auto; padding: 10px 14px; }
.lib-toolbar .btn i { margin-right: 8px; }


.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.list li {
  border: 1px solid #e5e7eb;
  background: #fff;
  border-radius: 14px;
  padding: 12px;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  box-shadow: 0 2px 8px rgba(16,24,40,0.04);
  transition: border-color var(--transition), box-shadow var(--transition), transform .05s ease;
}
.list li:hover {
  border-color: #c7d2fe;
  box-shadow: 0 6px 18px rgba(16,24,40,0.08);
}
.list li .title { font-weight: 700; color: #0f172a; font-size: 1rem; }


/* Selected state */
.list li.selected { outline: 3px solid rgba(13,110,253,0.18); background: #fff; }

/* Small/secondary buttons */
.btn.small { padding: 10px 12px; font-size: 0.9rem; }
.btn.secondary { background: #eef2ff; color: #1d4ed8; }
.btn.secondary:hover { background: #e0e7ff; }

/* Inline editor */
.editor { border: 1px dashed #c7d2fe; background: #f8fafc; border-radius: 12px; padding: 10px; margin-top: 10px; }
.editor .actions { display: flex; gap: 8px; }

/* Use form (placeholder fillers) */
.use-form { border: 1px dashed #fde68a; background: #fffbeb; border-radius: 12px; padding: 10px; margin-top: 10px; display: grid; gap: 10px; }
.use-form .actions { display: flex; gap: 8px; }

/* Responsive */
@media (max-width: 720px) {
  .lib-layout { grid-template-columns: 1fr; }
}


/* --- Sub-prompt preview + tiny link button --- */
.list li { align-items: flex-start; }            /* let items grow vertically */
.list li .col { display: grid; gap: 6px; min-width: 0; }

/* --- Sub-prompt preview --- */
.sub-preview {
  white-space: pre-wrap;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  line-height: 1.25rem;
  color: #334155;
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 10px 12px;
}



.list li.expanded .sub-preview {
  -webkit-line-clamp: unset;
  line-clamp: unset;
  overflow: visible;
}

.btn.tiny.link {
  background: #eef2ff;
  border: 1px solid #e0e7ff;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 0.8rem;
  color: #1d4ed8;
  cursor: pointer;
}
.btn.tiny.link:hover { background: #e0e7ff; }



/* View-only button sits to the LEFT of the add (+) button */
.view-fab {
  position: absolute;
  top: 10px;
  right: 58px;      /* push it left of the add-fab (42px width + ~6-8px gap) */
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 9999px;
  background: #0ea5e9; /* sky-ish to distinguish; change if you like */
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(16, 24, 40, 0.12);
  transition: background var(--transition, .2s), transform 0.05s ease;
  z-index: 2;
}
.view-fab:hover, .view-fab:focus-visible { background: #0284c7; }
.view-fab:active { transform: translateY(1px); }


/* Disabled button look */
.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  filter: grayscale(10%);
}


/* --- small centered popup used for placeholder filling --- */
.mini-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(17, 24, 39, 0.45);
  backdrop-filter: blur(3px);
  z-index: 60;
}
.mini-modal[hidden] { display: none; }

.mini-dialog {
  width: min(560px, calc(100vw - 32px));
  max-height: 80vh;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 16px;
  box-shadow: 0 30px 80px rgba(16,24,40,0.35);
  display: flex;
  flex-direction: column;
  overflow: hidden; /* keeps rounded corners when content scrolls */
}

/* Header */
.mini-dialog .modal-header {
  position: sticky; top: 0; z-index: 1;
  padding: 14px 18px;
  border-bottom: 1px solid #e5e7eb;
  background: linear-gradient(180deg, #ffffff, #f8fbff);
  display: flex; align-items: center; justify-content: space-between;
}
.mini-dialog .modal-header h3 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: #0f172a;
}
.mini-dialog .modal-close {
  background: transparent;
  border: 0;
  cursor: pointer;
  font-size: 18px;
  color: #64748b;
  padding: 4px 6px;
  border-radius: 8px;
}
.mini-dialog .modal-close:hover { color: #0f172a; background: #f1f5f9; }

/* Body + form grid */
.mini-dialog .modal-body {
  padding: 16px 18px;
  overflow: auto;
}
.mini-dialog .use-form {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr;
  margin: 0; padding: 0; border: 0; background: transparent;
}
.mini-dialog .use-form .field { display: grid; gap: 6px; }

/* Labels & inputs */
.mini-dialog .use-form label {
  font-size: 0.85rem; font-weight: 600; color: #374151;
}
.mini-dialog .use-form input {
  height: 42px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid #e5e7eb;
  background: #f9fafb;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}
.mini-dialog .use-form input:focus {
  background: #fff;
  border-color: #c7d2fe;
  box-shadow: 0 0 0 4px rgba(99,102,241,0.15);
}
.mini-dialog .use-form input::placeholder { color: #9ca3af; }

/* Actions row + compact buttons */
.mini-dialog .use-form .actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding-top: 4px;
}
.mini-dialog .btn { width: auto; padding: 10px 14px; border-radius: 10px; font-weight: 700; }
.mini-dialog .btn.secondary { background: #eef2ff; color: #1d4ed8; }
.mini-dialog .btn.secondary:hover { background: #e0e7ff; }
.mini-dialog .btn.with-icon { display: inline-flex; align-items: center; gap: 8px; }
.mini-dialog .btn:disabled { opacity: .6; cursor: not-allowed; }

/* Two-column on wider screens */
@media (min-width: 560px) {
  .mini-dialog .use-form { grid-template-columns: 1fr 1fr; }
  .mini-dialog .use-form .actions { grid-column: 1 / -1; }
}

.mini-dialog .use-form .actions { display: flex; gap: 8px; margin-top: 10px; }

/* Disabled button look (if you haven't added earlier) */
.btn:disabled { opacity: .6; cursor: not-allowed; filter: grayscale(10%); }


/* Hide legacy inline use forms inside the big modals */
.modal .use-form { 
  display: none !important;
}

/* Ensure the small centered popup form stays visible and clean */
.mini-dialog .use-form {
  display: grid;
  gap: 10px;
  border: none;
  background: transparent;
  padding: 0;
  margin: 0;
}


/* --- Compact icon buttons for row actions --- */
.list li .row-actions {
  display: inline-flex;
  gap: 6px;
  align-self: flex-start;
}

.icon-btn {
  width: 28px;
  height: 28px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
  color: #374151;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), transform .05s ease;
}

/* Slightly increase spacing in wider layout */
@media (min-width: 1024px) {
  .list li .row-actions { gap: 8px; }
}

.icon-btn:hover { background: #eef2ff; border-color: #c7d2fe; }
.icon-btn:active { transform: translateY(1px); }
.icon-btn i { font-size: 14px; line-height: 1; }

.icon-btn.primary { background: #eef2ff; color: #1d4ed8; border-color: #c7d2fe; }
.icon-btn.danger  { color: #b91c1c; border-color: #fecaca; }
.icon-btn.danger:hover { background: #fee2e2; border-color: #fecaca; }



/* When the + button is hidden, pull the eye button to the edge */
body.no-add-btn .view-fab { right: 10px; }

/* (Optional) make sure the + stays hidden */
body.no-add-btn #openPromptLib { display: none !important; }
