:root {
  --bg-page: #f4f8fc;
  --bg-page-soft: #fbfdff;
  --bg-accent: #e8f2ff;
  --surface: rgba(255, 255, 255, 0.94);
  --surface-strong: #ffffff;
  --surface-soft: #f7fafd;
  --surface-accent: #eef5ff;
  --border: rgba(15, 23, 42, 0.08);
  --border-strong: rgba(15, 23, 42, 0.12);
  --text: #162033;
  --text-muted: #637089;
  --text-soft: #8a96aa;
  --primary: #2563eb;
  --primary-strong: #0f4fd3;
  --primary-soft: #e9f1ff;
  --success: #11b981;
  --danger: #db5b5b;
  --shadow: 0 18px 45px rgba(17, 38, 74, 0.08);
  --shadow-soft: 0 10px 30px rgba(31, 60, 112, 0.06);
  --sidebar-width: 272px;
  --topbar-height: 72px;
  --radius: 20px;
  --radius-sm: 14px;
  --transition: all 0.2s ease;
  --pattern-opacity: 0.2;
  --sidebar-bg: rgba(255, 255, 255, 0.88);
  --sidebar-border: rgba(255, 255, 255, 0.75);
  --glass-bg: rgba(255, 255, 255, 0.82);
  --input-bg: rgba(248, 251, 255, 0.95);
  --card-bg: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(248, 251, 255, 0.96));
  --empty-bg: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(239, 246, 255, 0.9));
  --detail-bg: linear-gradient(180deg, rgba(233, 241, 255, 0.88), rgba(255, 255, 255, 0.95));
  --notice-bg: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(239, 246, 255, 0.9));
  --iframe-bg: #ffffff;
  --iframe-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
  --top-glow-a: rgba(37, 99, 235, 0.12);
  --top-glow-b: rgba(17, 185, 129, 0.08);
  --page-gradient-start: #fbfdff;
  --page-gradient-end: #f3f7fb;
}

html[data-theme="dark"] {
  --bg-page: #09111f;
  --bg-page-soft: #0d1728;
  --bg-accent: #16243d;
  --surface: rgba(11, 20, 35, 0.92);
  --surface-strong: #121d31;
  --surface-soft: #142036;
  --surface-accent: #1a2c4a;
  --border: rgba(167, 188, 235, 0.12);
  --border-strong: rgba(167, 188, 235, 0.18);
  --text: #eef4ff;
  --text-muted: #9aaac6;
  --text-soft: #73839f;
  --primary: #6ba5ff;
  --primary-strong: #9cc0ff;
  --primary-soft: rgba(80, 129, 219, 0.18);
  --success: #21d09a;
  --danger: #ff8b8b;
  --shadow: 0 22px 50px rgba(2, 6, 23, 0.48);
  --shadow-soft: 0 14px 34px rgba(2, 6, 23, 0.36);
  --pattern-opacity: 0.06;
  --sidebar-bg: rgba(12, 20, 35, 0.9);
  --sidebar-border: rgba(167, 188, 235, 0.08);
  --glass-bg: rgba(14, 23, 40, 0.82);
  --input-bg: rgba(16, 28, 46, 0.9);
  --card-bg: linear-gradient(180deg, rgba(16, 27, 45, 0.98), rgba(11, 20, 35, 0.96));
  --empty-bg: linear-gradient(180deg, rgba(17, 28, 46, 0.94), rgba(13, 21, 37, 0.94));
  --detail-bg: linear-gradient(180deg, rgba(18, 35, 62, 0.95), rgba(11, 20, 35, 0.96));
  --notice-bg: linear-gradient(180deg, rgba(16, 28, 46, 0.95), rgba(12, 21, 36, 0.94));
  --iframe-bg: #0f1727;
  --iframe-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
  --top-glow-a: rgba(71, 116, 211, 0.22);
  --top-glow-b: rgba(10, 189, 145, 0.1);
  --page-gradient-start: #09111f;
  --page-gradient-end: #0b1525;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 14px;
}

body {
  font-family: "Poppins", sans-serif;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at top right, var(--top-glow-a), transparent 22%),
    radial-gradient(circle at bottom left, var(--top-glow-b), transparent 18%),
    linear-gradient(180deg, var(--page-gradient-start) 0%, var(--page-gradient-end) 100%);
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: url("https://europamaut.com/assets/img/backgrounds/pattern-white.svg");
  background-size: 820px;
  background-repeat: repeat;
  opacity: var(--pattern-opacity);
  pointer-events: none;
}

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

