:root {
  --bg: #f6f8fb;
  --bg-soft: #eef6f4;
  --panel: rgba(255, 255, 255, .92);
  --panel-solid: #ffffff;
  --text: #111827;
  --muted: #5b677a;
  --muted-strong: #334155;
  --border: #d9e2ec;
  --border-strong: #c3ceda;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --primary-soft: #d8f3ee;
  --accent: #b7791f;
  --accent-soft: #fff4d6;
  --danger: #b42318;
  --danger-soft: #fee4e2;
  --success: #067647;
  --success-soft: #dcfae6;
  --warning: #b54708;
  --warning-soft: #fef0c7;
  --shadow: 0 20px 55px rgba(15, 23, 42, .11);
  --shadow-soft: 0 10px 28px rgba(15, 23, 42, .08);
  --radius: 8px;
  --radius-sm: 6px;
  --ring: 0 0 0 3px rgba(15, 118, 110, .2);
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 8% 4%, rgba(15, 118, 110, .12), transparent 32rem),
    radial-gradient(circle at 94% 0%, rgba(183, 121, 31, .12), transparent 30rem),
    linear-gradient(180deg, #f8fbfd 0%, var(--bg) 46%, #edf4f2 100%);
  color: var(--text);
}

body,
input,
textarea,
select,
button {
  font: 14px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea,
summary {
  transition: border-color .18s ease, background .18s ease, color .18s ease, box-shadow .18s ease;
}

.hidden {
  display: none !important;
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

h1 {
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.08;
  letter-spacing: 0;
}

h2 {
  color: #172033;
  font-size: 18px;
  line-height: 1.25;
}

p {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
  margin-top: 5px;
}

strong {
  color: #152033;
  font-weight: 750;
}

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

.login-card {
  width: min(440px, 100%);
  display: grid;
  gap: 18px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, .72);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 13px;
  min-width: 0;
}

.mark {
  width: 46px;
  height: 46px;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  background: linear-gradient(135deg, var(--primary), #134e4a);
  color: #fff;
  font-size: 19px;
  font-weight: 850;
  box-shadow: 0 10px 24px rgba(15, 118, 110, .28);
}

.mark.compact {
  width: 40px;
  height: 40px;
  font-size: 16px;
}

main {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 24px clamp(16px, 3vw, 32px) 36px;
}

.topbar {
  position: sticky;
  top: 16px;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
  padding: 12px;
  background: rgba(255, 255, 255, .78);
  border: 1px solid rgba(255, 255, 255, .7);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(18px);
}

.topbar h1 {
  font-size: 22px;
}

.topbar-actions,
.run-row,
.dialog-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.tabs {
  display: inline-flex;
  gap: 4px;
  margin-bottom: 18px;
  padding: 5px;
  background: rgba(255, 255, 255, .82);
  border: 1px solid rgba(255, 255, 255, .76);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(14px);
}

.tab {
  min-height: 38px;
  border-color: transparent;
  background: transparent;
  color: var(--muted-strong);
  box-shadow: none;
}

.tab:hover {
  background: #eef6f4;
  color: var(--primary-dark);
  box-shadow: none;
}

.tab.is-active {
  background: var(--primary);
  color: #fff;
}

.tab-panel {
  display: block;
}

.panel {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, .76);
  border-radius: var(--radius);
  padding: clamp(18px, 2vw, 24px);
  margin-bottom: 18px;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(14px);
}

.primary-panel {
  border-color: rgba(15, 118, 110, .18);
}

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

.eyebrow {
  display: inline-flex;
  margin-bottom: 6px;
  color: var(--primary-dark);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: .08em;
  text-transform: uppercase;
}

label {
  display: block;
  color: var(--muted-strong);
  font-size: 13px;
  font-weight: 720;
  margin-bottom: 14px;
}

input,
textarea,
select {
  width: 100%;
  margin-top: 7px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  color: var(--text);
  background: rgba(255, 255, 255, .96);
  outline: none;
}

input::placeholder,
textarea::placeholder {
  color: #94a3b8;
}

input:hover,
textarea:hover,
select:hover {
  border-color: var(--border-strong);
}

input:focus-visible,
textarea:focus-visible,
select:focus-visible,
button:focus-visible,
summary:focus-visible {
  border-color: var(--primary);
  box-shadow: var(--ring);
  outline: none;
}

textarea {
  min-height: 104px;
  resize: vertical;
}

textarea.short {
  min-height: 128px;
}

textarea.large {
  min-height: 300px;
}

button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  background: var(--primary);
  color: #fff;
  font-weight: 760;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}

