/* Тема — копия токенов Sandroom (apps/web/src/styles/global.scss). Шрифты системные: CSP не пускает внешние. */
:root {
  color-scheme: dark;
  --bg: #0a0c11;
  --surface-1: #141821;
  --surface-2: #1a1f2a;
  --line: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.13);
  --text-1: #f3f5f9;
  --text-2: #aab1c0;
  --text-3: #6f7789;
  --accent: #3fd8c7;
  --accent-soft: rgba(63, 216, 199, 0.12);
  --on-accent: #032421;
  --agent: #f7b04b;
  --agent-2: #ff7d5c;
  --danger: #ff7272;
  --danger-soft: rgba(255, 114, 114, 0.12);
  --radius: 14px;
  --top-h: 56px;
  --font: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text-1);
  font: 15px/1.5 var(--font);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

button {
  font: inherit;
  color: inherit;
}

.splash {
  height: 100dvh;
}

/* ─── Знак ─── */
.mark {
  display: block;
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--agent), var(--agent-2));
  box-shadow: 0 0 0 1px rgba(247, 176, 75, 0.25), 0 8px 32px -6px rgba(255, 125, 92, 0.35);
}

.mark::after {
  content: '';
  position: absolute;
  inset: 32%;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--bg);
}

.mark.small {
  width: 24px;
  height: 24px;
}

/* ─── Вход ─── */
.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 16px;
  background: radial-gradient(60% 50% at 50% 0%, rgba(63, 216, 199, 0.08), transparent 70%);
}

.login-card {
  width: min(400px, 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 32px 28px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface-1);
  box-shadow: 0 24px 64px -24px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.login-card h1 {
  margin: 8px 0 0;
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.lead {
  margin: 0 0 6px;
  color: var(--text-2);
  font-size: 14px;
}

#step-send,
#step-code {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.code {
  width: 100%;
  height: 56px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text-1);
  font: 600 26px/1 var(--mono);
  letter-spacing: 0.4em;
  text-align: center;
  outline: none;
}

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

.btn {
  height: 48px;
  border: 0;
  border-radius: var(--radius);
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, background-color 0.15s;
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.btn.primary {
  background: linear-gradient(135deg, #5ff0df, var(--accent));
  color: var(--on-accent);
}

.btn.quiet {
  background: transparent;
  color: var(--text-2);
}

.error {
  margin: 0;
  color: var(--danger);
  font-size: 14px;
}

.error:empty {
  display: none;
}

/* ─── Вкладки ─── */
.app {
  height: 100dvh;
  display: grid;
  grid-template-rows: var(--top-h) minmax(0, 1fr);
}

.top {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 12px 0 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(15, 18, 24, 0.9);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

.brand strong {
  font-weight: 650;
}

.brand span:last-child {
  color: var(--text-3);
  font-size: 13px;
}

.tabs {
  flex: 1;
  display: flex;
  gap: 4px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.tab {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text-2);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}

.tab svg {
  flex: none;
  opacity: 0.8;
}

.tab:hover {
  color: var(--text-1);
  background: rgba(255, 255, 255, 0.03);
}

.tab[aria-selected='true'] {
  color: var(--text-1);
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--line);
}

.tab[aria-selected='true'] svg {
  color: var(--accent);
  opacity: 1;
}

.actions {
  display: flex;
  gap: 4px;
}

.icon {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
}

.icon:hover {
  color: var(--text-1);
  background: rgba(255, 255, 255, 0.04);
}

.icon.danger:hover {
  color: var(--danger);
  background: var(--danger-soft);
}

svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.frames {
  position: relative;
  min-height: 0;
}

.frames iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--bg);
}

/* ─── Телефон: вкладки внизу, как в приложении ─── */
@media (max-width: 720px) {
  .app {
    grid-template-rows: 48px minmax(0, 1fr) calc(60px + env(safe-area-inset-bottom));
  }

  .top {
    display: contents;
  }

  .brand {
    grid-row: 1;
    padding: 0 16px;
    border-bottom: 1px solid var(--line);
    background: rgba(15, 18, 24, 0.9);
  }

  .actions {
    position: fixed;
    top: 6px;
    right: 8px;
  }

  .frames {
    grid-row: 2;
  }

  .tabs {
    grid-row: 3;
    gap: 0;
    padding: 0 4px env(safe-area-inset-bottom);
    border-top: 1px solid var(--line);
    background: rgba(15, 18, 24, 0.96);
  }

  .tab {
    flex: 1;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    height: 60px;
    padding: 0 4px;
    border-radius: 0;
    font-size: 11px;
  }

  .tab[aria-selected='true'] {
    background: transparent;
    box-shadow: none;
    color: var(--accent);
  }
}

