/* ============== Host card (метрики хоста) ============== */

section.host {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 0.75rem;
  padding: 0.75rem 1.5rem 0;
}

.host-tile {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 0.7rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.host-tile .ht-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #64748b;
  font-weight: 600;
}

.host-tile .ht-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: #00247D;
  line-height: 1;
}
.host-tile .ht-value small {
  font-size: 1rem;
  color: #64748b;
  margin-left: 0.15rem;
  font-weight: 500;
}

.host-tile .ht-sub {
  font-size: 0.78rem;
  color: #64748b;
}

.host-tile canvas.spark {
  width: 100%;
  height: 40px;
  margin-top: 0.4rem;
  display: block;
}

/* ============== View tabs ============== */

nav.view-tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.5rem 1.5rem 0;
  border-bottom: 1px solid #e2e8f0;
  background: #f8fafc;
}
nav.view-tabs .view-tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 0.5rem 0.9rem;
  font: inherit;
  font-weight: 500;
  color: #64748b;
  cursor: pointer;
  margin-bottom: -1px;
}
nav.view-tabs .view-tab:hover {
  color: #00247D;
}
nav.view-tabs .view-tab.active {
  color: #00247D;
  border-bottom-color: #00247D;
  font-weight: 600;
}

/* ============== Flat table ============== */

main.flat {
  flex: 1;
  padding: 0.75rem 1.5rem;
  overflow-x: auto;
}
table.flat-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  overflow: hidden;
}
table.flat-table th,
table.flat-table td {
  padding: 0.45rem 0.7rem;
  text-align: left;
  border-bottom: 1px solid #f1f5f9;
}
table.flat-table th {
  background: #f8fafc;
  font-weight: 600;
  color: #475569;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  position: sticky;
  top: 0;
}
table.flat-table th:hover {
  background: #e2e8f0;
}
table.flat-table th.num,
table.flat-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
table.flat-table th.sort-active {
  color: #00247D;
}
table.flat-table th.sort-active::after {
  content: ' ▲';
  font-size: 0.7em;
}
table.flat-table th.sort-active.sort-desc::after {
  content: ' ▼';
}
table.flat-table tbody tr:hover {
  background: #f8fafc;
}
table.flat-table td.num.lvl-warn {
  color: #b45309;
  font-weight: 600;
}
table.flat-table td.num.lvl-crit {
  color: #b91c1c;
  font-weight: 700;
}
.stack-tag {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  background: #eef2ff;
  color: #4f46e5;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 600;
}

/* ============== Container metrics ============== */

td.metrics {
  min-width: 220px;
}
.metrics-empty {
  color: #cbd5e1;
}
.metric-row {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  font-size: 0.78rem;
}
.metric-line {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  align-items: center;
  gap: 0.35rem;
}
.metric-line.metric-net {
  grid-template-columns: 32px 1fr;
}
.metric-label {
  text-transform: uppercase;
  font-size: 0.65rem;
  letter-spacing: 0.04em;
  color: #94a3b8;
  font-weight: 600;
}
.metric-value {
  font-variant-numeric: tabular-nums;
  color: #334155;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.metric-value.lvl-warn {
  color: #b45309;
  font-weight: 600;
}
.metric-value.lvl-crit {
  color: #b91c1c;
  font-weight: 700;
}
canvas.ctn-spark {
  width: 120px;
  height: 22px;
  display: block;
}

/* Reset / base */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f1f5f9;
  color: #0f172a;
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.4;
}

/* ============== Header ============== */

header.top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
  position: sticky;
  top: 0;
  z-index: 5;
}

header .title {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
}

header h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

header .subtitle {
  color: #94a3b8;
  font-size: 0.8rem;
  font-family: 'SF Mono', Consolas, Menlo, monospace;
}

header .status {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: #64748b;
  font-size: 0.8rem;
}

header .conn {
  color: #cbd5e1;
  font-size: 1.25rem;
  line-height: 1;
  transition: color 200ms ease;
}

header .conn.live {
  color: #22c55e;
}

header .conn.error {
  color: #ef4444;
}

/* ============== Body grid: stacks left, events right ============== */

.body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 360px);
  gap: 1rem;
  padding: 1rem 1.5rem;
  max-width: 1400px;
  margin: 0 auto;
  align-items: start;
}

.stacks {
  display: grid;
  gap: 1rem;
  min-width: 0;
}

