:root {
  --bg: #050505;
  --panel: #0c0b0a;
  --panel-2: #13110f;
  --ink: #f4eee5;
  --muted: #a9a096;
  --line: rgba(244, 238, 229, 0.12);
  --gold: #c79f62;
  --bronze: #8d552e;
  --cream: #efe9dd;
  --button: #efe9dd;
  --button-ink: #13110f;
  --button-hover: #fff8ea;
  --soft-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
  --touch-shadow: 0 12px 28px rgba(0, 0, 0, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  --touch-shadow-strong: 0 18px 40px rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.22);
  --motion-smooth: cubic-bezier(0.2, 0.78, 0.18, 1);
  --motion-settle: cubic-bezier(0.18, 0.92, 0.16, 1);
  --motion-hover: 360ms;
  --motion-press: 180ms;
  --glass-fill: color-mix(in srgb, var(--panel) 84%, transparent);
  --glass-fill-strong: color-mix(in srgb, var(--panel) 93%, transparent);
  --danger: #d76b5d;
  --ok: #8fc7a0;
}

.theme-light {
  --bg: #eee8dc;
  --panel: #fbf7ef;
  --panel-2: #f4ecdf;
  --ink: #19140f;
  --muted: #766b60;
  --line: rgba(57, 42, 28, 0.16);
  --gold: #9d6a2f;
  --bronze: #8b552d;
  --cream: #fffaf0;
  --button: #19140f;
  --button-ink: #fffaf0;
  --button-hover: #2b2118;
  --soft-shadow: 0 22px 58px rgba(93, 70, 46, 0.16);
  --touch-shadow: 0 12px 26px rgba(70, 48, 28, 0.14), inset 0 1px 0 rgba(255, 255, 255, 0.7);
  --touch-shadow-strong: 0 18px 38px rgba(70, 48, 28, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.78);
  --glass-fill: rgba(255, 250, 240, 0.66);
  --glass-fill-strong: rgba(255, 250, 240, 0.82);
  --danger: #b65349;
  --ok: #3d7c56;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  background: var(--bg);
}

@keyframes titleReveal {
  0% {
    opacity: 0;
    transform: translateX(-38px) translateY(2px) scale(0.975);
    filter: blur(12px);
  }
  62% {
    opacity: 1;
    transform: translateX(7px) translateY(0) scale(1.012);
    filter: blur(0);
  }
  100% {
    opacity: 1;
    transform: translateX(0) translateY(0) scale(1);
    filter: blur(0);
  }
}

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

button,
.button-link,
.header-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 20px;
  border: 1px solid color-mix(in srgb, var(--cream) 76%, transparent);
  border-radius: 999px;
  color: var(--button-ink);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-decoration: none;
  text-transform: uppercase;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.24), transparent 48%),
    var(--button);
  box-shadow: var(--touch-shadow);
  cursor: pointer;
  transition:
    transform var(--motion-hover) var(--motion-settle),
    background var(--motion-hover) ease,
    border-color var(--motion-hover) ease,
    box-shadow var(--motion-hover) var(--motion-smooth),
    color var(--motion-hover) ease;
}

button:hover,
.button-link:hover,
.header-action:hover {
  background: var(--button-hover);
  transform: translateY(-1px);
  box-shadow: var(--touch-shadow-strong);
}

button:active,
.button-link:active,
.header-action:active {
  transform: translateY(0) scale(0.985);
  transition-duration: var(--motion-press);
}

.login-body {
  min-height: 100vh;
  background:
    linear-gradient(rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0.92)),
    url("https://timeless.club/uploads/images/al_habtoor/1.jpg") center / cover,
    var(--bg);
}

.login-body.theme-light {
  background:
    linear-gradient(rgba(238, 232, 220, 0.66), rgba(238, 232, 220, 0.92)),
    url("https://timeless.club/uploads/images/al_habtoor/1.jpg") center / cover,
    var(--bg);
}

.login-screen {
  display: grid;
  grid-template-columns: minmax(0, 820px) 390px;
  gap: clamp(34px, 5vw, 82px);
  align-items: center;
  min-height: 100vh;
  width: min(1320px, calc(100% - 40px));
  margin: 0 auto;
}

