/* SKEYX design system: shared by /login, /app, /admin. No inline styles anywhere (CSP style-src 'self'). */

/* Public Sans (SIL OFL 1.1, fonts/LICENSE-OFL.txt), self-hosted: the console typeface. */
@font-face {
  font-family: "Public Sans";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/public-sans-latin-400.woff2") format("woff2");
}
@font-face {
  font-family: "Public Sans";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("fonts/public-sans-latin-500.woff2") format("woff2");
}
@font-face {
  font-family: "Public Sans";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("fonts/public-sans-latin-600.woff2") format("woff2");
}
@font-face {
  font-family: "Public Sans";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/public-sans-latin-700.woff2") format("woff2");
}

/* Console tokens (light and dark), mapped onto the names this design system already uses. */
:root {
  --bg: #fbfbfb;
  --surface: #ffffff;
  --surface-2: #f5f5f5;
  --surface-hover: #fafafa;
  --border: #e8e8e8;
  --border-strong: #e8e8e8;
  --text: #0a0a0a;
  --text-2: #3f3f3f;
  --muted: #606060;
  --primary: #3ea4ec;
  --primary-hover: #2b95e0;
  --primary-soft: #e9f4fd;
  --on-primary: #ffffff;
  --link: #0276ea;
  --ring: #42a6ff;
  --ok: #009767;
  --ok-soft: #e6f5ef;
  --warn: #cd8900;
  --warn-soft: #fbf3e2;
  --err: #e40014;
  --err-soft: #fde8ea;
  --info: #0084cc;
  --info-soft: #e5f3fa;
  --secondary: #eeeeee;
  --nav-bg: #fbfbfb;
  --nav-active: #e9f4fd;
  --nav-active-text: #0276ea;
  --accent-1: #4ca9ff;
  --accent-2: #00a3aa;
  --accent-3: #9095e8;
  --shadow: none;
  --shadow-lg: 0 16px 40px rgba(10, 10, 10, 0.12), 0 2px 6px rgba(10, 10, 10, 0.06);
  --radius: 16px;
  --radius-md: 13px;
  --radius-sm: 10px;
  --nav-w: 232px;
  --font: "Public Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #191715;
    --surface: #242221;
    --surface-2: #2c2a28;
    --surface-hover: #2a2826;
    --border: rgba(255, 255, 255, 0.1);
    --border-strong: rgba(255, 255, 255, 0.16);
    --text: #f4f3f0;
    --text-2: #d9d7d2;
    --muted: #b3b1ad;
    --primary: #eb8561;
    --primary-hover: #f09775;
    --primary-soft: #3a2a23;
    --on-primary: #13110f;
    --link: #eb8561;
    --ring: #eb8561;
    --ok: #82ad6a;
    --ok-soft: #26301f;
    --warn: #eca851;
    --warn-soft: #362a18;
    --err: #ff6367;
    --err-soft: #3b1f20;
    --info: #79aad8;
    --info-soft: #1f2a35;
    --secondary: #312f2d;
    --nav-bg: #191715;
    --nav-active: #353230;
    --nav-active-text: #fbfaf6;
    --accent-1: #eb8561;
    --accent-2: #82ad6a;
    --accent-3: #79aad8;
    --shadow: none;
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

a {
  color: var(--link);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-weight: 600;
  line-height: 1.3;
}

p {
  margin: 0 0 8px;
}

code,
.mono {
  font-family: var(--mono);
  font-size: 12.5px;
}

[hidden],
.hidden {
  display: none !important;
}

/* ---- app shell: left nav + main ---------------------------------------- */

.layout {
  display: grid;
  grid-template-columns: var(--nav-w) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: var(--nav-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 18px 20px 14px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.brand-mark {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--primary);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
}
.brand-sub {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 10px;
  flex: 1;
}
.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-weight: 500;
  white-space: nowrap;
}
.nav a:hover {
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}
.nav a.active {
  background: var(--nav-active);
  color: var(--primary);
}

.sidebar-foot {
  padding: 12px 16px 16px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.page-title {
  font-size: 18px;
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.content {
  padding: 24px 28px 48px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 1400px;
  width: 100%;
}

/* ---- cards --------------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 0;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.card-title {
  font-size: 15px;
}
.card-body {
  padding: 16px 20px;
}
.card-body > * + * {
  margin-top: 12px;
}

.grid {
  display: grid;
  gap: 16px;
}
.grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.grid-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.stat-label {
  color: var(--muted);
  font-size: 13px;
}
.stat-value {
  font-size: 24px;
  font-weight: 650;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}

.row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.row-between {
  justify-content: space-between;
}
.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.spacer {
  flex: 1;
}
.muted {
  color: var(--muted);
}
.small {
  font-size: 12.5px;
}
.nowrap {
  white-space: nowrap;
}
.break {
  word-break: break-all;
}

/* ---- tables -------------------------------------------------------------- */

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.table th,
.table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table td {
  white-space: nowrap;
}
.table td.wrap,
.table td .wrap {
  white-space: normal;
  word-break: break-word;
  min-width: 200px;
  max-width: 420px;
  display: inline-block;
}
.table td .chips {
  flex-wrap: nowrap;
}
.table th {
  background: var(--surface-hover);
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
}
.table tbody tr:last-child td {
  border-bottom: 0;
}
.table tbody tr:hover td {
  background: var(--surface-hover);
}
.table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.table .actions {
  white-space: nowrap;
  text-align: right;
}
.table .actions .btn + .btn {
  margin-left: 6px;
}
.table-empty {
  text-align: center !important;
  color: var(--muted);
  padding: 28px 12px !important;
}

/* ---- forms --------------------------------------------------------------- */

.form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 18px;
}
.form-grid .span-2 {
  grid-column: 1 / -1;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.field-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
}
.hint {
  font-size: 12px;
  color: var(--muted);
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="url"],
input[type="search"],
input:not([type]),
select,
textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 5px 12px;
  min-height: 32px;
  font-size: 14px;
  transition: border-color 0.12s, box-shadow 0.12s;
}
select {
  padding-right: 28px;
}
textarea {
  min-height: 84px;
  resize: vertical;
  font-family: var(--mono);
  font-size: 12.5px;
  border-radius: 12px;
  padding: 10px 12px;
}
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 22%, transparent);
}
input:disabled,
select:disabled,
textarea:disabled {
  background: var(--surface-2);
  color: var(--muted);
}
input[type="checkbox"],
input[type="radio"] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--primary);
  flex: none;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  min-height: 28px;
}
.checklist {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.form-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

fieldset.group {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px 16px;
  margin: 0;
  min-width: 0;
}
fieldset.group > legend {
  padding: 0 6px;
  font-weight: 600;
  font-size: 14px;
}
.group-desc {
  font-size: 12.5px;
  color: var(--muted);
  margin: -2px 0 12px;
}

.secret-state {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 12.5px;
  color: var(--muted);
}

/* ---- buttons ------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-weight: 500;
  font-size: 14px;
  padding: 5px 14px;
  min-height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover {
  background: var(--surface-2);
  border-color: var(--muted);
}
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
}
.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}
.btn-danger {
  color: var(--err);
  border-color: var(--err);
  background: var(--surface);
}
.btn-danger:hover {
  background: var(--err-soft);
  border-color: var(--err);
}
.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--text-2);
}
.btn-ghost:hover {
  background: var(--surface-2);
  border-color: transparent;
}
.btn-sm {
  padding: 3px 10px;
  min-height: 28px;
  font-size: 13px;
  border-radius: 8px;
}
.btn-block {
  width: 100%;
}

/* ---- chips / badges ------------------------------------------------------ */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  line-height: 20px;
  white-space: nowrap;
  border: 1px solid transparent;
}
.chip-ok {
  background: var(--ok-soft);
  color: var(--ok);
}
.chip-warn {
  background: var(--warn-soft);
  color: var(--warn);
}
.chip-err {
  background: var(--err-soft);
  color: var(--err);
}
.chip-info {
  background: var(--info-soft);
  color: var(--info);
}
.chip-primary {
  background: var(--primary-soft);
  color: var(--primary);
}
.chip-muted {
  background: var(--surface-2);
  color: var(--muted);
  border-color: var(--border);
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* ---- notices ------------------------------------------------------------- */

.notice {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--info-soft);
  color: var(--text-2);
  border: 1px solid var(--border);
  font-size: 13px;
}
.notice-warn {
  background: var(--warn-soft);
}
.notice-err {
  background: var(--err-soft);
  color: var(--err);
}
.notice-ok {
  background: var(--ok-soft);
}
.error-text {
  color: var(--err);
  font-size: 13px;
  margin: 0;
}

