* {
  box-sizing: border-box;
}

:root {
  --layout-gutter: 1rem;
  --acim-blue-950: #031734;
  --acim-blue-900: #06254a;
  --acim-blue-850: #0a2f59;
  --acim-blue-800: #0f3a69;
  --acim-blue-700: #17497f;
  --acim-gold-500: #d5b248;
  --acim-gold-400: #e4c96f;
  --ink-light: #f2f6ff;
  --ink-soft: #cfdcf3;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink-light);
  background: radial-gradient(1200px 700px at 20% -10%, var(--acim-blue-700), var(--acim-blue-900) 45%, var(--acim-blue-950));
}

.app-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--acim-blue-700);
  background: linear-gradient(180deg, var(--acim-blue-800), var(--acim-blue-900));
  color: var(--acim-gold-400);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  flex: 1 1 auto;
}

.header-logo {
  flex-shrink: 0;
  height: 52px;
  width: auto;
  max-height: 52px;
  object-fit: contain;
  display: block;
}

.header-copy {
  min-width: 0;
}

.app-header h1 {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 700;
}

.app-header p {
  margin: 0.3rem 0 0;
  color: var(--ink-soft);
  font-size: 0.92rem;
}

.session-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.app-main {
  padding: var(--layout-gutter);
  display: grid;
  gap: var(--layout-gutter);
}

.app-shell {
  --left-panel-width: 300px;
  --left-panel-min: 240px;
  --left-panel-max: 640px;
  --splitter-width: 14px;
  display: grid;
  grid-template-columns: minmax(var(--left-panel-min), var(--left-panel-width)) var(--splitter-width) minmax(0, 1fr);
  column-gap: var(--layout-gutter);
  align-items: start;
}

.app-content {
  display: grid;
  gap: 1rem;
}

.panel-splitter {
  position: relative;
  width: var(--splitter-width);
  min-height: 100%;
  cursor: col-resize;
  touch-action: none;
  border-radius: 6px;
  background: rgba(10, 47, 89, 0.35);
}

.panel-splitter::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 0.4rem;
  bottom: 0.4rem;
  width: 2px;
  transform: translateX(-50%);
  border-radius: 999px;
  background: rgba(228, 201, 111, 0.32);
}

.panel-splitter:hover::before,
.panel-splitter:focus-visible::before,
.app-shell.is-resizing .panel-splitter::before {
  background: rgba(228, 201, 111, 0.75);
}

.panel-splitter:focus-visible {
  outline: 2px solid rgba(228, 201, 111, 0.85);
  outline-offset: 1px;
}

body.is-resizing,
body.is-resizing * {
  cursor: col-resize !important;
  user-select: none !important;
}

.card {
  border: 1px solid var(--acim-blue-700);
  background: linear-gradient(180deg, rgba(6, 37, 74, 0.95), rgba(3, 23, 52, 0.95));
  border-radius: 6px;
  padding: 1rem;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.input-help {
  margin: 0 0 0.6rem;
  color: var(--ink-soft);
  font-size: 0.92rem;
}

textarea {
  width: 100%;
  border: 1px solid var(--acim-blue-700);
  border-radius: 6px;
  padding: 0.55rem 0.65rem;
  font: inherit;
  color: var(--ink-light);
  background: rgba(3, 23, 52, 0.9);
  resize: vertical;
}

input[type="email"],
input[type="password"] {
  width: 100%;
  border: 1px solid var(--acim-blue-700);
  border-radius: 6px;
  padding: 0.55rem 0.65rem;
  font: inherit;
  color: var(--ink-light);
  background: rgba(3, 23, 52, 0.9);
  margin-bottom: 0.55rem;
}

button {
  border: 1px solid #a7832a;
  border-radius: 6px;
  background: linear-gradient(180deg, #d8ba5a, #b59033);
  color: #1b2230;
  font-weight: 600;
  padding: 0.5rem 0.8rem;
  font-size: 0.9rem;
  cursor: pointer;
}

button:hover {
  background: linear-gradient(180deg, #e1c66d, #c09a3d);
}

.secondary-btn {
  border-color: var(--acim-blue-700);
  background: rgba(6, 37, 74, 0.8);
  color: var(--ink-light);
}

.secondary-btn:hover {
  background: rgba(15, 58, 105, 0.9);
}

button:disabled {
  opacity: 0.7;
  cursor: progress;
}

#askBtn {
  min-width: 4.2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.ask-btn-spinner {
  display: none;
  width: 0.95rem;
  height: 0.95rem;
  border: 2px solid rgba(27, 34, 48, 0.35);
  border-top-color: #1b2230;
  border-radius: 50%;
  animation: ask-btn-spin 0.8s linear infinite;
}

#askBtn.loading .ask-btn-label {
  display: none;
}

#askBtn.loading .ask-btn-spinner {
  display: inline-block;
}

@keyframes ask-btn-spin {
  to {
    transform: rotate(360deg);
  }
}

.actions {
  margin-top: 0.7rem;
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

#statusMessage {
  font-size: 0.9rem;
  color: var(--ink-soft);
}

#authStatus {
  margin: 0.3rem 0 0;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.section-title {
  margin-top: 0;
  margin-bottom: 0.55rem;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--acim-gold-400);
}