.events {
  position: sticky;
  /* header высотой ~3rem; столбец прибит сразу под ним */
  top: calc(3rem + 1rem);
  align-self: start;
  display: flex;
  flex-direction: column;
  /* ограничиваем по высоте окна минус header и небольшой отступ */
  max-height: calc(100vh - 3rem - 2rem);
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.events h2 {
  margin: 0;
  padding: 0.6rem 0.875rem;
  font-size: 0.7rem;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid #f1f5f9;
}

.events ul {
  list-style: none;
  margin: 0;
  padding: 0;
  font-family: 'SF Mono', Consolas, Menlo, monospace;
  font-size: 0.75rem;
  overflow-y: auto;
  flex: 1;
}

.events li {
  padding: 0.3rem 0.875rem;
  border-bottom: 1px solid #f8fafc;
  display: grid;
  grid-template-columns: 65px 1fr;
  grid-template-rows: auto auto;
  gap: 0 0.5rem;
  align-items: baseline;
  min-height: 2.2rem;
}

.events li:last-child {
  border-bottom: none;
}

.events .time {
  color: #94a3b8;
  grid-row: 1;
}

.events .ev-name {
  color: #0f172a;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  grid-row: 1;
}

.events .ev-action {
  color: #475569;
  font-size: 0.7rem;
  grid-column: 2;
  grid-row: 2;
}

.events .ev-action.die,
.events .ev-action.kill {
  color: #b45309;
}

.events .ev-extra {
  color: #64748b;
  font-size: 0.7rem;
  grid-column: 2;
  grid-row: 2;
  justify-self: end;
}

.events .ev-extra.bad {
  color: #dc2626;
}

.events .empty {
  padding: 1rem 0.875rem;
  color: #94a3b8;
  text-align: center;
  font-size: 0.75rem;
  font-family: -apple-system, sans-serif;
}

/* ============== Stacks cards ============== */

.loading {
  text-align: center;
  color: #94a3b8;
  padding: 3rem;
}

.stack {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.stack-header {
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #f1f5f9;
  flex-wrap: wrap;
  gap: 0.5rem;
  /* Header работает как drag-handle для пользовательской сортировки. */
  cursor: grab;
  user-select: none;
}
.stack-header:active {
  cursor: grabbing;
}
.stack-header .drag-grip {
  color: #cbd5e1;
  font-size: 1rem;
  line-height: 1;
  letter-spacing: -2px;
  transition: color 0.15s;
}
.stack-header:hover .drag-grip {
  color: #64748b;
}
.stack.dragging {
  opacity: 0.45;
  outline: 2px dashed #94a3b8;
  outline-offset: -2px;
}

.stack-header .left {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.stack-header h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.stack-header .file {
  color: #94a3b8;
  font-family: 'SF Mono', Consolas, Menlo, monospace;
  font-size: 0.75rem;
}

.stack-header .right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.lastredeploy {
  color: #94a3b8;
  font-size: 0.75rem;
}

/* ============== State badges ============== */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 4px;
  text-transform: lowercase;
  letter-spacing: 0.02em;
}

.badge-stable {
  background: #dcfce7;
  color: #166534;
}
.badge-degraded {
  background: #fef3c7;
  color: #92400e;
}
.badge-rebuilding {
  background: #dbeafe;
  color: #1e40af;
}
.badge-restarting {
  background: #ede9fe;
  color: #5b21b6;
}
.badge-down {
  background: #fee2e2;
  color: #991b1b;
}
.badge-empty {
  background: #f1f5f9;
  color: #64748b;
}

.stack-rebuilding .stack-header,
.stack-restarting .stack-header {
  background: linear-gradient(90deg, transparent, #f5f3ff 50%, transparent);
}

.stack-down .stack-header {
  background: linear-gradient(90deg, transparent, #fef2f2 50%, transparent);
}

/* ============== Containers table ============== */

table.containers {
  width: 100%;
  border-collapse: collapse;
}

table.containers th,
table.containers td {
  padding: 0.5rem 1rem;
  text-align: left;
  border-bottom: 1px solid #f8fafc;
  vertical-align: top;
}

table.containers thead th {
  font-weight: 500;
  color: #64748b;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: #fafbfc;
  border-bottom: 1px solid #e2e8f0;
}

table.containers tbody tr:last-child td {
  border-bottom: none;
}

.cname {
  font-weight: 500;
  color: #0f172a;
}

.cservice {
  color: #94a3b8;
  font-size: 0.75rem;
  margin-top: 0.125rem;
}

.health {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-weight: 500;
}

.health-healthy,
.health-running {
  color: #16a34a;
}

.health-unhealthy {
  color: #dc2626;
}

.health-starting {
  color: #ea580c;
}

.health-exited,
.health-dead {
  color: #94a3b8;
}

.health-created {
  color: #64748b;
}

.uptime {
  font-family: 'SF Mono', Consolas, Menlo, monospace;
  color: #475569;
}

.image {
  font-family: 'SF Mono', Consolas, Menlo, monospace;
  font-size: 0.75rem;
  color: #64748b;
}

/* ============== Flash animations (changes highlight) ============== */

@keyframes flash {
  0% {
    background-color: var(--flash-color, rgba(59, 130, 246, 0.18));
  }
  100% {
    background-color: transparent;
  }
}

.flash-up {
  --flash-color: rgba(34, 197, 94, 0.24);
  animation: flash 1.4s ease-out;
}

.flash-down {
  --flash-color: rgba(239, 68, 68, 0.24);
  animation: flash 1.4s ease-out;
}

.flash-neutral {
  --flash-color: rgba(59, 130, 246, 0.20);
  animation: flash 1.4s ease-out;
}

.flash-new {
  --flash-color: rgba(34, 197, 94, 0.28);
  animation: flash 1.6s ease-out;
}

/* Бейдж стека отдельно — не мигаем фоном строки, мигаем самим бейджем. */
.badge.flash-up,
.badge.flash-down,
.badge.flash-neutral {
  animation-duration: 1.4s;
  animation-name: flashBadge;
}

@keyframes flashBadge {
  0% {
    box-shadow: 0 0 0 4px var(--flash-color);
  }
  100% {
    box-shadow: 0 0 0 0 transparent;
  }
}

/* ============== Footer ============== */

.foot {
  text-align: center;
  color: #94a3b8;
  font-size: 0.75rem;
  padding: 0 1.5rem 2rem;
}

/* ============== Mobile / narrow screens ============== */

@media (max-width: 900px) {
  .body {
    grid-template-columns: 1fr;
  }

  .events {
    position: static;
    max-height: 320px;
  }
}

@media (max-width: 700px) {
  table.containers th,
  table.containers td {
    padding: 0.5rem;
  }
}
