:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #62707f;
  --line: #d9e0e7;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --warn: #a65f00;
  --bad: #b42318;
  --good: #157f3b;
  --chip: #edf2f7;
  --shadow: 0 10px 30px rgba(24, 39, 75, 0.08);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111417;
  --panel: #181d22;
  --text: #e8eef4;
  --muted: #9aa8b5;
  --line: #303943;
  --accent: #2dd4bf;
  --accent-strong: #14b8a6;
  --warn: #f2a93b;
  --bad: #ff6b5f;
  --good: #4ade80;
  --chip: #242b33;
  --shadow: 0 14px 34px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(1760px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 56px 0 28px;
}

.config-panel {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  align-items: end;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.floating-panel {
  position: fixed;
  z-index: 30;
}

.floating-panel[hidden] {
  display: none;
}

.config-panel.floating-panel {
  top: 52px;
  right: 12px;
  width: min(360px, calc(100vw - 24px));
  max-height: calc(100vh - 68px);
  overflow: auto;
}

.status-strip.floating-panel {
  top: 52px;
  left: 12px;
  width: min(220px, calc(100vw - 24px));
  max-height: calc(100vh - 68px);
  overflow: auto;
}

.floating-toggle {
  position: fixed;
  z-index: 35;
  top: 12px;
  height: 34px;
  border-color: var(--accent);
  box-shadow: var(--shadow);
}

.floating-status {
  left: 16px;
}

.floating-settings {
  right: 16px;
}

.floating-toggle[aria-expanded="true"] {
  background: var(--accent);
  color: #ffffff;
}

.brand-block {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

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

h1 {
  font-size: 22px;
  line-height: 1.15;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 11px;
  align-items: end;
}

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.field input,
.field select {
  width: 100%;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 11px;
  background-color: color-mix(in srgb, var(--panel) 88%, var(--bg));
  color: var(--text);
  outline: none;
}

.field input::placeholder {
  color: color-mix(in srgb, var(--muted) 78%, transparent);
}

.field input:disabled {
  cursor: default;
  background-color: var(--chip);
  color: var(--muted);
  opacity: 1;
}

.field select option {
  background-color: var(--panel);
  color: var(--text);
}

.field input:-webkit-autofill {
  -webkit-text-fill-color: var(--text);
  box-shadow: 0 0 0 1000px color-mix(in srgb, var(--panel) 88%, var(--bg)) inset;
}

.number-field {
  width: 86px;
}

.field input:focus,
.field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

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

button {
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 13px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
}

button.primary:hover:not(:disabled) {
  background: var(--accent-strong);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.status-strip {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin: 0;
}

.status-strip div {
  min-width: 0;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.status-strip span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.status-strip strong {
  display: block;
  margin-top: 5px;
  overflow: hidden;
  font-size: 22px;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(260px, 34fr) 8px minmax(420px, 66fr);
  gap: 0;
  min-height: calc(100vh - 230px);
}

.panel-splitter {
  cursor: col-resize;
  min-height: 100%;
  background: linear-gradient(to right, transparent 0 3px, var(--line) 3px 5px, transparent 5px 8px);
}

.panel-splitter:hover,
.panel-splitter:focus {
  background: linear-gradient(to right, transparent 0 2px, var(--accent) 2px 6px, transparent 6px 8px);
  outline: none;
}

body.is-resizing {
  cursor: col-resize;
  user-select: none;
}

.stream-column,
.cluster-column {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.stream-column {
  border-right: 0;
  border-radius: 8px 0 0 8px;
}

.cluster-column {
  border-left: 0;
  border-radius: 0 8px 8px 0;
}

.stream-column header,
.cluster-column header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
}

h2 {
  font-size: 16px;
}

header span {
  max-width: 55%;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.panel-threshold {
  display: inline-grid;
  grid-template-columns: auto 74px;
  gap: 7px;
  align-items: center;
}

.panel-threshold span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.panel-threshold input {
  width: 74px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 8px;
  background-color: color-mix(in srgb, var(--panel) 88%, var(--bg));
  color: var(--text);
  outline: none;
}

.panel-threshold input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.stream-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: calc(100vh - 282px);
  min-height: 420px;
  overflow: auto;
  padding: 12px;
}

.stream-item {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 10px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: color-mix(in srgb, var(--panel) 92%, var(--bg));
}

.avatar {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--chip);
  object-fit: cover;
}

.stream-item.no-avatar {
  grid-template-columns: 1fr;
}

.stream-body {
  min-width: 0;
}

.stream-meta {
  display: flex;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.stream-item p {
  margin-top: 5px;
  overflow-wrap: anywhere;
  line-height: 1.35;
}

.gift-kind {
  color: var(--accent);
}

.gift-amount {
  color: var(--warn);
}

.clusters {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 10px;
  height: calc(100vh - 282px);
  min-height: 420px;
  overflow: auto;
  padding: 12px;
  align-content: start;
}

.cluster-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 92%, var(--bg));
  overflow: hidden;
  transition:
    border-color 180ms ease,
    box-shadow 180ms ease;
}

.cluster-card.is-updated {
  border-color: var(--good);
  box-shadow: 0 0 0 3px rgba(21, 127, 59, 0.16);
}

.plain-message {
  grid-column: 1 / -1;
}

.cluster-head {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: start;
  padding: 10px;
  border-bottom: 1px solid var(--line);
}

.cluster-head h3 {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 15px;
  line-height: 1.25;
}

.cluster-head span {
  cursor: pointer;
  display: inline-flex;
  min-width: 32px;
  justify-content: center;
  border-radius: 999px;
  padding: 3px 8px;
  background: var(--accent);
  color: #ffffff;
  font-size: 12px;
  font-weight: 800;
}

.cluster-head span:hover {
  background: var(--accent-strong);
}

.cluster-latest {
  display: flex;
  gap: 7px;
  align-items: flex-start;
  min-width: 0;
  padding: 0 10px 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.latest-avatar {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  object-fit: cover;
}

.latest-text {
  min-width: 0;
}

.latest-user {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cluster-detail {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0 10px 10px;
  list-style: none;
}

.cluster-detail li {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 7px;
  min-width: 0;
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.detail-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  object-fit: cover;
}

.detail-text {
  min-width: 0;
}

.detail-user {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-content {
  margin-top: 2px;
  overflow-wrap: anywhere;
  font-size: 13px;
  line-height: 1.35;
}

.cluster-popover {
  position: fixed;
  z-index: 20;
  width: min(390px, calc(100vw - 24px));
  max-height: min(520px, calc(100vh - 32px));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.popover-head {
  position: sticky;
  top: 0;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.popover-head h3 {
  overflow: hidden;
  font-size: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.popover-head button {
  width: 30px;
  height: 30px;
  padding: 0;
}

.cluster-popover .cluster-detail {
  padding: 10px 12px 12px;
}

.empty-state {
  grid-column: 1 / -1;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 16px;
  background: color-mix(in srgb, var(--panel) 92%, var(--bg));
}

.empty-state h3 {
  font-size: 16px;
}

.empty-state p {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.45;
}

.is-good {
  color: var(--good);
}

.is-warn {
  color: var(--warn);
}

.is-bad {
  color: var(--bad);
}

@media (max-width: 1180px) {
  .config-panel.floating-panel {
    right: 10px;
    width: min(360px, calc(100vw - 20px));
  }

  .status-strip.floating-panel {
    left: 10px;
    width: min(220px, calc(100vw - 20px));
  }

  .workspace {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .panel-splitter {
    display: none;
  }

  .stream-column,
  .cluster-column {
    border: 1px solid var(--line);
    border-radius: 8px;
  }

  .stream-list,
  .clusters {
    height: 460px;
    min-height: 360px;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100vw - 20px, 1760px);
    padding-top: 54px;
  }

  h1 {
    font-size: 20px;
  }

  .settings-grid,
  .status-strip {
    grid-template-columns: 1fr;
  }

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

  button {
    padding: 0 8px;
  }
}
