:root {
  --forest-950: #102820;
  --forest-900: #17362e;
  --forest-800: #1d473a;
  --forest-700: #245a48;
  --forest-600: #2d7158;
  --forest-100: #dcebe3;
  --forest-50: #eef6f1;
  --paper: #fffef9;
  --canvas: #f3f1e9;
  --ink: #17221e;
  --muted: #64706a;
  --line: #d8ddd7;
  --amber: #aa7320;
  --amber-soft: #fff0cf;
  --red: #9b3c36;
  --red-soft: #fae7e3;
  --shadow: 0 16px 44px rgba(23, 54, 46, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--canvas);
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 8% 0%, rgba(45, 113, 88, 0.1), transparent 28rem),
    var(--canvas);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  text-rendering: optimizeLegibility;
}

button,
textarea,
input {
  font: inherit;
}

a {
  color: var(--forest-700);
  text-underline-offset: 0.2em;
}

:focus-visible {
  outline: 3px solid #d5932a;
  outline-offset: 3px;
}

.site-shell {
  width: min(100% - 28px, 1180px);
  margin-inline: auto;
  padding: 34px 0 56px;
}

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

.login-card {
  width: min(100%, 460px);
  border: 1px solid rgba(29, 71, 58, 0.16);
  border-radius: 18px;
  background: rgba(255, 254, 249, 0.97);
  box-shadow: var(--shadow);
  padding: clamp(24px, 6vw, 40px);
}

.login-card h1 {
  margin: 6px 0 12px;
  color: var(--forest-950);
  font-size: clamp(2rem, 9vw, 3.25rem);
  letter-spacing: -0.055em;
  line-height: 1;
}

.login-copy {
  margin: 0 0 28px;
  color: var(--muted);
  line-height: 1.65;
}

.login-form {
  display: grid;
  gap: 12px;
}

.login-form > label {
  color: var(--forest-900);
  font-size: 0.92rem;
  font-weight: 750;
}

.password-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.password-row input {
  min-width: 0;
  min-height: 48px;
  border: 1px solid #bdc8c1;
  border-radius: 11px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
}

.secondary-button {
  min-height: 48px;
  border: 1px solid #afbbb4;
  border-radius: 11px;
  background: #f7faf7;
  color: var(--forest-800);
  cursor: pointer;
  padding: 0 15px;
  font-weight: 750;
}

.secondary-button:hover:not(:disabled) {
  background: var(--forest-50);
}

.login-submit {
  width: 100%;
  margin-top: 4px;
}

.login-error {
  margin: 0;
  border: 1px solid #efc5bf;
  border-radius: 10px;
  background: var(--red-soft);
  color: var(--red);
  padding: 10px 12px;
  line-height: 1.5;
}

.hero {
  max-width: 790px;
  margin-bottom: 26px;
}

.hero-actions,
.report-actions {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.logout-control {
  display: grid;
  justify-items: end;
  gap: 6px;
}

.logout-button {
  min-height: 44px;
  white-space: nowrap;
}

.logout-error {
  max-width: 17rem;
  margin: 0;
  color: var(--red);
  font-size: 0.78rem;
  line-height: 1.4;
  text-align: right;
}

.hero h1,
.report-header h1 {
  max-width: 760px;
  margin: 6px 0 10px;
  color: var(--forest-950);
  font-size: clamp(2rem, 7vw, 4.75rem);
  font-weight: 750;
  letter-spacing: -0.055em;
  line-height: 0.98;
}

.hero > p:last-child,
.report-header > p:last-child {
  max-width: 680px;
  margin: 0;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.18rem);
  line-height: 1.7;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--forest-600);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.dashboard-shell {
  display: grid;
  gap: 14px;
}

.dashboard-side,
.report-view {
  display: grid;
  align-content: start;
  gap: 14px;
}

.panel {
  overflow: hidden;
  border: 1px solid rgba(29, 71, 58, 0.13);
  border-radius: 14px;
  background: rgba(255, 254, 249, 0.95);
  box-shadow: var(--shadow);
  padding: 18px;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 20px;
}