/* ─── Вкладка «Сервер» ─── */
:root {
  --ok: #5ee39a;
  --ok-soft: rgba(94, 227, 154, 0.12);
  --warn: #f6c453;
  --info: #6aa8ff;
}

.server {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.server-inner {
  max-width: 920px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

.server h2 {
  margin: 28px 4px 10px;
  color: var(--text-3);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

.card + .card {
  margin-top: 10px;
}

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

.empty {
  padding: 24px 4px;
  color: var(--text-3);
}

.summary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
}

.summary::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

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

.summary.bad {
  color: var(--danger);
  background: var(--danger-soft);
}

.dot {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--text-3);
}

.dot.ok {
  background: var(--ok);
  box-shadow: 0 0 0 3px var(--ok-soft);
}

.dot.warn {
  background: var(--warn);
}

.dot.bad {
  background: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-soft);
}

.dot.info {
  background: var(--info);
}

/* Сервер */
.host {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  padding: 18px;
}

.meter-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  color: var(--text-2);
  font-size: 13px;
}

.meter-top strong {
  color: var(--text-1);
  font: 600 18px/1.2 var(--mono);
}

.bar {
  height: 6px;
  margin: 8px 0 6px;
  border-radius: 3px;
  background: var(--surface-2);
  overflow: hidden;
}

.bar i {
  display: block;
  height: 100%;
  border-radius: 3px;
  background: var(--accent);
  transition: width 0.4s;
}

.bar i.warn {
  background: var(--warn);
}

.bar i.bad {
  background: var(--danger);
}

.meter small {
  color: var(--text-3);
  font-size: 12px;
}

.host-up {
  grid-column: 1 / -1;
  color: var(--text-3);
  font-size: 12px;
}

/* Сайты */
.site {
  padding: 14px 18px;
}

.site + .site {
  border-top: 1px solid var(--line);
}

.site-top {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}

.site-top strong {
  text-transform: uppercase;
  font-size: 13px;
  letter-spacing: 0.04em;
}

.hours {
  display: grid;
  grid-template-columns: repeat(24, 1fr);
  gap: 3px;
  margin: 12px 0 8px;
}

.hours i {
  height: 22px;
  border-radius: 3px;
  background: var(--surface-2);
}

.hours i.ok {
  background: rgba(94, 227, 154, 0.55);
}

.hours i.warn {
  background: var(--warn);
}

.hours i.bad {
  background: var(--danger);
}

.site-uptime {
  display: flex;
  gap: 16px;
  color: var(--text-3);
  font: 12px var(--mono);
}

/* Контейнеры */
.group-title {
  padding: 12px 18px 4px;
  color: var(--text-3);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 56px 64px auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 11px 18px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.row:hover {
  background: rgba(255, 255, 255, 0.025);
}

.row + .row {
  border-top: 1px solid var(--line);
}

.row-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.row-main strong {
  font-size: 14px;
  font-weight: 600;
}

.row-main small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.row-num {
  color: var(--text-2);
  font: 12px var(--mono);
  text-align: right;
}

.badge {
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(246, 196, 83, 0.12);
  color: var(--warn);
  font: 600 11px var(--mono);
}

/* События */
.events {
  margin: 0;
  padding: 4px 0;
  list-style: none;
}

.event {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 10px;
  padding: 9px 18px;
  font-size: 13px;
}

.event .dot {
  transform: translateY(-1px);
}

.event-text {
  color: var(--text-2);
}

.event-text strong {
  color: var(--text-1);
  font-weight: 600;
}

.event time {
  font: 12px var(--mono);
  white-space: nowrap;
}

/* ─── Разделы «Сервера» ─── */
.server-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.server-top .summary {
  margin: 0;
  border: 0;
  font-family: inherit;
  cursor: pointer;
}

.views {
  display: flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-1);
  overflow-x: auto;
  scrollbar-width: none;
}

.view {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}

.view[aria-selected='true'] {
  background: var(--surface-2);
  color: var(--text-1);
  box-shadow: inset 0 0 0 1px var(--line);
}

.count {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--danger-soft);
  color: var(--danger);
  font: 600 11px/18px var(--mono);
  font-style: normal;
  text-align: center;
}

.text-warn {
  color: var(--warn) !important;
}

.card.pad {
  padding: 16px 18px;
}

/* Графики */
.charts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 18px;
  padding: 18px;
}

