:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --text: #16181d;
  --muted: #687083;
  --border: #e3e7ee;
  --primary: #1f2937;
  --primary-hover: #111827;
  --danger: #b42318;
  --danger-bg: #fff1f0;
  --shadow: 0 20px 55px rgba(15, 23, 42, 0.08);
  --radius: 24px;
  --radius-sm: 14px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(226, 232, 240, 0.9), transparent 32rem),
    var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

.page-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 36px 0 22px;
}

.app-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 28px;
  margin-bottom: 24px;
}

.app-header h1,
.panel-heading h2 {
  margin: 0;
  letter-spacing: -0.04em;
}

.app-header h1 {
  font-size: clamp(2rem, 5vw, 4rem);
  line-height: 0.95;
}

.header-copy {
  max-width: 430px;
  margin: 0 0 8px;
  color: var(--muted);
  line-height: 1.6;
}

.header-side {
  display: grid;
  justify-items: end;
  gap: 12px;
}

.user-session {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.current-user {
  max-width: 220px;
  overflow: hidden;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.chat-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 22px;
}

.card {
  min-height: 590px;
  padding: 24px;
  border: 1px solid rgba(226, 232, 240, 0.88);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  transition:
    transform 180ms ease,
    box-shadow 180ms ease,
    border-color 180ms ease;
}

.card:hover {
  transform: translateY(-2px);
  border-color: #d5dbe7;
  box-shadow: 0 24px 65px rgba(15, 23, 42, 0.11);
}

.login-panel {
  min-height: auto;
  margin-bottom: 22px;
}

.login-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
}

.field-group {
  display: grid;
  gap: 8px;
}

.field-group label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.form-message {
  grid-column: 1 / -1;
  min-height: 22px;
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.form-message.is-error {
  color: var(--danger);
}

.login-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
}

.login-actions .send-button {
  min-width: 180px;
}

.panel-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.panel-heading h2 {
  font-size: 1.55rem;
}

.shortcut,
.status-badge {
  flex: 0 0 auto;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
}

.shortcut {
  max-width: 190px;
  color: var(--muted);
  text-align: left;
}

.status-badge {
  padding: 8px 12px;
  background: var(--surface-muted);
  color: var(--muted);
  border: 1px solid var(--border);
}

.status-badge.is-loading {
  color: #854d0e;
  background: #fffbeb;
  border-color: #fde68a;
}

.status-badge.is-error {
  color: var(--danger);
  background: var(--danger-bg);
  border-color: #fecaca;
}

.report-panel {
  display: flex;
  min-height: calc(100% - 84px);
  flex-direction: column;
}

textarea {
  width: 100%;
  resize: vertical;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  background: var(--surface-muted);
  color: var(--text);
  font: inherit;
  line-height: 1.65;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    background 160ms ease;
}

input {
  width: 100%;
  min-height: 52px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  background: var(--surface-muted);
  color: var(--text);
  font: inherit;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    background 160ms ease;
}

textarea:focus {
  background: #fff;
  border-color: #94a3b8;
  box-shadow: 0 0 0 4px rgba(148, 163, 184, 0.2);
}

input:focus {
  background: #fff;
  border-color: #94a3b8;
  box-shadow: 0 0 0 4px rgba(148, 163, 184, 0.2);
}

.report-panel textarea {
  flex: 1;
  min-height: 486px;
}

.conversation-panel {
  display: flex;
  flex-direction: column;
}

.send-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 0 22px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: white;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  transition:
    transform 160ms ease,
    background 160ms ease,
    opacity 160ms ease;
}

.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--primary);
  cursor: pointer;
  font: inherit;
  font-size: 0.86rem;
  font-weight: 800;
  text-decoration: none;
}

.ghost-button:hover:not(:disabled) {
  border-color: #cbd5e1;
  background: var(--surface-muted);
}

.ghost-button:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

.send-button:hover:not(:disabled) {
  transform: translateY(-1px);
  background: var(--primary-hover);
}

.send-button:disabled {
  cursor: not-allowed;
  opacity: 0.74;
}

.button-loader {
  display: none;
  width: 18px;
  height: 18px;
  margin-left: 10px;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

.send-button.is-loading .button-loader {
  display: inline-block;
}

.conversation-area {
  flex: 1;
  min-height: 365px;
  max-height: 470px;
  overflow-y: auto;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
  scroll-behavior: smooth;
}

.question-form {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.question-form textarea {
  min-height: 104px;
  max-height: 190px;
}

.question-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.question-actions .send-button {
  min-width: 180px;
}

.message-list {
  display: grid;
  gap: 14px;
}

.message {
  display: grid;
  gap: 6px;
}

.message.is-user {
  justify-items: end;
}

.message-label {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.message-bubble {
  max-width: min(92%, 680px);
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: #fff;
  color: #252a34;
  line-height: 1.7;
  overflow-wrap: anywhere;
}

.message.is-user .message-bubble {
  border-color: #1f2937;
  background: #1f2937;
  color: #fff;
}

.message.is-error .message-bubble {
  border-color: #fecaca;
  background: var(--danger-bg);
  color: var(--danger);
}

.message.is-loading .message-bubble {
  color: var(--muted);
  background: #fff;
}

.response-content {
  color: #252a34;
  line-height: 1.75;
  overflow-wrap: anywhere;
}

.response-content p {
  margin: 0 0 14px;
}

.response-content ul,
.response-content ol {
  margin: 0 0 14px;
  padding-left: 24px;
}

.response-content li {
  margin-bottom: 6px;
}

.response-content pre {
  overflow-x: auto;
  margin: 0 0 14px;
  padding: 16px;
  border: 1px solid #dbe1ea;
  border-radius: 12px;
  background: #111827;
  color: #e5e7eb;
  line-height: 1.55;
}

.response-content code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
}

.response-content :not(pre) > code {
  padding: 2px 6px;
  border-radius: 6px;
  background: #e9edf4;
  color: #111827;
}

.empty-state,
.processing-state,
.error-state {
  display: grid;
  min-height: 100%;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.empty-state p,
.processing-state p,
.error-state p {
  max-width: 320px;
  margin: 0;
  line-height: 1.6;
}

.empty-icon {
  display: block;
  margin-bottom: 10px;
  color: #94a3b8;
  font-size: 2rem;
}

.error-state {
  color: var(--danger);
}

.app-footer {
  padding-top: 18px;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

.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;
}

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

@media (max-width: 900px) {
  .app-header,
  .chat-grid {
    grid-template-columns: 1fr;
  }

  .app-header {
    display: block;
  }

  .header-copy {
    margin-top: 14px;
  }

  .header-side {
    justify-items: start;
  }

  .login-form {
    grid-template-columns: 1fr;
  }

  .card {
    min-height: auto;
  }

  .conversation-area {
    height: 420px;
    max-height: none;
  }
}

@media (max-width: 640px) {
  .page-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 22px;
  }

  .card {
    padding: 18px;
    border-radius: 18px;
  }

  .panel-heading {
    display: block;
  }

  .shortcut,
  .status-badge {
    display: inline-block;
    margin-top: 10px;
    text-align: left;
  }

  .report-panel textarea {
    min-height: 300px;
  }

  .question-actions {
    display: grid;
  }

  .question-actions .send-button {
    width: 100%;
    min-width: 0;
  }
}
