/* ============================================================
   Hermes UI 2.0 — Premium Dark / Modern SaaS Dashboard
   Overlay поверх проверенной функциональной вёрстки.
   ============================================================ */

:root {
  --bg-primary: #0b0f19;
  --bg-secondary: #111827;
  --bg-card: #151c2b;
  --bg-elevated: #1c2638;
  --bg-hover: #1c2638;
  --border-default: #293349;
  --border-color: #293349;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --accent-primary: #6366f1;
  --accent-hover: #818cf8;
  --accent-contrast: #ffffff;
  --accent-soft: rgba(99, 102, 241, 0.14);
  --status-success: #22c55e;
  --status-warning: #f59e0b;
  --status-danger: #ef4444;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 22px;
  --nav-height: 68px;
  --content-max: 1120px;
  --shadow-card: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 12px 32px rgba(2, 6, 23, 0.22);
  --shadow-pop: 0 28px 70px rgba(2, 6, 23, 0.56);
  color-scheme: dark;
}

[data-theme="light"] {
  --bg-primary: #f5f7fb;
  --bg-secondary: #eef2f8;
  --bg-card: #ffffff;
  --bg-elevated: #eef2f8;
  --bg-hover: #e8edf6;
  --border-default: #dfe6f0;
  --border-color: #dfe6f0;
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --accent-primary: #4f46e5;
  --accent-hover: #4338ca;
  --accent-contrast: #ffffff;
  --accent-soft: rgba(79, 70, 229, 0.1);
  --status-success: #16a34a;
  --status-warning: #d97706;
  --status-danger: #dc2626;
  --shadow-card: 0 1px 2px rgba(15, 23, 42, 0.04), 0 10px 30px rgba(15, 23, 42, 0.05);
  --shadow-pop: 0 28px 70px rgba(15, 23, 42, 0.18);
  color-scheme: light;
}

html {
  scroll-behavior: smooth;
}

body {
  min-height: 100dvh;
  background:
    radial-gradient(900px 480px at 85% -10%, color-mix(in srgb, var(--accent-primary) 7%, transparent), transparent 70%),
    var(--bg-primary);
  font-size: 15px;
  letter-spacing: -0.006em;
}

:where(button, a, input, select, textarea):focus-visible {
  outline: 2px solid var(--accent-hover);
  outline-offset: 2px;
}

.btn:not(.btn--small) {
  min-height: 44px;
}

.icon-btn {
  min-width: 44px;
  min-height: 44px;
}

.ssh-field input,
.ssh-field select,
.ssh-field textarea,
.chat-composer textarea {
  min-height: 44px;
}

h1, h2, h3, h4, .metric-value, .value, .task-stat__count {
  font-variant-numeric: tabular-nums;
}

h1 {
  font-size: clamp(24px, 5vw, 27px);
  font-weight: 720;
  letter-spacing: -0.035em;
  line-height: 1.15;
}

.page-head {
  margin-bottom: 18px;
}

.eyebrow {
  color: var(--accent-hover);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.page-sub {
  color: var(--text-secondary);
  font-size: 12.5px;
  line-height: 1.5;
  max-width: 60ch;
}

.section-head {
  margin-top: 20px;
  margin-bottom: 9px;
}

.section-head h2 {
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -0.015em;
}

.card {
  border-color: var(--border-default);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  box-shadow: var(--shadow-card);
}

.card-note, .muted, .metric-note, .service-sub {
  color: var(--text-secondary);
}

/* ---------- Navigation ---------- */

.topbar {
  background: color-mix(in srgb, var(--bg-primary) 88%, transparent);
  border-bottom-color: color-mix(in srgb, var(--border-default) 75%, transparent);
  backdrop-filter: blur(18px) saturate(1.2);
}

.brand-mark, .avatar {
  border-radius: 12px;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent-primary) 30%, transparent);
}

.side-nav {
  gap: 3px;
}

.side-link {
  border-radius: 10px;
  color: var(--text-secondary);
  font-size: 12.5px;
  font-weight: 550;
}

.side-link:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.side-link.is-active {
  background: var(--accent-soft);
  color: var(--accent-hover);
}

.bottom-nav {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding: 5px calc(6px + var(--safe-right)) var(--safe-bottom) calc(6px + var(--safe-left));
  border-top-color: color-mix(in srgb, var(--border-default) 80%, transparent);
  background: color-mix(in srgb, var(--bg-card) 94%, transparent);
  box-shadow: 0 -12px 36px rgba(2, 6, 23, 0.28);
  backdrop-filter: blur(20px) saturate(1.15);
}

