/*------------------------------------*\
  Kafka router — homepage section only.
  Tokens and layout match the "A · Broker log" spec. All rules live under
  #kafka-router; every class is prefixed kr-.
\*------------------------------------*/

#kafka-router {
  --kr-bg: #F1F4F7;
  --kr-card: #FFFFFF;
  --kr-border: #C9D2DA;
  --kr-ink: #16202A;
  --kr-body: #3E4852;
  --kr-muted: #56616B;
  --kr-teal: #0E5E63;
  --kr-teal-soft: #E3EFEF;
  --kr-orange: #F79A5E;
  --kr-orange-line: #E08A55;
  --kr-orange-text: #A8481A;
  --kr-idle-line: #B7C2CC;
  --kr-idle-cell: #D6DEE5;
  --kr-idle-cell-last: #F5C4A3;
  --kr-group-idle: #E7ECF0;
  /* Spec #8A949D is 2.8:1 on --kr-bg; muted meets 4.5:1. */
  --kr-poll-idle: #56616B;
  --kr-term-text: #E6ECF1;
  --kr-term-dim: #9FB3C2;
  --kr-term-teal: #7FC4C7;
  --kr-serif: 'Instrument Serif', Georgia, serif;
  --kr-sans: 'IBM Plex Sans', system-ui, sans-serif;
  --kr-mono: 'IBM Plex Mono', ui-monospace, monospace;

  padding: 40px 0;
  overflow-x: hidden;
  color: var(--kr-ink);
  background: var(--kr-bg);
  font-family: var(--kr-sans);
  font-size: 16px;
  line-height: 1.5;
}

#kafka-router > .gg-container {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

#kafka-router *,
#kafka-router *::before,
#kafka-router *::after {
  box-sizing: border-box;
}

#kafka-router :focus-visible {
  outline: 2px solid var(--kr-teal);
  outline-offset: 2px;
}

#kafka-router button {
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

/* 1. Header */

#kafka-router .kr-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 24px;
}

#kafka-router .kr-header__left {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#kafka-router .kr-caption {
  margin: 0;
  font-family: var(--kr-mono);
  font-size: 13px;
  font-weight: 400;
  line-height: 1.4;
  color: var(--kr-muted);
}

#kafka-router .kr-header h2 {
  margin: 0;
  font-family: var(--kr-serif);
  font-size: clamp(32px, 4vw, 52px);
  font-weight: 400;
  line-height: 1.05;
  color: var(--kr-ink);
}

/* 2. Graph */

#kafka-router .kr-graph {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
}

#kafka-router .kr-producer {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  padding: 22px;
  color: var(--kr-ink);
  background: var(--kr-card);
  border: 1.5px solid var(--kr-orange-line);
  border-radius: 12px;
}

#kafka-router .kr-producer__type {
  margin: 0;
  font-family: var(--kr-mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--kr-orange-text);
}

#kafka-router .kr-producer__name {
  margin: 0;
  font-family: var(--kr-serif);
  font-size: 30px;
  font-weight: 400;
  line-height: 1.05;
}

#kafka-router .kr-producer__bio {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--kr-body);
}

#kafka-router .kr-producer__meta {
  margin: 0;
  padding-top: 6px;
  font-family: var(--kr-mono);
  font-size: 11px;
  color: var(--kr-muted);
  border-top: 1px dashed var(--kr-border);
}

/* Dotted lines — background, not border-style, so the dots can move. */

#kafka-router .kr-line {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
  height: 10px;
}

#kafka-router .kr-dots {
  width: 100%;
  height: 4px;
  background-image: radial-gradient(circle, var(--kr-dot, var(--kr-idle-line)) 1.6px, transparent 2px);
  background-size: 12px 4px;
  background-repeat: repeat-x;
}

#kafka-router .kr-dots.is-live {
  --kr-dot: var(--kr-orange-line);
  animation: kr-flow .5s linear infinite;
}

#kafka-router .kr-dots.is-vert {
  width: 4px;
  height: 100%;
  background-size: 4px 12px;
  background-repeat: repeat-y;
}

#kafka-router .kr-dots.is-vert.is-live {
  animation-name: kr-flow-y;
}

#kafka-router .kr-packet {
  position: absolute;
  top: 1px;
  left: 0;
  width: 8px;
  height: 8px;
  border-radius: 4px;
  background: var(--kr-orange-text);
  box-shadow: 0 0 0 3px rgba(247, 154, 94, .35);
  animation: kr-travel 1.2s ease-in infinite;
}

#kafka-router .kr-packet.is-late {
  animation-delay: .6s;
}