.loading {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  padding: 24px 4px;
}
.spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  border-top-color: var(--primary);
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---- result rows (connection test layers etc.) --------------------------- */

.result-list {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.result-row {
  display: grid;
  grid-template-columns: 28px minmax(120px, 180px) minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.result-row:last-child {
  border-bottom: 0;
}
.result-row.sub {
  background: var(--surface-2);
  padding-left: 42px;
  grid-template-columns: 24px minmax(110px, 160px) minmax(0, 1fr);
}
.result-mark {
  font-weight: 700;
  font-size: 15px;
  line-height: 1.4;
  text-align: center;
}
.result-mark.ok {
  color: var(--ok);
}
.result-mark.fail {
  color: var(--err);
}
.result-mark.na {
  color: var(--muted);
}
.result-name {
  font-weight: 600;
}
.result-detail {
  color: var(--text-2);
  word-break: break-word;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  align-items: center;
}

.kv {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 6px 16px;
  font-size: 13px;
}
.kv dt {
  color: var(--muted);
}
.kv dd {
  margin: 0;
  word-break: break-word;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-end;
}
.filters .field {
  width: 180px;
}

/* ---- dialogs ------------------------------------------------------------- */

dialog.dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font);
  padding: 0;
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100vh - 40px);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}
dialog.dialog-wide {
  width: min(820px, calc(100vw - 24px));
}
dialog.dialog::backdrop {
  background: rgba(10, 10, 10, 0.4);
}
.dialog-header {
  padding: 20px 24px 0;
}
.dialog-title {
  font-size: 17px;
  font-weight: 700;
}
.dialog-body {
  padding: 14px 24px;
  overflow-y: auto;
  max-height: calc(100vh - 180px);
}
.dialog-text {
  white-space: pre-wrap;
  color: var(--text-2);
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 24px 20px;
  border-top: 0;
  flex-wrap: wrap;
}