.login-copy span,
.page-header p,
.form-kicker {
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.42em;
  text-transform: uppercase;
}

.login-brand-lockup {
  display: flex;
  align-items: center;
  gap: clamp(22px, 3.4vw, 46px);
  margin: 18px 0;
  min-width: 0;
}

.login-copy h1 {
  margin: 18px 0;
  font-family: Didot, "Bodoni 72", Georgia, serif;
  font-size: clamp(3.8rem, 5vw, 5.6rem);
  font-weight: 300;
  line-height: 0.96;
  white-space: nowrap;
}

.login-copy p {
  max-width: 620px;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.7;
}

.login-card,
.panel,
.stat-card,
.status-card,
.topic-card,
.logout-form {
  border: 1px solid color-mix(in srgb, var(--line) 88%, transparent);
  border-radius: 22px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), transparent 46%),
    radial-gradient(circle at 20% 0%, rgba(199, 159, 98, 0.08), transparent 34%),
    var(--glass-fill-strong);
  box-shadow: var(--touch-shadow);
  backdrop-filter: blur(16px) saturate(1.14);
}

.panel,
.stat-card,
.status-card,
.topic-card,
.resource-row {
  transform: translateY(0) scale(1);
  transform-origin: center;
  transition:
    transform 420ms var(--motion-settle),
    box-shadow 420ms var(--motion-smooth),
    border-color 360ms ease,
    background 420ms ease,
    filter 420ms ease;
  will-change: transform;
}

.panel:hover,
.stat-card:hover,
.status-card:hover,
.topic-card:hover,
.resource-row:hover {
  border-color: color-mix(in srgb, var(--gold) 32%, var(--line));
  transform: translateY(-5px) scale(1.014);
  box-shadow: var(--touch-shadow-strong);
}

.panel:active,
.stat-card:active,
.status-card:active,
.topic-card:active,
.resource-row:active {
  transform: translateY(-2px) scale(1.006);
  transition-duration: var(--motion-press);
}

.login-card {
  display: grid;
  gap: 18px;
  padding: 28px;
}

.stack-form {
  display: grid;
}

label {
  display: grid;
  gap: 14px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.login-card label {
  gap: 12px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid color-mix(in srgb, var(--line) 86%, transparent);
  border-radius: 18px;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), transparent 56%),
    color-mix(in srgb, var(--panel-2) 86%, transparent);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), inset 0 -16px 28px rgba(0, 0, 0, 0.08);
  transition:
    border-color var(--motion-hover) ease,
    box-shadow var(--motion-hover) var(--motion-smooth),
    background var(--motion-hover) ease;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--gold) 72%, var(--line));
  box-shadow:
    0 0 0 3px color-mix(in srgb, var(--gold) 18%, transparent),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

input,
select {
  min-height: 44px;
  padding: 0 14px;
}

input[type="range"] {
  min-height: 22px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  box-shadow: none;
  accent-color: var(--gold);
}

input[type="file"] {
  min-height: 54px;
  padding: 10px;
  color: var(--muted);
}

input[type="file"]::file-selector-button {
  min-height: 34px;
  margin-right: 12px;
  padding: 0 14px;
  border: 1px solid color-mix(in srgb, var(--cream) 70%, transparent);
  border-radius: 999px;
  color: var(--button-ink);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.24), transparent 48%),
    var(--button);
  box-shadow: var(--touch-shadow);
  cursor: pointer;
}

input[type="file"]::file-selector-button:hover {
  background: var(--button-hover);
}

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

.form-error {
  margin: 0;
  color: var(--danger);
  font-weight: 800;
}

.shell {
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  grid-template-rows: 92px 1fr;
  min-height: 100vh;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--bg) 96%, #000 4%) 0, color-mix(in srgb, var(--bg) 96%, #000 4%) 82px, var(--bg) 190px),
    var(--bg);
}

.theme-light .shell {
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--bg) 96%, #fff 4%) 0, color-mix(in srgb, var(--bg) 96%, #fff 4%) 82px, var(--bg) 190px),
    var(--bg);
}