.nav-item {
  position: relative;
  min-height: 52px;
  gap: 3px;
  border-radius: 12px;
  color: var(--text-secondary);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0;
  transition: color 140ms ease, background 140ms ease, transform 100ms ease;
}

.nav-item .icon {
  width: 20px;
  height: 20px;
  transition: transform 180ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.nav-item.is-active {
  color: var(--accent-hover);
  background: color-mix(in srgb, var(--accent-primary) 10%, transparent);
}

.nav-item.is-active .icon {
  transform: translateY(-1px);
  stroke-width: 2.15;
}

.nav-item:active {
  transform: scale(0.96);
}

/* ---------- Buttons / controls ---------- */

.btn {
  min-height: 40px;
  padding: 0 14px;
  border-radius: var(--radius-md);
  border-color: var(--border-default);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
  transition: background 130ms ease, border-color 130ms ease, transform 110ms ease, color 130ms ease;
}

.btn:hover {
  background: var(--bg-hover);
  border-color: color-mix(in srgb, var(--border-default) 60%, var(--text-secondary));
}

.btn:active {
  transform: scale(0.97);
}

.btn--ghost {
  background: transparent;
  border-color: var(--border-default);
  color: var(--text-secondary);
}

.btn--ghost:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn--primary, .btn:not(.btn--ghost):not(.btn--danger) {
  background: var(--accent-primary);
  border-color: transparent;
  color: var(--accent-contrast);
}

.btn--primary:hover, .btn:not(.btn--ghost):not(.btn--danger):hover {
  background: var(--accent-hover);
}

.btn--danger {
  background: color-mix(in srgb, var(--status-danger) 12%, transparent);
  border-color: color-mix(in srgb, var(--status-danger) 36%, var(--border-default));
  color: var(--status-danger);
}

.btn--small {
  min-height: 33px;
  padding: 0 10px;
  font-size: 11px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 11px;
  transition: background 130ms ease, color 130ms ease, transform 110ms ease;
}

.icon-btn:hover {
  background: var(--bg-hover);
}

.icon-btn:active {
  transform: scale(0.94);
}

.chip {
  min-height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.005em;
}

.progress {
  height: 6px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--bg-elevated) 80%, transparent);
}

.progress-fill {
  border-radius: inherit;
  transition: width 320ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* ---------- Dashboard ---------- */

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

.quick-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  color: var(--text-primary);
  text-decoration: none;
  transition: border-color 150ms ease, background 150ms ease, transform 120ms ease;
}

.quick-card:hover {
  border-color: color-mix(in srgb, var(--accent-primary) 48%, var(--border-default));
  background: var(--bg-hover);
}

.quick-card:active {
  transform: scale(0.985);
}

.quick-card__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  color: var(--accent-hover);
  background: var(--accent-soft);
}

.quick-card__title {
  margin-top: 3px;
  font-size: 12.5px;
  font-weight: 650;
}

.quick-card__sub {
  color: var(--text-secondary);
  font-size: 10.5px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.metrics-grid {
  gap: 8px;
}

.metric-card {
  padding: 13px;
  border-radius: var(--radius-md);
}

.metric-name {
  font-size: 12px;
  font-weight: 600;
}

.metric-value .value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.045em;
}

.metric-value .unit {
  font-size: 12px;
}

.metric-note {
  font-size: 10px;
  line-height: 1.4;
}

/* ---------- VPS hub ---------- */

.vps-hub {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}

.vps-hub-card {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
  padding: 13px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  color: var(--text-primary);
  text-decoration: none;
  transition: border-color 150ms ease, background 150ms ease;
}

.vps-hub-card:hover {
  border-color: color-mix(in srgb, var(--accent-primary) 45%, var(--border-default));
  background: var(--bg-hover);
}

.vps-hub-card__title {
  font-size: 12.5px;
  font-weight: 650;
}

.vps-hub-card__sub {
  color: var(--text-secondary);
  font-size: 10.5px;
  line-height: 1.4;
}

/* ---------- Chat ---------- */

.chat-shell {
  border-color: var(--border-default);
  border-radius: var(--radius-xl);
  background: color-mix(in srgb, var(--bg-card) 82%, var(--bg-primary));
  box-shadow: var(--shadow-card);
}

.chat-topline {
  border-bottom-color: color-mix(in srgb, var(--border-default) 70%, transparent);
}

.chat-messages {
  padding: 16px;
  gap: 12px;
}

.msg {
  max-width: min(94%, 760px);
}

.msg-bubble {
  padding: 10px 13px;
  border-radius: 15px;
  border-color: var(--border-default);
  background: var(--bg-card);
  font-size: 13.5px;
  line-height: 1.6;
}