a {
  color: inherit;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: rgba(15, 23, 42, 0.04);
}

::-webkit-scrollbar-thumb {
  background: rgba(37, 99, 235, 0.22);
  border-radius: 999px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(37, 99, 235, 0.4);
}

.sidebar {
  width: var(--sidebar-width);
  position: fixed;
  top: 16px;
  left: 16px;
  bottom: 16px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  backdrop-filter: blur(18px);
  border: 1px solid var(--sidebar-border);
  box-shadow: var(--shadow);
  border-radius: 26px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 22px 18px 18px;
  border-bottom: 1px solid var(--border);
  min-height: var(--topbar-height);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 14px;
  text-decoration: none;
  min-width: 0;
}

.logo-mark-img {
  width: 46px;
  height: 46px;
  object-fit: contain;
  border-radius: 14px;
  background: linear-gradient(180deg, var(--surface-strong), var(--surface-accent));
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.1);
  flex-shrink: 0;
}

.sidebar-logo-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.logo-main {
  font-size: 1.08rem;
  line-height: 1.1;
  font-weight: 700;
  color: var(--text);
}

.logo-sub {
  margin-top: 4px;
  font-size: 0.68rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-soft);
}

.sidebar-toggle,
.mobile-menu-btn {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-soft);
  cursor: pointer;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.sidebar-toggle:hover,
.mobile-menu-btn:hover {
  background: var(--primary-soft);
  color: var(--primary);
}

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 12px;
  overflow-y: auto;
}

.nav-section-label {
  padding: 12px 12px 6px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-soft);
}

.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  text-decoration: none;
  padding: 12px 14px;
  border-radius: 14px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  transition: var(--transition);
  position: relative;
  text-align: left;
}

.nav-item:hover {
  background: rgba(37, 99, 235, 0.06);
  color: var(--text);
}

.nav-item.active {
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.12), rgba(37, 99, 235, 0.04));
  color: var(--primary-strong);
}

.nav-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 10px;
  bottom: 10px;
  width: 4px;
  border-radius: 0 999px 999px 0;
  background: linear-gradient(180deg, var(--primary), #6da6ff);
}

.nav-item i {
  width: 18px;
  text-align: center;
}

.nav-item--sub {
  margin-left: 14px;
  width: calc(100% - 14px);
  font-size: 0.84rem;
}

.nav-item--sub::after {
  content: "";
  position: absolute;
  left: -10px;
  top: 50%;
  width: 10px;
  height: 1px;
  background: var(--border-strong);
}

.sidebar-footer {
  padding: 16px 18px 18px;
  border-top: 1px solid var(--border);
}

.sidebar-footer-info {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 999px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
}

.server-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.server-dot.online {
  background: var(--success);
  box-shadow: 0 0 0 4px rgba(17, 185, 129, 0.14);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 99;
  background: rgba(15, 23, 42, 0.32);
  backdrop-filter: blur(4px);
}

.main-content {
  margin-left: calc(var(--sidebar-width) + 28px);
  margin-right: 12px;
  width: auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 20px 12px;
  background: transparent;
}

.mobile-menu-btn {
  display: none;
}

.topbar-left {
  flex: 1;
}

.breadcrumb {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid rgba(37, 99, 235, 0.12);
  background: rgba(255, 255, 255, 0.82);
  box-shadow: var(--shadow-soft);
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 600;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-time {
  color: var(--text-soft);
  font-size: 0.78rem;
  font-family: "Rubik", sans-serif;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid rgba(37, 99, 235, 0.12);
  background: var(--glass-bg);
  box-shadow: var(--shadow-soft);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
}

.theme-toggle:hover {
  border-color: rgba(37, 99, 235, 0.24);
  color: var(--primary-strong);
  transform: translateY(-1px);
}

.theme-toggle i {
  color: var(--primary);
}

.topbar-user {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px 8px 8px;
  border-radius: 999px;
  background: var(--glass-bg);
  border: 1px solid rgba(37, 99, 235, 0.12);
  box-shadow: var(--shadow-soft);
  color: var(--text);
  font-size: 0.86rem;
  font-weight: 600;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--surface-accent), var(--surface-soft));
  color: var(--primary-strong);
  font-weight: 700;
  font-size: 0.76rem;
}

