:root {
  color-scheme: dark;
  --bg: #0d1319;
  --panel: #141c25;
  --panel-strong: #18232e;
  --panel-soft: #101820;
  --border: #2d3b49;
  --border-strong: #3a4b5b;
  --text: #f3f7fb;
  --muted: #91abc2;
  --blue: #52a8ff;
  --blue-strong: #1976c9;
  --green: #38d990;
  --green-soft: #113c2b;
  --red: #ff6476;
  --red-soft: #44212a;
  --yellow: #f1c64b;
  --yellow-soft: #403619;
  --orange: #ff9f43;
  --radius: 6px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-width: 320px;
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

body {
  min-height: 100vh;
  overflow: hidden;
  font-size: 13px;
}

button,
input,
select,
textarea {
  min-width: 0;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: #0f1720;
  color: var(--text);
  font: inherit;
  letter-spacing: 0;
}

button {
  min-height: 32px;
  padding: 6px 12px;
  cursor: pointer;
}

button:hover:not(:disabled),
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  border-color: var(--blue);
  outline: 2px solid rgb(82 168 255 / 22%);
  outline-offset: 1px;
}

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

input,
select {
  height: 34px;
  padding: 6px 9px;
}

textarea {
  width: 100%;
  resize: vertical;
  padding: 9px;
  line-height: 1.45;
}

label {
  display: grid;
  gap: 5px;
  min-width: 0;
  color: var(--muted);
  font-size: 11px;
}

label > input,
label > select {
  width: 100%;
}

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

.topbar {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 54px;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  background: #101821;
}

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

.brand-copy {
  display: grid;
  min-width: 0;
}

.brand-copy strong {
  font-size: 16px;
}

.brand-copy span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
}

.home-link,
.icon-button {
  display: inline-grid;
  width: 34px;
  height: 34px;
  min-height: 34px;
  flex: 0 0 34px;
  place-items: center;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: #111b25;
  color: var(--yellow);
}

.home-link svg,
.icon-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.icon-button {
  color: var(--blue);
}

.icon-button.loading svg {
  animation: spin 0.8s linear infinite;
}

.loading-line {
  position: absolute;
  right: 0;
  bottom: -1px;
  left: 0;
  height: 2px;
  overflow: hidden;
  background: #20303d;
}

.loading-line span {
  display: block;
  width: 34%;
  height: 100%;
  background: var(--blue);
  animation: loading 1.15s ease-in-out infinite;
}

.app-shell {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  height: calc(100vh - 54px);
  min-height: 0;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 8px;
  padding: 8px;
  border-bottom: 1px solid var(--border);
}

.summary-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  gap: 3px 10px;
  min-width: 0;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
}

.summary-item > span {
  color: #86bdf0;
  font-size: 10px;
  font-weight: 700;
}

.summary-item strong {
  grid-row: 1 / span 2;
  grid-column: 2;
  color: var(--text);
  font-size: 22px;
  line-height: 1;
}

.summary-item small {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 10px;
}

.filter-bar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 180px 170px auto;
  align-items: end;
  gap: 8px;
  padding: 8px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-soft);
}

.secondary-button {
  background: #182430;
}

.primary-button {
  border-color: #2d79b8;
  background: #164c78;
  font-weight: 700;
}

.workspace {
  display: grid;
  grid-template-columns: 238px minmax(380px, 1fr) 350px;
  min-height: 0;
  overflow: hidden;
}

.gateways-pane,
.feed-pane,
.publish-pane {
  min-width: 0;
  min-height: 0;
  background: var(--panel-soft);
}

