:root {
  --paper: #f5f6f8;
  --surface: #ffffff;
  --surface-soft: #f1f3f5;
  --ink: #1f1f1f;
  --muted: #54565a;
  --line: #d7dbe0;
  --accent: #0052a5;
  --accent-dark: #003f7f;
  --action: #d7193f;
  --action-dark: #b81232;
  --rose: #d7193f;
  --gold: #0052a5;
  --shadow: 0 12px 30px rgba(0, 39, 84, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: "Open Sans", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  cursor: pointer;
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 24px;
  animation: fade-rise 520ms ease both;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 520px);
  gap: 18px;
  align-items: start;
  min-height: 96px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 18px;
  box-shadow: 0 2px 12px rgba(0, 39, 84, 0.08);
}

.title-stack {
  display: grid;
  gap: 7px;
}

.title-line {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.title-line::after {
  content: "";
  width: 4px;
  height: 46px;
  order: 1;
  background: var(--action);
}

.brand-pair {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.brand-logo {
  flex: 0 0 auto;
  width: 68px;
  height: 48px;
  object-fit: contain;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 6px;
}

.quantica-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 48px;
  flex: 0 0 auto;
}

.quantica-mark img {
  display: block;
  width: 36px;
  height: 48px;
  object-fit: contain;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-dark);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  order: 2;
  font-family: "Open Sans", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: clamp(1.85rem, 4.2vw, 3.35rem);
  line-height: 1;
  min-width: 0;
}

h2 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.45rem;
}

.workspace {
  position: relative;
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  justify-content: stretch;
  transition: grid-template-columns 220ms ease;
}

.workspace.history-collapsed {
  grid-template-columns: minmax(104px, 130px) minmax(0, 980px) minmax(104px, 130px);
  justify-content: center;
}

.workspace.history-collapsed .history-panel {
  display: none;
}

.history-reopen {
  display: none;
  position: sticky;
  top: 18px;
  grid-column: 1;
  justify-self: start;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--surface);
  color: var(--accent-dark);
  box-shadow: var(--shadow);
  padding: 0 14px;
  font-weight: 850;
  transition: transform 150ms ease, background 150ms ease, border-color 150ms ease;
}

.history-reopen:hover {
  transform: translateY(-1px);
  background: #eef6ff;
  border-color: var(--accent-dark);
}

.workspace.history-collapsed .history-reopen {
  display: inline-flex;
}

.workspace.history-collapsed .flow {
  grid-column: 2;
}

.header-controls {
  display: grid;
  grid-template-columns: minmax(190px, 1.3fr) minmax(150px, 0.7fr);
  gap: 12px;
  justify-self: end;
  width: 100%;
}

.type-select,
.model-select {
  display: grid;
  gap: 7px;
  width: 100%;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
  text-transform: uppercase;
}

.type-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.help-button {
  display: inline-grid;
  place-items: center;
  width: 24px;
  min-height: 24px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--surface);
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 900;
  line-height: 1;
  text-transform: none;
}

.type-select select,
.model-select select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background-color: var(--surface);
  color: var(--ink);
  padding: 0 38px 0 12px;
  font: inherit;
  font-size: 0.98rem;
  font-weight: 800;
  text-transform: none;
  outline: none;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--accent-dark) 50%),
    linear-gradient(135deg, var(--accent-dark) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) 19px,
    calc(100% - 12px) 19px;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

.type-select select:focus,
.model-select select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 82, 165, 0.16);
}

.history-panel,
.form-panel,
.document-stage {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.history-panel {
  position: sticky;
  top: 18px;
  min-height: 280px;
  padding: 14px;
}

.history-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.history-hide-button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: transparent;
  color: var(--accent-dark);
  padding: 0 10px;
  font-size: 0.78rem;
  font-weight: 850;
  transition: transform 150ms ease, background 150ms ease, border-color 150ms ease;
}

.history-hide-button:hover {
  transform: translateY(-1px);
  background: #eef6ff;
  border-color: var(--accent);
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
  text-transform: uppercase;
}

.history-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  max-height: calc(100vh - 190px);
  overflow-y: auto;
  padding-right: 4px;
  scrollbar-gutter: stable;
}

.new-generation-button {
  width: 100%;
  min-height: 40px;
  margin-top: 14px;
  border: 1px solid var(--action);
  border-radius: 6px;
  background: var(--action);
  color: white;
  font-weight: 850;
  transition: transform 150ms ease, background 150ms ease, border-color 150ms ease;
}

.new-generation-button:hover {
  transform: translateY(-1px);
  background: var(--action-dark);
  border-color: var(--action-dark);
}

.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  gap: 6px;
  align-items: stretch;
  width: 100%;
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  color: inherit;
  overflow: hidden;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.history-item:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
  background: #eef6ff;
}

.history-open-button {
  display: grid;
  gap: 3px;
  min-width: 0;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 9px 10px;
  text-align: left;
}

