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

:root {
  --bg: #0b0e14;
  --bg2: #12161f;
  --bg3: #1a1f2b;
  --bg4: #222836;
  --border: #262d3a;
  --border-soft: #1e242f;
  --text: #e8eef6;
  --muted: #8a97ab;
  --faint: #5d6879;
  --accent: #f7b32b;
  --accent-dim: rgba(247, 179, 43, .14);
  --accent-text: #17120a;
  --green: #46c95c;
  --red: #f85149;
  --yellow: #d29922;
  --blue: #58a6ff;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 16px rgba(0, 0, 0, .35);
  --shadow-lg: 0 20px 50px rgba(0, 0, 0, .55);
  --ease: cubic-bezier(.4, 0, .2, 1);
}

/* The page itself never scrolls - scrolling happens only inside the areas
   meant for it (.content, .login-wrap, .modal, .table-wrap). */
html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Takes no space in the text flow (see the comment in index.html). */
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.error { color: var(--red); margin-top: 12px; font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

.icon {
  width: 16px; height: 16px;
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon.lg { width: 18px; height: 18px; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Login ---------- */
.login-wrap {
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  /* Only if the card is taller than the window - no scrollbar otherwise. */
  overflow-y: auto;
  background: radial-gradient(ellipse 80% 60% at 50% -10%, rgba(247, 179, 43, .07), transparent 70%);
}
.login-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 36px 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
  animation: rise .35s var(--ease);
}
.login-card label { text-align: left; }
.login-card .logo { justify-content: center; font-size: 24px; }
.login-card .subtitle { text-align: center; color: var(--muted); margin: 6px 0 28px; font-size: 13px; }

.logo {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -.2px;
}
.logo .icon { width: 20px; height: 20px; color: var(--accent); stroke-width: 2; }

/* ---------- Layout ---------- */
.layout { display: flex; height: 100dvh; overflow: hidden; }

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--bg2);
  border-right: 1px solid var(--border-soft);
  padding: 22px 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  height: 100%;
  overflow-y: auto;
}
.sidebar .logo { padding: 0 8px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  background: none;
  border: none;
  color: var(--muted);
  text-align: left;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13.5px;
  font-family: inherit;
  transition: background .15s var(--ease), color .15s var(--ease);
}
.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active { background: var(--accent-dim); color: var(--accent); font-weight: 600; }
.nav-item.active::before {
  content: '';
  position: absolute;
  left: -14px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}

.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--border-soft);
  font-size: 12.5px;
}
#whoami { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* The only scrolling area once signed in. */
.content { flex: 1; padding: 30px 34px 60px; min-width: 0; overflow-y: auto; }
.content > .page { max-width: 1280px; }
h1 { font-size: 21px; font-weight: 650; letter-spacing: -.3px; margin-bottom: 22px; }
h2 {
  font-size: 12px;
  margin: 28px 0 12px;
  color: var(--faint);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .7px;
}
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}
.page-head h1 { margin: 0; }
.page { animation: fade .25s var(--ease); }

/* ---------- Inputs / Buttons ---------- */
label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 16px; font-weight: 500; }
input, select, textarea {
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
input::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a97ab' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 15px;
  padding-right: 32px;
  cursor: pointer;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  white-space: nowrap;
  transition: background .15s var(--ease), border-color .15s var(--ease), transform .1s var(--ease);
}
.btn:hover { background: var(--bg4); border-color: #333c4d; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}
.btn.primary:hover { background: #ffc247; border-color: #ffc247; }
.btn.danger { color: var(--red); }
.btn.danger:hover { background: rgba(248, 81, 73, .12); border-color: rgba(248, 81, 73, .45); }
.btn.solid-danger { background: var(--red); border-color: var(--red); color: #fff; font-weight: 600; }
.btn.solid-danger:hover { background: #ff6259; border-color: #ff6259; }
.btn.ghost { background: none; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--bg3); color: var(--text); border-color: transparent; }
.btn.small { padding: 6px 10px; font-size: 12px; }
.btn.icon-only { padding: 6px; }
.btn.full { width: 100%; margin-top: 10px; }

/* ---------- Stats ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
  gap: 12px;
}
.stat-card {
  background: var(--bg2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 16px 18px;
  transition: border-color .15s var(--ease);
}
.stat-card:hover { border-color: var(--border); }
.stat-card .num { font-size: 27px; font-weight: 680; letter-spacing: -.8px; line-height: 1.15; }
.stat-card .lbl { font-size: 12px; color: var(--muted); margin-top: 3px; }
.stat-card.warn .num { color: var(--red); }
.stat-card.ok .num { color: var(--green); }

/* ---------- Tables ---------- */
.table-wrap {
  background: var(--bg2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 11px 14px; text-align: left; white-space: nowrap; }
th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg2);
  color: var(--faint);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  border-bottom: 1px solid var(--border);
}
tbody tr { border-bottom: 1px solid var(--border-soft); transition: background .12s var(--ease); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg3); }
td.mono { color: var(--text); }
.empty-cell { color: var(--faint); text-align: center; padding: 32px 14px; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .2px;
}
.badge.active { background: rgba(70, 201, 92, .14); color: var(--green); }
.badge.paused { background: rgba(210, 153, 34, .14); color: var(--yellow); }
.badge.banned { background: rgba(248, 81, 73, .14); color: var(--red); }
.badge.expired { background: rgba(138, 151, 171, .13); color: var(--muted); }

/* Pin the actions column to the right edge: stays reachable even when the
   table scrolls horizontally. */
.with-actions th:last-child,
.with-actions td:last-child {
  position: sticky;
  right: 0;
  background: var(--bg2);
  box-shadow: -8px 0 12px -8px rgba(0, 0, 0, .6);
}
.with-actions th:last-child { z-index: 2; }
.with-actions tbody tr:hover td:last-child { background: var(--bg3); }

.log-action { display: inline-flex; align-items: center; gap: 8px; }
.dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--faint);
}
.dot.ok { background: var(--green); }
.dot.err { background: var(--red); }
.dot.warn { background: var(--yellow); }
.dot.accent { background: var(--accent); }