.section-subtitle {
  margin: 0 0 0.6rem;
  color: var(--ink-soft);
  font-size: 0.92rem;
  font-style: italic;
  line-height: 1.45;
}

.history-card {
  height: fit-content;
}

.history-reset {
  margin: 0 0 0.7rem;
  color: var(--ink-soft);
  font-size: 0.82rem;
}

.history-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.45rem;
}

.history-empty {
  color: var(--ink-soft);
  font-style: italic;
  padding: 0.2rem 0;
}

.history-item {
  width: 100%;
  text-align: left;
  border: 1px solid rgba(228, 201, 111, 0.2);
  border-radius: 8px;
  background: rgba(4, 28, 59, 0.45);
  color: var(--ink-light);
  padding: 0.55rem 0.65rem;
  display: grid;
  gap: 0.2rem;
}

.history-item:hover {
  background: rgba(15, 58, 105, 0.55);
}

.history-item.selected {
  border-color: var(--acim-gold-400);
  background: rgba(15, 58, 105, 0.75);
}

.history-item-input {
  display: block;
  font-size: 0.9rem;
  line-height: 1.3;
}

.history-item-meta {
  display: block;
  color: var(--ink-soft);
  font-size: 0.75rem;
}

#answerOutput {
  white-space: normal;
  line-height: 1.5;
}

#answerOutput p {
  margin: 0 0 0.8rem;
}

#answerOutput p:last-child {
  margin-bottom: 0;
}

#answerOutput h1,
#answerOutput h2,
#answerOutput h3 {
  margin: 0.95rem 0 0.55rem;
  color: var(--acim-gold-400);
  line-height: 1.25;
}

#answerOutput h1:first-child,
#answerOutput h2:first-child,
#answerOutput h3:first-child {
  margin-top: 0;
}

#answerOutput ul,
#answerOutput ol {
  margin: 0.45rem 0 0.85rem 1.2rem;
}

#answerOutput li {
  margin-bottom: 0.35rem;
}

#answerOutput blockquote {
  margin: 0.6rem 0 0.9rem;
  padding: 0.45rem 0.8rem;
  border-left: 3px solid rgba(228, 201, 111, 0.65);
  background: rgba(4, 28, 59, 0.45);
}

.answer-ref-link {
  color: var(--acim-gold-400);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.answer-ref-link:hover {
  color: #f0d98f;
}

.output-empty,
.quotes-empty li {
  color: var(--ink-soft);
  font-style: italic;
}

#answerOutput.output-empty {
  min-height: 3.5rem;
}

#retrievedQuotesList {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.9rem;
}

#retrievedQuotesList li {
  scroll-margin-top: 96px;
  border: 1px solid rgba(228, 201, 111, 0.25);
  border-radius: 8px;
  background: rgba(4, 28, 59, 0.55);
  padding: 0.75rem 0.8rem;
}

.quote-item-ref {
  color: var(--acim-gold-400);
  font-weight: 600;
  margin-bottom: 0.2rem;
}

.quote-item-text {
  white-space: pre-wrap;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 960px) {
  .app-main {
    padding: calc(var(--layout-gutter) * 0.8);
    gap: calc(var(--layout-gutter) * 0.8);
  }

  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-logo {
    height: 44px;
    max-height: 44px;
  }

  .app-shell {
    grid-template-columns: 1fr;
    row-gap: calc(var(--layout-gutter) * 0.8);
    column-gap: 0;
  }

  .panel-splitter {
    display: none;
  }
}
