:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --border: #d8e0e8;
  --text: #182230;
  --muted: #667085;
  --blue: #1261a6;
  --blue-dark: #0b4b82;
  --blue-soft: #e8f2fb;
  --green: #18794e;
  --green-soft: #e8f6ef;
  --orange: #a45108;
  --orange-soft: #fff2e4;
  --red: #b42318;
  --red-soft: #fff0ee;
  --shadow: 0 14px 40px rgb(28 47 69 / 16%);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 Inter, "Segoe UI", Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 224px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 22px 14px;
  background: #102f4b;
  color: #eaf2f8;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px 24px;
  color: white;
  font-size: 15px;
  font-weight: 700;
  text-decoration: none;
}

.brand-mark {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 1px solid #6ea8d3;
  border-radius: 6px;
  background: #164e77;
}

nav {
  display: grid;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 6px;
  color: #cbd9e5;
  text-decoration: none;
}

.nav-item:hover,
.nav-item.active {
  background: #194765;
  color: white;
}

.nav-icon {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border: 1px solid #6b8da7;
  border-radius: 5px;
  font-size: 10px;
  font-weight: 800;
}

.cluster-state {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: auto;
  padding: 12px 10px;
  border-top: 1px solid #36566f;
}

.cluster-state div {
  display: grid;
}

.cluster-state span:last-child {
  color: #9fb7ca;
  font-size: 12px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 0 3px rgb(74 222 128 / 15%);
}

main {
  min-width: 0;
  padding: 28px 32px 48px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  max-width: 1400px;
  margin: 0 auto 24px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 20px;
}

.button {
  min-height: 38px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-weight: 650;
}

.button.primary {
  background: var(--blue);
  color: white;
}

.button.primary:hover {
  background: var(--blue-dark);
}

.button.secondary {
  border-color: var(--border);
  background: white;
  color: var(--text);
}

.button.secondary:hover {
  background: var(--surface-muted);
}