.app-topbar {
  position: relative;
  z-index: 4;
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: 292px minmax(0, 1fr) auto;
  align-items: center;
  min-width: 0;
  padding: 0 clamp(18px, 3vw, 54px) 0 18px;
  background:
    linear-gradient(90deg, color-mix(in srgb, var(--panel) 92%, transparent), transparent 56%),
    color-mix(in srgb, var(--bg) 96%, #000 4%);
}

.app-topbar::after {
  content: none;
}

.theme-light .app-topbar {
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.16), transparent 64%),
    color-mix(in srgb, var(--bg) 96%, #fff 4%);
}

.theme-light .app-topbar::after {
  content: none;
}

.sidebar {
  position: relative;
  z-index: 1;
  grid-column: 1;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: calc(100vh - 92px);
  padding: 0 18px 18px;
  border-right: 0;
  background: transparent;
}

.theme-light .sidebar {
  background: transparent;
}

.brand-strip {
  display: flex;
  align-items: center;
  min-width: 0;
  min-height: 100%;
  margin: 0;
  padding: 0;
  background: transparent;
}

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

.brand-trigger {
  justify-content: flex-start;
  min-height: 44px;
  padding: 0;
  border: 0;
  border-radius: 14px;
  color: var(--ink);
  text-transform: none;
  background: transparent;
  box-shadow: none;
}

.brand-trigger:hover {
  background: transparent;
  box-shadow: none;
  transform: none;
}

.brand-trigger:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--gold) 72%, transparent);
  outline-offset: 6px;
}

.brand-wordmark {
  display: inline-flex;
  align-items: baseline;
  gap: 0.22em;
  min-width: 0;
  white-space: nowrap;
  font-family: Didot, "Bodoni 72", Georgia, serif;
  font-size: 1.48rem;
  font-weight: 300;
  overflow: visible;
  text-overflow: ellipsis;
}

.brand-x {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 0.86em;
  height: 1.22em;
  color: var(--ink);
}

.brand-x-letter {
  transform-origin: 50% 62%;
  transition: opacity 260ms ease, transform 520ms cubic-bezier(0.16, 1, 0.3, 1), filter 360ms ease;
}

.brand-hookah {
  position: absolute;
  left: 50%;
  bottom: -0.03em;
  width: 0.9em;
  height: 1.22em;
  color: var(--ink);
  opacity: 0;
  transform: translateX(-50%) translateY(0.14em) scale(0.82);
  transform-origin: 50% 100%;
  transition: opacity 260ms ease 90ms, transform 620ms cubic-bezier(0.16, 1, 0.3, 1) 70ms;
  pointer-events: none;
}

.hookah-bowl,
.hookah-stem,
.hookah-base,
.hookah-hose,
.hookah-smoke {
  position: absolute;
  display: block;
}

.hookah-bowl {
  left: 50%;
  top: 0.1em;
  width: 0.4em;
  height: 0.15em;
  border: 1px solid currentColor;
  border-radius: 0.08em 0.08em 0.18em 0.18em;
  transform: translateX(-50%);
  background: color-mix(in srgb, var(--gold) 18%, transparent);
}

.hookah-stem {
  left: 50%;
  top: 0.25em;
  width: 1px;
  height: 0.58em;
  border-radius: 999px;
  background: currentColor;
  transform: translateX(-50%);
}

.hookah-base {
  left: 50%;
  bottom: 0.03em;
  width: 0.48em;
  height: 0.34em;
  border: 1px solid currentColor;
  border-radius: 48% 48% 42% 42%;
  transform: translateX(-50%);
  background: radial-gradient(circle at 50% 18%, color-mix(in srgb, var(--gold) 28%, transparent), transparent 58%);
}

.hookah-hose {
  right: 0.04em;
  bottom: 0.27em;
  width: 0.42em;
  height: 0.4em;
  border-right: 1px solid currentColor;
  border-bottom: 1px solid currentColor;
  border-radius: 0 0 0.34em 0;
  transform: rotate(-12deg);
}

