/* WG Portal — dark-first control panel */

:root {
  --bg: #0b0f17;
  --bg-2: #111827;
  --panel: #151d2b;
  --panel-2: #1b2537;
  --line: #263349;
  --line-soft: #1e2a3d;
  --txt: #e6edf7;
  --txt-2: #93a4bd;
  --txt-3: #64748b;
  --accent: #38bdf8;
  --accent-2: #0ea5e9;
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 12px 34px rgba(0, 0, 0, .45);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

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

body {
  background:
    radial-gradient(1100px 620px at 82% -12%, rgba(56, 189, 248, .10), transparent 60%),
    radial-gradient(900px 520px at 8% 108%, rgba(52, 211, 153, .07), transparent 60%),
    var(--bg);
  color: var(--txt);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

.hidden { display: none !important; }

/* ------------------------------------------------------------------ login */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 390px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 34px 30px;
  box-shadow: var(--shadow);
}

.login-card .brand {
  display: flex;
  align-items: center;
  gap: 11px;
  margin-bottom: 6px;
}

.login-card h1 { font-size: 21px; margin: 0; letter-spacing: -.2px; }
.login-card .sub { color: var(--txt-2); font-size: 13.5px; margin: 0 0 24px; }

/* ------------------------------------------------------------------ shell */
.shell { max-width: 1240px; margin: 0 auto; padding: 22px 22px 70px; }

header.top {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  background: linear-gradient(180deg, rgba(27, 37, 55, .9), rgba(21, 29, 43, .9));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 22px;
  backdrop-filter: blur(8px);
}

.brand { display: flex; align-items: center; gap: 11px; }
.brand .logo { width: 30px; height: 30px; flex: none; }
.brand .name { font-weight: 640; letter-spacing: -.2px; font-size: 16px; }
.brand .ver { color: var(--txt-3); font-size: 11.5px; font-family: var(--mono); }

.top .spacer { flex: 1; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--txt-2);
  white-space: nowrap;
}

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--txt-3); flex: none; }
.dot.up { background: var(--ok); box-shadow: 0 0 0 3px rgba(52, 211, 153, .16); }
.dot.down { background: var(--bad); box-shadow: 0 0 0 3px rgba(248, 113, 113, .16); }
.dot.idle { background: var(--txt-3); }

/* ------------------------------------------------------------------ cards */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.stat .label {
  color: var(--txt-3);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .07em;
  font-weight: 600;
}

.stat .value { font-size: 27px; font-weight: 640; margin-top: 6px; letter-spacing: -.6px; }
.stat .value small { font-size: 14px; color: var(--txt-3); font-weight: 500; }
.stat .foot { color: var(--txt-2); font-size: 12.5px; margin-top: 4px; }

/* ------------------------------------------------------------------ panel */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--line-soft);
  flex-wrap: wrap;
}

.panel-head h2 { font-size: 15.5px; margin: 0; font-weight: 620; }
.panel-head .spacer { flex: 1; }

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

thead th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--txt-3);
  font-weight: 620;
  padding: 11px 18px;
  background: rgba(11, 15, 23, .35);
  border-bottom: 1px solid var(--line-soft);
  white-space: nowrap;
}

tbody td {
  padding: 13px 18px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 14px;
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(56, 189, 248, .035); }

.cell-name { font-weight: 560; }
.cell-name .desc { color: var(--txt-3); font-size: 12.5px; font-weight: 400; margin-top: 2px; }
.mono { font-family: var(--mono); font-size: 13px; }
.muted { color: var(--txt-3); }
.nowrap { white-space: nowrap; }

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

.empty { padding: 52px 20px; text-align: center; color: var(--txt-3); }
.empty h3 { color: var(--txt-2); font-weight: 560; margin: 0 0 6px; font-size: 15px; }

/* ------------------------------------------------------------------ badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 560;
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge.on     { background: rgba(52, 211, 153, .12); color: var(--ok);   border-color: rgba(52, 211, 153, .28); }
.badge.off    { background: rgba(100, 116, 139, .14); color: var(--txt-2); border-color: rgba(100, 116, 139, .3); }
.badge.paused { background: rgba(251, 191, 36, .12); color: var(--warn); border-color: rgba(251, 191, 36, .3); }

/* ------------------------------------------------------------------ inputs */
label.field { display: block; margin-bottom: 14px; }

label.field > span {
  display: block;
  font-size: 12.5px;
  color: var(--txt-2);
  margin-bottom: 6px;
  font-weight: 560;
}

label.field .hint { color: var(--txt-3); font-weight: 400; font-size: 12px; }

input[type=text], input[type=password], input[type=number],
input[type=search], input[type=datetime-local], select, textarea {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-2);
  color: var(--txt);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color .12s, box-shadow .12s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, .14);
}

input::placeholder { color: var(--txt-3); }
textarea { resize: vertical; min-height: 84px; font-family: var(--mono); font-size: 12.5px; }

.check { display: flex; align-items: flex-start; gap: 9px; margin-bottom: 14px; font-size: 13.5px; }
.check input { margin-top: 2px; accent-color: var(--accent-2); width: 15px; height: 15px; }
.check span small { display: block; color: var(--txt-3); font-size: 12px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }

/* ------------------------------------------------------------------ buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--txt);
  font: inherit;
  font-size: 13.5px;
  font-weight: 560;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s, opacity .12s;
}

.btn:hover { background: #22304a; border-color: #33455f; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn.primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: #06212e;
  font-weight: 640;
}
.btn.primary:hover { filter: brightness(1.07); }

.btn.danger { color: var(--bad); border-color: rgba(248, 113, 113, .32); background: rgba(248, 113, 113, .08); }
.btn.danger:hover { background: rgba(248, 113, 113, .16); }

.btn.ghost { background: transparent; }
.btn.icon { padding: 7px 9px; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn.block { width: 100%; }

.btn svg { width: 15px; height: 15px; flex: none; }

/* ------------------------------------------------------------------ modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 6, 12, .72);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  padding: 22px;
  z-index: 60;
  overflow-y: auto;
}

.modal {
  width: 100%;
  max-width: 520px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  max-height: calc(100vh - 44px);
  display: flex;
  flex-direction: column;
}

.modal.wide { max-width: 720px; }

.modal-head {
  display: flex;
  align-items: center;
  padding: 17px 20px;
  border-bottom: 1px solid var(--line-soft);
}

.modal-head h3 { margin: 0; font-size: 16px; font-weight: 620; }
.modal-head .spacer { flex: 1; }

.modal-body { padding: 20px; overflow-y: auto; }

.modal-foot {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 15px 20px;
  border-top: 1px solid var(--line-soft);
}

/* ------------------------------------------------------------------ misc */
.code {
  font-family: var(--mono);
  font-size: 12.5px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 13px;
  white-space: pre-wrap;
  word-break: break-all;
  color: #b8cbe6;
  line-height: 1.55;
}

.copy-row { display: flex; gap: 8px; align-items: stretch; }
.copy-row .code { flex: 1; margin: 0; }

.qr-box { text-align: center; padding: 6px 0 2px; }
.qr-box img {
  width: 244px;
  height: 244px;
  border-radius: 10px;
  background: #fff;
  padding: 8px;
  image-rendering: pixelated;
}

.note {
  font-size: 12.5px;
  color: var(--txt-2);
  background: rgba(56, 189, 248, .06);
  border: 1px solid rgba(56, 189, 248, .2);
  border-left-width: 3px;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin: 14px 0;
}

.note.warn { background: rgba(251, 191, 36, .06); border-color: rgba(251, 191, 36, .28); color: #e8d6a8; }
.note.bad  { background: rgba(248, 113, 113, .07); border-color: rgba(248, 113, 113, .3); color: #f3c1c1; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line-soft); margin: -4px 0 18px; }

.tab {
  padding: 9px 14px;
  font-size: 13.5px;
  color: var(--txt-2);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  background: none;
  border-top: 0; border-left: 0; border-right: 0;
  font-family: inherit;
  font-weight: 560;
}

.tab.active { color: var(--txt); border-bottom-color: var(--accent); }

.toasts {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  z-index: 90;
}

.toast {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 11px 15px;
  font-size: 13.5px;
  box-shadow: var(--shadow);
  max-width: 380px;
  animation: slide-in .18s ease-out;
}

.toast.ok  { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--bad); }

@keyframes slide-in {
  from { opacity: 0; transform: translateX(14px); }
  to   { opacity: 1; transform: none; }
}

.err-text { color: var(--bad); font-size: 13px; min-height: 18px; margin-bottom: 10px; }

.spin {
  width: 15px; height: 15px;
  border: 2px solid rgba(255, 255, 255, .22);
  border-top-color: var(--txt);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.search-box { position: relative; }
.search-box input { padding-left: 32px; width: 220px; }
.search-box svg {
  position: absolute; left: 10px; top: 50%;
  transform: translateY(-50%);
  width: 14px; height: 14px; color: var(--txt-3);
}

.audit-list { max-height: 420px; overflow-y: auto; }
.audit-row { display: flex; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line-soft); font-size: 13px; }
.audit-row:last-child { border-bottom: 0; }
.audit-row .when { color: var(--txt-3); font-family: var(--mono); font-size: 11.5px; white-space: nowrap; min-width: 132px; }
.audit-row .what { flex: 1; }

footer.foot { text-align: center; color: var(--txt-3); font-size: 12.5px; padding: 26px 0 0; }

.table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Shown only on very narrow screens, where the Tunnel IP column is dropped. */
.cell-name .ip {
  display: none;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--txt-3);
  margin-top: 3px;
}

@media (max-width: 860px) {
  .shell { padding: 14px 12px 60px; }
  header.top { flex-wrap: wrap; row-gap: 10px; }
  .panel-head { row-gap: 10px; }
  .search-box { flex: 1 1 100%; order: 5; }
  .search-box input { width: 100%; }
  .hide-sm { display: none; }
  .grid-2 { grid-template-columns: 1fr; }

  /* Drop "last handshake" and "transfer" — the status pill already says
     whether the peer is live, and the numbers need too much room. */
  thead th:nth-child(4), tbody td:nth-child(4),
  thead th:nth-child(5), tbody td:nth-child(5) { display: none; }

  thead th, tbody td { padding-left: 12px; padding-right: 12px; }
  .row-actions { flex-wrap: wrap; gap: 5px; }
  .btn.icon.sm { padding: 5px 7px; }
  .btn.icon.sm svg { width: 14px; height: 14px; }
  .modal-foot { flex-wrap: wrap; }
  .qr-box img { width: min(244px, 72vw); height: auto; }
}

@media (max-width: 520px) {
  /* Very narrow: the tunnel IP moves under the name (see .cell-name .ip). */
  thead th:nth-child(2), tbody td:nth-child(2) { display: none; }
  .cell-name .ip { display: block; }
}
