:root {
  --bg: #f6f2ea;
  --bg-rgb: 246, 242, 234;
  --glass: rgba(255, 255, 255, 0.78);
  --glass-strong: rgba(255, 255, 255, 0.9);
  --glass-border: rgba(0, 0, 0, 0.08);
  --text: #1c1916;
  --ink: #1c1916;
  --text-secondary: rgba(28, 25, 22, 0.62);
  --faint: rgba(28, 25, 22, 0.12);
  --accent: #3a3532;
  --accent-hover: #2a2624;
  --accent-soft: rgba(58, 53, 50, 0.1);
  --btn-primary-text: #fff;
  --input-bg: rgba(255, 255, 255, 0.55);
  --input-bg-focus: rgba(255, 255, 255, 0.72);
  --border: rgba(58, 50, 43, 0.08);
  --shadow-glass: 0 8px 30px rgba(0, 0, 0, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.85);
  --shadow-lift: 0 12px 36px rgba(0, 0, 0, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.9);
  --radius: 22px;
  --radius-sm: 14px;
  --font: "Poppins", -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", sans-serif;
  --error: #d70015;
  --status-queued-bg: rgba(58, 53, 50, 0.08);
  --status-queued-fg: rgba(28, 25, 22, 0.72);
  --status-running-bg: rgba(47, 143, 134, 0.14);
  --status-running-fg: #1b6b64;
  --status-completed-bg: rgba(47, 143, 134, 0.16);
  --status-completed-fg: #166534;
  --status-failed-bg: rgba(215, 0, 21, 0.1);
  --status-failed-fg: #d70015;
  --progress-track: rgba(28, 25, 22, 0.08);
  color-scheme: light;
}

html[data-theme="dark"] {
  --bg: #1c1916;
  --bg-rgb: 28, 25, 22;
  --glass: rgba(48, 44, 40, 0.78);
  --glass-strong: rgba(58, 54, 50, 0.9);
  --glass-border: rgba(255, 255, 255, 0.1);
  --text: #f3eee6;
  --ink: #f3eee6;
  --text-secondary: #b8aea4;
  --faint: rgba(243, 238, 230, 0.14);
  --accent: #f3eee6;
  --accent-hover: #e4d9cc;
  --accent-soft: rgba(243, 238, 230, 0.12);
  --btn-primary-text: #1c1916;
  --input-bg: rgba(255, 255, 255, 0.06);
  --input-bg-focus: rgba(255, 255, 255, 0.1);
  --border: rgba(255, 255, 255, 0.08);
  --shadow-glass: 0 8px 30px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  --shadow-lift: 0 12px 36px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  --error: #ff6b6b;
  --status-queued-bg: rgba(255, 255, 255, 0.08);
  --status-queued-fg: #d4c8bc;
  --status-running-bg: rgba(47, 143, 134, 0.22);
  --status-running-fg: #8ed8d0;
  --status-completed-bg: rgba(47, 143, 134, 0.2);
  --status-completed-fg: #9bd4a8;
  --status-failed-bg: rgba(255, 107, 107, 0.14);
  --status-failed-fg: #ff6b6b;
  --progress-track: rgba(255, 255, 255, 0.1);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
}

.topbar {
  position: fixed;
  inset: 0 0 auto;
  z-index: 50;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 0;
  padding: 1rem clamp(1rem, 3vw, 2rem);
  border: 0;
  background: rgba(var(--bg-rgb), 0.78);
  box-shadow: none;
  backdrop-filter: blur(12px) saturate(1.25);
  -webkit-backdrop-filter: blur(12px) saturate(1.25);
  transition: background 280ms ease, backdrop-filter 280ms ease, box-shadow 280ms ease;
}

.topbar.is-scrolled {
  background:
    linear-gradient(
      145deg,
      rgba(var(--bg-rgb), 0.58) 0%,
      rgba(var(--bg-rgb), 0.42) 42%,
      rgba(var(--bg-rgb), 0.52) 100%
    );
  backdrop-filter: blur(16px) saturate(1.35);
  -webkit-backdrop-filter: blur(16px) saturate(1.35);
  box-shadow: 0 12px 32px rgba(28, 25, 22, 0.03);
}

.brand {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
}

.brand-home {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  line-height: 0;
}

.brand-logo-wrap {
  --logo-h: 2.9rem;
  position: relative;
  display: block;
  height: var(--logo-h);
  width: calc(var(--logo-h) * 539 / 227);
  overflow: hidden;
}