.hookah-smoke {
  z-index: 3;
  left: 50%;
  top: -0.36em;
  width: 0.86em;
  height: 0.86em;
  border: 1.5px solid color-mix(in srgb, var(--ink) 34%, transparent);
  border-right-color: transparent;
  border-bottom-color: transparent;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 34%, color-mix(in srgb, var(--ink) 13%, transparent), transparent 62%);
  opacity: 0;
  transform: translateX(-50%) translateY(0.28em) scale(0.34) rotate(-18deg);
  filter: blur(0.75px);
}

.smoke-two {
  margin-left: 0.12em;
  animation-delay: 170ms;
}

.smoke-three {
  margin-left: -0.12em;
  animation-delay: 310ms;
}

.brand-trigger.is-hookah-active .brand-x-letter {
  opacity: 0;
  transform: scale(0.42) rotate(-18deg);
  filter: blur(4px);
}

.brand-trigger.is-hookah-active .brand-hookah {
  opacity: 1;
  transform: translateX(-50%) translateY(0) scale(1);
}

.brand-trigger.is-hookah-active .hookah-smoke {
  animation: hookahSmoke 2.8s cubic-bezier(0.16, 1, 0.3, 1) infinite;
}

@keyframes hookahSmoke {
  0% {
    opacity: 0;
    transform: translateX(-50%) translateY(0.28em) scale(0.34) rotate(-18deg);
  }
  18% {
    opacity: 0.56;
  }
  64% {
    opacity: 0.3;
  }
  100% {
    opacity: 0;
    transform: translateX(-50%) translateY(-1.28em) scale(2.15) rotate(22deg);
  }
}

.rai-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 38px;
  height: 36px;
  border-radius: 10px;
  background: none;
}

.rai-mark img {
  display: block;
  width: 30px;
  height: 29px;
  object-fit: contain;
}

.theme-light .rai-mark {
  background: none;
}

.theme-light .rai-mark img {
  content: url("/static/rai-logo-light.png");
}

.login-rai-mark {
  width: clamp(126px, 8.6vw, 154px);
  height: clamp(120px, 8.2vw, 148px);
  border-radius: 0;
  background: none;
  box-shadow: none;
  backdrop-filter: none;
}

.login-rai-mark img {
  width: 100%;
  height: 100%;
  background: transparent;
}

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

.topbar-title {
  min-width: 0;
  padding: 0 clamp(24px, 3vw, 44px);
}

.topbar-title h1 {
  margin: 0;
  font-family: Didot, "Bodoni 72", Georgia, serif;
  font-size: 1.48rem;
  font-weight: 300;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  animation: titleReveal 980ms cubic-bezier(0.16, 1, 0.3, 1) 80ms both;
  will-change: opacity, transform, filter;
}

.nav {
  display: grid;
  gap: 0;
  border-top: 1px solid var(--line);
}

.nav-link {
  position: relative;
  display: grid;
  gap: 3px;
  min-height: 58px;
  padding: 13px 4px 12px 18px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  color: var(--ink);
  text-decoration: none;
  background: transparent;
  transition:
    color var(--motion-hover) ease,
    background 420ms ease,
    transform 420ms var(--motion-settle);
}

.nav-link:hover,
.nav-link.is-active {
  color: var(--cream);
  background: linear-gradient(90deg, rgba(199, 159, 98, 0.12), transparent 70%);
}

.nav-link:hover {
  transform: translateX(5px);
}

.nav-link::before {
  position: absolute;
  left: 0;
  top: 16px;
  bottom: 16px;
  width: 2px;
  border-radius: 999px;
  background: transparent;
  content: "";
}

.nav-link.is-active::before {
  background: var(--gold);
}

.nav-link span {
  color: var(--muted);
  font-size: 0.76rem;
}

.logout-form {
  display: grid;
  gap: 12px;
  margin-top: auto;
  padding: 18px 0 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.sidebar-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.compact-controls {
  width: fit-content;
  min-height: 34px;
  padding: 3px;
  border: 1px solid color-mix(in srgb, var(--line) 78%, transparent);
  border-radius: 999px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent 56%),
    color-mix(in srgb, var(--panel) 74%, transparent);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    inset 0 -14px 28px rgba(0, 0, 0, 0.12);
  backdrop-filter: blur(14px) saturate(1.18);
}