.page-content {
  padding: 8px 20px 32px;
  flex: 1;
}

.page-header {
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: clamp(1.75rem, 2.2vw, 2.45rem);
  line-height: 1.08;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 12px;
}

.page-header h1 i {
  color: var(--primary);
}

.page-subtitle {
  display: block;
  max-width: 760px;
  margin-top: 8px;
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.6;
}

.dashboard-grid {
  display: grid;
  gap: 24px;
  grid-template-columns: minmax(0, 2fr) minmax(360px, 1fr);
}

.dashboard-grid--wide {
  grid-template-columns: minmax(0, 1.8fr) minmax(390px, 1fr);
}

.dashboard-grid--full {
  grid-template-columns: minmax(0, 1fr);
}

.card {
  position: relative;
  overflow: hidden;
  background: var(--card-bg);
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card::before {
  content: "";
  position: absolute;
  inset: 0 auto auto 0;
  width: 100%;
  height: 1px;
  background: linear-gradient(90deg, rgba(37, 99, 235, 0.15), rgba(17, 185, 129, 0.08), transparent 80%);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 20px 22px 16px;
  border-bottom: 1px solid var(--border);
}

.card-header h3 {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.card-header h3 i {
  color: var(--primary);
}

.card-body {
  padding: 22px;
}

.card-body--compact {
  padding-top: 16px;
}

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

.count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--primary-soft);
  border: 1px solid rgba(37, 99, 235, 0.16);
  color: var(--primary-strong);
  font-size: 0.8rem;
  font-family: "Rubik", sans-serif;
  font-weight: 700;
}