.summary-grid {
  max-width: 1400px;
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  margin: 0 auto 20px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.summary-item {
  min-width: 0;
  padding: 18px 20px;
  border-right: 1px solid var(--border);
}

.summary-item:last-child {
  border-right: 0;
}

.summary-item span,
.summary-item small {
  display: block;
  color: var(--muted);
}

.summary-item strong {
  display: block;
  margin: 4px 0 2px;
  font-size: 26px;
}

.workspace {
  max-width: 1400px;
  margin: 0 auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

input,
select {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid #b9c5d1;
  border-radius: 6px;
  background: white;
  color: var(--text);
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgb(18 97 166 / 12%);
}

.search {
  width: min(340px, 45%);
}

.toolbar select {
  min-width: 145px;
}

.toolbar .button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.result-count {
  margin-left: auto;
  color: var(--muted);
  white-space: nowrap;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  white-space: nowrap;
}

th,
td {
  padding: 13px 16px;
  border-bottom: 1px solid #e7ecf1;
  text-align: left;
  vertical-align: middle;
}

.select-column {
  width: 44px;
  padding-right: 4px;
  text-align: center;
}

.select-column input {
  width: 16px;
  min-height: 16px;
  margin: 0;
  accent-color: var(--blue);
}

th {
  background: var(--surface-muted);
  color: #475467;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

tbody tr:hover {
  background: #fafcff;
}

.user-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: var(--blue-soft);
  color: var(--blue);
  font-weight: 800;
  text-transform: uppercase;
}

.user-cell div {
  display: grid;
}

.user-cell small {
  color: var(--muted);
}

.badges {
  display: flex;
  gap: 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 7px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 700;
}

.badge.anytls {
  background: var(--blue-soft);
  color: var(--blue-dark);
}

.badge.hysteria2 {
  background: var(--orange-soft);
  color: var(--orange);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-transform: capitalize;
}

.status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.status.active::before {
  background: var(--green);
}

.status.disabled::before,
.status.expired::before {
  background: #98a2b3;
}

.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.text-button {
  padding: 5px 7px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--blue);
  font-weight: 650;
}

.text-button:hover {
  background: var(--blue-soft);
}

.text-button.danger {
  color: var(--red);
}

.text-button.danger:hover {
  background: var(--red-soft);
}

.empty-state {
  display: grid;
  place-items: center;
  gap: 5px;
  padding: 54px 20px;
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  color: var(--text);
}

dialog {
  width: min(620px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  color: var(--text);
}

dialog::backdrop {
  background: rgb(9 30 48 / 54%);
}

.dialog-header,
.dialog-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
}

.dialog-header {
  border-bottom: 1px solid var(--border);
}

.dialog-footer {
  justify-content: flex-end;
  border-top: 1px solid var(--border);
}

.dialog-body {
  display: grid;
  gap: 18px;
  padding: 20px;
  overflow-y: auto;
}

.icon-button {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.icon-button:hover {
  background: var(--surface-muted);
}

.field {
  display: grid;
  gap: 6px;
  font-weight: 650;
}

.field small,
fieldset small {
  color: var(--muted);
  font-weight: 400;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

legend {
  margin-bottom: 8px;
  font-weight: 650;
}

.protocol-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.protocol-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  cursor: pointer;
}

.protocol-option:has(input:checked) {
  border-color: var(--blue);
  background: var(--blue-soft);
}

.protocol-option input {
  width: 16px;
  min-height: 16px;
  margin: 2px 0 0;
}

.protocol-option span {
  display: grid;
}

.input-suffix,
.password-control {
  display: flex;
  align-items: center;
}

.input-suffix {
  border: 1px solid #b9c5d1;
  border-radius: 6px;
}

.input-suffix:focus-within {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgb(18 97 166 / 12%);
}

.input-suffix input {
  border: 0;
  box-shadow: none;
}

.input-suffix span {
  padding-right: 10px;
  color: var(--muted);
}

.password-control {
  gap: 8px;
}

.password-control .button {
  flex: 0 0 auto;
}

.field-error {
  margin: 6px 0 0;
  color: var(--red);
  font-size: 12px;
}

.notice {
  padding: 10px 12px;
  border: 1px solid #f3c58b;
  border-radius: 6px;
  background: var(--orange-soft);
  color: #7a3e08;
}

.credential-list {
  display: grid;
  gap: 0;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 7px;
}

.credential-list div {
  display: grid;
  grid-template-columns: 120px 1fr;
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
}

.credential-list div:last-child {
  border-bottom: 0;
}

.credential-list dt {
  color: var(--muted);
}

.credential-list dd {
  margin: 0;
  overflow-wrap: anywhere;
}

code {
  font-family: "Cascadia Code", Consolas, monospace;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 10;
  padding: 10px 14px;
  border-radius: 6px;
  background: #17324a;
  color: white;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: 160ms ease;
}

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 72px minmax(0, 1fr);
  }

  .sidebar {
    padding-inline: 10px;
  }

  .brand span:last-child,
  .nav-item:not(.active)::after,
  .nav-item {
    font-size: 0;
  }

  .brand,
  .nav-item {
    justify-content: center;
  }

  .nav-icon {
    font-size: 10px;
  }

  .cluster-state div {
    display: none;
  }

  .summary-grid {
    grid-template-columns: 1fr 1fr;
  }

  .summary-item:nth-child(2) {
    border-right: 0;
  }

  .summary-item:nth-child(-n+2) {
    border-bottom: 1px solid var(--border);
  }
}

@media (max-width: 640px) {
  main {
    padding: 20px 14px 36px;
  }

  .app-shell {
    display: block;
  }

  .sidebar {
    position: static;
    width: 100%;
    height: auto;
    flex-direction: row;
    align-items: center;
    padding: 10px 14px;
  }

  .brand {
    padding: 0;
  }

  .sidebar nav {
    display: none;
  }

  .cluster-state {
    margin: 0 0 0 auto;
    padding: 0;
    border: 0;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 14px;
  }

  .topbar .button {
    width: 100%;
  }

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

  .summary-item:nth-child(odd) {
    border-right: 1px solid var(--border);
  }

  .summary-item:nth-child(-n+2) {
    border-bottom: 1px solid var(--border);
  }

  .summary-item:nth-child(n+3) {
    border-bottom: 0;
  }

  .field-row,
  .protocol-options {
    grid-template-columns: 1fr;
  }

  .summary-item:last-child {
    border-right: 0;
    border-bottom: 0;
  }

  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .search,
  .toolbar label:not(.search) {
    width: 100%;
  }

  .toolbar label:not(.search) {
    flex: none;
  }

  .result-count {
    width: 100%;
    margin: 0;
  }
}