.inline-switch {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0;
}

.inline-switch button {
  min-width: 42px;
  min-height: 28px;
  padding: 0 10px;
  border-color: transparent;
  border-radius: 999px;
  color: color-mix(in srgb, var(--muted) 86%, var(--ink));
  font-size: 0.66rem;
  letter-spacing: 0.04em;
  background: transparent;
  box-shadow: none;
  transform: none;
  transition:
    color var(--motion-hover) ease,
    background var(--motion-hover) ease,
    box-shadow var(--motion-hover) var(--motion-smooth),
    transform var(--motion-hover) var(--motion-settle);
}

.inline-switch button:hover {
  color: var(--ink);
  background: color-mix(in srgb, var(--ink) 8%, transparent);
}

.inline-switch button.is-active {
  color: var(--button-ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.26), transparent 48%),
    var(--button);
  box-shadow:
    0 8px 18px rgba(0, 0, 0, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.34);
  transform: translateY(-1px);
}

.switch-divider {
  width: 1px;
  height: 24px;
  margin: 0 2px;
  background: color-mix(in srgb, var(--line) 84%, transparent);
}

.theme-light .compact-controls {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), transparent 64%),
    rgba(25, 20, 15, 0.06);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.72),
    inset 0 -12px 26px rgba(25, 20, 15, 0.06);
}

.theme-light .inline-switch button.is-active {
  box-shadow:
    0 8px 18px rgba(25, 20, 15, 0.14),
    inset 0 1px 0 rgba(255, 255, 255, 0.34);
}

.main {
  position: relative;
  z-index: 1;
  grid-column: 2;
  display: grid;
  align-content: start;
  gap: 22px;
  min-width: 0;
  padding: 24px clamp(22px, 3vw, 54px) 92px;
}

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

.page-header h1 {
  margin: 0;
  font-family: Didot, "Bodoni 72", Georgia, serif;
  font-size: clamp(3rem, 6vw, 6.2rem);
  font-weight: 300;
  line-height: 0.95;
}

.stats-grid,
.status-grid,
.settings-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.stat-card {
  display: grid;
  gap: 8px;
  min-height: 116px;
  padding: 22px;
}

.stat-card span,
.topic-card span,
.panel-head span,
th {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.stat-card strong {
  font-family: Didot, "Bodoni 72", Georgia, serif;
  font-size: 3.2rem;
  font-weight: 300;
}

.status-card {
  display: flex;
  gap: 12px;
  min-height: 104px;
  padding: 18px;
}

.settings-card {
  align-items: center;
  min-height: 96px;
}

.settings-card strong,
.settings-card p {
  white-space: nowrap;
}

.settings-card p {
  margin: 8px 0 0;
}

.status-dot {
  width: 10px;
  height: 10px;
  margin-top: 6px;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 4px color-mix(in srgb, currentColor 12%, transparent);
}

.status-connected .status-dot { background: var(--ok); }
.status-error .status-dot { background: var(--danger); }
.status-not_connected .status-dot { background: var(--gold); }

.status-card strong,
.panel h2,
.topic-card h3 {
  margin: 0;
}

.queue-state {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  width: fit-content;
  min-height: 30px;
  padding: 6px 11px;
  border: 1px solid color-mix(in srgb, var(--gold) 30%, var(--line));
  border-radius: 999px;
  color: var(--gold);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent 54%),
    color-mix(in srgb, var(--gold) 9%, transparent);
}

.queue-state span {
  color: color-mix(in srgb, var(--muted) 78%, var(--gold));
  font-size: inherit;
  letter-spacing: 0;
  text-transform: none;
}

.queue-state strong {
  color: var(--gold);
  font-size: inherit;
  font-weight: 900;
  white-space: nowrap;
}

.status-card p,
.panel p,
.topic-card p {
  color: var(--muted);
  line-height: 1.55;
}

.status-card small {
  color: var(--gold);
  font-weight: 800;
  text-transform: uppercase;
}

.status-meta {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
}

.panel {
  min-width: 0;
  padding: 22px;
}

.search-layout .panel {
  padding: clamp(28px, 3vw, 44px);
}

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

