/* Personal Ops Orchestrator — тёмная минималистичная тема */

:root {
  color-scheme: dark;
  --bg: #0b0d10;
  --surface: #12151a;
  --surface-2: #171b21;
  --line: #1f242c;
  --ink: #e6e9ee;
  --muted: #8b94a1;
  --accent: #7c9eff;
  --accent-soft: rgba(124, 158, 255, 0.12);
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --mono: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

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

/* ---------- каркас ---------- */

.layout {
  display: grid;
  grid-template-columns: 232px 1fr;
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--surface);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 18px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
  animation: pulse 2.4s ease-in-out infinite;
}

.brand-name {
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.brand-sub {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  cursor: pointer;
  user-select: none;
}

.nav-item:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }

.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.nav-key {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
}

.nav-item.active .nav-key { border-color: var(--accent); color: var(--accent); }

.main {
  padding: 28px 32px 48px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

/* ---------- шапка страницы ---------- */

.page-head {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}

.page-title { margin: 0; font-size: 20px; font-weight: 700; }

.page-sub { color: var(--muted); font-size: 13px; margin: 2px 0 0; }

.head-actions { margin-left: auto; display: flex; align-items: center; gap: 12px; }

.refresh-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.refresh-btn:hover { border-color: var(--accent); background: var(--accent-soft); }
.refresh-btn:disabled { opacity: 0.5; cursor: default; }

.refresh-btn .spin {
  width: 12px;
  height: 12px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: rotate 0.8s linear infinite;
  display: none;
}

.refresh-btn.loading .spin { display: inline-block; }

/* круговой таймер автообновления */
.autorefresh {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-family: var(--mono);
}

.autorefresh svg { transform: rotate(-90deg); }
.autorefresh .ring-bg { stroke: var(--line); }
.autorefresh .ring-fg { stroke: var(--accent); transition: stroke-dashoffset 1s linear; }

/* ---------- поиск и фильтры ---------- */

.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.search {
  flex: 1;
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 14px;
  color: var(--ink);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search::placeholder { color: var(--muted); }

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

.chip {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}

.chip:hover { border-color: var(--accent); color: var(--ink); }
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* ---------- карточки и сетки ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
  animation: fadeUp 0.35s ease both;
}

.card:hover {
  border-color: #2c333d;
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.card-title { font-weight: 600; font-size: 14px; }

.card-kind {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 6px;
}

.card-body { color: var(--muted); font-size: 13px; }

.card-meta {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

/* staggered fade-in */
.grid > .card:nth-child(2) { animation-delay: 0.04s; }
.grid > .card:nth-child(3) { animation-delay: 0.08s; }
.grid > .card:nth-child(4) { animation-delay: 0.12s; }
.grid > .card:nth-child(5) { animation-delay: 0.16s; }
.grid > .card:nth-child(6) { animation-delay: 0.2s; }
.grid > .card:nth-child(n+7) { animation-delay: 0.24s; }

/* ---------- статусы ---------- */

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  position: relative;
}

.dot.ok { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot.warn { background: var(--warn); box-shadow: 0 0 8px var(--warn); }
.dot.bad { background: var(--bad); box-shadow: 0 0 8px var(--bad); }
.dot.idle { background: var(--muted); }

.dot.ok::after, .dot.warn::after, .dot.bad::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 1px solid currentColor;
  opacity: 0;
  animation: ripple 2s ease-out infinite;
}

.dot.ok::after { color: var(--ok); }
.dot.warn::after { color: var(--warn); animation-delay: 0.3s; }
.dot.bad::after { color: var(--bad); animation-delay: 0.6s; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--mono);
  border: 1px solid var(--line);
  color: var(--muted);
  background: var(--surface-2);
  white-space: nowrap;
}

.pill.ok { color: var(--ok); border-color: rgba(52, 211, 153, 0.35); background: rgba(52, 211, 153, 0.08); }
.pill.warn { color: var(--warn); border-color: rgba(251, 191, 36, 0.35); background: rgba(251, 191, 36, 0.08); }
.pill.bad { color: var(--bad); border-color: rgba(248, 113, 113, 0.35); background: rgba(248, 113, 113, 0.08); }
.pill.accent { color: var(--accent); border-color: rgba(124, 158, 255, 0.35); background: var(--accent-soft); }

/* ---------- статистика обзора ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 14px;
  margin-bottom: 18px;
}

.donut-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.donut { width: 96px; height: 96px; flex-shrink: 0; }
.donut .hole { fill: var(--surface); }
.donut text { fill: var(--ink); font-family: var(--mono); font-size: 20px; font-weight: 700; }
.donut .caption { fill: var(--muted); font-size: 8px; font-weight: 400; }

.legend { display: grid; gap: 6px; font-size: 12px; color: var(--muted); }
.legend-item { display: flex; align-items: center; gap: 8px; }
.legend-swatch { width: 8px; height: 8px; border-radius: 2px; }
.legend-count { margin-left: auto; font-family: var(--mono); color: var(--ink); }

.big-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px;
}

.big-stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  animation: fadeUp 0.35s ease both;
}

.big-stat-value {
  font-family: var(--mono);
  font-size: 28px;
  font-weight: 700;
  line-height: 1.1;
}

.big-stat-label { color: var(--muted); font-size: 12px; margin-top: 4px; }

/* ---------- списки (пайплайны, MR, задачи) ---------- */

.list {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  transition: background 0.15s;
  animation: fadeUp 0.3s ease both;
}

.list-row:last-child { border-bottom: 0; }
.list-row:hover { background: var(--surface-2); }

.list-main { min-width: 0; flex: 1; }
.list-title {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-sub {
  font-size: 12px;
  color: var(--muted);
  font-family: var(--mono);
  margin-top: 2px;
}

.section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 24px 0 10px;
}

.section-title:first-child { margin-top: 0; }

/* ---------- скелетон и пустые состояния ---------- */

.skeleton {
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  min-height: 96px;
}

.empty {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.error-box {
  border: 1px solid rgba(248, 113, 113, 0.35);
  background: rgba(248, 113, 113, 0.06);
  color: var(--bad);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 13px;
  margin-bottom: 14px;
}

/* ---------- переходы страниц ---------- */

.page { animation: pageIn 0.25s ease; }

.hidden { display: none !important; }

.mono { font-family: var(--mono); }
.muted { color: var(--muted); }

.snapshot-time { font-family: var(--mono); font-size: 12px; color: var(--muted); }

/* ---------- анимации ---------- */

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

@keyframes ripple {
  0% { transform: scale(0.6); opacity: 0.7; }
  100% { transform: scale(1.6); opacity: 0; }
}

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

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

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pageIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- адаптив ---------- */

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 10px;
  }
  .brand { border-bottom: 0; padding-bottom: 6px; width: 100%; }
  .nav-key { display: none; }
  .main { padding: 18px 16px 36px; }
  .stat-grid { grid-template-columns: 1fr; }
}

