:root {
  --bg: #070d16;
  --bg-soft: #0c1623;
  --panel: #0f1b2a;
  --panel-2: #132438;
  --line: #21354d;
  --line-strong: #2e4a68;
  --text: #eef6ff;
  --muted: #93a9c8;
  --brand: #81f0d0;
  --brand-strong: #173c35;
  --accent: #4fb8ff;
  --warn: #ffd37b;
  --danger: #ff9d9d;
  --danger-bg: #422427;
  --shadow: 0 22px 54px rgba(0, 0, 0, 0.26);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
}

body {
  margin: 0;
  font: 16px "Segoe UI", Tahoma, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(79, 184, 255, 0.08), transparent 24%),
    radial-gradient(circle at bottom right, rgba(129, 240, 208, 0.05), transparent 22%),
    linear-gradient(180deg, #08111d 0%, #060c14 100%);
}

button,
input,
select,
textarea {
  font: inherit;
}

.hidden {
  display: none !important;
}

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

.sidebar {
  padding: 26px 20px;
  background: linear-gradient(180deg, #0d1723, #09121d);
  border-right: 1px solid rgba(53, 80, 110, 0.45);
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 54px;
  height: 54px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--brand), var(--accent));
  color: #08231a;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.brand-mark-image {
  overflow: hidden;
  background: #0e1622;
  border: 1px solid rgba(129, 240, 208, 0.22);
}

.brand-mark-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.brand-title {
  font-size: 1.18rem;
  font-weight: 700;
}

.brand-subtitle {
  color: var(--brand);
  font-size: 0.82rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.nav-section-label {
  margin: 10px 4px 2px;
  color: #b9a4ff;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.nav-link {
  display: block;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 12px 14px;
  text-align: left;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

.nav-link:hover,
.nav-link.active {
  transform: translateX(4px);
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(129, 240, 208, 0.28);
}

.sidebar-note,
.panel-header p,
.page-header p,
.summary-hint,
.empty-state,
td .muted,
.card-label {
  color: var(--muted);
}

.main {
  padding: 28px;
}

.page-header,
.panel-header,
.detail-head,
.stack-mobile {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 16px;
}

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

h1,
h2,
h3,
h4,
summary span:first-child {
  margin: 0;
}

.toolbar,
.filters,
.detail-actions,
.form-actions,
.modal-actions,
.row-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.button,
.input,
.select,
textarea {
  width: 100%;
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: var(--bg-soft);
  color: var(--text);
}

textarea {
  min-height: 120px;
  resize: vertical;
}

.button {
  width: auto;
  cursor: pointer;
}

.button:hover {
  filter: brightness(1.05);
}

.button-primary {
  background: var(--brand);
  color: #08231a;
  border-color: var(--brand);
}

.button-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: #7a3e45;
}

.button-warn {
  background: #3b2e16;
  color: var(--warn);
  border-color: #80653a;
}

.status-banner {
  margin-bottom: 16px;
  padding: 12px 14px;
  border-radius: 10px;
  background: #13293f;
  border: 1px solid #36536f;
}

.ops-overview {
  margin-bottom: 16px;
}

.ops-overview-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  margin-bottom: 14px;
}

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

.ops-pill {
  flex: 0 0 auto;
  border: 1px solid rgba(185, 164, 255, 0.42);
  border-radius: 999px;
  color: #d7cbff;
  background: rgba(96, 73, 154, 0.18);
  padding: 7px 11px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.ops-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
}

.ops-item {
  min-height: 150px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border: 1px solid rgba(53, 80, 110, 0.74);
  border-radius: 10px;
  background: rgba(8, 16, 26, 0.58);
  padding: 14px;
}

.ops-item-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.ops-label,
.ops-note {
  color: var(--muted);
  font-size: 0.84rem;
}

.ops-value {
  font-size: 1.08rem;
  font-weight: 800;
  word-break: break-word;
}