/* ---- toasts -------------------------------------------------------------- */

.toast-stack {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(380px, calc(100vw - 32px));
}
.toast {
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--info);
  box-shadow: var(--shadow-lg);
  font-size: 13.5px;
  cursor: pointer;
  word-break: break-word;
  animation: toast-in 0.16s ease-out;
}
.toast-ok {
  border-left-color: var(--ok);
}
.toast-warn {
  border-left-color: var(--warn);
}
.toast-err {
  border-left-color: var(--err);
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
}

/* ---- login --------------------------------------------------------------- */

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}
/* rc.40 login: no card, a centred form on the page background, pill inputs, full-width pill button */
.auth-card {
  width: 100%;
  max-width: 416px;
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  padding: 8px 4px;
}
.auth-card .btn-primary {
  width: 100%;
  border-radius: 999px;
  min-height: 34px;
}
.auth-card .brand {
  padding: 0 0 6px;
  justify-content: center;
}
.auth-sub {
  text-align: center;
  color: var(--muted);
  margin-bottom: 20px;
  font-size: 13px;
}

/* ---- responsive ---------------------------------------------------------- */

@media (max-width: 1024px) {
  .grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .grid-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 768px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto 1fr; /* keep the top bar its own height on short pages */
  }
  .sidebar {
    position: sticky;
    top: 0;
    height: auto;
    z-index: 10;
    flex-direction: row;
    align-items: center;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    overflow: visible;
  }
  .brand {
    padding: 10px 12px;
    font-size: 15px;
  }
  .brand-sub {
    display: none;
  }
  .nav {
    flex-direction: row;
    overflow-x: auto;
    padding: 6px 4px;
    scrollbar-width: none;
  }
  .nav a {
    padding: 7px 10px;
  }
  .sidebar-foot {
    display: none;
  }
  .topbar {
    position: static;
    padding: 12px 16px;
  }
  .content {
    padding: 16px 12px 40px;
    gap: 14px;
  }
  .card-header,
  .card-body {
    padding-left: 14px;
    padding-right: 14px;
  }
  .grid-2,
  .grid-3,
  .form-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .filters .field {
    width: calc(50% - 5px);
  }
  .result-row,
  .result-row.sub {
    grid-template-columns: 22px minmax(0, 1fr);
  }
  .result-row .result-detail {
    grid-column: 2;
  }
  .result-row.sub {
    padding-left: 24px;
  }
}

@media (max-width: 420px) {
  .grid-4 {
    grid-template-columns: minmax(0, 1fr);
  }
  .filters .field {
    width: 100%;
  }
  .auth-card {
    padding: 22px 18px 18px;
  }
  .topbar {
    flex-wrap: wrap;
  }
}