.row-actions { display: flex; gap: 3px; justify-content: flex-end; }
.row-actions .btn { color: var(--muted); }
.row-actions .btn:hover { color: var(--text); }
.row-actions .btn.danger:hover { color: var(--red); }

/* ---------- Filters / Pager ---------- */
.filters { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.filters select, .filters input { width: auto; min-width: 170px; margin-top: 0; }
.filters .search { flex: 1; min-width: 200px; }
.pager { display: flex; align-items: center; gap: 14px; margin-top: 16px; justify-content: center; }

/* ---------- Apps ---------- */
.apps-list { display: flex; flex-direction: column; gap: 14px; }
.app-card {
  background: var(--bg2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 20px;
  transition: border-color .15s var(--ease);
}
.app-card:hover { border-color: var(--border); }
.app-card .app-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.app-card .app-name { font-size: 16px; font-weight: 650; letter-spacing: -.2px; }
.app-meta {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px 16px;
  font-size: 13px;
  padding-bottom: 4px;
}
.app-meta .kv { color: var(--muted); display: flex; gap: 6px; min-width: 0; }
.app-meta .kv b { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.secret-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  padding: 8px 8px 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
}
.secret-row .label { color: var(--faint); font-size: 12px; }
.secret-row code {
  flex: 1;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}
.app-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border-soft);
  flex-wrap: wrap;
}
.app-actions .spacer { flex: 1; }

/* ---------- Card ---------- */
.card {
  background: var(--bg2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 22px;
}
.card.narrow { max-width: 440px; }
.card h2 { margin: 0 0 18px; }
/* Last form field: the gap to the button row comes from .card-actions. */
.card form label:last-of-type { margin-bottom: 0; }
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 460px));
  gap: 18px;
  align-items: start;
}

/* Notice for an outdated server process */
.stale-banner {
  display: flex;
  gap: 11px;
  align-items: flex-start;
  margin-bottom: 22px;
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  background: rgba(210, 153, 34, .1);
  border: 1px solid rgba(210, 153, 34, .3);
  color: #f0cd8a;
  font-size: 13px;
  line-height: 1.55;
}
.stale-banner .icon { color: var(--yellow); flex-shrink: 0; margin-top: 2px; }
.stale-banner strong { color: var(--text); }
.stale-banner code {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12px;
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 4px;
}

/* ---------- Integration ---------- */
/* All blocks share the width of the code block below. */
.int-bar, .int-quick, .code-wrap, .int-warn { max-width: 940px; }

.int-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  font-size: 13px;
}
.int-bar .spacer { flex: 1; }

.int-quick {
  margin: 0 0 18px;
  padding-left: 20px;
  font-size: 13.5px;
  color: var(--muted);
  line-height: 2;
}
.int-quick li { padding-left: 4px; }
.int-quick b { color: var(--text); font-weight: 600; }
.int-quick code {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12.5px;
  background: var(--bg);
  padding: 2px 7px;
  border-radius: 4px;
  color: var(--accent);
}

.int-warn {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  margin-top: 14px;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.6;
  max-width: 940px;
}
.int-warn .icon { color: var(--yellow); flex-shrink: 0; margin-top: 2px; }
.int-warn strong { color: var(--text); }

.int-lang-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--accent-dim);
  color: var(--accent);
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
}
.int-lang-badge .icon { width: 15px; height: 15px; }

/* ---------- Code block ---------- */
.code-wrap {
  max-width: 940px;
  background: var(--bg);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.code-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 8px 7px 14px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border-soft);
}
.code-bar .mono { color: var(--muted); }
.code-block {
  margin: 0;
  padding: 16px 18px;
  overflow-x: auto;
  max-height: 520px;
  overflow-y: auto;
}
.code-block code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.65;
  color: var(--text);
  white-space: pre;
  display: block;
}