.history-item strong,
.history-item span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item strong {
  font-size: 0.88rem;
  line-height: 1.18;
  white-space: nowrap;
}

.history-item span {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.2;
  white-space: nowrap;
}

.history-delete-button {
  width: 34px;
  border: 0;
  border-left: 1px solid var(--line);
  background: transparent;
  color: var(--action);
  font-size: 1.3rem;
  font-weight: 800;
  transition: background 150ms ease, color 150ms ease;
}

.history-delete-button:hover {
  background: var(--action);
  color: white;
}

.flow {
  display: grid;
  gap: 14px;
  width: 100%;
  min-width: 0;
}

.primary-button,
.ghost-button,
.line-button,
.icon-button,
.danger-button {
  min-height: 40px;
  border-radius: 6px;
  border: 1px solid var(--line);
  transition: transform 150ms ease, background 150ms ease, border-color 150ms ease, opacity 150ms ease;
}

.primary-button {
  border-color: var(--action);
  background: var(--action);
  color: white;
}

.danger-button {
  border-color: var(--action);
  background: var(--action);
  color: white;
  padding: 0 16px;
  font-weight: 850;
}

.primary-button:hover {
  background: var(--action-dark);
  border-color: var(--action-dark);
}

.danger-button:hover:not(:disabled) {
  background: var(--action-dark);
  border-color: var(--action-dark);
}

.primary-button:hover,
.ghost-button:hover,
.line-button:hover,
.icon-button:hover,
.danger-button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.form-panel {
  overflow: hidden;
  padding: 18px;
  transition: max-height 420ms ease, opacity 260ms ease, transform 260ms ease;
}

.form-panel.folded {
  max-height: 64px;
}

.form-panel.folded .resolution-form {
  pointer-events: none;
  opacity: 0;
  transform: translateY(-8px);
}

.hidden {
  display: none !important;
}

.resolution-form {
  display: grid;
  gap: 16px;
  margin-top: 18px;
  transition: opacity 220ms ease, transform 220ms ease;
}

.form-title-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.form-section {
  display: grid;
  gap: 16px;
}

.form-section.hidden,
[hidden] {
  display: none;
}

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

label {
  display: grid;
  gap: 7px;
  min-width: 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 750;
}

input,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  outline: none;
}

input {
  min-height: 44px;
  padding: 10px 12px;
}

textarea {
  resize: vertical;
  padding: 12px;
  line-height: 1.45;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 82, 165, 0.16);
}

.legal-bases {
  display: grid;
  gap: 12px;
}

.extra-base {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  gap: 8px;
  align-items: end;
  animation: fade-rise 220ms ease both;
}

.line-button,
.ghost-button,
.icon-button {
  background: transparent;
  color: var(--accent-dark);
  font-weight: 800;
}

.line-button {
  width: fit-content;
  padding: 0 14px;
}

.ghost-button {
  padding: 0 14px;
}

.icon-button {
  width: 40px;
  padding: 0;
}

.remove-button {
  color: var(--rose);
}

.choice-field {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
}

.report-actions,
#extraReportActions {
  display: grid;
  gap: 14px;
}

.activity-fieldset {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
}

.activity-fieldset .line-button {
  justify-self: start;
}

legend {
  padding: 0 6px;
  color: var(--muted);
  font-weight: 800;
}

.choice-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 650;
}

.choice-row input[type="radio"],
.choice-row input[type="checkbox"] {
  width: 18px;
  min-height: 18px;
  accent-color: var(--accent);
}

.custom-date {
  flex-wrap: wrap;
}

.inline-input {
  flex: 1 1 220px;
}

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

.generation-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.form-error {
  min-height: 22px;
  margin: 0;
  color: var(--rose);
  font-weight: 800;
}

.primary-button {
  min-width: 164px;
  padding: 0 18px;
  font-weight: 850;
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.68;
}

.document-stage {
  min-height: 520px;
  padding: 18px;
}

.document-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.document-viewbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  padding: 8px;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-right: auto;
}

.document-actions {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.editor-command {
  min-width: 38px;
  padding: 0 10px;
}

.more-actions {
  position: relative;
}

.more-actions-button {
  min-width: 42px;
  padding: 0 10px;
  letter-spacing: 0;
}

.more-actions-menu {
  position: absolute;
  z-index: 8;
  top: calc(100% + 8px);
  right: 0;
  display: grid;
  min-width: 190px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 6px;
}

.menu-action {
  min-height: 36px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--accent-dark);
  padding: 0 10px;
  text-align: left;
  font-weight: 800;
}

.menu-action:hover:not(:disabled) {
  background: #eef6ff;
}

.menu-action:disabled {
  cursor: default;
  opacity: 0.48;
}

.copy-button {
  min-height: 36px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--surface);
  color: var(--accent-dark);
  padding: 0 14px;
  font-weight: 850;
  transition: transform 150ms ease, background 150ms ease, border-color 150ms ease, opacity 150ms ease;
}

