:root {
  --canvas: #08090a;
  --panel: #0f1011;
  --panel-2: #141516;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #ecedee;
  --text-dim: #9ba1a6;
  --text-faint: #6b7075;
  --accent: #7170ff;
  --accent-dim: rgba(113, 112, 255, 0.14);
  --ok: #4cb782;
  --warn: #d6a03a;
  --danger: #e05a5a;
  --radius: 10px;
  --radius-sm: 6px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--canvas);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body { min-height: 100vh; }

button, input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  color: inherit;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- shell ---------- */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 640px;
  margin: 0 auto;
  padding: 0 12px 72px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
  background: var(--canvas);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.brand svg { display: block; }

.brand-sub {
  color: var(--text-faint);
  font-size: 12px;
  font-weight: 400;
}

.topbar-spacer { flex: 1; }

.status-badges { display: flex; align-items: center; gap: 6px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  font-size: 11px;
  letter-spacing: 0.02em;
  color: var(--text-dim);
  white-space: nowrap;
}

.badge-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-faint);
}

.badge-live { color: var(--ok); border-color: rgba(76, 183, 130, 0.3); }
.badge-live .badge-dot { background: var(--ok); }
.badge-demo { color: var(--accent); border-color: rgba(113, 112, 255, 0.35); }
.badge-demo .badge-dot { background: var(--accent); }
.badge-offline { color: var(--danger); border-color: rgba(224, 90, 90, 0.35); }
.badge-offline .badge-dot { background: var(--danger); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--text-dim);
  cursor: pointer;
}

.icon-btn:hover { border-color: var(--border-strong); color: var(--text); }

/* ---------- tabs ---------- */
.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar { display: none; }

.tab {
  flex: 0 0 auto;
  padding: 6px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  white-space: nowrap;
}

.tab:hover { color: var(--text); background: var(--panel); }

.tab[aria-selected="true"] {
  color: var(--text);
  background: var(--accent-dim);
  border-color: rgba(113, 112, 255, 0.35);
}

/* the apps slot shows the short «Прил.» on phones (see the <960px block) so the
   label is never ellipsised; the full name stays in aria-label/title */
.tab-label-short { display: none; }

/* ---------- content ---------- */
.content { padding: 16px 0; display: flex; flex-direction: column; gap: 14px; }

.section-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  margin: 4px 0 0;
  font-weight: 600;
}

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 14px;
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.card-title { font-weight: 600; font-size: 14px; }
.card-note { color: var(--text-faint); font-size: 12px; }

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

.kpi {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 12px;
}

.kpi-label { color: var(--text-faint); font-size: 12px; }
.kpi-value { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi-sub { color: var(--text-faint); font-size: 11px; margin-top: 2px; }

.rows { display: flex; flex-direction: column; }

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-top: 1px solid var(--border);
}

.row:first-child { border-top: 0; }

.row-main { flex: 1; min-width: 0; }
.row-title { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { color: var(--text-faint); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { color: var(--text-dim); font-size: 11px; font-variant-numeric: tabular-nums; white-space: nowrap; }

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
}

.pill-running { color: var(--accent); border-color: rgba(113, 112, 255, 0.35); }
.pill-completed { color: var(--ok); border-color: rgba(76, 183, 130, 0.3); }
.pill-failed { color: var(--danger); border-color: rgba(224, 90, 90, 0.3); }
.pill-queued { color: var(--warn); border-color: rgba(214, 160, 58, 0.3); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
}

.btn:hover:not(:disabled) { border-color: rgba(255, 255, 255, 0.24); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #0a0a12; font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: #8281ff; }
.btn-danger { color: var(--danger); border-color: rgba(224, 90, 90, 0.35); background: transparent; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-sm { padding: 4px 9px; font-size: 12px; }

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

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; }
.field label { color: var(--text-dim); font-size: 12px; }

.input, .select, .textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--canvas);
  color: var(--text);
}

.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.textarea { min-height: 74px; resize: vertical; }

.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.filters .input { flex: 1 1 160px; }
.filters .select { flex: 0 0 auto; width: auto; }

.progress {
  position: relative;
  height: 6px;
  border-radius: 999px;
  background: var(--panel-2);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 999px;
  transition: width 240ms ease;
}

