/* GSB brand system: deep purple core, single coral accent, lavender surfaces.
   80/15/5 rule: purple family / lavender surface / coral. */

:root {
  --royal: #42206B;
  --indigo: #27123F;
  --violet: #6B2D8A;
  --grape: #5A2C8F;
  --lavender: #8979B5;
  --mauve: #A87E8F;
  --coral: #D98675;
  --coral-deep: #C06B59;
  --surface: #EFEAF5;
  --ink: #241A3B;
  --soft: #4A3F63;
  --white: #FFFFFF;
  --gradient: linear-gradient(125deg, #27123F 0%, #42206B 38%, #6B2D8A 72%, #D98675 100%);
  --display: 'Bricolage Grotesque', 'Hanken Grotesk', sans-serif;
  --body: 'Hanken Grotesk', -apple-system, sans-serif;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(39, 18, 63, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--surface);
}

h1, h2, h3, h4, .display {
  font-family: var(--display);
  letter-spacing: -0.01em;
  line-height: 1.15;
}

.eyebrow {
  font-family: var(--display);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--violet);
}

/* ---------- App layout ---------- */

.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ---------- Sidebar ---------- */

.sidebar {
  width: 292px;
  flex-shrink: 0;
  background: var(--indigo);
  color: var(--surface);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

/* Sunburst: fine radiating lines fanning from the corner, low contrast */
.sidebar::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-conic-gradient(
    from 180deg at 110% -10%,
    rgba(239, 234, 245, 0.06) 0deg 0.7deg,
    transparent 0.7deg 7deg
  );
  pointer-events: none;
}

.sidebar > * { position: relative; }

.sidebar-head {
  padding: 22px 20px 16px;
  border-bottom: 1px solid rgba(137, 121, 181, 0.25);
}

.brand {
  margin-bottom: 16px;
}

.brand-logo {
  display: block;
  width: 100%;
  max-width: 224px;
}

.brand-app {
  font-family: var(--display);
  font-weight: 700;
  font-size: 14.5px;
  color: var(--coral);
  margin-top: 10px;
  letter-spacing: 0.02em;
}

.topbar-logo {
  height: 38px;
  width: auto;
}

.topbar-divider {
  width: 1.5px;
  height: 36px;
  background: #D9D0E6;
  flex-shrink: 0;
}

.monogram {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: var(--royal);
  color: var(--white);
  font-family: var(--display);
  font-weight: 700;
  font-size: 21px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-name {
  font-family: var(--display);
  font-weight: 700;
  font-size: 17px;
  color: var(--white);
}

.brand-sub {
  font-size: 11.5px;
  color: var(--lavender);
  line-height: 1.35;
}

.new-chat {
  width: 100%;
  padding: 11px 14px;
  border: none;
  border-radius: 10px;
  background: var(--coral);
  color: #2B1208;
  font-family: var(--display);
  font-weight: 700;
  font-size: 14.5px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.new-chat:hover { background: #E29684; }

.conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 12px 8px;
}

.conv-label {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--lavender);
  padding: 0 8px 8px;
  font-weight: 700;
}

.conv-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 10px;
  margin-bottom: 3px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--surface);
  font-family: var(--body);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}

.conv-item:hover { background: rgba(66, 32, 107, 0.6); }
.conv-item.active { background: var(--royal); }

.conv-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-delete, .conv-act {
  border: none;
  background: none;
  color: var(--lavender);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 5px;
  border-radius: 6px;
  visibility: hidden;
}

.conv-act { font-size: 13px; }

.conv-item:hover .conv-delete, .conv-item:hover .conv-act { visibility: visible; }
.conv-delete:hover, .conv-act:hover { color: var(--coral); background: rgba(0,0,0,0.25); }

/* On the active (royal purple) row, brighten the icons so they read clearly */
.conv-item.active .conv-delete, .conv-item.active .conv-act { color: var(--surface); }

/* Touch screens have no hover: keep rename and delete reachable and tappable */
@media (hover: none) {
  .conv-delete, .conv-act { visibility: visible; padding: 6px 7px; }
  .conv-title { margin-right: 2px; }
}

.conv-empty {
  padding: 8px 10px;
  font-size: 13px;
  color: var(--lavender);
}

.sidebar-foot {
  padding: 14px 20px 18px;
  border-top: 1px solid rgba(137, 121, 181, 0.25);
  font-size: 11.5px;
  color: var(--lavender);
  line-height: 1.5;
}

