:root {
  --bg: #08111f;
  --bg2: #0d1727;
  --panel: #111c2e;
  --panel2: #162338;
  --ink: #edf4ff;
  --muted: #9fb0c8;
  --line: #263854;
  --accent: #5eead4;
  --accent2: #8b5cf6;
  --gold: #f5c451;
  --red: #fb7185;
  --green: #34d399;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.32);
  --card-bg: rgba(17, 28, 46, 0.86);
  --soft-bg: rgba(255, 255, 255, 0.04);
}

:root[data-theme="light"] {
  --bg: #eef4fb;
  --bg2: #ffffff;
  --panel: #ffffff;
  --panel2: #f4f7fb;
  --ink: #101828;
  --muted: #516070;
  --line: #d8e1ed;
  --accent: #0f766e;
  --accent2: #6d28d9;
  --gold: #b7791f;
  --red: #be123c;
  --green: #047857;
  --shadow: 0 24px 70px rgba(21, 35, 55, 0.13);
  --card-bg: rgba(255, 255, 255, 0.9);
  --soft-bg: rgba(16, 24, 40, 0.04);
}

* {
  box-sizing: border-box;
  min-width: 0;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 8%, rgba(94, 234, 212, 0.18), transparent 30%),
    radial-gradient(circle at 80% 0%, rgba(139, 92, 246, 0.18), transparent 26%),
    var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: var(--accent);
  font-weight: 800;
  text-decoration: none;
}

.is-hidden {
  display: none !important;
}

.landing {
  min-height: 100vh;
  padding: 24px 6vw 56px;
}

.nav-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.auth-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(560px, 100%);
  padding: 28px;
  background: rgba(17, 28, 46, 0.9);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.auth-card h1 {
  margin-top: 22px;
  font-size: clamp(30px, 5vw, 48px);
}

.login-form,
#registerForm {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.landing-nav,
.workspace-top,
.top-actions,
.hero-actions,
.brand {
  display: flex;
  align-items: center;
}

.landing-nav,
.workspace-top {
  justify-content: space-between;
  gap: 18px;
}

.brand {
  gap: 12px;
}

.brand img {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: transparent;
  display: block;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: var(--muted);
  font-size: 13px;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.48fr);
  gap: 40px;
  align-items: center;
  min-height: calc(100vh - 120px);
}

.hero-copy {
  max-width: 850px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 18px;
  font-size: clamp(38px, 6vw, 78px);
  line-height: 0.98;
}

h2 {
  margin-bottom: 10px;
  font-size: 22px;
}

h3 {
  margin-bottom: 8px;
  font-size: 17px;
}

p {
  color: var(--muted);
  line-height: 1.6;
}

.hero-copy > p:not(.eyebrow) {
  max-width: 720px;
  font-size: 18px;
}

.hero-actions {
  gap: 12px;
  margin-top: 26px;
}

.trust-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 22px;
}