/* ---------- канбан ---------- */

.kanban {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(220px, 1fr);
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 16px;
}

.kanban-col {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  min-height: 120px;
}

.kanban-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding: 2px 4px 10px;
}

.kanban-count {
  font-family: var(--mono);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 8px;
  font-size: 11px;
}

.kanban-card {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 8px;
  transition: border-color 0.15s, transform 0.15s;
  animation: fadeUp 0.3s ease both;
}

.kanban-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.kanban-card a { font-size: 12px; }
.kanban-empty { color: var(--muted); font-size: 12px; text-align: center; padding: 16px 0; }

/* ---------- формы ---------- */

.form-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.form-row .search { flex: 1; min-width: 140px; }
.form-row textarea.search { resize: vertical; font-family: inherit; }
.form-row .refresh-btn { flex-shrink: 0; margin-top: 0; }
select.search { appearance: none; cursor: pointer; }

/* ---------- meter ---------- */

.meter {
  height: 4px;
  background: var(--line);
  border-radius: 999px;
  margin-top: 8px;
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.6s ease;
}

.meter-fill.ok { background: var(--ok); }
.meter-fill.warn { background: var(--warn); }
.meter-fill.bad { background: var(--bad); }

/* ---------- полировка v2 ---------- */

body {
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(124, 158, 255, 0.07), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(52, 211, 153, 0.05), transparent 60%),
    var(--bg);
}