.sidebar-foot a { color: var(--lavender); }

/* ---------- Main column ---------- */

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  background: var(--white);
  padding: 14px 28px 12px;
  border-bottom: 2px solid var(--lavender);
  display: flex;
  align-items: center;
  gap: 14px;
}

.menu-btn {
  display: none;
  border: none;
  background: none;
  font-size: 22px;
  color: var(--royal);
  cursor: pointer;
  padding: 4px 8px;
}

.topbar h1 {
  margin: 0;
  font-size: 21px;
  color: var(--grape);
  font-weight: 700;
}

.topbar .eyebrow { display: block; margin-bottom: 1px; }

.kb-pill {
  margin-left: auto;
  font-size: 12.5px;
  color: var(--soft);
  background: var(--surface);
  padding: 5px 12px;
  border-radius: 999px;
  white-space: nowrap;
}

.export-wrap { position: relative; }

.export-btn {
  border: 1.5px solid #D9D0E6;
  background: var(--white);
  color: var(--grape);
  font-family: var(--display);
  font-weight: 700;
  font-size: 13px;
  padding: 7px 13px;
  border-radius: 9px;
  cursor: pointer;
  white-space: nowrap;
}

.export-btn:hover { border-color: var(--lavender); }

.export-drop {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--white);
  border-radius: 10px;
  box-shadow: 0 8px 30px rgba(39, 18, 63, 0.18);
  padding: 6px;
  z-index: 40;
  min-width: 200px;
}

.export-drop.show { display: block; }

.export-drop button {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  font-family: var(--body);
  font-size: 14px;
  color: var(--ink);
  padding: 9px 11px;
  border-radius: 7px;
  cursor: pointer;
}

.export-drop button:hover { background: var(--surface); }

/* ---------- Chat ---------- */

.chat {
  flex: 1;
  overflow-y: auto;
  padding: 28px 28px 12px;
}

.chat-inner {
  max-width: 780px;
  margin: 0 auto;
}

/* Empty state */
.hero {
  background: var(--gradient);
  border-radius: 18px;
  color: var(--white);
  padding: 44px 40px;
  position: relative;
  overflow: hidden;
  margin-top: 4vh;
}

.hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-conic-gradient(
    from 200deg at 105% -8%,
    rgba(255, 255, 255, 0.07) 0deg 0.6deg,
    transparent 0.6deg 6deg
  );
  pointer-events: none;
}

.hero > * { position: relative; }

.hero .eyebrow { color: rgba(239, 234, 245, 0.85); }

.hero h2 {
  margin: 8px 0 10px;
  font-size: 34px;
  font-weight: 700;
  color: var(--white);
}

.hero p {
  margin: 0 0 22px;
  max-width: 52ch;
  color: rgba(239, 234, 245, 0.92);
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.chip {
  border: 1px solid rgba(239, 234, 245, 0.45);
  background: rgba(39, 18, 63, 0.35);
  color: var(--white);
  border-radius: 999px;
  padding: 8px 16px;
  font-family: var(--body);
  font-size: 13.5px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.chip:hover { background: rgba(39, 18, 63, 0.65); }

/* Messages */
.msg {
  margin-bottom: 18px;
  display: flex;
}

.msg.user { justify-content: flex-end; }

.bubble {
  max-width: 86%;
  padding: 13px 18px;
  border-radius: var(--radius);
}

.msg.user .bubble {
  background: var(--royal);
  color: var(--white);
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}

.msg.assistant .bubble {
  background: var(--white);
  color: var(--ink);
  box-shadow: var(--shadow);
  border-bottom-left-radius: 4px;
  max-width: 94%;
}

.bubble p { margin: 0 0 10px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 0 0 10px; padding-left: 22px; }
.bubble li { margin-bottom: 4px; }
.bubble h4 {
  margin: 14px 0 6px;
  font-size: 16px;
  color: var(--grape);
}
.bubble code {
  background: var(--surface);
  border-radius: 5px;
  padding: 1px 5px;
  font-size: 0.9em;
}
.bubble strong { color: var(--royal); }

.cite {
  display: inline-block;
  background: var(--coral);
  color: #2B1208;
  font-size: 10.5px;
  font-weight: 700;
  border-radius: 5px;
  padding: 0 5px;
  margin: 0 2px;
  cursor: help;
  vertical-align: super;
  line-height: 1.5;
}

.sources {
  margin-top: 12px;
  border-top: 1px solid var(--surface);
  padding-top: 10px;
}

.sources summary {
  cursor: pointer;
  font-family: var(--display);
  font-weight: 700;
  font-size: 12.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--violet);
}

.source-item {
  display: flex;
  gap: 10px;
  margin-top: 10px;
  font-size: 13.5px;
  color: var(--soft);
}

.source-num {
  flex-shrink: 0;
  background: var(--coral);
  color: #2B1208;
  font-weight: 700;
  font-size: 11px;
  border-radius: 5px;
  padding: 1px 6px;
  height: fit-content;
  margin-top: 2px;
}

.source-title { font-weight: 600; color: var(--ink); }

.source-quote {
  display: block;
  margin-top: 2px;
  font-style: italic;
  color: var(--soft);
}

.thinking-dots {
  display: inline-flex;
  gap: 5px;
  padding: 4px 0;
}

.thinking-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--lavender);
  animation: pulse 1.2s infinite ease-in-out;
}