.trust-row span {
  padding: 9px 12px;
  color: var(--ink);
  background: var(--soft-bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
}

.primary,
.ghost,
.action,
.step-button {
  min-height: 42px;
  padding: 0 15px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-weight: 900;
}

.mini {
  min-width: 64px;
}

.primary,
.action.primary-action {
  color: #05201d;
  background: var(--accent);
  border-color: var(--accent);
}

.ghost,
.action,
.step-button {
  color: var(--ink);
  background: var(--soft-bg);
}

.hero-panel,
.workflow-preview article,
.step-card,
.rail,
.project-box,
.admin-panel,
.metric,
.output-card {
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.hero-panel {
  padding: 26px;
}

.hero-panel span,
.workflow-preview span,
.project-box span,
.metric span {
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.hero-panel strong {
  display: block;
  margin-top: 12px;
  font-size: 28px;
  line-height: 1.15;
}

.workflow-preview {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.workflow-preview article {
  padding: 20px;
}

.standard-section,
.integrity-band,
.pricing-section,
.landing-footer {
  margin-top: 18px;
}

.standard-section {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 18px;
  align-items: start;
  padding: 28px;
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.standard-section h2 {
  font-size: clamp(28px, 4vw, 48px);
  line-height: 1.05;
}

.standard-grid,
.pricing-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.standard-grid article,
.pricing-grid article {
  padding: 16px;
  background: var(--soft-bg);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.standard-grid strong,
.standard-grid span,
.pricing-grid span,
.pricing-grid strong {
  display: block;
}

.standard-grid span {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.45;
}

.integrity-band {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 18px;
  align-items: center;
  padding: 24px;
  background: linear-gradient(135deg, rgba(94, 234, 212, 0.14), rgba(139, 92, 246, 0.16));
  border: 1px solid var(--line);
  border-radius: 18px;
}

.integrity-band h2 {
  font-size: clamp(24px, 3vw, 38px);
}

.pricing-section {
  padding: 24px;
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: 18px;
}

.pricing-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.pricing-grid span {
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.pricing-grid strong {
  margin-top: 8px;
  font-size: 28px;
}

.landing-footer {
  padding: 28px 0 6px;
  color: var(--muted);
  text-align: center;
  line-height: 1.6;
}

.app {
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
  min-height: 100vh;
}

.rail {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: 22px;
  padding: 22px;
  border-radius: 0;
}

.rail-brand {
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.phase-nav {
  display: grid;
  align-content: start;
  gap: 8px;
  overflow: auto;
}

.phase-button {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 2px 10px;
  width: 100%;
  padding: 11px;
  color: var(--muted);
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
}

.phase-button span {
  grid-row: span 2;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  color: var(--accent);
  background: rgba(94, 234, 212, 0.08);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 900;
}

.phase-button strong {
  color: var(--ink);
  font-size: 14px;
}

.phase-button small {
  line-height: 1.3;
}

.phase-button.active {
  background: linear-gradient(135deg, rgba(94, 234, 212, 0.18), rgba(139, 92, 246, 0.18));
  border-color: rgba(94, 234, 212, 0.38);
}

.project-box {
  padding: 16px;
}

.project-box strong,
.project-box small {
  display: block;
  margin-top: 7px;
}

.project-box small {
  color: var(--muted);
  line-height: 1.4;
}

.admin-panel {
  display: grid;
  gap: 10px;
  padding: 16px;
}

.admin-panel > span,
.user-list small {
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.admin-panel strong,
.user-list strong,
.user-list small {
  display: block;
}

.user-list {
  display: grid;
  gap: 8px;
  max-height: 160px;
  overflow: auto;
}

.user-list div {
  padding: 9px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.form-message {
  min-height: 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  padding: 0 12px;
  color: var(--accent);
  background: rgba(94, 234, 212, 0.08);
  border: 1px solid rgba(94, 234, 212, 0.24);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
}

.workspace {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 18px;
  padding: 24px;
}

.workspace-top h1 {
  margin-bottom: 0;
  font-size: clamp(28px, 4vw, 46px);
}

.top-actions {
  flex-wrap: wrap;
  gap: 10px;
}

select,
input,
textarea {
  width: 100%;
  color: var(--ink);
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
}

select,
input {
  height: 42px;
  padding: 0 12px;
}

textarea {
  min-height: 118px;
  padding: 14px;
  resize: vertical;
  line-height: 1.55;
}

select:focus,
input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(94, 234, 212, 0.12);
}

.stepper {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 7px;
}

.step-button {
  min-height: 44px;
  padding: 0;
  color: var(--muted);
  font-size: 12px;
}

.step-button.active {
  color: #05201d;
  background: var(--accent);
  border-color: var(--accent);
}

.step-button.locked,
.phase-button.locked {
  opacity: 0.55;
  cursor: not-allowed;
  filter: grayscale(0.4);
}

.approval-block {
  display: grid;
  gap: 10px;
  padding: 14px 16px;
  border: 1px dashed var(--accent);
  border-radius: 12px;
  background: rgba(80, 200, 180, 0.06);
}

.approval-toggle {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 13px;
  line-height: 1.5;
}

.approval-toggle input {
  margin-top: 4px;
}

.ref-source {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(80, 200, 180, 0.16);
  color: var(--accent);
}

.ref-source-pubmed {
  background: rgba(80, 130, 240, 0.18);
  color: #5a82f0;
}

.ref-source-crossref {
  background: rgba(255, 170, 90, 0.18);
  color: #ffaa5a;
}

.step-card {
  display: grid;
  gap: 18px;
  min-height: 0;
  padding: 20px;
  overflow: auto;
}

.card-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.08fr);
  gap: 18px;
}

.panel {
  display: grid;
  align-content: start;
  gap: 12px;
}

.panel h2 {
  font-size: 26px;
}

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

label span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

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

.progress-note,
.error-banner {
  border-radius: 14px;
  margin-top: 16px;
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.5;
}

.progress-note {
  border: 1px solid rgba(64, 211, 176, 0.34);
  background: rgba(64, 211, 176, 0.11);
  color: #c8fff1;
}

.error-banner {
  border: 1px solid rgba(255, 116, 116, 0.36);
  background: rgba(255, 116, 116, 0.1);
  color: #ffd0d0;
}

.output {
  display: grid;
  gap: 12px;
  align-content: start;
}

.output-card {
  padding: 15px;
  box-shadow: none;
}

.output-card p {
  margin-bottom: 0;
}

.title-card {
  border-left: 4px solid var(--accent);
}

.warning-card {
  border-left: 4px solid var(--gold);
}

.danger-card {
  border-left: 4px solid var(--red);
}

.success-card {
  border-left: 4px solid var(--green);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.metric {
  padding: 14px;
  box-shadow: none;
}

.metric strong {
  display: block;
  margin-top: 4px;
  font-size: 22px;
}

.editor {
  min-height: 520px;
  font-family: ui-serif, Georgia, "Times New Roman", serif;
  font-size: 16px;
}

.reference-table,
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.reference-table th,
.reference-table td,
.data-table th,
.data-table td {
  padding: 10px;
  vertical-align: top;
  border: 1px solid var(--line);
}

.reference-table th,
.data-table th {
  text-align: left;
  color: var(--ink);
  background: rgba(94, 234, 212, 0.1);
}

.download-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.download-tile {
  display: grid;
  gap: 8px;
  min-height: 140px;
  padding: 16px;
  color: var(--ink);
  text-align: left;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.download-tile span {
  width: max-content;
  padding: 5px 9px;
  color: #05201d;
  background: var(--accent);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 900;
}

pre {
  margin: 0;
  padding: 14px;
  overflow: auto;
  color: #dce3eb;
  background: #07111f;
  border-radius: 10px;
}

@media (max-width: 1120px) {
  .hero,
  .app,
  .card-grid,
  .standard-section,
  .integrity-band {
    grid-template-columns: 1fr;
  }

  .rail {
    border-radius: 0 0 14px 14px;
  }

  .phase-nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .stepper {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .landing,
  .workspace,
  .rail {
    padding: 14px;
  }

  .landing-nav,
  .workspace-top {
    align-items: stretch;
    flex-direction: column;
  }

  .workflow-preview,
  .standard-grid,
  .pricing-grid,
  .phase-nav,
  .metrics,
  .download-list {
    grid-template-columns: 1fr;
  }

  .stepper {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  h1 {
    font-size: 34px;
  }
}

/* ========== Epistechma AI Chat (floating launcher + side drawer) ========== */

.chat-launcher {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 1100;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #05201d;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.2px;
  cursor: pointer;
  box-shadow: 0 12px 32px rgba(80, 200, 180, 0.28);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.chat-launcher:hover {
  transform: translateY(-1px);
  box-shadow: 0 16px 40px rgba(80, 200, 180, 0.4);
}

.chat-launcher.is-hidden {
  display: none;
}

.chat-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(420px, 100vw);
  height: 100vh;
  background: var(--surface, #0c1929);
  border-left: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  z-index: 1200;
  box-shadow: -24px 0 48px rgba(0, 0, 0, 0.4);
  transform: translateX(100%);
  transition: transform 0.25s ease;
}

[data-theme="light"] .chat-drawer {
  background: #ffffff;
  border-left-color: rgba(0, 0, 0, 0.08);
}

.chat-drawer:not(.is-hidden) {
  transform: translateX(0);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  gap: 12px;
}

[data-theme="light"] .chat-header {
  border-bottom-color: rgba(0, 0, 0, 0.08);
}

.chat-header strong {
  display: block;
  font-size: 14px;
  letter-spacing: 0.4px;
}

.chat-header small {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-message {
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  max-width: 92%;
  word-wrap: break-word;
}

.chat-message.user {
  align-self: flex-end;
  background: var(--accent);
  color: #05201d;
  border-bottom-right-radius: 4px;
}

.chat-message.assistant {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-bottom-left-radius: 4px;
}

[data-theme="light"] .chat-message.assistant {
  background: rgba(0, 0, 0, 0.04);
  border-color: rgba(0, 0, 0, 0.08);
}

.chat-message.system-tip {
  align-self: stretch;
  background: rgba(80, 200, 180, 0.08);
  border: 1px dashed rgba(80, 200, 180, 0.3);
  font-size: 12px;
  color: var(--muted);
  font-style: italic;
}

.chat-message.error {
  align-self: stretch;
  background: rgba(255, 100, 100, 0.08);
  border: 1px solid rgba(255, 100, 100, 0.3);
  color: #ffbcbc;
}

.chat-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 16px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

[data-theme="light"] .chat-form {
  border-top-color: rgba(0, 0, 0, 0.08);
}

.chat-form textarea {
  width: 100%;
  resize: vertical;
  min-height: 56px;
  max-height: 220px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.45;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.2);
  color: inherit;
  font-family: inherit;
}

[data-theme="light"] .chat-form textarea {
  background: #f8fafc;
  border-color: rgba(0, 0, 0, 0.12);
}

.chat-form-actions {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.chat-form-actions .ghost.mini {
  padding: 6px 10px;
  font-size: 12px;
}

.chat-form-actions .primary {
  padding: 8px 18px;
  font-size: 13px;
}

@media (max-width: 480px) {
  .chat-launcher span {
    display: none;
  }
  .chat-launcher {
    padding: 14px;
  }
  .chat-drawer {
    width: 100vw;
  }
}

/* Chat message action buttons */
.chat-message-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

[data-theme="light"] .chat-message-actions {
  border-top-color: rgba(0, 0, 0, 0.08);
}

.chat-action-btn {
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 700;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.12s ease;
}

[data-theme="light"] .chat-action-btn {
  border-color: rgba(0, 0, 0, 0.12);
  background: rgba(0, 0, 0, 0.04);
}

.chat-action-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.chat-action-btn.primary {
  border-color: var(--accent);
  background: rgba(94, 234, 212, 0.16);
  color: var(--accent);
}

.chat-action-btn.warning {
  border-color: rgba(255, 170, 90, 0.5);
  background: rgba(255, 170, 90, 0.12);
  color: #ffaa5a;
}

.chat-message-content {
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* Toast */
.chat-toast {
  position: fixed;
  bottom: 80px;
  right: 20px;
  z-index: 1300;
  padding: 10px 16px;
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.chat-toast.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Figure thumbnail grid in proposal step */
.figure-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.figure-thumb {
  margin: 0;
  padding: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
}

[data-theme="light"] .figure-thumb {
  background: rgba(0, 0, 0, 0.02);
  border-color: rgba(0, 0, 0, 0.08);
}

.figure-thumb img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 8px;
  background: #ffffff;
}

.figure-thumb figcaption {
  margin-top: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-align: center;
}

/* Inline image render in chat messages (AI-generated or user-uploaded) */
.chat-figure {
  margin: 10px 0 4px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
}

[data-theme="light"] .chat-figure {
  background: rgba(0, 0, 0, 0.03);
  border-color: rgba(0, 0, 0, 0.08);
}

.chat-figure img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 6px;
  background: #ffffff;
}

.chat-figure figcaption {
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  font-style: italic;
}