.progress-fill.is-warn { background: var(--warn); }
.progress-fill.is-danger { background: var(--danger); }
.progress-fill.is-ok { background: var(--ok); }

.metric { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.metric-head { display: flex; justify-content: space-between; color: var(--text-dim); font-size: 12px; }
.metric-value { color: var(--text); font-variant-numeric: tabular-nums; }

.mono { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--text-faint); }
.dim { color: var(--text-dim); }

.empty, .error-box, .loading {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 18px 14px;
  text-align: center;
  color: var(--text-faint);
  font-size: 13px;
}

.error-box { border-style: solid; border-color: rgba(224, 90, 90, 0.3); color: var(--danger); text-align: left; }

.skeleton {
  height: 12px;
  border-radius: 4px;
  background: linear-gradient(90deg, #141516 0%, #1c1d1f 50%, #141516 100%);
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
  margin-bottom: 8px;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.notice {
  border: 1px solid rgba(113, 112, 255, 0.3);
  background: var(--accent-dim);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 12px;
  color: var(--text);
}

.warn-notice {
  border-color: rgba(214, 160, 58, 0.35);
  background: rgba(214, 160, 58, 0.1);
}

/* ---------- modal + palette ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(4, 5, 6, 0.72);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
}

.overlay[hidden] { display: none; }

.modal {
  width: 100%;
  max-width: 460px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 16px;
}

.modal-title { font-weight: 600; margin-bottom: 8px; }
.modal-body { color: var(--text-dim); font-size: 13px; margin-bottom: 14px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

.palette { align-items: flex-start; padding-top: 60px; }

.palette-box {
  width: 100%;
  max-width: 520px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
}

.palette-input {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: var(--canvas);
  padding: 12px 14px;
  font-size: 14px;
}

.palette-input:focus { outline: none; }
.palette-list { max-height: 320px; overflow-y: auto; }

.palette-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.palette-item:hover, .palette-item[data-active="true"] { background: var(--panel-2); }
.palette-item small { color: var(--text-faint); margin-left: auto; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 60;
  max-width: 90vw;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  padding: 9px 12px;
  font-size: 13px;
}

.toast[hidden] { display: none; }
.toast.is-error { border-color: rgba(224, 90, 90, 0.4); color: var(--danger); }

.footer-note { color: var(--text-faint); font-size: 11px; text-align: center; padding-top: 8px; }

.tag-list { display: flex; gap: 5px; flex-wrap: wrap; }

/* ---------- mobile: fixed bottom tab bar (<960px) ---------- */
@media (max-width: 959px) {
  .app-shell {
    padding: 0 12px;
    /* clears the fixed tab bar (~56px) plus the gesture/safe area */
    padding-bottom: calc(84px + env(safe-area-inset-bottom));
  }

  .tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 2px;
    padding: 6px 8px;
    padding-bottom: calc(6px + env(safe-area-inset-bottom));
    overflow-x: visible;
    background: var(--canvas);
    border-top: 1px solid var(--border);
    border-bottom: 0;
    box-shadow: 0 -10px 22px rgba(0, 0, 0, 0.45);
  }

  .tab {
    width: 100%;
    min-width: 0;
    padding: 8px 4px;
    font-size: 11.5px;
    letter-spacing: 0;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* one fifth of a 360px bar cannot hold «Приложения»: swap in the short word
     instead of letting text-overflow cut it to «Приложе…» */
  .tab-label-full { display: none; }
  .tab-label-short { display: inline; }

  .toast {
    bottom: calc(78px + env(safe-area-inset-bottom));
  }
}

/* ---------- desktop ---------- */
@media (min-width: 960px) {
  .app-shell {
    max-width: 1180px;
    display: grid;
    grid-template-columns: 232px minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    gap: 0 24px;
    padding: 0 24px 32px;
  }

  .topbar { grid-column: 1 / -1; }
  .tabs {
    grid-column: 1;
    grid-row: 2;
    flex-direction: column;
    border-bottom: 0;
    border-right: 1px solid var(--border);
    padding: 16px 12px 16px 0;
    overflow: visible;
    height: max-content;
  }

  .tab { width: 100%; text-align: left; }
  .content { grid-column: 2; padding: 20px 0; }
  .kpi-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .overlay { align-items: center; padding-top: 0; }
}