.gateways-pane,
.feed-pane {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border-right: 1px solid var(--border);
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 45px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.panel-heading.compact {
  min-height: 42px;
  padding: 7px 10px;
}

.block-label {
  display: block;
  margin-top: 2px;
  font-size: 10px;
}

.gateway-list,
.status-feed,
.publication-history {
  min-height: 0;
  overflow: auto;
  scrollbar-color: #607488 #111820;
  scrollbar-width: thin;
}

.gateway-filter-button {
  display: grid;
  width: 100%;
  min-height: 58px;
  padding: 9px 10px;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  background: transparent;
  text-align: left;
}

.gateway-filter-button:hover:not(:disabled) {
  background: #18232e;
}

.gateway-filter-button.selected {
  box-shadow: inset 3px 0 var(--blue);
  background: #1a2733;
}

.gateway-row-main,
.gateway-row-meta,
.status-header,
.status-meta,
.command-top,
.composer-options {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

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

.gateway-row-meta {
  color: var(--muted);
  font-size: 10px;
}

.readiness-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 0 2px rgb(255 100 118 / 15%);
}

.readiness-dot.ready {
  background: var(--green);
  box-shadow: 0 0 0 2px rgb(56 217 144 / 15%);
}

.status-feed {
  padding: 8px;
  background: var(--bg);
}

.status-card {
  margin-bottom: 8px;
  padding: 11px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--blue);
  border-radius: var(--radius);
  background: var(--panel);
}

.status-card.expired {
  border-left-color: #687989;
  opacity: 0.82;
}

