:root {
  color-scheme: light;
  --tg-viewport-height: 100vh;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --text: #17202a;
  --muted: #627083;
  --line: #dbe2ea;
  --accent: #0f766e;
  --accent-soft: #dff5f1;
  --danger: #b42318;
  --danger-soft: #fee4e2;
  --warn: #946200;
  --warn-soft: #fff4cc;
  --ok: #067647;
  --ok-soft: #dcfae6;
  --shadow: 0 10px 30px rgba(16, 24, 40, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1560px, calc(100vw - 32px));
  height: max(var(--tg-viewport-height), 100vh);
  margin: 0 auto;
  padding: 18px 0 24px;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 58px;
  gap: 16px;
}

h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.1;
  font-weight: 760;
  letter-spacing: 0;
}

.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.icon-button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(120px, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.metric {
  min-height: 76px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.metric-label {
  color: var(--muted);
  font-size: 12px;
}

.metric-value {
  margin-top: 8px;
  font-size: 24px;
  line-height: 1;
  font-weight: 780;
}

.workspace {
  display: grid;
  grid-template-columns: 280px minmax(620px, 1fr) 360px;
  gap: 12px;
  align-items: stretch;
  min-height: 0;
  overflow: hidden;
}

.sidebar,
.details {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  max-height: 100%;
}

.sidebar {
  overflow: hidden;
}

.panel,
.main-panel,
.details {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel {
  padding: 12px;
}

.panel-title {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.project-list,
.service-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.project-list {
  max-height: min(36vh, 360px);
}

.service-list {
  max-height: calc(100vh - 560px);
  min-height: 180px;
}

.project-button {
  display: flex;
  justify-content: space-between;
  width: 100%;
  min-height: 36px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.project-button.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

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

.service-item {
  display: grid;
  grid-template-columns: 10px 1fr;
  gap: 8px;
  align-items: start;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.service-item:first-child {
  border-top: 0;
}

.service-name {
  font-weight: 650;
}

.service-detail {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.dot {
  width: 10px;
  height: 10px;
  margin-top: 5px;
  border-radius: 50%;
  background: var(--muted);
}

.dot.running,
.dot.ok {
  background: var(--ok);
}

.dot.warn,
.dot.restarting,
.dot.created,
.dot.paused {
  background: #d18b00;
}

.dot.down,
.dot.exited,
.dot.dead,
.dot.not_found,
.dot.error {
  background: var(--danger);
}

.main-panel {
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.search-box {
  display: grid;
  gap: 5px;
  width: min(360px, 100%);
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.search-box input {
  width: 100%;
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--text);
}

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

.segmented button,
.action-button {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
}

.segmented button.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: #064e49;
}

.table-wrap {
  overflow: auto;
  min-height: 0;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

tbody tr {
  background: var(--panel);
}

tbody tr:hover,
tbody tr.selected {
  background: #edf7f5;
}

.name-cell {
  display: grid;
  grid-template-columns: 12px 1fr;
  gap: 10px;
  align-items: center;
  min-width: 0;
}

.container-name {
  font-weight: 680;
  overflow-wrap: anywhere;
}

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

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.pill.ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.pill.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.pill.down {
  background: var(--danger-soft);
  color: var(--danger);
}

.details {
  min-height: 420px;
  padding: 14px;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.details h2 {
  margin: 0 0 6px;
  font-size: 18px;
  overflow-wrap: anywhere;
}

.detail-section {
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.detail-section:first-child {
  border-top: 0;
  padding-top: 0;
}

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

.detail-row {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 10px;
}

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

.detail-value {
  overflow-wrap: anywhere;
}

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

.action-button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.action-button.danger {
  border-color: var(--danger);
  color: var(--danger);
}

.action-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.empty-state {
  display: grid;
  min-height: 280px;
  place-items: center;
  color: var(--muted);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(460px, calc(100vw - 36px));
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}

.blocked {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.blocked-card {
  width: min(520px, 100%);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.blocked-card h1 {
  margin-bottom: 10px;
}

.blocked-card p {
  margin: 0;
  color: var(--muted);
}

@media (max-width: 1180px) {
  .summary-grid {
    grid-template-columns: repeat(4, minmax(120px, 1fr));
  }

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

  .details {
    grid-column: 1 / -1;
    min-height: auto;
    max-height: 42vh;
  }
}

@media (max-width: 760px) {
  html,
  body {
    height: auto;
    min-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
  }

  body {
    overscroll-behavior-y: auto;
  }

  .app-shell {
    width: 100%;
    height: auto;
    min-height: var(--tg-viewport-height);
    padding: 12px;
    overflow: visible;
    display: block;
  }

  .topbar {
    align-items: start;
  }

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

  .workspace {
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .sidebar,
  .details,
  .main-panel {
    max-height: none;
    height: auto;
    overflow: visible;
  }

  .sidebar {
    margin-bottom: 12px;
  }

  .project-list {
    max-height: none;
    overflow: visible;
  }

  .services-panel {
    display: none;
  }

  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .search-box {
    width: 100%;
  }

  .table-wrap {
    max-height: none;
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
  }

  table {
    min-width: 680px;
  }

  .action-grid {
    grid-template-columns: 1fr;
  }
}