.brand-logo {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  object-fit: fill;
}

.brand-logo--inverse {
  width: calc(100% * 595 / 539);
  height: calc(100% * 283 / 227);
  inset: auto;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  opacity: 0;
  pointer-events: none;
}

html[data-theme="dark"] .brand-logo:not(.brand-logo--inverse) {
  opacity: 0;
}

html[data-theme="dark"] .brand-logo--inverse {
  opacity: 1;
}

.brand-portal {
  flex-shrink: 0;
  padding-left: 0.85rem;
  border-left: 1px solid rgba(28, 25, 22, 0.12);
  font-size: 0.84rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--ink);
  text-decoration: none;
}

.brand-portal:hover {
  color: var(--ink);
}

html[data-theme="dark"] .brand-portal {
  border-left-color: rgba(255, 255, 255, 0.16);
}

.topbar-end,
.topbar-actions {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.topbar-actions form {
  margin: 0;
}

.wrap {
  position: relative;
  z-index: 1;
  flex: 1;
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
  padding: 7rem 24px 64px;
}

.foot {
  position: relative;
  z-index: 1;
  padding: 20px 28px 28px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 12px;
}

.foot p {
  margin: 0;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 32px;
}

.page-head h1,
.login-card h1 {
  margin: 0 0 4px;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.page-head .muted {
  margin: 1em 0 0;
}

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

h2 {
  margin-bottom: 12px;
  font-size: 18px;
  letter-spacing: -0.02em;
}

.muted {
  color: var(--text-secondary);
}

.card {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-glass);
  backdrop-filter: saturate(180%) blur(28px);
  -webkit-backdrop-filter: saturate(180%) blur(28px);
}

.card {
  margin-bottom: 20px;
  padding: 28px;
}

.narrow,
.login-card {
  max-width: 400px;
  margin: 48px auto 0;
}

.empty {
  margin-top: 40px;
  text-align: center;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 8px;
}

.form label,
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form label > span,
.field-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}

.form small {
  color: var(--text-secondary);
  font-weight: 400;
}

.field.check {
  flex-direction: row;
  align-items: center;
  gap: 10px;
}

.field.check input[type="checkbox"] {
  width: auto;
  padding: 0;
  flex-shrink: 0;
}

.form-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
}

input,
textarea,
select {
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  padding: 11px 13px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  background: var(--input-bg);
  color: var(--text);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--input-bg-focus);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.actions,
.progress-head,
.job-state {
  display: flex;
  align-items: center;
}

.actions,
.job-state {
  gap: 10px;
}

.actions {
  flex-wrap: wrap;
}

.btn,
.btn-primary,
.btn-secondary,
.btn-ghost {
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  border-radius: 0;
  min-height: 2.75rem;
  padding: 0 1.15rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  box-shadow: none;
  color: inherit;
  background: transparent;
  transition: transform 180ms ease, background 180ms ease, border-color 180ms ease;
}

.btn:hover,
.btn-primary:hover,
.btn-secondary:hover,
.btn-ghost:hover {
  transform: translateY(-1px);
}

.btn.primary,
.btn-primary {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}

.btn.secondary,
.btn-secondary,
.btn.ghost,
.btn-ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--faint);
}

.btn.secondary:hover,
.btn-secondary:hover,
.btn.ghost:hover,
.btn-ghost:hover {
  border-color: var(--ink);
}

.login-card .btn.primary,
.login-card .btn-primary,
.narrow .btn.primary,
.narrow .btn-primary {
  margin-top: 4px;
  width: 100%;
  padding: 12px;
}

.theme-toggle,
.profile-btn {
  position: relative;
  z-index: 1;
  box-sizing: border-box;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  box-shadow: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  line-height: 0;
  font-size: 0;
}

.theme-toggle:hover,
.profile-btn:hover,
.profile-btn[aria-expanded="true"] {
  color: var(--ink);
}