.status-author {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.status-author > div {
  min-width: 0;
}

.status-author strong,
.status-author small {
  display: block;
  min-width: 0;
  overflow-wrap: anywhere;
}

.author-initials {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  place-items: center;
  border: 1px solid #42617a;
  border-radius: 50%;
  background: #1b3142;
  color: #bce0ff;
  font-size: 11px;
  font-weight: 800;
}

.status-time {
  flex: 0 0 auto;
  color: var(--muted);
  text-align: right;
  font-size: 10px;
}

.status-body {
  margin: 10px 0;
  color: var(--text);
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  line-height: 1.45;
}

.status-body.empty-copy {
  color: var(--muted);
  font-style: italic;
}

.status-meta {
  align-items: flex-start;
  color: var(--muted);
  font-size: 10px;
}

.status-view-count {
  margin-left: 6px;
  color: var(--green);
  font-weight: 700;
}

.gateway-observations {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 9px;
}

.gateway-chip,
.type-chip,
.state-badge {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  max-width: 100%;
  padding: 2px 6px;
  border: 1px solid #405263;
  border-radius: 3px;
  background: #17222c;
  color: #b8cede;
  overflow-wrap: anywhere;
  font-size: 10px;
}

.type-chip {
  color: #8fcaff;
}

.state-badge.ready,
.state-badge.succeeded {
  border-color: #27875f;
  background: var(--green-soft);
  color: var(--green);
}

.state-badge.pending,
.state-badge.picked,
.state-badge.running,
.state-badge.partial {
  border-color: #8d7628;
  background: var(--yellow-soft);
  color: var(--yellow);
}

.state-badge.failed,
.state-badge.cancelled,
.state-badge.offline {
  border-color: #9b3b4b;
  background: var(--red-soft);
  color: var(--red);
}

.state-badge.neutral {
  color: var(--muted);
}

.status-media {
  display: grid;
  gap: 7px;
  margin: 10px 0;
}

.media-preview,
.media-placeholder,
.media-file {
  display: grid;
  gap: 5px;
  min-width: 0;
  padding: 7px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #0d151c;
}

.media-preview img,
.media-preview video {
  display: block;
  width: 100%;
  max-height: 440px;
  border-radius: 3px;
  object-fit: contain;
  background: #080d12;
}

.media-preview audio {
  width: 100%;
  min-width: 0;
}

.media-meta {
  color: var(--muted);
  overflow-wrap: anywhere;
  font-size: 10px;
}

.media-file {
  color: var(--blue);
  text-decoration: none;
}

.media-placeholder button {
  justify-self: start;
}

.publish-pane {
  display: grid;
  grid-template-rows: auto minmax(180px, 1fr);
  overflow: hidden;
}

.composer-section,
.history-section {
  min-width: 0;
  min-height: 0;
}

.history-section {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border-top: 1px solid var(--border);
}

.publish-form {
  display: grid;
  gap: 10px;
  padding: 10px;
}

.field-label {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 11px;
}

.color-swatches {
  display: flex;
  align-items: center;
  gap: 6px;
}

.color-swatch {
  width: 26px;
  height: 26px;
  min-height: 26px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 50%;
  background: var(--swatch);
}

.color-swatch.selected {
  border-color: white;
  box-shadow: 0 0 0 2px var(--blue);
}

.form-message {
  min-height: 18px;
  color: var(--muted);
  overflow-wrap: anywhere;
  font-size: 11px;
}

.form-message.success {
  color: var(--green);
}

.form-message.error {
  color: var(--red);
}

.publication-history {
  padding: 0 10px 10px;
}

.command-row {
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}

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

.command-body {
  margin-top: 5px;
  overflow: hidden;
  color: #d8e4ed;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.command-meta,
.command-error {
  margin-top: 4px;
  color: var(--muted);
  overflow-wrap: anywhere;
  font-size: 10px;
}

.command-error {
  color: var(--red);
}

.empty-state {
  display: grid;
  min-height: 140px;
  place-items: center;
  padding: 20px;
  color: var(--muted);
  text-align: center;
}

.login-panel {
  display: grid;
  min-height: calc(100vh - 54px);
  place-items: start center;
  padding: 70px 16px 24px;
}

.login-box {
  display: grid;
  width: min(360px, 100%);
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--panel);
}

.login-box h1 {
  margin: 0 0 3px;
  font-size: 17px;
}

.toast {
  position: fixed;
  z-index: 30;
  right: 16px;
  bottom: 16px;
  max-width: min(420px, calc(100vw - 32px));
  padding: 10px 12px;
  border: 1px solid #2d79b8;
  border-radius: var(--radius);
  background: #142a3b;
  box-shadow: 0 10px 30px rgb(0 0 0 / 35%);
  overflow-wrap: anywhere;
}

.toast.error {
  border-color: #9b3b4b;
  background: #361b23;
}

[hidden] {
  display: none !important;
}

@keyframes loading {
  from { transform: translateX(-115%); }
  to { transform: translateX(310%); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 1120px) {
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: calc(100vh - 54px);
  }

  .workspace {
    grid-template-columns: 220px minmax(0, 1fr);
    overflow: visible;
  }

  .gateways-pane,
  .feed-pane {
    min-height: 620px;
  }

  .publish-pane {
    grid-column: 1 / -1;
    grid-template-columns: minmax(320px, 420px) minmax(320px, 1fr);
    grid-template-rows: minmax(360px, auto);
    border-top: 1px solid var(--border);
  }

  .history-section {
    border-top: 0;
    border-left: 1px solid var(--border);
  }
}

@media (max-width: 760px) {
  .topbar {
    height: auto;
    min-height: 54px;
    align-items: flex-start;
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .top-actions {
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  #last-update,
  #current-user {
    width: 100%;
    text-align: right;
  }

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

  .filter-bar {
    grid-template-columns: 1fr 1fr;
  }

  .search-field {
    grid-column: 1 / -1;
  }

  .workspace {
    display: block;
  }

  .gateways-pane,
  .feed-pane {
    min-height: 0;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .gateway-list {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(190px, 240px);
    overflow-x: auto;
  }

  .gateway-filter-button {
    border-right: 1px solid var(--border);
  }

  .feed-pane {
    height: 600px;
  }

  .publish-pane {
    display: block;
  }

  .history-section {
    min-height: 280px;
    border-top: 1px solid var(--border);
    border-left: 0;
  }
}

@media (max-width: 480px) {
  .brand-copy span,
  #last-update,
  #current-user {
    display: none;
  }

  .summary-strip {
    grid-template-columns: 1fr;
  }

  .filter-bar {
    grid-template-columns: 1fr;
  }

  .search-field {
    grid-column: auto;
  }

  .summary-item strong {
    font-size: 19px;
  }

  .status-header {
    align-items: flex-start;
  }
}