.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes pulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.85); }
  40% { opacity: 1; transform: scale(1); }
}

.msg-error { color: #A33C28; font-size: 14px; }

/* ---------- Composer ---------- */

.composer {
  padding: 12px 28px 20px;
}

.composer-inner {
  max-width: 780px;
  margin: 0 auto;
  background: var(--white);
  border-radius: 16px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: flex-end;
  padding: 10px 10px 10px 18px;
  gap: 10px;
  border: 1.5px solid transparent;
  transition: border-color 0.15s ease;
}

.composer-inner:focus-within { border-color: var(--lavender); }

#input {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-family: var(--body);
  font-size: 16px; /* 16px minimum stops iOS Safari zooming the page on focus */
  line-height: 1.5;
  color: var(--ink);
  max-height: 160px;
  padding: 6px 0;
  background: transparent;
}

#send {
  border: none;
  border-radius: 11px;
  background: var(--coral);
  color: #2B1208;
  font-family: var(--display);
  font-weight: 700;
  font-size: 14.5px;
  padding: 11px 20px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s ease;
}

#send:hover:not(:disabled) { background: #E29684; }
#send:disabled { opacity: 0.45; cursor: default; }

.composer-note {
  max-width: 780px;
  margin: 8px auto 0;
  text-align: center;
  font-size: 11.5px;
  color: var(--lavender);
}

/* ---------- Admin ---------- */

.admin-bg {
  min-height: 100vh;
  background: var(--surface);
}

.admin-login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gradient);
  position: relative;
  overflow: hidden;
  padding: 20px;
}

.admin-login::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-conic-gradient(
    from 200deg at 108% -8%,
    rgba(255, 255, 255, 0.06) 0deg 0.6deg,
    transparent 0.6deg 6deg
  );
}

.login-card {
  position: relative;
  background: var(--white);
  border-radius: 18px;
  padding: 38px 36px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 14px 50px rgba(39, 18, 63, 0.4);
}

.login-card h1 {
  margin: 14px 0 4px;
  font-size: 26px;
  color: var(--grape);
}

.login-card .sub {
  color: var(--soft);
  font-size: 14.5px;
  margin: 0 0 22px;
}

label {
  display: block;
  font-family: var(--display);
  font-weight: 700;
  font-size: 13px;
  color: var(--soft);
  margin: 14px 0 5px;
}

input[type='email'], input[type='password'], input[type='text'], textarea.field {
  width: 100%;
  padding: 11px 13px;
  border: 1.5px solid #D9D0E6;
  border-radius: 10px;
  font-family: var(--body);
  font-size: 16px; /* 16px minimum stops iOS Safari zooming the page on focus */
  color: var(--ink);
  background: var(--white);
}

input:focus, textarea.field:focus {
  outline: none;
  border-color: var(--lavender);
}

.btn {
  border: none;
  border-radius: 10px;
  font-family: var(--display);
  font-weight: 700;
  font-size: 14.5px;
  padding: 11px 20px;
  cursor: pointer;
  transition: filter 0.15s ease;
}

.btn:hover:not(:disabled) { filter: brightness(1.07); }
.btn:disabled { opacity: 0.5; cursor: default; }