.copy-button:hover:not(:disabled) {
  transform: translateY(-1px);
  background: #eef6ff;
  border-color: var(--accent-dark);
}

.copy-button:disabled {
  cursor: default;
  opacity: 0.48;
}

.document-page {
  min-height: 480px;
  padding: clamp(24px, 5vw, 58px);
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #ffffff;
  box-shadow: inset 0 0 0 4px #f2f6fb, 0 20px 45px rgba(0, 39, 84, 0.1);
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 360px;
  color: var(--muted);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.15rem;
  text-align: center;
}

pre {
  display: none;
  margin: 0;
  white-space: pre-wrap;
  color: #1e1b17;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.05rem;
  line-height: 1.72;
}

.markdown-output {
  display: none;
  color: #1e1b17;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.06rem;
  line-height: 1.72;
}

.markdown-block {
  margin: 0 0 1.15rem;
}

.markdown-block:last-child {
  margin-bottom: 0;
}

.markdown-heading {
  text-align: center;
  font-weight: 700;
  letter-spacing: 0;
}

.markdown-output strong {
  font-weight: 800;
}

.markdown-output em {
  font-style: italic;
}

.document-page.streaming .markdown-output,
.document-page.ready .markdown-output {
  display: block;
  animation: dissolve-in 260ms ease both;
}

.document-page.streaming .empty-state,
.document-page.ready .empty-state {
  display: none;
}

.document-page.editing {
  box-shadow: inset 0 0 0 4px #eef6ff, 0 20px 45px rgba(0, 39, 84, 0.12);
}

.document-page.editing .markdown-output {
  outline: none;
}

.document-page.editing .markdown-output:focus {
  box-shadow: 0 0 0 3px rgba(0, 82, 165, 0.14);
}

.feedback-panel {
  display: grid;
  gap: 12px;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  padding: 14px;
}

.feedback-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
}

.feedback-header h3 {
  margin: 2px 0 0;
  color: var(--ink);
  font-size: 1.03rem;
  line-height: 1.25;
}

.feedback-status {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
  text-align: right;
}

.rating-group {
  display: grid;
  grid-template-columns: repeat(6, minmax(42px, 1fr));
  gap: 8px;
}

.rating-choice {
  display: block;
  color: var(--accent-dark);
  font-size: 0.96rem;
  font-weight: 850;
}

.rating-choice input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.rating-choice span {
  display: grid;
  place-items: center;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease, opacity 150ms ease;
}

.rating-choice input:checked + span {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.rating-choice input:disabled + span,
.feedback-save:disabled {
  cursor: default;
  opacity: 0.48;
}

.feedback-save {
  justify-self: end;
}

.confirm-dialog {
  width: min(420px, calc(100vw - 32px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: transparent;
}

.confirm-dialog::backdrop {
  background: rgba(31, 31, 31, 0.38);
  backdrop-filter: blur(2px);
}

.confirm-card {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-top: 4px solid var(--action);
  border-radius: 8px;
  background: var(--surface);
  padding: 20px;
  box-shadow: var(--shadow);
}

.confirm-card h3 {
  margin: 0;
  color: var(--ink);
  font-size: 1.2rem;
  line-height: 1.25;
}

.confirm-card p {
  margin: 0;
  color: var(--muted);
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}

.stream-cursor::after {
  content: "";
  display: inline-block;
  width: 8px;
  height: 1.05em;
  margin-left: 3px;
  vertical-align: text-bottom;
  background: var(--gold);
  animation: blink 820ms steps(2, start) infinite;
}

@keyframes fade-rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes dissolve-in {
  from {
    opacity: 0;
    filter: blur(4px);
  }
  to {
    opacity: 1;
    filter: blur(0);
  }
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .workspace.history-collapsed {
    grid-template-columns: 1fr;
  }

  .workspace.history-collapsed .flow {
    grid-column: 1;
  }

  .history-reopen {
    position: static;
    justify-self: start;
    margin-bottom: 12px;
  }

  .history-panel {
    position: static;
    order: 2;
  }
}

@media (max-width: 680px) {
  .app-shell {
    padding: 14px;
  }

  .topbar {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  .header-controls {
    grid-template-columns: 1fr;
    justify-self: stretch;
  }

  .field-grid {
    grid-template-columns: 1fr;
  }

  .form-actions,
  .document-toolbar,
  .document-viewbar,
  .feedback-header {
    align-items: stretch;
    flex-direction: column;
  }

  .primary-button,
  .ghost-button,
  .copy-button {
    width: 100%;
  }

  .document-actions,
  .form-title-actions,
  .generation-actions,
  .editor-toolbar {
    width: 100%;
  }

  .feedback-status {
    text-align: left;
  }

  .rating-group {
    grid-template-columns: repeat(3, minmax(42px, 1fr));
  }
}