.chart-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  color: var(--text-2);
  font-size: 13px;
}

.chart-top strong {
  color: var(--text-1);
  font: 600 15px var(--mono);
}

.spark {
  display: block;
  width: 100%;
  height: 56px;
  margin: 8px 0 4px;
  border-bottom: 1px solid var(--line);
}

.chart-empty {
  display: grid;
  place-items: center;
  height: 56px;
  margin: 8px 0 4px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  font-size: 12px;
}

.chart small {
  font-size: 11px;
}

/* Базы */
.db-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px 4px;
}

.db-head strong {
  text-transform: uppercase;
  font-size: 13px;
  letter-spacing: 0.04em;
}

.db-head .muted {
  font: 12px var(--mono);
}

.db-stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
  padding: 12px 18px 16px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.stat span {
  font-size: 12px;
}

.stat strong {
  font: 600 17px var(--mono);
}

.stat small {
  font-size: 11px;
}

.tables {
  border-top: 1px solid var(--line);
  padding: 6px 0;
}

.tables-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 80px 80px 56px;
  gap: 10px;
  padding: 6px 18px;
  font: 12px var(--mono);
}

.tables-row span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tables-row span:not(:first-child) {
  text-align: right;
}

.tables-head {
  font-family: var(--font);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.long {
  padding: 12px 18px;
}

.long + .long {
  border-top: 1px solid var(--line);
}

.long-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
}

.long code {
  display: block;
  margin-top: 6px;
  color: var(--text-2);
  font: 12px/1.5 var(--mono);
  word-break: break-word;
}

/* Инциденты */
.incident {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: baseline;
  gap: 10px;
  padding: 11px 18px;
  font-size: 13px;
}

.incident + .incident {
  border-top: 1px solid var(--line);
}

.incident.open {
  background: rgba(255, 114, 114, 0.04);
}

.incident-main {
  display: flex;
  flex-direction: column;
  gap: 3px;
  color: var(--text-2);
}

.incident-main strong {
  color: var(--text-1);
}

.incident-main small {
  font-size: 12px;
}

@media (max-width: 720px) {
  .server-top {
    flex-direction: column;
    align-items: stretch;
  }

  .server-top .summary {
    align-self: flex-start;
  }

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

  .tables-row {
    grid-template-columns: minmax(0, 1fr) 64px 64px 44px;
    padding: 6px 14px;
  }
}

/* ─── Шторка ─── */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 7, 11, 0.72);
}

.sheet-panel {
  position: relative;
  width: min(440px, calc(100% - 32px));
  padding: 20px;
  border: 1px solid var(--line-strong);
  border-radius: 22px;
  background: var(--surface-1);
  box-shadow: 0 24px 64px -16px rgba(0, 0, 0, 0.7);
}

.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sheet-head h3 {
  margin: 0;
  font-size: 17px;
}

.sheet-info {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px 16px;
  margin: 16px 0 18px;
  font-size: 14px;
}

.sheet-info dt {
  color: var(--text-3);
}

.sheet-info dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.sheet-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.btn.soft {
  background: var(--surface-2);
  color: var(--text-1);
}

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

.note {
  margin: 10px 0 0;
  color: var(--text-2);
  font-size: 13px;
}

.note:empty {
  display: none;
}

/* ─── Логи ─── */
.logs {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--bg);
}

.logs-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px calc(10px) 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: var(--surface-1);
}

.logs-head strong {
  white-space: nowrap;
}

.logs-head input {
  flex: 1;
  min-width: 0;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text-1);
  font: 14px var(--font);
  outline: none;
}

.logs-body {
  margin: 0;
  padding: 12px 16px calc(24px + env(safe-area-inset-bottom));
  overflow: auto;
  font: 12px/1.55 var(--mono);
  white-space: pre-wrap;
  word-break: break-word;
}

.logs-body.loading {
  opacity: 0.5;
}

.log {
  color: var(--text-2);
}

.log.warn {
  color: var(--warn);
}

.log.error {
  color: var(--danger);
}

.log-time {
  margin-right: 10px;
  color: var(--text-3);
}

/* ─── Телефон ─── */
@media (max-width: 720px) {
  .host {
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
  }

  .row {
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    gap: 10px;
    padding: 11px 14px;
  }

  .row-num.cpu {
    display: none;
  }

  .sheet {
    place-items: end center;
  }

  .sheet-panel {
    width: 100%;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
    border-radius: 22px 22px 0 0;
  }

  .site-uptime {
    gap: 12px;
  }
}