.panel-head.compact {
  align-items: center;
  margin-bottom: 30px;
}

.panel h2 {
  font-family: Didot, "Bodoni 72", Georgia, serif;
  font-size: 2rem;
  font-weight: 300;
}

.search-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(20px, 2.4vw, 34px);
}

.stack-form {
  gap: 26px;
}

.search-layout .stack-form {
  gap: 30px;
}

.search-layout .stack-form label {
  gap: 16px;
}

.search-layout input:not([type="checkbox"]):not([type="hidden"]) {
  min-height: 58px;
  padding: 0 18px;
  border-radius: 23px;
  font-size: 0.95rem;
}

.tag-editor {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 10px;
  min-height: 128px;
  width: 100%;
  padding: 15px;
  border: 1px solid color-mix(in srgb, var(--line) 86%, transparent);
  border-radius: 24px;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), transparent 56%),
    color-mix(in srgb, var(--panel-2) 86%, transparent);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), inset 0 -16px 28px rgba(0, 0, 0, 0.08);
  cursor: text;
  transition:
    border-color var(--motion-hover) ease,
    box-shadow var(--motion-hover) var(--motion-smooth),
    background var(--motion-hover) ease;
}

.tag-editor:focus-within {
  border-color: color-mix(in srgb, var(--gold) 72%, var(--line));
  box-shadow:
    0 0 0 3px color-mix(in srgb, var(--gold) 18%, transparent),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.tag-editor.is-invalid {
  border-color: color-mix(in srgb, var(--danger) 76%, var(--line));
  box-shadow:
    0 0 0 3px color-mix(in srgb, var(--danger) 14%, transparent),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.tag-list {
  display: contents;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  max-width: 100%;
  padding: 0 8px 0 13px;
  border: 1px solid color-mix(in srgb, var(--gold) 36%, var(--line));
  border-radius: 999px;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: none;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.18), transparent 54%),
    color-mix(in srgb, var(--gold) 12%, var(--panel));
  box-shadow:
    0 8px 18px rgba(0, 0, 0, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.16);
  transition:
    transform var(--motion-hover) var(--motion-settle),
    border-color var(--motion-hover) ease,
    box-shadow var(--motion-hover) var(--motion-smooth);
}

.tag-chip button {
  display: inline-grid;
  place-items: center;
  min-height: 24px;
  width: 24px;
  padding: 0;
  border-radius: 999px;
  font-size: 1rem;
  line-height: 1;
  letter-spacing: 0;
  box-shadow: none;
}

.tag-chip button:hover {
  transform: scale(1.08);
}

.tag-editor input {
  flex: 1 1 220px;
  min-width: min(220px, 100%);
  min-height: 36px !important;
  padding: 0 10px !important;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.tag-editor input:focus {
  box-shadow: none;
}

.check-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}

.check-row label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.check-row input {
  width: auto;
  min-height: auto;
}

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

.topic-card {
  position: relative;
  display: grid;
  gap: 12px;
  padding: 18px;
  cursor: pointer;
}

.topic-delete-form {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 2;
  margin: 0;
}

.topic-card:focus-visible {
  outline: none;
  border-color: color-mix(in srgb, var(--gold) 72%, var(--line));
  box-shadow:
    0 0 0 3px color-mix(in srgb, var(--gold) 18%, transparent),
    var(--touch-shadow-strong);
}

.keyword-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.keyword-list span,
.keyword-more,
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 11px;
  border: 1px solid color-mix(in srgb, var(--line) 84%, transparent);
  border-radius: 999px;
  color: var(--cream);
  font-size: 0.74rem;
  font-weight: 800;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent 52%),
    rgba(255, 255, 255, 0.04);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  transition:
    transform var(--motion-hover) var(--motion-settle),
    border-color var(--motion-hover) ease,
    background var(--motion-hover) ease,
    box-shadow var(--motion-hover) var(--motion-smooth);
}

.topic-card:hover .keyword-list span,
.topic-card:hover .keyword-more {
  transform: translateY(-1px);
  border-color: color-mix(in srgb, var(--gold) 28%, var(--line));
}