.msg--user .msg-bubble {
  background: linear-gradient(180deg, var(--accent-primary), color-mix(in srgb, var(--accent-primary) 86%, #000));
  border-color: transparent;
  color: var(--accent-contrast);
  box-shadow: 0 8px 24px color-mix(in srgb, var(--accent-primary) 18%, transparent);
}

.msg--assistant .msg-bubble {
  border-color: color-mix(in srgb, var(--border-default) 85%, transparent);
}

.msg-meta {
  font-size: 10px;
}

.chat-composer {
  border-top-color: color-mix(in srgb, var(--border-default) 70%, transparent);
  background: color-mix(in srgb, var(--bg-card) 92%, transparent);
  padding-bottom: calc(8px + var(--safe-bottom));
}

.chat-composer textarea {
  border-radius: var(--radius-md);
  border-color: var(--border-default);
  background: var(--bg-primary);
  font-size: 14px;
  line-height: 1.5;
}

.chat-composer textarea:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.chat-send {
  background: var(--accent-primary);
  color: var(--accent-contrast);
  border-radius: var(--radius-md);
}

.chat-send:hover {
  background: var(--accent-hover);
}

.code-block {
  border-color: var(--border-default);
  border-radius: 10px;
  background: #0a0e17;
}

.code-block pre, .code-block code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.6;
}

/* Markdown tabular data stays inside the message. */
.msg-bubble table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  font-size: 11.5px;
}

.msg-bubble th, .msg-bubble td {
  padding: 6px 8px;
  border: 1px solid var(--border-default);
}

/* ---------- Modal / bottom sheet ---------- */

.modal {
  align-items: flex-end;
}

.modal-backdrop {
  background: rgba(2, 6, 23, 0.68);
  backdrop-filter: blur(6px);
  animation: uiFadeIn 180ms ease both;
}

.modal-card {
  max-width: 560px;
  max-height: min(88dvh, 760px);
  padding: 18px calc(18px + var(--safe-right)) calc(18px + var(--safe-bottom)) calc(18px + var(--safe-left));
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  border-color: var(--border-default);
  background: var(--bg-card);
  box-shadow: var(--shadow-pop);
  animation: uiSheetIn 240ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.modal-head h2 {
  font-size: 17px;
  font-weight: 680;
}

.modal-body {
  font-size: 13px;
  line-height: 1.55;
}

.modal-foot .btn {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

/* ---------- States ---------- */

body.keyboard-open .bottom-nav {
  transform: translateY(120%);
  opacity: 0;
  pointer-events: none;
}

body.keyboard-open .chat-shell {
  min-height: 0;
}

body.keyboard-open .chat-composer {
  padding-bottom: calc(8px + var(--safe-bottom));
}

.empty-state {
  padding: 22px 12px;
  color: var(--text-secondary);
}

.empty-state h3 {
  color: var(--text-primary);
  font-size: 13px;
}

.empty-state p {
  font-size: 11.5px;
  line-height: 1.5;
}

.notice {
  border-color: color-mix(in srgb, var(--accent-primary) 24%, var(--border-default));
  background: color-mix(in srgb, var(--accent-primary) 6%, transparent);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 10.5px;
}

.skeleton {
  position: relative;
  overflow: hidden;
  border-radius: 7px;
  background: var(--bg-elevated);
}

.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--text-primary) 7%, transparent), transparent);
  animation: uiShimmer 1.4s infinite;
}

/* ---------- Motion ---------- */

.view:not([hidden]) {
  animation: uiViewIn 190ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

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

@keyframes uiFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes uiSheetIn {
  from { opacity: 0; transform: translateY(18px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes uiShimmer {
  to { transform: translateX(100%); }
}

@media (pointer: coarse) {
  .card:hover, .quick-card:hover, .vps-hub-card:hover {
    border-color: var(--border-default);
    background: var(--bg-card);
  }

  .card:active, .quick-card:active {
    transform: scale(0.99);
  }
}

@media (min-width: 900px) {
  .modal {
    align-items: center;
  }

  .modal-card {
    border-radius: var(--radius-xl);
    border-bottom: 1px solid var(--border-default);
    animation: uiModalIn 220ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
  }

  .quick-grid, .vps-hub {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .content {
    max-width: var(--content-max);
    margin: 0 auto;
  }
}

@keyframes uiModalIn {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 380px) {
  h1 { font-size: 23px; }
  .nav-item { font-size: 9px; }
  .quick-grid, .vps-hub { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Keep long technical values inside cards. */
.ssh-fingerprint, .task-detail-id, .job-id, .chat-session-id, code, pre {
  overflow-wrap: anywhere;
}
