:root {
  --navy: #0f2438;
  --navy-soft: #1a3348;
  --blue: #2563eb;
  --blue-soft: #dbeafe;
  --pale: #f0f5fa;
  --line: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --bg: #f8fafc;
  --white: #fff;
  --green: #0d9488;
  --red: #dc2626;
  --serif: "Instrument Serif", Georgia, serif;
  --sans: "DM Sans", system-ui, sans-serif;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.04);
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-family: var(--sans);
  font-weight: 600;
  letter-spacing: -0.02em;
}

/* Header */
.app-header {
  background: var(--navy);
  color: white;
  padding: 16px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.brand h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 400;
  letter-spacing: -0.01em;
}

.brand p {
  margin: 2px 0 0;
  color: #94a3b8;
  font-size: 13px;
}

.badge {
  font-size: 12px;
  background: var(--navy-soft);
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.1);
}

main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

/* Cards & Panels */
.card, .panel {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.login-card { max-width: 480px; margin: 40px auto; }

.panel-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 10px;
}

/* Workspace Layout */
.workspace {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 20px;
  align-items: start;
}

.library-panel {
  position: sticky;
  top: 20px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  padding: 20px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.panel-head h2 {
  margin: 0;
  font-size: 18px;
}

.workspace-main {
  min-width: 0;
}

/* Inputs */
input, select, textarea {
  font-family: var(--sans);
  font-size: 15px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--text);
  background: var(--white);
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-soft);
}

textarea {
  width: 100%;
  min-height: 120px;
  resize: vertical;
  line-height: 1.65;
}

#prompt { min-height: 100px; }
.feedback { min-height: 90px; }

.search-box input {
  width: 100%;
  margin-bottom: 12px;
}

/* Buttons */
button {
  font-family: var(--sans);
  border: 0;
  border-radius: 9px;
  padding: 10px 16px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

button:active { transform: scale(0.98); }

.primary { background: var(--blue); color: white; }
.primary:hover { background: #1d4ed8; }

.secondary { background: var(--pale); color: var(--navy); border: 1px solid var(--line); }
.secondary:hover { background: #e2e8f0; }

.compact { padding: 7px 12px; font-size: 13px; }

.choice {
  background: var(--pale);
  color: var(--navy);
  border: 1px solid var(--line);
  text-align: left;
  padding: 12px 14px;
}

.choice:hover { border-color: var(--blue); background: var(--blue-soft); }

.row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 14px;
}

.choices {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 14px 0;
}

/* Library */
.library-list { margin-top: 8px; }

.library-item {
  padding: 12px 14px;
  border-radius: 10px;
  cursor: pointer;
  margin-bottom: 6px;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}

.library-item:hover { background: var(--pale); }
.library-item.active { background: var(--blue-soft); border-color: #93c5fd; }

.library-title {
  font-weight: 600;
  font-size: 14px;
  line-height: 1.4;
}

.library-summary {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.45;
}

.library-tags, .tag-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.tag, .tag-chip {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--pale);
  color: var(--muted);
  border: 1px solid var(--line);
}

.tag-chip {
  cursor: pointer;
  background: transparent;
}

.tag-chip.active, .tag-chip:hover {
  background: var(--blue-soft);
  color: var(--blue);
  border-color: #93c5fd;
}

.prefs-list .pill {
  display: inline-block;
  background: var(--pale);
  padding: 6px 10px;
  border-radius: 8px;
  margin: 4px 4px 0 0;
  font-size: 12px;
}

/* Response Workspace */
.result-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.versions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.version {
  background: var(--pale);
  color: var(--navy);
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--line);
}

.version.active {
  background: var(--blue);
  color: white;
  border-color: var(--blue);
}

.action-bar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.action-btn {
  background: var(--white);
  color: var(--navy);
  border: 1px solid var(--line);
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 600;
}

.action-btn:hover {
  background: var(--pale);
  border-color: #94a3b8;
}

/* Structured Response Hero */
.response-hero {
  display: grid;
  gap: 16px;
  margin-bottom: 20px;
}

.hero-block {
  padding: 18px 20px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--white);
}

.hero-executive-summary {
  background: linear-gradient(135deg, #f0f5fa 0%, #fff 100%);
  border-color: #cbd5e1;
}

.hero-recommendation {
  border-left: 4px solid var(--blue);
}

.hero-next-step {
  border-left: 4px solid var(--green);
  background: #f0fdfa;
}

.hero-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.hero-icon {
  font-size: 13px;
  opacity: 0.7;
}

.hero-content {
  font-size: 15px;
  line-height: 1.65;
  white-space: pre-wrap;
}

.hero-executive-summary .hero-content {
  font-family: var(--serif);
  font-size: 20px;
  line-height: 1.5;
  color: var(--navy);
}

.hero-list {
  margin: 0;
  padding-left: 20px;
}

.hero-list li {
  margin-bottom: 6px;
  line-height: 1.55;
}

/* Expandable Sections */
.expandable-sections {
  display: grid;
  gap: 8px;
}

.expand-section {
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: var(--white);
}

.expand-section summary {
  padding: 14px 18px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--pale);
  user-select: none;
}

.expand-section summary::-webkit-details-marker { display: none; }

.expand-section summary::after {
  content: "+";
  font-size: 18px;
  color: var(--muted);
  font-weight: 400;
}

.expand-section[open] summary::after { content: "−"; }

.expand-content {
  padding: 16px 18px;
  white-space: pre-wrap;
  line-height: 1.65;
  font-size: 14px;
  color: var(--text);
  border-top: 1px solid var(--line);
}

/* Sources & Notes */
.note {
  border-left: 4px solid var(--green);
  padding: 12px 16px;
  background: #f0fdfa;
  margin: 12px 0;
  font-size: 13px;
  border-radius: 0 8px 8px 0;
}

.sources h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 16px 0 8px;
}

.sources a {
  display: block;
  margin: 6px 0;
  color: var(--blue);
  font-size: 14px;
  text-decoration: none;
}

.sources a:hover { text-decoration: underline; }

.feedback-panel {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

/* Utilities */
.hidden { display: none !important; }
.small { font-size: 13px; color: var(--muted); }
.muted { color: var(--muted); }
.status-text { min-height: 20px; }

hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 20px 0;
}

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid #cbd5e1;
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
}

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

/* Responsive */
@media (max-width: 960px) {
  .workspace { grid-template-columns: 1fr; }
  .library-panel { position: static; max-height: none; }
  .choices { grid-template-columns: 1fr; }
  .result-toolbar { flex-direction: column; }
  .action-bar { width: 100%; }
}

@media (max-width: 600px) {
  main { padding: 16px; }
  .hero-executive-summary .hero-content { font-size: 18px; }
}