button:hover {
  background: var(--primary-dark);
  box-shadow: 0 8px 18px rgba(15, 118, 110, .2);
}

button:disabled {
  opacity: .6;
  cursor: not-allowed;
  box-shadow: none;
}

button.loading::before {
  content: "";
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, .45);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .75s linear infinite;
}

button.secondary,
button.ghost {
  background: #f8fafc;
  color: #1f2937;
  border-color: var(--border);
}

button.secondary:hover,
button.ghost:hover {
  background: #eef6f4;
  border-color: rgba(15, 118, 110, .28);
  color: var(--primary-dark);
  box-shadow: none;
}

button.secondary.loading::before,
button.ghost.loading::before {
  border-color: rgba(15, 118, 110, .24);
  border-top-color: var(--primary);
}

button.danger {
  color: var(--danger);
}

button.danger:hover {
  background: #fff5f4;
  border-color: #fecdca;
  color: #912018;
}

.run-button {
  min-width: 152px;
  background: linear-gradient(135deg, var(--primary), #134e4a);
  box-shadow: 0 12px 28px rgba(15, 118, 110, .24);
}

.grid {
  display: grid;
  gap: 16px;
}

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

.run-row {
  justify-content: space-between;
  margin-top: 4px;
  padding-top: 8px;
}

.toggle-group {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 8px;
}

.check {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  margin: 0;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  cursor: pointer;
}

.check:hover {
  border-color: rgba(15, 118, 110, .35);
  background: #f7fbfa;
}

.check input {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  margin: 0;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(180px, 1.4fr);
  gap: 10px;
  align-items: start;
  margin-bottom: 14px;
}

.inline-form input {
  margin: 0;
}

.inline-form button {
  width: 100%;
}

.journal-form {
  grid-template-columns: minmax(180px, .75fr) minmax(320px, 1.5fr) minmax(96px, auto) minmax(96px, auto);
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.journal-list {
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.list,
.history {
  display: grid;
  gap: 10px;
}

.list-item,
.history-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  background: var(--panel-solid);
}

.list-item {
  box-shadow: 0 1px 0 rgba(15, 23, 42, .04);
}

.history-item {
  padding: 16px;
}

.history-item.is-pending {
  border-color: rgba(15, 118, 110, .3);
  background: linear-gradient(180deg, #f8fffd, #ffffff);
}

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

.item-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 4px 10px;
  background: #eef2f7;
  color: #475467;
  font-size: 12px;
  font-weight: 760;
}

.badge.done {
  background: var(--success-soft);
  color: var(--success);
}

.badge.fail {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge.processing {
  background: var(--warning-soft);
  color: var(--warning);
}

.mini-spinner,
.loader {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid rgba(181, 71, 8, .28);
  border-top-color: var(--warning);
  border-radius: 50%;
  animation: spin .75s linear infinite;
}

.loader {
  width: 18px;
  height: 18px;
  border-color: rgba(15, 118, 110, .2);
  border-top-color: var(--primary);
  flex: 0 0 auto;
}

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

details {
  margin-top: 14px;
}

summary {
  width: max-content;
  max-width: 100%;
  border-radius: var(--radius-sm);
  color: var(--primary-dark);
  cursor: pointer;
  font-size: 13px;
  font-weight: 780;
}

summary:hover {
  color: var(--primary);
}

pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: #111827;
  color: #f9fafb;
  padding: 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
}

.processing-note {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted-strong);
  background: #f0fdfa;
  border: 1px solid #99f6e4;
  border-radius: var(--radius-sm);
  padding: 12px;
}

.result-section {
  border-top: 1px solid var(--border);
  padding-top: 16px;
  margin-top: 16px;
}

.result-section:first-child {
  border-top: 0;
  padding-top: 0;
}

.result-section h3 {
  color: #172033;
  font-size: 16px;
  margin: 0 0 12px;
}

.metric-row {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  margin: 0 8px 10px 0;
}

.metric-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 820;
  text-transform: uppercase;
}