.form-grid {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

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

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-label {
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.form-input {
  width: 100%;
  color: var(--text);
  background: var(--input-bg);
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 16px;
  padding: 13px 15px;
  transition: var(--transition);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.form-input:hover {
  border-color: rgba(37, 99, 235, 0.18);
}

.form-input:focus {
  outline: none;
  border-color: rgba(37, 99, 235, 0.5);
  box-shadow:
    0 0 0 4px rgba(37, 99, 235, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
  background: var(--surface-strong);
}

.form-input::placeholder {
  color: #91a0b7;
}

.form-input--textarea {
  min-height: 220px;
  resize: vertical;
  line-height: 1.65;
}

.systemprompt-editor {
  min-height: 360px;
}

.form-toolbar {
  display: flex;
  gap: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 10px 18px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  transition: var(--transition);
}

.btn-primary {
  color: #ffffff;
  background: linear-gradient(135deg, #2563eb, #0f4fd3);
  box-shadow: 0 14px 28px rgba(37, 99, 235, 0.18);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 18px 32px rgba(37, 99, 235, 0.22);
}

.btn-secondary {
  color: var(--text);
  background: var(--input-bg);
  border-color: rgba(15, 23, 42, 0.08);
}

.btn-secondary:hover {
  color: var(--primary-strong);
  border-color: rgba(37, 99, 235, 0.24);
  background: var(--surface-strong);
}

.btn--ghost {
  color: var(--primary-strong);
  background: var(--primary-soft);
  border-color: rgba(37, 99, 235, 0.16);
}

.btn--ghost:hover {
  background: #dbe9ff;
}

.btn--danger {
  color: var(--danger);
  background: rgba(219, 91, 91, 0.08);
  border-color: rgba(219, 91, 91, 0.16);
}

.btn--danger:hover {
  background: rgba(219, 91, 91, 0.14);
}

.btn--small {
  padding: 8px 14px;
  font-size: 0.76rem;
}

.btn[disabled] {
  opacity: 0.72;
  cursor: progress;
}

.status-box {
  margin-top: 18px;
  padding: 15px 16px;
  border-radius: 16px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  background: var(--input-bg);
  color: var(--text-muted);
  line-height: 1.6;
}

.status-box--notice {
  color: var(--text-muted);
  background: var(--notice-bg);
  border-style: dashed;
  border-color: rgba(37, 99, 235, 0.18);
}

#threadStatus {
  margin-top: 0;
  margin-bottom: 16px;
}

.status-box.is-success {
  color: #0f7f5e;
  background: rgba(17, 185, 129, 0.1);
  border-color: rgba(17, 185, 129, 0.2);
}

.status-box.is-error {
  color: #b34545;
  background: rgba(219, 91, 91, 0.09);
  border-color: rgba(219, 91, 91, 0.18);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.thread-list-item {
  cursor: pointer;
  padding: 14px 16px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.thread-list-item:hover,
.thread-list-item:focus-visible {
  border-color: rgba(37, 99, 235, 0.28);
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.1);
  outline: none;
}

.thread-list-item__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.thread-list-item__title {
  margin: 0;
  font-size: 0.96rem;
  line-height: 1.4;
  color: var(--text);
}

.thread-list-item .thread-progress {
  margin-top: 10px;
}

.card-header--detail {
  display: flex;
  align-items: center;
  gap: 14px;
}

.card-header--detail h3 {
  margin: 0;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread-detail-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.thread-detail-toolbar__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.thread-detail-toolbar__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.history-item--detail {
  padding: 0;
  border: none;
  box-shadow: none;
  background: transparent;
}

.history-item {
  padding: 18px;
  border-radius: 18px;
  background: var(--surface-strong);
  border: 1px solid rgba(15, 23, 42, 0.08);
  box-shadow: var(--shadow-soft);
}

.history-item__head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 10px;
}

.history-item__head-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

.thread-link-actions {
  display: grid;
  gap: 8px;
  justify-items: stretch;
  width: 100%;
  min-width: 170px;
}

.thread-link-actions .btn {
  width: 100%;
}

.history-item h3 {
  font-size: 0.96rem;
  line-height: 1.4;
  color: var(--text);
}

.history-item time {
  color: var(--text-soft);
  font-size: 0.76rem;
  white-space: nowrap;
  font-family: "Rubik", sans-serif;
}

.history-item p {
  color: var(--text-muted);
  line-height: 1.6;
  white-space: pre-wrap;
  margin: 0 0 14px;
}

.history-preview {
  display: block;
}

.history-item__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.history-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 11px;
  border-radius: 999px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.72rem;
  line-height: 1;
}

.history-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.empty-state {
  text-align: center;
  padding: 30px 22px;
  border-radius: 18px;
  border: 1px dashed rgba(37, 99, 235, 0.18);
  background: var(--empty-bg);
  color: var(--text-muted);
}

.empty-state i {
  display: block;
  font-size: 1.9rem;
  margin-bottom: 12px;
  color: rgba(37, 99, 235, 0.65);
}

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

.thread-filters {
  display: flex;
  align-items: end;
  gap: 16px;
  flex-wrap: nowrap;
  margin-bottom: 20px;
}

.thread-filters__row {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 16px;
  flex: 1 1 auto;
}

.thread-filters__row--date {
  grid-template-columns: minmax(170px, 1fr) minmax(170px, 1fr) auto;
  align-items: end;
  flex: 1.2 1 auto;
}

.thread-filters__actions {
  display: flex;
  justify-content: flex-end;
  align-items: flex-end;
  white-space: nowrap;
}

.metric-card {
  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid rgba(37, 99, 235, 0.12);
  background: linear-gradient(180deg, rgba(233, 241, 255, 0.9), rgba(255, 255, 255, 0.98));
  display: grid;
  gap: 6px;
}

.metric-card__label {
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-soft);
  font-weight: 700;
}

.metric-card__value {
  font-size: 1.18rem;
  color: var(--text);
}

.history-item--thread {
  display: grid;
  gap: 16px;
}

.history-item--thread.is-collapsed {
  gap: 10px;
}

.history-item--thread.is-collapsed .thread-body {
  display: none;
}

.history-item--thread.is-collapsed .history-item__meta,
.history-item--thread.is-collapsed .thread-info-grid,
.history-item--thread.is-collapsed .history-item__head time {
  display: none;
}

.history-item--thread.is-collapsed:not(.is-thread-active) .thread-progress {
  display: none;
}

.thread-kicker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.thread-kicker__item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.08);
  color: var(--text-muted);
  font-size: 0.72rem;
  line-height: 1;
  border: 1px solid rgba(37, 99, 235, 0.12);
}

.thread-kicker__item i {
  color: var(--primary);
}

.thread-subline {
  margin-top: 6px;
  color: var(--text-muted);
  line-height: 1.55;
  white-space: pre-wrap;
}

.history-item--thread.is-collapsed .thread-subline {
  margin: 0;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 5;
  overflow: hidden;
}

.thread-progress {
  display: grid;
  gap: 8px;
}

.history-item--thread.is-collapsed .thread-progress {
  gap: 6px;
}

.thread-progress__bar {
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.08);
  overflow: hidden;
}