#kafka-router .kr-line.is-vert .kr-packet {
  top: 0;
  left: 1px;
  animation-name: kr-travel-y;
}

#kafka-router .kr-prod-line {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 10px;
  height: 36px;
  margin: 0 auto;
}

#kafka-router .kr-prod-line .kr-line {
  width: 10px;
  height: 36px;
}

#kafka-router .kr-topics {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 12px;
  padding: 4px 0;
}

#kafka-router .kr-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}

#kafka-router .kr-tick {
  display: none;
}

#kafka-router .kr-topic,
#kafka-router .kr-group {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 44px;
}

#kafka-router .kr-topic {
  gap: 8px;
  padding: 14px 16px;
  background: var(--kr-card);
  border: 2px solid var(--kr-border);
  border-radius: 10px;
}

#kafka-router .kr-topic.is-selected {
  background: var(--kr-teal-soft);
  border-color: var(--kr-orange-line);
}

#kafka-router .kr-topic__top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

#kafka-router .kr-topic__name {
  font-family: var(--kr-mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--kr-teal);
}

#kafka-router .kr-topic__meta {
  font-family: var(--kr-mono);
  font-size: 11px;
  color: var(--kr-muted);
}

#kafka-router .kr-topic__title {
  font-size: 17px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--kr-ink);
}

#kafka-router .kr-log {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 0;
  overflow: visible;
}

#kafka-router .kr-cell {
  flex: none;
  width: 14px;
  height: 14px;
  background: var(--kr-idle-cell);
  border-radius: 3px;
}

#kafka-router .kr-cell.is-head {
  background: var(--kr-idle-cell-last);
}

#kafka-router .kr-topic.is-selected .kr-cell {
  background: var(--kr-teal);
}

#kafka-router .kr-topic.is-selected .kr-cell.is-head {
  background: var(--kr-orange);
  transform-origin: center;
  animation: kr-pulse 1.2s ease-in-out infinite;
}

#kafka-router .kr-append {
  padding-left: 6px;
  font-family: var(--kr-mono);
  font-size: 11px;
  color: var(--kr-muted);
}

#kafka-router .kr-conn {
  display: flex;
  flex: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 100%;
  padding: 0;
}

#kafka-router .kr-conn .kr-line {
  width: 10px;
  height: 28px;
}

#kafka-router .kr-poll {
  font-family: var(--kr-mono);
  font-size: 11px;
  color: var(--kr-poll-idle);
}

#kafka-router .kr-row.is-selected .kr-poll {
  color: var(--kr-orange-text);
}

#kafka-router .kr-group {
  gap: 4px;
  min-height: 76px;
  padding: 12px 16px;
  background: var(--kr-group-idle);
  border: 2px solid var(--kr-border);
  border-radius: 10px;
}

#kafka-router .kr-group.is-selected {
  background: var(--kr-orange);
  border-color: var(--kr-orange);
}

#kafka-router .kr-group__id {
  font-family: var(--kr-mono);
  font-size: 11px;
  color: var(--kr-ink);
  opacity: .85;
}

#kafka-router .kr-group__label {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--kr-ink);
}

/* 3. poll() console */

#kafka-router .kr-console {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 172px;
  padding: 18px 22px;
  color: var(--kr-term-text);
  background: var(--kr-ink);
  border-radius: 12px;
  font-family: var(--kr-mono);
  font-size: 13px;
  line-height: 1.45;
}

#kafka-router .kr-console__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 16px;
}

#kafka-router .kr-console__stmt,
#kafka-router .kr-console__live,
#kafka-router .kr-console__rows {
  margin: 0;
}

#kafka-router .kr-console__dim {
  color: var(--kr-term-dim);
}

#kafka-router .kr-console__group {
  color: var(--kr-orange);
}

#kafka-router .kr-live-dot {
  color: var(--kr-orange);
  animation: kr-blink 1.2s ease-in-out infinite;
}

#kafka-router .kr-record {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 18px;
  min-height: 22px;
}

#kafka-router .kr-record__part {
  flex: 1 1 100%;
  color: var(--kr-term-teal);
}

#kafka-router .kr-record__key {
  color: var(--kr-orange);
}

#kafka-router .kr-record__title {
  flex: 1 1 auto;
  color: var(--kr-term-text);
}

#kafka-router .kr-record__link {
  color: var(--kr-term-teal);
  text-decoration: none;
}

#kafka-router .kr-record__link:hover,
#kafka-router .kr-record__link:focus-visible {
  text-decoration: underline;
}

/* Motion */

@keyframes kr-flow {
  from { background-position: 0 0; }
  to { background-position: 12px 0; }
}

@keyframes kr-flow-y {
  from { background-position: 0 0; }
  to { background-position: 0 12px; }
}