.ops-note {
  line-height: 1.35;
}

.ops-badge {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 0.75rem;
  font-weight: 800;
}

.ops-badge.good {
  color: #9ff5d8;
  background: rgba(23, 60, 53, 0.82);
}

.ops-badge.warn {
  color: #ffd37b;
  background: rgba(88, 59, 16, 0.6);
}

.ops-badge.muted {
  color: #c2d1e8;
  background: rgba(116, 145, 173, 0.14);
}

.ops-link {
  margin-top: auto;
  color: var(--brand);
  font-weight: 800;
  text-decoration: none;
}

.ops-link:hover {
  text-decoration: underline;
}

.cards-grid,
.panel-grid {
  display: grid;
  gap: 16px;
}

.cards-grid {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-bottom: 16px;
}

.two-col {
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  margin-bottom: 16px;
}

.card,
.panel,
.collapsible,
.subpanel,
.inline-form-shell {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card,
.panel,
.subpanel {
  padding: 18px;
}

.card-value {
  font-size: 1.9rem;
  font-weight: 700;
}

.card-clickable {
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.card-clickable:hover {
  transform: translateY(-2px);
  border-color: rgba(129, 240, 208, 0.34);
  background: rgba(19, 36, 56, 0.95);
}

.card-note {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.83rem;
  line-height: 1.35;
}

.inline-form-shell {
  margin: 18px 0 10px;
  padding: 14px;
  background: var(--bg-soft);
}

.inline-form-shell summary,
.collapsible summary,
.collapsible-section summary {
  cursor: pointer;
  list-style: none;
}

.inline-form-shell summary::-webkit-details-marker,
.collapsible summary::-webkit-details-marker,
.collapsible-section summary::-webkit-details-marker {
  display: none;
}

.admin-form {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.compact-form {
  margin-bottom: 14px;
}

.manual-export-panel {
  margin: 12px 0 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(79, 184, 255, 0.05);
}

.manual-export-panel .toolbar {
  margin-bottom: 12px;
}

.form-span-2 {
  grid-column: span 2;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: var(--bg-soft);
}

.checkbox input {
  width: auto;
}

.panel > .panel-header,
.subpanel > .panel-header {
  margin-bottom: 14px;
}

.collapsible,
.collapsible-section {
  padding: 0;
  overflow: hidden;
}

.collapsible summary,
.collapsible-section summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 18px;
}

.panel-content {
  padding: 0 18px 18px;
}

.flat-subpanel {
  padding: 0;
  border: 0;
  box-shadow: none;
  background: transparent;
}

.chart-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chart-row {
  display: grid;
  grid-template-columns: 120px 1fr 110px;
  gap: 12px;
  align-items: center;
}

.chart-bar-track {
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: #0f1d2d;
  overflow: hidden;
  border: 1px solid var(--line);
}

.chart-bar {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--brand), var(--accent));
}

.node-overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.metric-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(11, 18, 27, 0.78);
  padding: 14px 16px;
}

.metric-card-title {
  color: var(--muted);
  font-size: 0.82rem;
  margin-bottom: 8px;
}

.metric-card-value {
  font-size: 1.32rem;
  font-weight: 700;
}

.metric-card-note {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.8rem;
}

.panel-inline-note {
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(12, 22, 35, 0.9);
  border: 1px solid var(--line);
  color: var(--muted);
}

.table-wrap {
  overflow-x: auto;
}

.scroll-panel {
  max-height: 260px;
  overflow: auto;
  border: 1px solid rgba(53, 80, 110, 0.42);
  border-radius: 14px;
}

#recent-sessions-table .table-wrap {
  max-height: 260px;
  overflow: auto;
}

#recent-sessions-table th,
#active-sessions-table th {
  position: sticky;
  top: 0;
  z-index: 1;
}

.active-session-controls {
  margin: 18px 0;
  align-items: center;
}