.theme-light .keyword-list span,
.theme-light .keyword-more,
.theme-light .badge {
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.64), transparent 58%),
    rgba(255, 255, 255, 0.46);
}

.keyword-more {
  width: auto;
  border-color: color-mix(in srgb, var(--gold) 38%, var(--line));
  color: var(--gold);
  cursor: pointer;
}

.keyword-dialog {
  width: min(560px, calc(100vw - 36px));
  padding: 22px;
  border: 1px solid color-mix(in srgb, var(--line) 88%, transparent);
  border-radius: 22px;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent 46%),
    radial-gradient(circle at 20% 0%, rgba(199, 159, 98, 0.1), transparent 34%),
    var(--glass-fill-strong);
  box-shadow: var(--touch-shadow-strong);
  backdrop-filter: blur(18px) saturate(1.16);
}

.keyword-dialog[open] {
  animation: dialogSettle 360ms var(--motion-settle) both;
}

.keyword-dialog::backdrop {
  background: rgba(0, 0, 0, 0.54);
  backdrop-filter: blur(4px);
}

.keyword-dialog[open]::backdrop {
  animation: backdropSettle 360ms ease both;
}

@keyframes dialogSettle {
  0% {
    opacity: 0;
    transform: translateY(18px) scale(0.975);
    filter: blur(8px);
  }
  72% {
    opacity: 1;
    transform: translateY(-2px) scale(1.004);
    filter: blur(0);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: blur(0);
  }
}

@keyframes backdropSettle {
  0% {
    opacity: 0;
    backdrop-filter: blur(0);
  }
  100% {
    opacity: 1;
    backdrop-filter: blur(4px);
  }
}

.keyword-dialog-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.keyword-dialog-head h3 {
  margin: 5px 0 0;
  font-size: 1.28rem;
}

.keyword-list-full {
  max-height: 46vh;
  overflow: auto;
}

.badge-target,
.badge-warm_target,
.badge-sent,
.badge-joined {
  border-color: rgba(143, 199, 160, 0.45);
  color: var(--ok);
}

.badge-rejected,
.badge-error,
.badge-join_failed {
  border-color: rgba(215, 107, 93, 0.45);
  color: var(--danger);
}

.badge-not_connected,
.badge-found {
  border-color: rgba(199, 159, 98, 0.45);
  color: var(--gold);
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border-radius: 18px;
}

table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
}

th,
td {
  padding: 14px 12px;
  border-top: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

td {
  color: var(--ink);
  font-size: 0.92rem;
}

tbody tr {
  transition: background var(--motion-hover) ease;
}

tbody tr:hover {
  background: color-mix(in srgb, var(--ink) 4%, transparent);
}

.excerpt {
  max-width: 520px;
  color: var(--muted);
  line-height: 1.55;
}

.assistant-panel textarea {
  min-height: 160px;
}

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

.assistant-prompt-panel {
  max-width: 1180px;
}

.prompt-area {
  min-height: 280px;
  line-height: 1.55;
}

.temperature-control {
  padding: 16px 18px;
  border: 1px solid color-mix(in srgb, var(--line) 86%, transparent);
  border-radius: 20px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), transparent 56%),
    color-mix(in srgb, var(--panel-2) 80%, transparent);
}

.temperature-control > span {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.temperature-control strong {
  color: var(--ink);
  font-weight: 900;
}

.field-help,
.quiet-meta {
  color: var(--muted);
  font-size: 0.82rem;
}

.upload-widget {
  display: grid;
  gap: 20px;
  margin-top: 22px;
}

.assistant-two-col {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(160px, 0.65fr);
  gap: 18px;
}

.usage-meter {
  display: grid;
  gap: 8px;
  margin: 18px 0 16px;
  padding: 12px;
  border: 1px solid color-mix(in srgb, var(--line) 78%, transparent);
  border-radius: 20px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), transparent 58%),
    color-mix(in srgb, var(--panel-2) 54%, transparent);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.usage-meter-head,
.usage-meter-foot {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.usage-meter-head span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.usage-meter-head strong {
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 900;
}

.usage-meter-foot {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.usage-bar {
  position: relative;
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent 56%),
    color-mix(in srgb, var(--muted) 18%, transparent);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.18);
}