@keyframes kr-travel {
  0% { left: 0; opacity: 0; }
  15% { opacity: 1; }
  85% { opacity: 1; }
  100% { left: calc(100% - 8px); opacity: 0; }
}

@keyframes kr-travel-y {
  0% { top: 0; opacity: 0; }
  15% { opacity: 1; }
  85% { opacity: 1; }
  100% { top: calc(100% - 8px); opacity: 0; }
}

@keyframes kr-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.5); }
}

@keyframes kr-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: .25; }
}

#kafka-router.is-paused *,
#kafka-router.is-paused *::before,
#kafka-router.is-paused *::after {
  animation-play-state: paused !important;
}

@media (prefers-reduced-motion: reduce) {
  #kafka-router * {
    animation: none !important;
  }
}

/* < 720px: produce and poll lines run top-to-bottom. */
@media (max-width: 719px) {
  #kafka-router .kr-prod-line .kr-dots,
  #kafka-router .kr-conn .kr-dots {
    width: 4px;
    height: 100%;
    background-size: 4px 12px;
    background-repeat: repeat-y;
  }

  #kafka-router .kr-prod-line .kr-dots.is-live,
  #kafka-router .kr-conn .kr-dots.is-live {
    animation-name: kr-flow-y;
  }

  #kafka-router .kr-prod-line .kr-packet,
  #kafka-router .kr-conn .kr-packet {
    top: 0;
    left: 1px;
    animation-name: kr-travel-y;
  }
}

/* ≥ 720px: console rows on one line; hide append until 1100. */

@media (min-width: 720px) {
  #kafka-router .kr-append { display: none; }

  #kafka-router .kr-record {
    flex-wrap: nowrap;
  }

  #kafka-router .kr-record__part {
    flex: none;
    width: 250px;
  }

  #kafka-router .kr-record__key {
    flex: none;
    width: 150px;
  }
}

/* 720–1099: shrink cards, keep the row horizontal. */

@media (min-width: 720px) and (max-width: 1099px) {
  #kafka-router .kr-graph {
    flex-direction: row;
    align-items: center;
    min-width: 0;
  }

  #kafka-router .kr-producer {
    width: 180px;
    flex: none;
  }

  #kafka-router .kr-prod-line {
    width: 28px;
    height: 10px;
    margin: 0;
  }

  #kafka-router .kr-prod-line .kr-line {
    width: 28px;
    height: 10px;
  }

  #kafka-router .kr-topics {
    min-width: 0;
    padding: 4px 0;
    border-left: 3px dotted var(--kr-border);
  }

  #kafka-router .kr-row {
    flex-direction: row;
    align-items: center;
    gap: 0;
    min-width: 0;
  }

  #kafka-router .kr-tick {
    display: flex;
    align-items: center;
    width: 24px;
    height: 10px;
    flex: none;
  }

  #kafka-router .kr-topic {
    flex: 1 1 240px;
    min-width: 0;
    width: auto;
  }

  #kafka-router .kr-conn {
    flex: 1 1 48px;
    width: auto;
    min-width: 48px;
    padding: 0 8px;
  }

  #kafka-router .kr-conn .kr-line {
    width: 100%;
    height: 10px;
  }

  #kafka-router .kr-group {
    width: 220px;
    flex: none;
  }
}

/* ≥ 1100px: exact desktop sizes from the spec. */

@media (min-width: 1100px) {
  #kafka-router .kr-append { display: inline; }

  #kafka-router .kr-graph {
    flex-direction: row;
    align-items: center;
    min-width: 0;
  }

  #kafka-router .kr-producer {
    width: 230px;
    flex: none;
  }

  #kafka-router .kr-prod-line {
    width: 36px;
    height: 10px;
    margin: 0;
  }

  #kafka-router .kr-prod-line .kr-line {
    width: 36px;
    height: 10px;
  }

  #kafka-router .kr-topics {
    padding: 4px 0;
    border-left: 3px dotted var(--kr-border);
  }

  #kafka-router .kr-row {
    flex-direction: row;
    align-items: center;
    gap: 0;
  }

  #kafka-router .kr-tick {
    display: flex;
    align-items: center;
    width: 32px;
    height: 10px;
    flex: none;
  }

  #kafka-router .kr-topic {
    width: 420px;
    flex: none;
  }

  #kafka-router .kr-conn {
    flex: 1;
    width: auto;
    min-width: 80px;
    padding: 0 8px;
  }

  #kafka-router .kr-conn .kr-line {
    width: 100%;
    height: 10px;
  }

  #kafka-router .kr-group {
    width: 270px;
    flex: none;
  }
}