.sidebar {
  background: rgba(18, 21, 26, 0.85);
  backdrop-filter: blur(12px);
}

.brand-mark {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  flex-shrink: 0;
  background: linear-gradient(135deg, #7c9eff 0%, #34d399 100%);
  box-shadow: 0 0 18px rgba(124, 158, 255, 0.45);
  animation: brandGlow 3.5s ease-in-out infinite;
}

@keyframes brandGlow {
  0%, 100% { box-shadow: 0 0 12px rgba(124, 158, 255, 0.35); }
  50% { box-shadow: 0 0 22px rgba(52, 211, 153, 0.5); }
}

.nav-item svg {
  width: 15px;
  height: 15px;
  fill: currentColor;
  stroke: currentColor;
  flex-shrink: 0;
  opacity: 0.85;
}

.nav-item {
  position: relative;
}

.nav-item.active::before {
  content: "";
  position: absolute;
  left: -14px;
  top: 20%;
  bottom: 20%;
  width: 3px;
  border-radius: 999px;
  background: linear-gradient(180deg, #7c9eff, #34d399);
}

.nav-badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--bad);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  font-family: var(--mono);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  animation: pulse 1.6s ease-in-out infinite;
}

.nav-badge.warn-only { background: var(--warn); color: #1a1200; }

.sidebar-foot {
  margin-top: auto;
  padding: 12px 10px 4px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  font-family: var(--mono);
}

/* липкая шапка */
.page-head {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(11, 13, 16, 0.8);
  backdrop-filter: blur(12px);
  padding: 14px 0;
  margin: -14px 0 18px;
  border-bottom: 1px solid transparent;
}

/* стеклянные карточки */
.card, .big-stat, .donut-card, .list, .kanban-col {
  background: rgba(18, 21, 26, 0.75);
  backdrop-filter: blur(8px);
}

.card {
  border-top: 1px solid rgba(124, 158, 255, 0.12);
}

.card:hover {
  border-color: rgba(124, 158, 255, 0.45);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(124, 158, 255, 0.15);
}

/* баннер алертов */
.alert-banner {
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 13px;
  border: 1px solid;
  animation: fadeUp 0.3s ease both;
}

.alert-banner.critical {
  border-color: rgba(248, 113, 113, 0.5);
  background: linear-gradient(90deg, rgba(248, 113, 113, 0.14), rgba(248, 113, 113, 0.05));
  color: #fca5a5;
}

.alert-banner.warning {
  border-color: rgba(251, 191, 36, 0.45);
  background: linear-gradient(90deg, rgba(251, 191, 36, 0.12), rgba(251, 191, 36, 0.04));
  color: #fcd34d;
}

.alert-banner .alert-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 3px 0;
}

.alert-banner .alert-src {
  font-family: var(--mono);
  font-size: 11px;
  opacity: 0.75;
  flex-shrink: 0;
  min-width: 110px;
}

/* анимация доната */
.donut circle[stroke] {
  transition: stroke-dasharray 0.8s ease, stroke-dashoffset 0.8s ease;
}

/* числовые статы — лёгкий подъём при наведении */
.big-stat { transition: transform 0.2s, border-color 0.2s; }
.big-stat:hover { transform: translateY(-2px); border-color: #2c333d; }

/* скроллбар */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 999px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #2c333d; }

/* ---------- спарклайны и кнопки задач ---------- */

.spark { width: 100%; height: 56px; display: block; }
.spark-meta {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 11px;
  margin-top: 6px;
}
.alert-task { flex-shrink: 0; margin-left: auto; }
.alert-row { align-items: center; }

/* ---------- экран «только через Telegram» ---------- */

.lock-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  color: var(--muted);
}

.lock-screen h1 { color: var(--ink); font-size: 20px; margin: 0; }
.lock-screen p { font-size: 14px; line-height: 1.6; }
.lock-screen b { color: var(--accent); }
.lock-screen .brand-mark { width: 40px; height: 40px; border-radius: 12px; }