.usage-bar::after {
  position: absolute;
  inset: 0;
  border: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  border-radius: inherit;
  content: "";
  pointer-events: none;
}

.usage-bar span {
  display: block;
  height: 100%;
  min-width: 4px;
  border-radius: inherit;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.28), transparent 46%),
    var(--gold);
}

.resource-list {
  display: grid;
  gap: 12px;
}

.runtime-list {
  display: grid;
  gap: 10px;
}

.runtime-row {
  display: grid;
  grid-template-columns: minmax(160px, 0.45fr) minmax(0, 1fr);
  gap: 8px 16px;
  align-items: baseline;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.runtime-row:last-child {
  border-bottom: 0;
}

.runtime-row span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.runtime-row strong,
.runtime-row small {
  min-width: 0;
  overflow-wrap: anywhere;
}

.runtime-row small {
  grid-column: 2;
  color: var(--muted);
}

.resource-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid color-mix(in srgb, var(--line) 84%, transparent);
  border-radius: 20px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), transparent 54%),
    color-mix(in srgb, var(--panel-2) 72%, transparent);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.resource-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid color-mix(in srgb, var(--gold) 36%, var(--line));
  border-radius: 14px;
  color: var(--gold);
  font-size: 0.66rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.1), transparent 54%),
    color-mix(in srgb, var(--gold) 10%, transparent);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.resource-row div {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.resource-row strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.resource-row span,
.resource-row small {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.resource-row div > span {
  font-size: 0.78rem;
  font-weight: 800;
}

.resource-row form {
  margin: 0;
}

.ghost-button {
  min-height: 34px;
  padding: 0 14px;
  border-color: color-mix(in srgb, var(--line) 84%, transparent);
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent 52%),
    color-mix(in srgb, var(--panel) 66%, transparent);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.danger-button {
  border-color: color-mix(in srgb, var(--danger) 62%, var(--line));
  color: var(--danger);
}

.notice {
  padding: 12px 16px;
  border: 1px solid color-mix(in srgb, var(--line) 84%, transparent);
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), transparent 56%),
    color-mix(in srgb, var(--panel) 88%, transparent);
  box-shadow: var(--touch-shadow);
}

.notice-ok {
  color: var(--ok);
}

.notice-error {
  color: var(--danger);
}

.rai-signature {
  position: fixed;
  right: 18px;
  bottom: 14px;
  z-index: 30;
  pointer-events: none;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  box-shadow: var(--soft-shadow);
  backdrop-filter: blur(12px);
}

@media (max-width: 980px) {
  .shell,
  .login-screen {
    grid-template-columns: 1fr;
  }

  .login-screen {
    width: min(100% - 28px, 680px);
    gap: 28px;
    padding: 34px 0;
  }

  .login-brand-lockup {
    gap: 14px;
  }

  .login-copy h1 {
    font-size: clamp(2.45rem, 10vw, 4rem);
  }

  .login-rai-mark {
    width: clamp(68px, 18vw, 104px);
    height: clamp(66px, 17vw, 100px);
  }

  .shell {
    grid-template-rows: auto auto auto;
  }

  .app-topbar {
    grid-template-columns: minmax(0, 1fr) auto;
    row-gap: 10px;
    min-width: 0;
    padding: 18px;
  }

  .brand-strip {
    min-height: auto;
  }

  .topbar-title {
    grid-column: 1 / -1;
    grid-row: 2;
    padding: 0;
  }

  .topbar-title h1 {
    font-size: 1.28rem;
  }

  .sidebar {
    grid-column: 1;
    min-height: auto;
  }

  .main {
    grid-column: 1;
  }

  .stats-grid,
  .status-grid,
  .settings-grid,
  .search-layout,
  .topic-grid,
  .assistant-grid,
  .assistant-two-col {
    grid-template-columns: 1fr;
  }

  .page-header,
  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

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

  .runtime-row small {
    grid-column: 1;
  }

  .main {
    padding-top: 30px;
  }

  .rai-signature {
    position: static;
    width: fit-content;
    margin: 0 18px 18px auto;
  }
}

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