.panel-heading h2,
.report-section h2,
.unavailable-state h2 {
  margin: 0;
  color: var(--forest-900);
  font-size: clamp(1.2rem, 3vw, 1.55rem);
  letter-spacing: -0.025em;
}

.search-form,
.field-stack {
  display: grid;
  gap: 10px;
}

.field-heading {
  display: flex;
  justify-content: space-between;
  color: var(--forest-900);
  font-size: 0.92rem;
  font-weight: 750;
}

.field-heading span,
.field-hint,
.muted-copy,
.job-id,
.date-range {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
}

textarea {
  width: 100%;
  min-height: 116px;
  resize: vertical;
  border: 1px solid #bdc8c1;
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  padding: 14px;
  line-height: 1.55;
}

textarea::placeholder {
  color: #8a948f;
}

.field-hint {
  margin: 0;
  line-height: 1.5;
}

.option-grid {
  display: grid;
  gap: 14px;
  margin: 8px 0 4px;
}

fieldset {
  min-width: 0;
  margin: 0;
  border: 0;
  padding: 0;
}

legend {
  margin-bottom: 8px;
  color: var(--forest-900);
  font-size: 0.86rem;
  font-weight: 750;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.segmented-control label {
  position: relative;
  cursor: pointer;
}

.segmented-control input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.segmented-control span {
  display: grid;
  min-height: 44px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8faf8;
  color: #435149;
  font-size: 0.86rem;
  font-weight: 700;
  text-align: center;
  transition: border-color 140ms ease, background 140ms ease, color 140ms ease;
}

.segmented-control input:checked + span {
  border-color: var(--forest-700);
  background: var(--forest-100);
  color: var(--forest-950);
}

.segmented-control input:focus-visible + span {
  outline: 3px solid #d5932a;
  outline-offset: 2px;
}

.primary-button {
  min-height: 50px;
  margin-top: 8px;
  border: 0;
  border-radius: 11px;
  background: var(--forest-800);
  color: #fff;
  cursor: pointer;
  font-weight: 800;
  letter-spacing: 0.01em;
}

.primary-button:hover:not(:disabled) {
  background: var(--forest-700);
}

.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.connection-status {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f8faf8;
  padding: 5px 10px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  white-space: nowrap;
}

.connection-status > span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #8d9691;
}

.connection-online > span {
  background: #2e8b61;
  box-shadow: 0 0 0 3px rgba(46, 139, 97, 0.14);
}

.connection-offline > span {
  background: var(--red);
}

.status-badge {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  border-radius: 999px;
  background: var(--forest-50);
  color: var(--forest-800);
  padding: 4px 9px;
  font-size: 0.72rem;
  font-weight: 800;
  white-space: nowrap;
}

.status-partial,
.status-interrupted {
  background: var(--amber-soft);
  color: #7c5011;
}

.status-failed,
.status-cancelled {
  background: var(--red-soft);
  color: var(--red);
}

.progress-summary {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  color: var(--forest-700);
  font-size: 0.82rem;
  font-weight: 750;
}

progress {
  width: 100%;
  height: 8px;
  overflow: hidden;
  border: 0;
  border-radius: 999px;
  background: var(--forest-100);
}

progress::-webkit-progress-bar {
  background: var(--forest-100);
}

progress::-webkit-progress-value {
  border-radius: 999px;
  background: var(--forest-600);
}

progress::-moz-progress-bar {
  border-radius: 999px;
  background: var(--forest-600);
}

.engine-list,
.history-list,
.limitations ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.engine-list {
  display: grid;
  gap: 8px;
}

.engine-list li {
  display: grid;
  grid-template-columns: minmax(8rem, auto) 1fr;
  align-items: center;
  gap: 12px;
  border-radius: 10px;
  background: #f6f8f6;
  padding: 10px;
  font-size: 0.84rem;
  font-weight: 700;
}