.btn-coral { background: var(--coral); color: #2B1208; }
.btn-purple { background: var(--royal); color: var(--white); }
.btn-ghost { background: transparent; color: var(--soft); border: 1.5px solid #D9D0E6; }
.btn-full { width: 100%; margin-top: 20px; }

.form-error {
  color: #A33C28;
  font-size: 13.5px;
  margin-top: 12px;
  min-height: 18px;
}

/* Admin dashboard */
.admin-top {
  background: var(--indigo);
  color: var(--white);
  padding: 18px 32px;
  display: flex;
  align-items: center;
  gap: 14px;
  position: relative;
  overflow: hidden;
}

.admin-top::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-conic-gradient(
    from 180deg at 108% -10%,
    rgba(239, 234, 245, 0.06) 0deg 0.7deg,
    transparent 0.7deg 7deg
  );
  pointer-events: none;
}

.admin-top > * { position: relative; }
.admin-top h1 { margin: 0; font-size: 19px; color: var(--white); }
.admin-top .spacer { flex: 1; }
.admin-top a { color: var(--lavender); font-size: 13.5px; margin-right: 16px; }

.admin-wrap {
  max-width: 920px;
  margin: 28px auto;
  padding: 0 24px 60px;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}

.stat-card .num {
  font-family: var(--display);
  font-weight: 700;
  font-size: 30px;
  color: var(--grape);
  line-height: 1.1;
}

.stat-card .lbl {
  font-size: 12.5px;
  color: var(--soft);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 600;
}

.panel {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 22px;
}

.panel h2 {
  margin: 0 0 4px;
  font-size: 18px;
  color: var(--grape);
}

.panel .hint { color: var(--soft); font-size: 13.5px; margin: 0 0 16px; }

.dropzone {
  border: 2px dashed var(--lavender);
  border-radius: 12px;
  background: var(--surface);
  padding: 34px 20px;
  text-align: center;
  color: var(--soft);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.dropzone.drag { border-color: var(--coral); background: #F7F0EC; }
.dropzone strong { color: var(--grape); }

label.check {
  display: flex;
  align-items: center;
  gap: 9px;
  font-family: var(--body);
  font-weight: 500;
  font-size: 13.5px;
  color: var(--soft);
  margin-top: 14px;
  cursor: pointer;
}

label.check input { accent-color: var(--royal); width: 16px; height: 16px; }

.upload-status { margin-top: 12px; font-size: 14px; color: var(--soft); }
.upload-status .ok { color: #2E6B3E; }
.upload-status .err { color: #A33C28; }

.table-scroll { overflow-x: auto; }

table.docs {
  width: 100%;
  min-width: 480px;
  border-collapse: collapse;
  font-size: 14.5px;
}

table.docs th {
  text-align: left;
  font-family: var(--display);
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--violet);
  padding: 8px 10px;
  border-bottom: 2px solid var(--surface);
}

table.docs td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--surface);
  color: var(--ink);
  vertical-align: top;
}

table.docs td.meta { color: var(--soft); font-size: 13px; white-space: nowrap; }

.del-btn {
  border: none;
  background: none;
  color: var(--mauve);
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 7px;
}

.del-btn:hover { color: #A33C28; background: #F7ECEC; }

.row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.row > div { flex: 1; min-width: 200px; }

/* ---------- Responsive ---------- */

@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    z-index: 30;
    height: 100%;
    left: -300px;
    transition: left 0.22s ease;
    box-shadow: 6px 0 30px rgba(39, 18, 63, 0.35);
  }
  .sidebar.open { left: 0; }
  .menu-btn { display: block; }
  .chat, .composer { padding-left: 16px; padding-right: 16px; }
  .topbar { padding: 12px 16px; }
  .topbar h1 { font-size: 17px; }
  .topbar-logo, .topbar-divider { display: none; }
  .kb-pill { display: none; }
  .hero { padding: 32px 24px; }
  .hero h2 { font-size: 26px; }
  .stat-row { grid-template-columns: 1fr; }
}

.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(39, 18, 63, 0.45);
  z-index: 20;
}

.overlay.show { display: block; }

@media (max-width: 640px) {
  .admin-top { padding: 14px 16px; gap: 10px; }
  .admin-top .admin-logo { display: none; }
  .admin-top h1 { font-size: 16px; }
  .admin-top a { margin-right: 8px; white-space: nowrap; }
  .admin-wrap { margin-top: 18px; padding: 0 14px 40px; }
  .panel { padding: 18px; }
}