.thread-progress__fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #3b82f6, #11b981);
  transition: width 0.35s ease;
}
/* ── Animated progress bar for active threads ─────────────────── */
.is-thread-active .thread-progress__fill {
  background: linear-gradient(90deg, #3b82f6 0%, #11b981 50%, #3b82f6 100%);
  background-size: 200% 100%;
  animation: progressShimmer 1.8s linear infinite;
}

@keyframes progressShimmer {
  0%   { background-position: 200% 50%; }
  100% { background-position: -200% 50%; }
}


.history-item--thread.is-status-failed .thread-progress__fill,
.thread-message.is-status-failed .history-chip {
  background: linear-gradient(90deg, #db5b5b, #f59f9f);
}

.thread-progress__meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 600;
}

.history-item--thread.is-collapsed .thread-progress__meta {
  font-size: 0.76rem;
}

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

.thread-body {
  display: grid;
}

.thread-details {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 16px;
}

.thread-main {
  display: grid;
  gap: 16px;
  align-self: start;
}

.thread-info-pill {
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  background: rgba(248, 251, 255, 0.84);
  display: grid;
  gap: 4px;
}

.thread-info-pill span {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-soft);
  font-weight: 700;
}

.thread-info-pill strong {
  font-size: 0.9rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread-content-sections,
.thread-conversation {
  display: grid;
  gap: 14px;
}

.thread-toc {
  position: sticky;
  top: calc(var(--topbar-height) + 16px);
  align-self: start;
  max-height: calc(100vh - var(--topbar-height) - 32px);
  overflow-y: auto;
  border-radius: 16px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  background: rgba(255, 255, 255, 0.82);
  padding: 15px;
  box-shadow: var(--shadow-soft);
}

.thread-toc__head {
  margin-bottom: 10px;
}

.thread-toc__head h4 {
  font-size: 0.9rem;
  color: var(--text);
}

.thread-toc__list {
  display: grid;
  gap: 8px;
}

.thread-toc__link {
  display: block;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.82rem;
  line-height: 1.45;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid transparent;
  transition: var(--transition);
}

.thread-toc__link:hover {
  color: var(--primary-strong);
  background: var(--primary-soft);
  border-color: rgba(37, 99, 235, 0.14);
}

.thread-toc__link--active {
  color: var(--text);
  font-weight: 700;
  background: rgba(37, 99, 235, 0.08);
  border-color: rgba(37, 99, 235, 0.2);
}

.thread-toc__link--heading.thread-toc__link--active {
  color: var(--primary-strong);
}

.thread-section,
.thread-message,
.thread-root-message {
  border-radius: 16px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  background: rgba(255, 255, 255, 0.78);
  padding: 15px 16px;
}

.thread-section__head,
.thread-message__head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 10px;
}

.thread-section__head h4 {
  font-size: 0.92rem;
  color: var(--text);
}

.thread-section__hint {
  margin: 6px 0 0;
  color: var(--text-soft);
  font-size: 0.83rem;
  line-height: 1.55;
}

.thread-pre {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.6;
  color: var(--text-muted);
  font-family: "Rubik", sans-serif;
}

.thread-pre--compact {
  font-size: 0.88rem;
}

.thread-markdown {
  display: grid;
  gap: 2px;
  margin: 0;
  color: var(--text-muted);
  font-family: "Rubik", sans-serif;
}

.thread-markdown__line {
  white-space: pre-wrap;
  line-height: 1.6;
}

.thread-markdown__heading {
  scroll-margin-top: 96px;
  color: var(--text);
  font-weight: 700;
}

.thread-markdown__heading--h1 {
  margin-top: 10px;
  font-size: 1rem;
}

.thread-markdown__heading--h2 {
  margin-top: 8px;
  font-size: 0.92rem;
  color: var(--primary-strong);
}

.thread-markdown__line--empty {
  min-height: 0.85rem;
}