.theme-toggle svg,
.profile-btn svg {
  width: 1.15rem;
  height: 1.15rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-toggle .icon-sun {
  display: none;
}

html[data-theme="dark"] .theme-toggle .icon-moon {
  display: none;
}

html[data-theme="dark"] .theme-toggle .icon-sun {
  display: block;
}

.profile-menu {
  position: relative;
  width: 2.25rem;
  height: 2.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.profile-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 220px;
  padding: 8px;
  border-radius: 14px;
  border: 1px solid var(--glass-border);
  background: var(--glass-strong);
  box-shadow: var(--shadow-lift);
  backdrop-filter: saturate(180%) blur(22px);
  -webkit-backdrop-filter: saturate(180%) blur(22px);
  z-index: 60;
}

.profile-dropdown-name {
  margin: 0;
  padding: 10px 12px 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.profile-dropdown-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  background: transparent;
  border: 0;
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
}

.profile-dropdown-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.profile-dropdown-item:hover {
  background: var(--accent-soft);
}

.logout-form {
  margin: 0;
}

.flash,
.error-box {
  margin-bottom: 20px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.flash {
  background: rgba(196, 146, 60, 0.12);
  border: 1px solid rgba(196, 146, 60, 0.28);
  color: var(--text);
}

.flash.success {
  background: rgba(220, 242, 220, 0.92);
  border: 1px solid rgba(47, 143, 134, 0.22);
}

html[data-theme="dark"] .flash.success {
  background: rgba(47, 143, 134, 0.2);
  border-color: rgba(142, 216, 208, 0.28);
}

.wrap:has(.login-card) .flash {
  max-width: 400px;
  margin: 0 auto 18px;
  background: rgba(215, 0, 21, 0.08);
  border: 1px solid rgba(215, 0, 21, 0.22);
  color: var(--error);
}

.flash p {
  margin: 0;
}

.error-box {
  margin-top: 22px;
  color: var(--error);
  background: rgba(215, 0, 21, 0.08);
  border: 1px solid rgba(215, 0, 21, 0.22);
}

.error-box pre {
  margin: 10px 0 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.cards {
  display: grid;
  gap: 18px;
}

.analysis-card {
  margin-bottom: 0;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.analysis-card:hover {
  transform: translateY(-2px);
  background: var(--glass-strong);
  box-shadow: var(--shadow-lift);
}

.analysis-card h2 {
  margin: 0 0 4px;
  font-size: 18px;
  letter-spacing: -0.02em;
}

.analysis-card .topic {
  margin: 0;
  font-size: 13px;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 18px;
}

.card-head h2 {
  margin: 0 0 4px;
}

.card-toggle {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.card-toggle h2 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.card-chevron {
  display: inline-block;
  width: 0.45rem;
  height: 0.45rem;
  margin-top: 0.45rem;
  flex-shrink: 0;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
}

.analysis-card:not(.is-collapsed) .card-chevron {
  margin-top: 0.35rem;
  transform: rotate(45deg);
}

.analysis-card.is-collapsed .actions,
.analysis-card.is-collapsed .topic {
  display: none;
}

.analysis-card.is-collapsed .card-head {
  margin-bottom: 0;
}

.job-publish {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin: 14px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--faint);
}

.status {
  display: inline-block;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  text-transform: capitalize;
  background: var(--status-queued-bg);
  color: var(--status-queued-fg);
}

.status.running {
  color: var(--status-running-fg);
  background: var(--status-running-bg);
}

.status.completed {
  color: var(--status-completed-fg);
  background: var(--status-completed-bg);
}

.status.failed {
  color: var(--status-failed-fg);
  background: var(--status-failed-bg);
}

.progress-head {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
}

.progress-track {
  display: block;
  height: 10px;
  margin-bottom: 18px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--progress-track);
}

.progress-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--ink);
}

.back-link {
  display: inline-block;
  margin-bottom: 8px;
  color: var(--text-secondary);
  text-decoration: none;
}

.back-link:hover {
  color: var(--ink);
}

.note {
  margin: 18px 0 0;
  font-size: 12px;
}

.details dl {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 8px 16px;
  margin: 0;
}

.details dt {
  color: var(--text-secondary);
}

.details dd {
  margin: 0;
  overflow-wrap: anywhere;
}

@media (max-width: 640px) {
  .brand {
    gap: 0.6rem;
  }

  .brand-portal {
    padding-left: 0.65rem;
    font-size: 0.72rem;
  }

  .wrap {
    padding-top: 6.25rem;
  }

  .page-head h1,
  .login-card h1 {
    font-size: 24px;
  }

  .page-head,
  .card-head {
    align-items: flex-start;
  }

  .page-head {
    flex-direction: column;
  }

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

  @media (max-width: 420px) {
    .brand-portal {
      display: none;
    }
  }
}