.inline-alert,
.limitations,
.unavailable-state {
  border: 1px solid #efd1a0;
  border-radius: 10px;
  background: var(--amber-soft);
  color: #70470d;
  padding: 11px 12px;
  line-height: 1.55;
}

.text-link,
.source-card a,
.back-link {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  font-weight: 750;
}

.history-list {
  display: grid;
  gap: 2px;
}

.history-list li + li {
  border-top: 1px solid #e6e9e6;
}

.history-list a {
  display: grid;
  min-height: 58px;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "query status" "time time";
  align-items: center;
  gap: 3px 10px;
  color: inherit;
  padding: 10px 2px;
  text-decoration: none;
}

.history-query {
  grid-area: query;
  overflow: hidden;
  font-weight: 720;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-list .status-badge {
  grid-area: status;
}

.history-list time {
  grid-area: time;
  color: var(--muted);
  font-size: 0.74rem;
}

.empty-state,
.loading-state {
  margin: 0;
  color: var(--muted);
  line-height: 1.65;
}

.report-shell {
  max-width: 980px;
}

.report-header {
  margin-bottom: 24px;
}

.report-header h1 {
  font-size: clamp(2rem, 6vw, 3.65rem);
}

.back-link {
  margin-bottom: 18px;
  text-decoration: none;
}

.report-actions {
  margin-bottom: 18px;
}

.report-actions .back-link {
  margin-bottom: 0;
}

.job-id {
  overflow-wrap: anywhere;
}

.report-overview {
  border-color: rgba(45, 113, 88, 0.35);
  background: linear-gradient(145deg, #f7fcf8, var(--paper));
}

.source-status-list,
.tag-row,
.source-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.source-status-list {
  margin-bottom: 18px;
}

.source-status-list span,
.tag-row span,
.source-meta span,
.source-meta time {
  border-radius: 999px;
  background: #edf1ee;
  color: #536159;
  padding: 4px 8px;
  font-size: 0.72rem;
  font-weight: 700;
}

.source-status-list .source-degraded {
  background: var(--amber-soft);
  color: #74490c;
}

.source-status-list .source-ok {
  background: var(--forest-50);
  color: var(--forest-700);
}

.theme-grid,
.source-grid {
  display: grid;
  gap: 10px;
}

.theme-card,
.source-card {
  border: 1px solid #e0e4e0;
  border-radius: 12px;
  background: #fff;
  padding: 14px;
}

.theme-card h3,
.source-card h4,
.limitations h3 {
  margin: 0 0 7px;
  color: var(--forest-900);
  font-size: 1rem;
}

.theme-card p,
.source-card p {
  margin: 0 0 10px;
  color: #4d5a53;
  line-height: 1.65;
}

.limitations {
  margin: 18px 0;
}

.limitations li + li {
  margin-top: 6px;
}

.source-grid {
  margin-top: 18px;
}

.source-meta {
  margin-bottom: 10px;
}

.source-card .engagement {
  color: var(--forest-600);
  font-size: 0.78rem;
  font-weight: 750;
}

@media (min-width: 620px) {
  .site-shell {
    width: min(100% - 48px, 1180px);
    padding-top: 48px;
  }

  .option-grid,
  .theme-grid,
  .source-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 619px) {
  .hero-actions,
  .report-actions {
    display: grid;
  }

  .logout-control,
  .logout-button {
    width: 100%;
  }

  .logout-control {
    justify-items: stretch;
  }

  .logout-error {
    max-width: none;
    text-align: left;
  }
}

@media (min-width: 820px) {
  .site-shell {
    padding-top: 68px;
  }

  .hero {
    margin-bottom: 38px;
  }

  .dashboard-shell {
    grid-template-columns: minmax(0, 1.24fr) minmax(310px, 0.76fr);
    gap: 18px;
  }

  .dashboard-side,
  .report-view {
    gap: 18px;
  }

  .panel {
    border-radius: 18px;
    padding: 24px;
  }

  .search-panel {
    position: sticky;
    top: 20px;
    align-self: start;
  }

  textarea {
    min-height: 154px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