.thread-toc__link--heading {
  padding-left: 18px;
  font-size: 0.78rem;
}

.thread-toc__link--heading-h1 {
  border-left: 2px solid rgba(37, 99, 235, 0.18);
}

.thread-toc__link--heading-h2 {
  margin-left: 10px;
  border-left: 2px solid rgba(17, 185, 129, 0.18);
}

.thread-section--result {
  background: linear-gradient(180deg, rgba(17, 185, 129, 0.08), rgba(255, 255, 255, 0.98));
}

.thread-section--error,
.thread-message.is-status-failed {
  background: linear-gradient(180deg, rgba(219, 91, 91, 0.08), rgba(255, 255, 255, 0.98));
}

.thread-section,
.thread-message,
.thread-root-message {
  scroll-margin-top: 96px;
}

.thread-root-message {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
  align-items: flex-start;
}

.thread-root-message__icon {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-soft);
  color: var(--primary);
}

.thread-root-message p,
.thread-message p {
  margin: 6px 0 0;
  color: var(--text-muted);
  line-height: 1.6;
}

.thread-message {
  display: grid;
  gap: 10px;
}

.thread-message__status {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.thread-message__duration {
  color: var(--text-soft);
  font-size: 0.76rem;
}

.thread-message--revision {
  margin-top: 12px;
  margin-left: 18px;
  border-left: 3px solid rgba(37, 99, 235, 0.18);
}

.thread-message--ai-comment {
  margin-top: 12px;
  margin-left: 18px;
  border-left: 3px solid rgba(245, 158, 11, 0.22);
  background: linear-gradient(180deg, rgba(245, 158, 11, 0.08), rgba(255, 255, 255, 0.98));
}

.thread-message--ai-recommendation {
  margin-top: 12px;
  margin-left: 18px;
  border-left: 3px solid rgba(16, 185, 129, 0.22);
  background: linear-gradient(180deg, rgba(16, 185, 129, 0.08), rgba(255, 255, 255, 0.98));
}

.thread-message__error {
  color: var(--danger);
  margin: 0;
  font-size: 0.84rem;
}

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

.thread-comment-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.detail-banner {
  margin-bottom: 14px;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid rgba(37, 99, 235, 0.14);
  background: var(--detail-bg);
  color: var(--text-muted);
  font-size: 0.84rem;
}

.embed-frame-wrap {
  width: 100%;
  min-height: 72vh;
  overflow: hidden;
  border-radius: 18px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  background: var(--iframe-bg);
  box-shadow: var(--iframe-shadow);
}

.embed-frame-wrap--backlinks {
  min-height: 78vh;
}

.embed-frame {
  width: 100%;
  min-height: 72vh;
  border: 0;
  background: var(--iframe-bg);
}

html[data-theme="dark"] .card {
  border-color: rgba(167, 188, 235, 0.1);
}

html[data-theme="dark"] .card::before {
  background: linear-gradient(90deg, rgba(107, 165, 255, 0.28), rgba(33, 208, 154, 0.14), transparent 80%);
}

html[data-theme="dark"] .sidebar-toggle,
html[data-theme="dark"] .mobile-menu-btn,
html[data-theme="dark"] .nav-item,
html[data-theme="dark"] .topbar-user,
html[data-theme="dark"] .theme-toggle,
html[data-theme="dark"] .breadcrumb {
  border-color: rgba(167, 188, 235, 0.12);
}

html[data-theme="dark"] .form-input,
html[data-theme="dark"] .btn-secondary,
html[data-theme="dark"] .status-box,
html[data-theme="dark"] .history-item,
html[data-theme="dark"] .history-chip,
html[data-theme="dark"] .embed-frame-wrap {
  border-color: rgba(167, 188, 235, 0.12);
}

html[data-theme="dark"] .sidebar-overlay {
  background: rgba(2, 6, 23, 0.62);
}


/* ── Thread toggle group (collapse + doc-actions) ─────────────── */
.thread-toggle-group {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.thread-doc-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* ── KI-Rückfragen Checkbox ───────────────────────────────────── */
.form-checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  cursor: pointer;
  transition: var(--transition);
}

.form-checkbox-row:hover {
  border-color: rgba(37, 99, 235, 0.2);
  background: var(--primary-soft);
}

.form-checkbox-row input[type="checkbox"] {
  width: 17px;
  height: 17px;
  cursor: pointer;
  accent-color: var(--primary);
  flex-shrink: 0;
}

.form-checkbox-row__label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 7px;
}