/* Syntax highlighting */
.tok-kw { color: #58a6ff; }
.tok-str { color: #7ee787; }
.tok-com { color: #6b7688; font-style: italic; }
.tok-num { color: #ffab70; }
.tok-meta { color: #d2a8ff; }

/* ---------- Two-factor ---------- */
.tfa-status {
  display: flex;
  /* Align to the top: with two-line text the icon would otherwise sit centred. */
  align-items: flex-start;
  gap: 9px;
  font-size: 13.5px;
  margin-bottom: 10px;
}
.tfa-status .icon { width: 17px; height: 17px; margin-top: 2px; }
.tfa-status.on { color: var(--green); }
.tfa-status.off { color: var(--muted); }
.qr-frame {
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 12px;
  width: fit-content;
  margin: 4px auto 14px;
  line-height: 0;
}
.qr-frame svg { width: 190px; height: 190px; display: block; }
.secret-manual {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 9px 9px 9px 12px;
  margin-top: 4px;
}
.secret-manual code {
  flex: 1;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11.5px;
  word-break: break-all;
  color: var(--accent);
}
.code-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px 14px;
  margin: 12px 0;
  padding: 14px;
  background: var(--bg);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12.5px;
  letter-spacing: .4px;
}
.code-list span.used { color: var(--faint); text-decoration: line-through; }
.dialog-hint.center { text-align: center; }
.card-actions { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
/* Hint under a form field: visually belongs to the field above, not the one
   below. Doubled class so the rule reliably beats the general .dialog-hint
   declaration further down. */
.dialog-hint.field-hint { margin: -9px 0 16px; }
.err-text { color: var(--red); }
.login-card .btn.ghost.full { margin-top: 6px; }

/* ---------- Modal & Dialog ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 11, .68);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
  animation: fade .18s var(--ease);
}
#dialog-backdrop { z-index: 150; }

.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  width: 500px;
  max-width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: rise .22s var(--ease);
}
.modal.compact { width: 420px; }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 18px; }
.modal-head h2 {
  margin: 0;
  color: var(--text);
  font-size: 16px;
  font-weight: 650;
  text-transform: none;
  letter-spacing: -.2px;
}
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }
.modal-actions .btn { min-width: 92px; }

.dialog-msg { color: var(--muted); font-size: 13.5px; line-height: 1.6; }
.dialog-msg strong { color: var(--text); font-weight: 600; }
.dialog-msg code {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12.5px;
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 4px;
  color: var(--accent);
}
.dialog-note {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  line-height: 1.5;
  background: rgba(248, 81, 73, .09);
  border: 1px solid rgba(248, 81, 73, .22);
  color: #ffa9a3;
}
.dialog-note .icon { color: var(--red); margin-top: 1px; }
.dialog-note.info {
  background: var(--accent-dim);
  border-color: rgba(247, 179, 43, .25);
  color: #f3cf8a;
}
.dialog-note.info .icon { color: var(--accent); }
.dialog-field { margin-top: 18px; }
.dialog-field label { margin-bottom: 0; }
.dialog-hint { font-size: 12px; color: var(--faint); margin-top: 7px; }

.keys-output {
  width: 100%;
  height: 210px;
  margin-top: 12px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12px;
  line-height: 1.7;
  resize: vertical;
}

/* ---------- Toast ---------- */
.toast-host {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-end;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-left: 3px solid var(--green);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  max-width: 380px;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: slide-in .25s var(--ease);
  pointer-events: auto;
}
.toast.out { animation: slide-out .2s var(--ease) forwards; }
.toast .icon { color: var(--green); }
.toast.err { border-left-color: var(--red); }
.toast.err .icon { color: var(--red); }

/* ---------- Animations ---------- */
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(10px) scale(.985); } to { opacity: 1; transform: none; } }
@keyframes slide-in { from { opacity: 0; transform: translateX(18px); } to { opacity: 1; transform: none; } }
@keyframes slide-out { to { opacity: 0; transform: translateX(18px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    flex-shrink: 0;
    flex-direction: row;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    border-right: none;
    border-bottom: 1px solid var(--border-soft);
    overflow-x: auto;
    overflow-y: hidden;
  }
  .sidebar .logo { display: none; }
  .sidebar nav { flex-direction: row; gap: 4px; }
  .nav-item { padding: 8px 11px; }
  .nav-item span { display: none; }
  .nav-item.active::before { display: none; }
  .sidebar-footer { padding-top: 0; border-top: none; }
  #whoami { display: none; }
  .content { padding: 22px 18px 48px; }
  .toast-host { left: 16px; right: 16px; bottom: 16px; align-items: stretch; }
  .toast { max-width: none; }
}