.active-session-controls .input {
  min-width: min(340px, 100%);
}

.session-count-pill {
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(129, 240, 208, 0.05);
}

.active-sessions-table-wrap {
  max-height: calc(100vh - 360px);
  min-height: 280px;
  overflow: auto;
}

.table-sort-button {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 999px;
  background: rgba(129, 240, 208, 0.045);
  color: var(--muted);
  cursor: pointer;
  padding: 5px 8px;
  text-align: left;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.table-sort-button:hover,
.table-sort-button.active {
  color: var(--brand);
  border-color: rgba(129, 240, 208, 0.35);
  background: rgba(129, 240, 208, 0.1);
}

.sort-arrow {
  color: var(--brand);
  font-size: 0.8rem;
}

.row-active-session {
  background: rgba(129, 240, 208, 0.035);
}

.row-stale-session {
  background: rgba(238, 188, 104, 0.045);
}

.row-error-session,
.session-error-detail-row {
  background: rgba(255, 110, 110, 0.045);
}

.session-error-detail-row details {
  border: 1px solid rgba(255, 110, 110, 0.22);
  border-radius: 12px;
  padding: 10px 12px;
  background: rgba(47, 20, 24, 0.52);
}

.session-error-detail-row summary {
  cursor: pointer;
  color: var(--danger);
  font-weight: 700;
}

.session-error-detail-row pre {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 10px 0 0;
  color: #ffd2d2;
  font-size: 0.86rem;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid rgba(53, 80, 110, 0.42);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

.action-link {
  border: 0;
  background: transparent;
  color: var(--brand);
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.8rem;
  background: #1c3551;
  color: var(--warn);
}

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

.badge.active,
.badge.success,
.badge.clean {
  background: var(--brand-strong);
  color: var(--brand);
}

.badge.muted {
  background: rgba(116, 145, 173, 0.12);
  color: var(--muted);
}

.badge.auto {
  background: rgba(116, 145, 173, 0.12);
  color: var(--muted);
}

.badge.manual-export {
  background: #3b2e16;
  color: var(--warn);
}

.badge.external-app,
.badge.amnezia-compatible,
.badge.awg2 {
  background: #1a3148;
  color: #8ed2ff;
}

.badge.paused,
.badge.maintenance {
  background: #3b2e16;
  color: var(--warn);
}

.badge.expired,
.badge.disabled,
.badge.error,
.badge.suspicious {
  background: var(--danger-bg);
  color: var(--danger);
}

.badge.grace,
.badge.degraded {
  background: #3d2b1f;
  color: #f8bb8b;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin: 18px 0;
}

.meta-card {
  padding: 14px;
  border-radius: 14px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
}

.meta-label {
  color: var(--muted);
  font-size: 0.88rem;
  margin-bottom: 8px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.empty-state {
  padding: 18px;
}

.summary-hint {
  font-size: 0.92rem;
  text-align: right;
}

.toolbar .button,
.filters .button,
.filters .input,
.filters .select {
  width: auto;
}

.modal-shell {
  width: min(920px, calc(100vw - 32px));
  max-width: 920px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel);
  color: var(--text);
  padding: 0;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.42);
}

.modal-shell::backdrop {
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(4px);
}

.modal-card {
  padding: 20px;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 16px;
  margin-bottom: 16px;
}

.modal-subtitle {
  margin-top: 6px;
  color: var(--muted);
}

.modal-close {
  min-width: 44px;
}

.modal-actions {
  margin-top: 14px;
  justify-content: flex-end;
}

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

@media (max-width: 980px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    padding-bottom: 12px;
  }

  .page-header,
  .panel-header,
  .detail-head,
  .stack-mobile,
  .ops-overview-head,
  .modal-head {
    flex-direction: column;
  }

  .chart-row {
    grid-template-columns: 1fr;
  }

  .form-span-2 {
    grid-column: span 1;
  }

  .main {
    padding: 18px;
  }
}
