:root {
  color-scheme: light;
  --bg: #f3f5f1;
  --surface: #ffffff;
  --surface-raised: #fbfcfa;
  --surface-muted: #eef1ec;
  --ink: #151816;
  --text: #2c312d;
  --muted: #6a746d;
  --line: #d9dfd6;
  --line-strong: #c4cdc2;
  --green: #18715c;
  --green-soft: #e5f3ed;
  --blue: #285fba;
  --blue-soft: #e9f1ff;
  --amber: #a95f14;
  --amber-soft: #fff3dd;
  --red: #b3261e;
  --red-soft: #fff0ee;
  --purple: #6654c7;
  --purple-soft: #f0edff;
  --shadow: 0 10px 28px rgba(30, 36, 31, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

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

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

button {
  letter-spacing: 0;
}

a {
  color: inherit;
}

.app-shell {
  min-height: 100vh;
}

.app-page[hidden] {
  display: none !important;
}

.public-mode [data-admin-only] {
  display: none !important;
}

.workspace-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(220px, auto) minmax(240px, 1fr) auto auto;
  gap: 14px;
  align-items: center;
  min-height: 72px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(251, 252, 250, 0.96);
  backdrop-filter: blur(14px);
}

.brand {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-width: 0;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid #27302b;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-weight: 800;
  font-size: 13px;
}

.brand strong,
.brand small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand strong {
  color: var(--ink);
  font-size: 15px;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.header-nav {
  display: flex;
  gap: 4px;
  align-items: center;
  min-width: 0;
  overflow-x: auto;
}

.header-nav a {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  text-decoration: none;
  white-space: nowrap;
}

.header-nav a:hover {
  background: var(--surface-muted);
  color: var(--ink);
}

.header-nav a.active {
  background: var(--ink);
  color: #fff;
}

.header-status {
  display: grid;
  gap: 4px;
  justify-items: end;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
}

.status-pill.ok {
  border-color: rgba(24, 113, 92, 0.28);
  background: var(--green-soft);
  color: var(--green);
}

.status-pill.warn {
  border-color: rgba(169, 95, 20, 0.28);
  background: var(--amber-soft);
  color: var(--amber);
}

.actions,
.form-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.form-row > * {
  flex: 1 1 0;
}

.form-row.end {
  justify-content: flex-end;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
  box-shadow: 0 1px 0 rgba(20, 24, 21, 0.04);
}

.button.primary {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
}

.button.secondary:hover {
  background: var(--surface-muted);
}

.button.primary:hover {
  background: #115a49;
}

.button.full {
  width: 100%;
}

.button.compact {
  min-height: 34px;
  padding-inline: 10px;
}

.button:disabled {
  cursor: wait;
  opacity: 0.58;
}

.workbench {
  display: grid;
  grid-template-columns: 292px minmax(470px, 1fr) 420px;
  gap: 14px;
  align-items: start;
  padding: 14px 18px 18px;
}

.settings-page {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.72fr);
  gap: 14px;
  align-items: start;
  padding: 14px 18px 18px;
}

.source-rail,
.detail-rail {
  position: sticky;
  top: 86px;
  display: grid;
  gap: 14px;
  max-height: calc(100vh - 104px);
  overflow: auto;
  scrollbar-width: thin;
}

.stream-column {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.panel {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 14px 15px;
  border-bottom: 1px solid var(--line);
}

.panel-head.compact {
  min-height: 58px;
}

.eyebrow {
  display: block;
  margin-bottom: 3px;
  color: var(--green);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

h1 {
  color: var(--ink);
  font-size: 24px;
  line-height: 1.15;
}

h2 {
  color: var(--ink);
  font-size: 16px;
  line-height: 1.2;
}

.counter {
  display: inline-flex;
  min-width: 32px;
  height: 28px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
  color: var(--ink);
  font-weight: 750;
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric {
  min-width: 0;
  padding: 13px 14px;
  border-right: 1px solid var(--line);
}

.metric:last-child {
  border-right: 0;
}

.metric span {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric strong {
  display: block;
  margin-top: 4px;
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
}

.metric.good strong {
  color: var(--green);
}

.metric.warn strong {
  color: var(--amber);
}

.metric.muted strong {
  color: var(--purple);
}

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

.stream-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-raised);
}

.stream-head p {
  margin-top: 8px;
  max-width: 720px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.feed-total {
  display: grid;
  justify-items: end;
  min-width: 82px;
}

.feed-total strong {
  color: var(--ink);
  font-size: 28px;
  line-height: 1;
}

.feed-total span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.feed-total small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.filterbar {
  position: sticky;
  top: 72px;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(12px);
}

.filterbar > select,
.filterbar > input {
  flex: 1 1 136px;
}

.filterbar > input[type="search"] {
  flex: 2 1 220px;
}

.segmented {
  display: inline-grid;
  grid-auto-flow: column;
  flex: 0 0 auto;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface-muted);
}

.segmented button {
  min-width: 58px;
  min-height: 34px;
  border: 0;
  border-right: 1px solid var(--line-strong);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
}

.segmented button:last-child {
  border-right: 0;
}

.segmented button.active {
  background: var(--ink);
  color: #fff;
}

select,
input,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 8px 10px;
  outline: none;
  font-size: 13px;
}

select:focus,
input:focus,
textarea:focus {
  border-color: rgba(24, 113, 92, 0.72);
  box-shadow: 0 0 0 3px rgba(24, 113, 92, 0.11);
}

textarea {
  min-height: 78px;
  resize: vertical;
  line-height: 1.45;
}

label span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.source-form,
.form {
  display: grid;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-raised);
}

.form {
  border-top: 1px solid var(--line);
  border-bottom: 0;
}

.post-list,
.source-list,
.prompt-list,
.channel-list {
  display: grid;
}

.post-list {
  gap: 10px;
  padding: 12px;
  background: #f8faf7;
}

.signal-card {
  display: grid;
  gap: 10px;
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-left: 4px solid transparent;
  border-radius: 8px;
  padding: 13px 14px;
  background: var(--surface);
  cursor: pointer;
  transition:
    border-color 0.16s ease,
    box-shadow 0.16s ease,
    transform 0.16s ease;
}

.signal-card:hover,
.signal-card.active {
  border-color: var(--line-strong);
  border-left-color: var(--green);
  box-shadow: 0 8px 20px rgba(31, 38, 33, 0.08);
}

.signal-card:hover {
  transform: translateY(-1px);
}

.signal-card.filtered {
  border-left-color: var(--purple);
  background: #fdfcff;
}

.signal-card.pending {
  border-left-color: var(--amber);
}

.signal-top,
.source-top,
.detail-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.signal-source {
  min-width: 0;
}

.signal-source strong,
.source-name {
  display: block;
  overflow: hidden;
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.signal-source span,
.source-meta,
.detail-meta,
.runtime-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.signal-summary {
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
}

.signal-text {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.card-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.card-thumb,
.card-file {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-raised);
  text-decoration: none;
}

.card-thumb {
  display: block;
  position: relative;
  width: 54px;
  height: 54px;
}

.card-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb-label {
  position: absolute;
  right: 4px;
  bottom: 4px;
  border-radius: 999px;
  background: rgba(15, 22, 18, 0.78);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  padding: 3px 5px;
}

.card-file {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 54px;
  height: 54px;
  padding: 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.signal-footer,
.asset-list,
.detail-chipline {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  max-width: 100%;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
}

.pill.bullish,
.badge.bullish {
  border-color: rgba(24, 113, 92, 0.28);
  background: var(--green-soft);
  color: var(--green);
}

.pill.bearish,
.badge.bearish {
  border-color: rgba(179, 38, 30, 0.25);
  background: var(--red-soft);
  color: var(--red);
}

.pill.watch,
.badge.watch {
  border-color: rgba(169, 95, 20, 0.28);
  background: var(--amber-soft);
  color: var(--amber);
}

.pill.neutral,
.badge.neutral {
  border-color: rgba(40, 95, 186, 0.24);
  background: var(--blue-soft);
  color: var(--blue);
}

.pill.filtered,
.badge.filtered {
  border-color: rgba(102, 84, 199, 0.24);
  background: var(--purple-soft);
  color: var(--purple);
}

.pill.pending,
.badge.pending {
  border-color: rgba(169, 95, 20, 0.28);
  background: var(--amber-soft);
  color: var(--amber);
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.source-row {
  display: grid;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.source-row:last-child,
.prompt-row:last-child,
.channel-row:last-child {
  border-bottom: 0;
}

.source-identity {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-width: 0;
}

.avatar,
.avatar-fallback {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
  object-fit: cover;
}

.avatar-fallback {
  display: grid;
  place-items: center;
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

.source-focus {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.source-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.toggle,
.checkline {
  display: inline-flex;
  gap: 7px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.toggle input,
.checkline input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--green);
}

.detail-panel {
  min-height: 320px;
}

.detail-body {
  display: grid;
  gap: 14px;
  padding: 15px;
}

.detail-title h2 {
  font-size: 18px;
}

.detail-section {
  display: grid;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.detail-section h3 {
  color: var(--ink);
  font-size: 13px;
}

.detail-section p,
.detail-section li,
.raw-text {
  color: var(--text);
  font-size: 13px;
  line-height: 1.55;
}

.detail-section ul {
  margin: 0;
  padding-left: 18px;
}

.strategy-grid {
  display: grid;
  gap: 8px;
}

.strategy-item {
  display: grid;
  gap: 3px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-raised);
}

.strategy-item span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.strategy-item p {
  color: var(--text);
  font-size: 13px;
}

.empty-note {
  color: var(--muted) !important;
}

.raw-text {
  display: block;
  width: 100%;
  max-height: 260px;
  overflow: auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfbf8;
  white-space: pre-wrap;
}

.raw-preview {
  text-align: left;
  cursor: pointer;
}

.raw-preview:hover,
.raw-preview:focus-visible {
  border-color: var(--line-strong);
  box-shadow: 0 0 0 3px rgba(24, 113, 92, 0.12);
  outline: none;
}

.pill-button {
  cursor: pointer;
}

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

.inline-attachments {
  display: grid;
  gap: 8px;
  padding-top: 4px;
}

.inline-attachments h3,
.modal-attachment-block h3 {
  color: var(--muted);
  font-size: 12px;
}

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

.attachment-thumb,
.attachment-file {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-raised);
  color: var(--text);
  text-decoration: none;
}

.attachment-thumb {
  position: relative;
  aspect-ratio: 1.25;
}

.attachment-grid.large .attachment-thumb {
  aspect-ratio: 1.35;
}

.attachment-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.attachment-file {
  display: flex;
  grid-column: 1 / -1;
  align-items: center;
  min-height: 40px;
  padding: 9px 10px;
  font-size: 13px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(21, 24, 22, 0.52);
}

.modal-backdrop[hidden] {
  display: none !important;
}

.modal-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(920px, 100%);
  max-height: min(86vh, 860px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(15, 22, 18, 0.24);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-raised);
}

.modal-head h2 {
  color: var(--ink);
  font-size: 18px;
}

.icon-button {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}

.icon-button:hover,
.icon-button:focus-visible {
  border-color: var(--line-strong);
  outline: none;
}

.modal-body {
  display: grid;
  gap: 16px;
  overflow: auto;
  padding: 18px;
}

.modal-raw-text {
  color: var(--text);
  font-size: 15px;
  line-height: 1.7;
  white-space: pre-wrap;
}

.modal-attachment-block {
  display: grid;
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

body.modal-open {
  overflow: hidden;
}

.load-more-row {
  display: flex;
  justify-content: center;
  padding: 12px;
  border-top: 1px solid var(--line);
  background: #f8faf7;
}

.prompt-row,
.channel-row {
  display: grid;
  gap: 6px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.prompt-row strong,
.channel-row strong {
  color: var(--ink);
  font-size: 13px;
}

.prompt-row p,
.channel-row p {
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.empty {
  padding: 26px 16px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(16px);
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1280px) {
  .workspace-header {
    grid-template-columns: minmax(220px, auto) minmax(0, 1fr) auto;
  }

  .header-status {
    display: none;
  }

  .workbench {
    grid-template-columns: 280px minmax(0, 1fr);
  }

  .settings-page {
    grid-template-columns: 1fr;
  }

  .detail-rail {
    grid-column: 1 / -1;
    position: static;
    max-height: none;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: start;
    overflow: visible;
  }

  .detail-panel {
    min-height: 0;
  }
}

@media (max-width: 980px) {
  .workspace-header {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .header-nav {
    order: 3;
  }

  .actions {
    order: 2;
  }

  .workbench {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .stream-column {
    order: 1;
  }

  .detail-rail {
    order: 2;
  }

  .source-rail {
    order: 3;
    position: static;
    max-height: none;
    overflow: visible;
  }

  .detail-rail {
    grid-template-columns: 1fr;
  }

  .metric-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .metric:nth-child(3) {
    border-right: 0;
  }

  .metric:nth-child(-n + 3) {
    border-bottom: 1px solid var(--line);
  }

  .filterbar {
    top: 0;
  }

}

@media (max-width: 640px) {
  body {
    min-width: 320px;
  }

  .workspace-header {
    padding: 10px;
  }

  .actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
    width: 100%;
  }

  .button {
    width: 100%;
    padding-inline: 8px;
  }

  .stream-head,
  .signal-top,
  .source-top,
  .detail-title {
    display: grid;
  }

  .feed-total {
    justify-items: start;
  }

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

  .metric {
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
  }

  .metric:nth-child(2n) {
    border-right: 0;
  }

  .metric:nth-last-child(-n + 2) {
    border-bottom: 0;
  }

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

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

  .modal-backdrop {
    padding: 10px;
  }

  .modal-card {
    max-height: 92vh;
  }

  .modal-head,
  .modal-body {
    padding: 14px;
  }

  .card-thumb,
  .card-file {
    width: 48px;
    height: 48px;
  }

}
