:root {
  --bg: #0b1628;
  --card: #12233b;
  --card-2: #173057;
  --line: rgba(255,255,255,.13);
  --text: #eef4ff;
  --muted: #b6c8e8;
  --blue: #2f7cff;
  --blue-2: #1f6fff;
  --green: #18c37e;
  --red: #ff5d73;
  --orange: #ffb02e;
  --radius: 18px;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(70, 125, 255, 0.22), transparent 28%),
    linear-gradient(180deg, #0a1628, #0c1b31 60%, #0b182b);
  color: var(--text);
}

a {
  color: #8cc3ff;
  text-decoration: none;
}

a:hover { color: #b6d6ff; }

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

.sidebar {
  border-right: 1px solid var(--line);
  background: rgba(5, 11, 22, 0.72);
  backdrop-filter: blur(10px);
  padding: 24px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.brand {
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 28px;
  letter-spacing: .3px;
}

.brand span { color: #75a7ff; }

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

.side-nav a,
.side-nav button {
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  text-decoration: none;
  font-size: 15px;
  cursor: pointer;
  transition: .2s ease;
}

.side-nav a:hover,
.side-nav button:hover {
  background: rgba(255,255,255,.04);
  border-color: var(--line);
}

.side-nav a.active {
  background: rgba(47, 124, 255, 0.18);
  border-color: rgba(47,124,255,.35);
}

.main {
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.page-intro h1,
.page-intro .title {
  font-size: 30px;
  font-weight: 800;
  margin: 0;
}

.page-intro .subtitle {
  color: var(--muted);
  margin-top: 6px;
  font-size: 14px;
}

.logout-form { margin: 0; }

.sidebar-logout {
  margin-top: auto;
  padding-top: 18px;
}

.sidebar-logout button {
  width: 100%;
  text-align: center;
  justify-content: center;
  background: rgba(255,255,255,.05);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.sidebar-logout button:hover {
  background: rgba(255,255,255,.09);
}

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

.grid > .card,
.grid > .stats-card,
.grid > .span-12 { grid-column: span 12; }
.grid > .span-6 { grid-column: span 6; }
.grid > .span-4 { grid-column: span 4; }
.grid > .span-3 { grid-column: span 3; }

.card,
.stats-card {
  background: linear-gradient(180deg, rgba(13,26,45,.96), rgba(10,21,36,.98));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
  padding: 22px;
}

.card h2,
.card h3,
.stats-card h2 {
  margin: 0 0 14px;
  font-size: 20px;
}

.card p,
.card li,
.card small {
  color: var(--text);
}

.note,
.muted,
.small,
small.hint,
.card p.note {
  color: var(--muted);
}

.small { font-size: 13px; }
.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  word-break: break-all;
}

.stats-number {
  font-size: 42px;
  font-weight: 800;
  line-height: 1;
}

.stats-label {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 10px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 14px;
}

.field { grid-column: span 12; }
.field.half { grid-column: span 6; }
.field.third { grid-column: span 4; }

label {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
  color: #dce8ff;
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  padding: 13px 14px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.14);
  background: #102542;
  color: var(--text);
  outline: none;
  font-size: 15px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(84, 142, 255, .8);
  box-shadow: 0 0 0 3px rgba(47,124,255,.16);
}

input::placeholder,
textarea::placeholder {
  color: #8ea2c8;
}

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

.btn,
button,
.link-btn {
  appearance: none;
  border: none;
  background: var(--blue);
  color: #fff;
  padding: 12px 16px;
  border-radius: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: .2s ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn:hover,
button:hover,
.link-btn:hover {
  background: var(--blue-2);
  transform: translateY(-1px);
}

.btn.secondary,
button.secondary,
.link-btn.secondary {
  background: rgba(255,255,255,.05);
  color: var(--text);
  border: 1px solid var(--line);
}

.btn.secondary:hover,
button.secondary:hover,
.link-btn.secondary:hover {
  background: rgba(255,255,255,.08);
}

.btn.red,
button.danger,
.link-btn.danger {
  background: var(--red);
}

.btn.red:hover,
button.danger:hover,
.link-btn.danger:hover {
  filter: brightness(.96);
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.inline-form {
  display: inline;
}

.alert {
  padding: 14px 16px;
  border-radius: 14px;
  margin-bottom: 16px;
  font-weight: 600;
  border: 1px solid transparent;
}

.alert.ok,
.alert.success {
  background: rgba(24,195,126,.12);
  border-color: rgba(24,195,126,.28);
  color: #c9ffe7;
}

.alert.err,
.alert.error {
  background: rgba(255,93,115,.12);
  border-color: rgba(255,93,115,.28);
  color: #ffd6dc;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
  border-radius: 14px;
}

thead th,
tr:first-child th {
  text-align: left;
  font-size: 13px;
  color: var(--muted);
  font-weight: 700;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

tbody td,
td {
  padding: 14px;
  border-bottom: 1px solid rgba(255,255,255,.06);
  vertical-align: middle;
}

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

.badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.badge.online {
  background: rgba(24,195,126,.12);
  color: #86efac;
}

.badge.offline {
  background: rgba(255,93,115,.12);
  color: #fca5a5;
}

.badge.unknown {
  background: rgba(148,163,184,.15);
  color: #d1d5db;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #64748b;
  display: inline-block;
}

.dot.online {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(24,195,126,.14);
}

.dot.offline {
  background: var(--red);
  box-shadow: 0 0 0 4px rgba(255,93,115,.12);
}

.list-steps {
  margin: 0;
  padding-left: 20px;
  display: grid;
  gap: 10px;
}

.checkbox-list {
  display: grid;
  gap: 10px;
  max-height: 260px;
  overflow: auto;
  padding-right: 4px;
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  background: rgba(255,255,255,.02);
}

.checkbox-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--blue);
}

.checkbox-item .meta {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.kv-list {
  display: grid;
  gap: 12px;
}

.kv-item {
  border: 1px solid var(--line);
  background: rgba(255,255,255,.02);
  border-radius: 14px;
  padding: 14px;
}

.kv-item strong {
  display: block;
  margin-bottom: 6px;
}

.code-inline {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(255,255,255,.03);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}


/* Login page */
.login-page {
  min-height: 100vh;
}

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: min(100%, 440px);
  padding: 28px;
}

.login-brand {
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 20px;
  letter-spacing: .3px;
}

.login-brand span {
  color: #75a7ff;
}

.login-card h1 {
  margin: 0 0 22px;
  font-size: 30px;
  font-weight: 800;
}

.login-form button.login-submit {
  margin-top: 4px;
}

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  .sidebar-logout {
    margin-top: 10px;
    padding-top: 0;
  }
}

@media (max-width: 760px) {
  .main { padding: 16px; }
  .field.half, .field.third, .grid > .span-6, .grid > .span-4, .grid > .span-3 {
    grid-column: span 12;
  }
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }
  .table-wrap { overflow-x: auto; }
}

/* Added: search, toast, QR modal, public connect page */
.search-form {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.search-form input {
  min-width: min(420px, 100%);
}

.toast {
  position: fixed;
  right: 24px;
  top: 24px;
  z-index: 9999;
  background: rgba(24, 195, 126, .95);
  color: #06111f;
  font-weight: 800;
  padding: 12px 16px;
  border-radius: 14px;
  transform: translateY(-20px);
  opacity: 0;
  pointer-events: none;
  transition: .2s ease;
  box-shadow: 0 12px 30px rgba(0,0,0,.25);
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.modal.hidden { display: none; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 9998;
  background: rgba(0,0,0,.62);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-card {
  width: min(440px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 24px;
  position: relative;
  text-align: center;
  box-shadow: 0 24px 70px rgba(0,0,0,.45);
}

.modal-card img {
  width: min(320px, 100%);
  background: #fff;
  border-radius: 16px;
  padding: 12px;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  padding: 0;
  background: rgba(255,255,255,.08);
}

.public-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.public-card {
  width: min(520px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 28px;
  text-align: center;
  box-shadow: 0 24px 70px rgba(0,0,0,.32);
}

.qr-box img {
  width: min(320px, 100%);
  background: white;
  border-radius: 16px;
  padding: 12px;
  margin: 16px auto;
}

.public-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 18px 0;
}

.public-url {
  display: block;
  word-break: break-all;
  white-space: normal;
  margin-top: 14px;
}

.checkbox-list .checkbox-item {
  display: flex;
  align-items: center;
  gap: 10px;
}

.checkbox-list .checkbox-item input[type="checkbox"] {
  width: auto;
  min-width: 16px;
  margin: 0;
}

@media (max-width: 720px) {
  .search-form,
  .public-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .toast {
    left: 16px;
    right: 16px;
    text-align: center;
  }
}

.flag-icon {
  width: 20px;
  height: 14px;
  object-fit: cover;
  border-radius: 3px;
  vertical-align: -2px;
  margin-right: 7px;
  box-shadow: 0 0 0 1px rgba(255,255,255,.14);
}
.checkbox-item .flag-icon {
  margin-right: 6px;
}

/* v3 client limits/editor additions */
.nodes-select-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.check-all {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
  margin: 0;
}

.node-list {
  gap: 10px;
}

.node-quota-row {
  display: grid !important;
  grid-template-columns: auto 1fr 120px;
  align-items: center;
  gap: 12px;
}

.node-quota-row.readonly {
  grid-template-columns: 1fr 140px;
}

.node-quota-field input {
  width: 100%;
  padding: 9px 10px;
  border-radius: 10px;
}

.extend-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.extend-form input {
  width: 90px;
  padding: 9px 10px;
  border-radius: 10px;
}

@media (max-width: 720px) {
  .node-quota-row,
  .node-quota-row.readonly {
    grid-template-columns: auto 1fr;
  }
  .node-quota-row .node-quota-field,
  .node-quota-row.readonly .node-quota-field {
    grid-column: 1 / -1;
  }
}

/* v5 fixes */
.clean-form .field,
.field {
  margin-bottom: 18px;
}
.field label {
  display: block;
  margin-bottom: 7px;
}
.field .hint,
.field small {
  display: block;
  margin-top: 6px;
  opacity: 0.78;
  line-height: 1.4;
}
.nodes-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 18px 0 12px;
}
.select-all-box {
  display: inline-flex !important;
  align-items: center;
  gap: 8px;
  width: auto !important;
  padding: 9px 13px;
  border: 1px solid rgba(80,150,255,.42);
  border-radius: 14px;
  background: rgba(35,120,255,.16);
  cursor: pointer;
  white-space: nowrap;
}
.select-all-box input {
  width: auto;
  min-width: 16px;
  margin: 0;
}
.node-list {
  display: grid;
  gap: 10px;
}
.node-item {
  display: grid !important;
  grid-template-columns: auto 1fr 120px;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  border: 1px solid rgba(120,170,230,.18);
  border-radius: 14px;
  background: rgba(255,255,255,.04);
}
.node-item > input[type="checkbox"] {
  width: 16px;
  min-width: 16px;
  margin: 0;
}
.node-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.node-info small {
  margin: 0;
  opacity: .72;
}
.node-gb-input {
  min-width: 90px;
}
.btn-pair {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
@media (max-width: 700px) {
  .nodes-head {
    align-items: flex-start;
    flex-direction: column;
  }
  .node-item {
    grid-template-columns: auto 1fr;
  }
  .node-gb-input {
    grid-column: 1 / -1;
    width: 100%;
  }
}

/* v6 fixes */
.action-buttons {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 260px;
}
.action-buttons .inline-form { margin: 0; }
.action-buttons .inline-form button { width: auto; }
.table-wrap table td { vertical-align: middle; }
.btn-pair { min-width: 220px; }
.detail-hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
}
.detail-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 190px;
}
.link-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}
.copy-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  gap: 8px;
  align-items: center;
}
.copy-row input { width: 100%; }
.node-edit-row { grid-template-columns: 0 1fr 120px !important; }
@media (max-width: 800px) {
  .detail-hero { flex-direction: column; }
  .detail-actions { width: 100%; }
  .copy-row { grid-template-columns: 1fr; }
  .action-buttons { min-width: 0; }
  .btn-pair { min-width: 0; }
}

/* v7 table/button cleanup */
.actions .secondary,
.actions .danger,
.actions button,
.actions .link-btn {
  min-width: 112px;
  text-align: center;
}
.clients-card .table-wrap {
  overflow-x: auto;
}
.clients-table {
  table-layout: fixed;
  min-width: 1180px;
}
.clients-table th,
.clients-table td {
  vertical-align: middle;
}
.clients-table .check-col { width: 48px; text-align: center; }
.clients-table .link-col { width: 250px; }
.clients-table .actions-col { width: 320px; }
.btn-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}
.btn-main,
.btn-secondary,
.btn-danger,
.btn-qr {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 16px;
  border-radius: 13px;
  border: 1px solid transparent;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  line-height: 1;
}
.btn-main {
  min-width: 150px;
  background: #2388ff;
  color: #fff;
}
.btn-secondary,
.btn-qr {
  background: rgba(255,255,255,.055);
  color: #fff;
  border-color: rgba(160,190,230,.22);
}
.btn-secondary { min-width: 112px; }
.btn-danger {
  min-width: 118px;
  background: #ff5573;
  color: #fff;
}
.btn-qr {
  min-width: 58px;
  padding: 0 14px;
}
.actions-stack {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}
.actions-stack .inline-form { margin: 0; }
.actions-stack .inline-form button { width: auto; }
.bulk-row {
  display: flex;
  gap: 12px;
  align-items: end;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.bulk-row button { width: auto; }
.editor-modal {
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  overflow: auto;
}
.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.soft-sep {
  border: 0;
  border-top: 1px solid rgba(160,190,230,.16);
  margin: 18px 0;
}
.stretch-row input { flex: 1; min-width: 120px; }
@media (max-width: 900px) {
  .clients-table { min-width: 1040px; }
  .clients-table .link-col { width: 220px; }
  .clients-table .actions-col { width: 290px; }
  .btn-main { min-width: 135px; }
}

/* v9 compact tables and equal action buttons */
.clients-card .table-wrap { overflow-x: auto; }
.clients-table { table-layout: auto; min-width: 1060px; }
.clients-table th, .clients-table td { padding: 10px 10px; }
.clients-table .check-col { width: 34px; text-align: center; }
.clients-table th:nth-child(2), .clients-table td:nth-child(2) { width: 54px; }
.clients-table th:nth-child(3), .clients-table td:nth-child(3) { width: 135px; }
.clients-table th:nth-child(4), .clients-table td:nth-child(4) { width: 135px; }
.clients-table th:nth-child(5), .clients-table td:nth-child(5) { width: 115px; }
.clients-table th:nth-child(6), .clients-table td:nth-child(6) { width: 118px; }
.clients-table .link-col { width: 220px; }
.clients-table .actions-col { width: 245px; }
.btn-row { gap: 6px; }
.btn-main, .btn-secondary, .btn-danger, .btn-qr {
  min-height: 38px; height: 38px; padding: 0 13px; border-radius: 12px; font-size: 14px;
}
.btn-main { min-width: 136px; }
.btn-secondary { min-width: 104px; }
.btn-danger { min-width: 108px; }
.btn-qr { min-width: 52px; padding: 0 12px; }
.actions-stack { gap: 8px; justify-content: flex-start; }
.actions-stack .btn-main, .actions-stack .btn-secondary { min-width: 112px; }
.node-actions {
  display: grid; grid-template-columns: repeat(3, 112px); gap: 8px; align-items: center; margin-top: 0;
}
.node-actions .inline-form, .node-actions a { width: 112px; margin: 0; }
.node-actions button, .node-actions .link-btn { width: 112px; min-height: 40px; padding: 0 10px; justify-content: center; }
@media (max-width: 900px) {
  .clients-table { min-width: 980px; }
  .clients-table .link-col { width: 205px; }
  .clients-table .actions-col { width: 230px; }
  .btn-main { min-width: 126px; }
  .btn-secondary { min-width: 96px; }
  .btn-qr { min-width: 48px; }
}