.text-block {
  margin-top: 10px;
}

.text-block h4,
.review-card h4,
.aspect-title,
.list-panel h4 {
  margin: 0;
}

.text-block h4 {
  font-size: 13px;
  margin-bottom: 4px;
}

.review-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
}

.review-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  padding: 14px;
  box-shadow: 0 1px 0 rgba(15, 23, 42, .04);
}

.review-card h4 {
  color: #172033;
  font-size: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.aspect {
  padding: 12px 0;
  border-bottom: 1px solid #edf1f6;
}

.aspect:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.aspect-title {
  color: var(--primary-dark);
  font-size: 13px;
  font-weight: 820;
  margin-bottom: 6px;
}

.aspect-body p,
.aspect-body ul,
.list-panel ul {
  margin: 0;
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

.aspect-body ul,
.list-panel ul {
  padding-left: 20px;
}

.nested-line {
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 4px;
}

.summary-box {
  border: 1px solid #fde68a;
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  padding: 12px;
  color: #713f12;
  font-size: 14px;
  line-height: 1.55;
  margin-bottom: 12px;
}

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

.list-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  overflow: hidden;
}

.list-panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
}

.list-panel-head h4 {
  font-size: 13px;
}

.list-panel-head span {
  min-width: 28px;
  height: 24px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 850;
}

.list-panel ul,
.empty-note {
  padding: 12px;
}

.list-panel li {
  margin-bottom: 10px;
}

.list-panel li:last-child {
  margin-bottom: 0;
}

.citation-item {
  display: grid;
  gap: 4px;
}

.citation-primary {
  font-weight: 700;
}

.citation-meta {
  display: grid;
  gap: 2px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.empty-note {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.error {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid #fecdca;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 12px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  background: #111827;
  color: #fff;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  box-shadow: 0 12px 36px rgba(0, 0, 0, .22);
}

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: min(640px, calc(100% - 32px));
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(15, 23, 42, .42);
  backdrop-filter: blur(3px);
}

.dialog-body {
  display: grid;
  gap: 14px;
  padding: 22px;
}

.dialog-actions {
  justify-content: flex-end;
}

@media (max-width: 760px) {
  main {
    padding: 16px;
  }

  .topbar,
  .panel-head,
  .item-row {
    flex-direction: column;
    align-items: stretch;
  }

  .grid.two,
  .inline-form,
  .citation-columns {
    grid-template-columns: 1fr;
  }

  .topbar-actions,
  .dialog-actions {
    width: 100%;
  }

  .tabs {
    width: 100%;
  }

  .tab {
    flex: 1 1 0;
  }

  .topbar-actions button,
  .dialog-actions button,
  .run-button {
    flex: 1 1 auto;
  }

  textarea.large {
    min-height: 230px;
  }
}

@media (max-width: 460px) {
  .login-card,
  .panel {
    padding: 18px;
  }

  .brand-lockup {
    align-items: flex-start;
  }

  .run-row,
  .toggle-group,
  .check,
  .run-button {
    width: 100%;
  }

  .item-actions {
    justify-content: stretch;
  }

  .item-actions button {
    flex: 1 1 auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}