.form-checkbox-row__label i {
  color: var(--primary);
}

.form-checkbox-row__hint {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--text-soft);
  white-space: nowrap;
}

/* ── KI Question Card ─────────────────────────────────────────── */
.question-card {
  margin-top: 20px;
  border-radius: 18px;
  border: 1px solid rgba(37, 99, 235, 0.22);
  background: var(--detail-bg);
  overflow: hidden;
  animation: fadeInUp 0.22s ease;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.question-card__head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.09), rgba(37, 99, 235, 0.02));
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.question-card__head-icon {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-soft);
  color: var(--primary);
  flex-shrink: 0;
  font-size: 1rem;
}

.question-card__head-text strong {
  font-size: 0.96rem;
  color: var(--text);
  display: block;
  margin-bottom: 2px;
}

.question-card__head-text p {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.45;
}

.question-card__body {
  padding: 20px;
  display: grid;
  gap: 16px;
}

.question-item {
  display: grid;
  gap: 7px;
}

.question-item__label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.5;
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.question-item__num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 1px;
}

.question-card__actions {
  padding: 4px 20px 20px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.card--history,
.card--thread-detail {
  overflow: visible;
}

.hidden {
  display: none;
}

@media (max-width: 1200px) {
  .content-metrics,
  .thread-info-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .thread-filters {
    display: grid;
  }

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

  .thread-filters__actions {
    justify-content: flex-start;
    grid-column: 1 / -1;
  }
}

@media (max-width: 1200px) {
  .dashboard-grid--wide,
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .thread-details {
    grid-template-columns: 1fr;
  }

  .thread-toc {
    position: sticky;
    top: calc(var(--topbar-height) + 12px);
    order: -1;
  }

  .sidebar {
    top: 0;
    left: 0;
    bottom: 0;
    border-radius: 0 24px 24px 0;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay.open {
    display: block;
  }

  .main-content {
    margin-left: 0;
    width: 100%;
  }

  .mobile-menu-btn {
    display: inline-flex;
  }

  .topbar {
    padding: 18px 18px 10px;
  }

  .page-content {
    padding: 8px 18px 24px;
  }

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

  .thread-filters {
    display: grid;
  }

  .thread-filters__row {
    grid-template-columns: 1fr;
  }
}

.research-filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.worker-badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

.discovery-list {
  display: grid;
  gap: 14px;
}

.discovery-card {
  padding: 16px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-strong);
  box-shadow: var(--shadow-soft);
}

.discovery-card__head {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.discovery-card__type,
.discovery-card__country,
.discovery-card__status {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-strong);
}

.discovery-card__title {
  margin: 0 0 8px;
  font-size: 1.05rem;
}

.discovery-card__meta,
.discovery-card__angle,
.discovery-card__links {
  margin: 0 0 8px;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.discovery-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.mentions-table-wrap {
  overflow-x: auto;
}

.mentions-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.mentions-table th,
.mentions-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.mentions-table th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.mentions-row--unread {
  background: var(--primary-soft);
}

.mentions-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 24px 12px;
}

.empty-state {
  padding: 28px 16px;
  text-align: center;
  color: var(--text-muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: var(--empty-bg);
}

@media (max-width: 640px) {
  .content-metrics,
  .thread-info-grid {
    grid-template-columns: 1fr;
  }

  .topbar-right {
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .topbar-time {
    display: none;
  }

  .theme-toggle span {
    display: none;
  }

  .card-header,
  .history-item__head {
    flex-direction: column;
    align-items: flex-start;
  }

  .history-item__head-actions {
    width: 100%;
    align-items: flex-start;
  }

  .thread-link-actions {
    min-width: 0;
  }

  .thread-section__head,
  .thread-message__head,
  .thread-comment-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .thread-message--revision {
    margin-left: 0;
  }

  .thread-message--ai-comment,
  .thread-message--ai-recommendation {
      margin-left: 0;
    }

  .thread-toc__link {
    font-size: 0.8rem;
  }

  .card-body,
  .card-header {
    padding-left: 18px;
    padding-right: 18px;
  }
}
