/* Omnigate design system. Datadog-inspired: navy sidebar, light content, purple primary.
   Tokens are CSS custom properties; dark mode swaps them. No web fonts, no emoji. */
:root {
  color-scheme: light dark;
  --tk-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --tk-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --tk-bg: #f6f7f9;
  --tk-surface: #ffffff;
  --tk-surface-2: #f0f1f5;
  --tk-border: #dcdfe6;
  --tk-text: #1d1b29;
  --tk-muted: #565a6e;
  --tk-link: #5a28a0;
  --tk-primary: #632ca6;
  --tk-primary-hover: #51228a;
  --tk-primary-active: #411a70;
  --tk-on-primary: #ffffff;
  --tk-focus: #7c3aed;
  --tk-row-hover: #f3effa;

  --tk-side-bg: #1b1730;
  --tk-side-bg-2: #2b2342;
  --tk-side-text: #cdc8e2;
  --tk-side-muted: #a8a2c4;
  --tk-side-active-bg: #5b2ea0;
  --tk-side-active-text: #ffffff;

  --tk-ok-bg: #e2f4e9;   --tk-ok-fg: #0b5d33;   --tk-ok-dot: #1a9d57;
  --tk-warn-bg: #fdf0d3; --tk-warn-fg: #6e4300; --tk-warn-dot: #d98a00;
  --tk-err-bg: #fde7ea;  --tk-err-fg: #9c1c2b;  --tk-err-dot: #d9364a;
  --tk-off-bg: #eceef3;  --tk-off-fg: #474a5c;  --tk-off-dot: #8a8da0;
  --tk-info-bg: #e8effd; --tk-info-fg: #1c4a9e; --tk-info-dot: #3b78e7;

  --tk-shadow-1: 0 1px 2px rgba(27, 23, 48, .06);
  --tk-shadow-2: 0 4px 14px rgba(27, 23, 48, .14);
  --tk-radius: 4px;
  --tk-side-w: 232px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --tk-bg: #121020;
    --tk-surface: #1c1a2e;
    --tk-surface-2: #25223a;
    --tk-border: #3a3655;
    --tk-text: #ececf6;
    --tk-muted: #aaa7c2;
    --tk-link: #c4adff;
    --tk-primary: #7a35d6;
    --tk-primary-hover: #8a4ae0;
    --tk-primary-active: #6a2bc0;
    --tk-focus: #b69cff;
    --tk-row-hover: #272443;

    --tk-side-bg: #0e0c1a;
    --tk-side-bg-2: #1b1730;
    --tk-side-active-bg: #5b2ea0;

    --tk-ok-bg: #12301f;   --tk-ok-fg: #7fe0aa;
    --tk-warn-bg: #3a2a08; --tk-warn-fg: #ffc861;
    --tk-err-bg: #3d1620;  --tk-err-fg: #ff9aa8;
    --tk-off-bg: #2a2740;  --tk-off-fg: #bdbad3;
    --tk-info-bg: #14284d; --tk-info-fg: #9dc0ff;
    --tk-shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
    --tk-shadow-2: 0 6px 20px rgba(0, 0, 0, .55);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--tk-bg); color: var(--tk-text);
  font: 14px/1.5 var(--tk-font); overflow-wrap: break-word;
}
h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.25; font-weight: 600; }
h1 { font-size: 22px; } h2 { font-size: 18px; } h3 { font-size: 15px; }
p { margin: 0 0 1em; }
a { color: var(--tk-link); }
a:hover { text-decoration-thickness: 2px; }
hr { border: 0; border-top: 1px solid var(--tk-border); margin: 16px 0; }
img, svg, video { max-width: 100%; }
code, kbd, samp, .mono { font-family: var(--tk-mono); font-size: .92em; }
code { background: var(--tk-surface-2); border: 1px solid var(--tk-border); border-radius: 3px; padding: 1px 5px; }
.muted { color: var(--tk-muted); }
.small { font-size: 12px; }

:focus-visible { outline: 2px solid var(--tk-focus); outline-offset: 2px; border-radius: 2px; }
.sidebar :focus-visible { outline-color: #d8c8ff; }

.sr-only {
  position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}
.skip-link { position: absolute; left: 8px; top: -60px; z-index: 100; background: var(--tk-primary); color: var(--tk-on-primary); padding: 8px 12px; border-radius: var(--tk-radius); }
.skip-link:focus { top: 8px; }

/* Icons: <svg class="icon" aria-hidden="true"><use href="/static/icons.svg#tunnel"/></svg> */
.icon { width: 16px; height: 16px; flex: none; vertical-align: -3px; fill: none; stroke: currentColor; }
.icon-lg { width: 20px; height: 20px; }

/* ---------- App shell ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--tk-side-w); flex: none; background: var(--tk-side-bg); color: var(--tk-side-text);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 16px; color: #fff; font-weight: 700; font-size: 16px; text-decoration: none; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 6px; background: var(--tk-primary); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; flex: none;
}
.brand-mark .icon { width: 18px; height: 18px; }
.sidebar .brand-mark { background: #7a35d6; }
.nav { list-style: none; margin: 0; padding: 8px; display: flex; flex-direction: column; gap: 2px; }
.nav-label { padding: 14px 12px 4px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--tk-side-muted); }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: var(--tk-radius);
  color: var(--tk-side-text); text-decoration: none; font-weight: 500; background: none; border: 0; width: 100%; font: inherit; font-weight: 500; cursor: pointer; text-align: left;
}
.nav-item:hover { background: var(--tk-side-bg-2); color: #fff; }
.nav-item.active, .nav-item[aria-current="page"] { background: var(--tk-side-active-bg); color: var(--tk-side-active-text); }
.sidebar-foot { margin-top: auto; padding: 8px; border-top: 1px solid var(--tk-side-bg-2); }
.sidebar-user { padding: 8px 12px; font-size: 12px; color: var(--tk-side-muted); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; min-height: 56px; padding: 8px 24px;
  background: var(--tk-surface); border-bottom: 1px solid var(--tk-border); position: sticky; top: 0; z-index: 20;
}
.breadcrumb { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; color: var(--tk-muted); font-size: 13px; }
.breadcrumb li + li::before { content: "/"; margin-right: 6px; color: var(--tk-muted); }
.breadcrumb [aria-current] { color: var(--tk-text); font-weight: 600; font-size: 16px; }
.topbar-title { margin: 0; font-size: 16px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.env-pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px;
  border: 1px solid var(--tk-border); background: var(--tk-surface-2); color: var(--tk-text); font-size: 12px; font-weight: 600;
}
.env-pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--tk-ok-dot); }
.env-pill.warn::before { background: var(--tk-warn-dot); }
.env-pill.err::before { background: var(--tk-err-dot); }
.content { padding: 24px; max-width: 1280px; width: 100%; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); }
.stack > * + * { margin-top: 16px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- Cards ---------- */
.card { background: var(--tk-surface); border: 1px solid var(--tk-border); border-radius: var(--tk-radius); box-shadow: var(--tk-shadow-1); min-width: 0; }
.card-header { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--tk-border); }
.card-header h2, .card-header h3 { margin: 0; font-size: 14px; }
.card-header .actions { margin-left: auto; display: flex; gap: 8px; }
.card-body { padding: 16px; }
.card-footer { padding: 10px 16px; border-top: 1px solid var(--tk-border); background: var(--tk-surface-2); }
.stat-label { font-size: 12px; color: var(--tk-muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.stat-value { font-size: 28px; font-weight: 600; line-height: 1.2; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 32px; padding: 5px 14px;
  border-radius: var(--tk-radius); border: 1px solid var(--tk-primary); background: var(--tk-primary); color: var(--tk-on-primary);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--tk-primary-hover); border-color: var(--tk-primary-hover); }
.btn:active { background: var(--tk-primary-active); border-color: var(--tk-primary-active); }
.btn-secondary { background: var(--tk-surface); color: var(--tk-link); border-color: var(--tk-primary); }
.btn-secondary:hover { background: var(--tk-row-hover); border-color: var(--tk-primary-hover); }
.btn-secondary:active { background: var(--tk-surface-2); }
.btn-ghost { background: transparent; color: var(--tk-text); border-color: transparent; }
.btn-ghost:hover { background: var(--tk-surface-2); border-color: var(--tk-border); }
.btn-danger { background: #b4232f; border-color: #b4232f; color: #fff; }
.btn-danger:hover { background: #961c27; border-color: #961c27; }
.btn-danger-outline { background: var(--tk-surface); color: var(--tk-err-fg); border-color: var(--tk-err-dot); }
.btn-danger-outline:hover { background: var(--tk-err-bg); }
.btn-sm { min-height: 26px; padding: 2px 10px; font-size: 12px; }
.btn-icon { padding: 5px; min-width: 32px; }
.btn-sm.btn-icon { min-width: 26px; padding: 2px; }
.btn-block { display: flex; width: 100%; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn.is-loading { position: relative; color: transparent; pointer-events: none; }
.btn.is-loading::after { content: ""; position: absolute; width: 14px; height: 14px; border: 2px solid #fff; border-right-color: transparent; border-radius: 50%; animation: tk-spin .7s linear infinite; }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.label { display: block; font-weight: 600; margin-bottom: 4px; }
.hint { display: block; margin-top: 4px; font-size: 12px; color: var(--tk-muted); }
.input, .select, .textarea {
  display: block; width: 100%; min-height: 34px; padding: 6px 10px; font: inherit; color: var(--tk-text);
  background: var(--tk-surface); border: 1px solid #8a8fa3; border-radius: var(--tk-radius);
}
.textarea { min-height: 90px; resize: vertical; }
.input.mono, .textarea.mono { font-family: var(--tk-mono); font-size: 13px; }
.input::placeholder { color: var(--tk-muted); opacity: 1; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--tk-primary); }
.input:focus, .select:focus, .textarea:focus { outline: 2px solid var(--tk-focus); outline-offset: 0; border-color: var(--tk-primary); box-shadow: 0 0 0 4px rgba(124, 58, 237, .18); }
.input[aria-invalid="true"], .is-invalid { border-color: var(--tk-err-dot); }
.field-error { display: block; margin-top: 4px; font-size: 12px; font-weight: 600; color: var(--tk-err-fg); }
.input:disabled, .select:disabled, .textarea:disabled { background: var(--tk-surface-2); cursor: not-allowed; }
.input-group { display: flex; gap: 0; }
.input-group .input { border-top-right-radius: 0; border-bottom-right-radius: 0; flex: 1; min-width: 0; }
.input-group .btn { border-top-left-radius: 0; border-bottom-left-radius: 0; margin-left: -1px; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: 16px; height: 16px; accent-color: var(--tk-primary); }

/* ---------- Tables ---------- */
.table-wrap { overflow: auto; max-width: 100%; max-height: 70vh; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.table th, .table td { overflow-wrap: normal; padding: 7px 12px; text-align: left; border-bottom: 1px solid var(--tk-border); vertical-align: middle; }
.table th {
  position: sticky; top: 0; z-index: 1; background: var(--tk-surface-2); color: var(--tk-muted);
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; white-space: nowrap;
}
.table tbody tr:hover td { background: var(--tk-row-hover); }
.table td { white-space: nowrap; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table .cell-actions { text-align: right; white-space: nowrap; }
.table-wrap:focus-visible { outline-offset: -2px; }

/* ---------- Chips, tags ---------- */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 1px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--tk-off-bg); color: var(--tk-off-fg); }
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--tk-off-dot); }
.chip-ok { background: var(--tk-ok-bg); color: var(--tk-ok-fg); } .chip-ok::before { background: var(--tk-ok-dot); }
.chip-warn { background: var(--tk-warn-bg); color: var(--tk-warn-fg); } .chip-warn::before { background: var(--tk-warn-dot); }
.chip-err { background: var(--tk-err-bg); color: var(--tk-err-fg); } .chip-err::before { background: var(--tk-err-dot); }
.chip-off { background: var(--tk-off-bg); color: var(--tk-off-fg); }
.tag { display: inline-block; padding: 0 6px; border: 1px solid var(--tk-border); border-radius: 3px; background: var(--tk-surface-2); color: var(--tk-text); font-size: 11px; font-weight: 600; line-height: 18px; }
.tag-mono { font-family: var(--tk-mono); font-weight: 500; }
.copyable { white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; font-family: var(--tk-mono); font-size: 12.5px; }
.secret { font-family: var(--tk-mono); letter-spacing: .04em; }

/* ---------- Tooltip (CSS-only; target needs tabindex=0 or be a button) ---------- */
.tooltip { position: relative; }
.tooltip::after {
  content: attr(data-tip); position: absolute; left: 50%; bottom: calc(100% + 6px); transform: translateX(-50%);
  background: #1b1730; color: #fff; border: 1px solid #4a4268; padding: 4px 8px; border-radius: var(--tk-radius);
  font: 500 12px/1.4 var(--tk-font); white-space: nowrap; max-width: 80vw; pointer-events: none; opacity: 0; visibility: hidden; transition: opacity .12s; z-index: 50;
}
.tooltip:hover::after, .tooltip:focus-visible::after, .tooltip:focus-within::after { opacity: 1; visibility: visible; }

/* ---------- Alerts / toasts ---------- */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border: 1px solid; border-left-width: 4px; border-radius: var(--tk-radius); margin-bottom: 12px; }
.alert .icon { margin-top: 2px; }
.alert-body { flex: 1; min-width: 0; }
.alert-title { font-weight: 700; display: block; }
.alert-error { background: var(--tk-err-bg); color: var(--tk-err-fg); border-color: var(--tk-err-dot); }
.alert-success { background: var(--tk-ok-bg); color: var(--tk-ok-fg); border-color: var(--tk-ok-dot); }
.alert-info { background: var(--tk-info-bg); color: var(--tk-info-fg); border-color: var(--tk-info-dot); }
.alert-warn { background: var(--tk-warn-bg); color: var(--tk-warn-fg); border-color: var(--tk-warn-dot); }
.alert a { color: inherit; font-weight: 600; }
.toast-region { position: fixed; right: 16px; bottom: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; width: min(360px, calc(100vw - 32px)); }
.toast-region .alert { margin: 0; box-shadow: var(--tk-shadow-2); animation: tk-in .18s ease-out; }

/* ---------- Modal (works with <dialog class="modal"> and .modal-backdrop > .modal) ---------- */
dialog.modal { padding: 0; border: 1px solid var(--tk-border); border-radius: 6px; background: var(--tk-surface); color: var(--tk-text); width: min(480px, calc(100vw - 32px)); box-shadow: var(--tk-shadow-2); }
dialog.modal::backdrop { background: rgba(14, 12, 26, .6); }
.modal-backdrop { position: fixed; inset: 0; background: rgba(14, 12, 26, .6); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 300; }
.modal-backdrop[hidden] { display: none; }
.modal-backdrop > .modal { background: var(--tk-surface); color: var(--tk-text); border: 1px solid var(--tk-border); border-radius: 6px; width: min(480px, 100%); box-shadow: var(--tk-shadow-2); }
.modal-header { display: flex; align-items: center; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--tk-border); }
.modal-header h2 { margin: 0; font-size: 16px; flex: 1; }
.modal-body { padding: 16px; max-height: 70vh; overflow: auto; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; padding: 12px 16px; border-top: 1px solid var(--tk-border); }

/* ---------- Empty state, skeleton ---------- */
.empty { text-align: center; padding: 40px 16px; color: var(--tk-muted); }
.empty > .icon { width: 40px; height: 40px; color: var(--tk-primary); margin-bottom: 8px; }
.empty h3 { color: var(--tk-text); margin-bottom: 4px; }
.skeleton { display: block; height: 14px; border-radius: 3px; background: linear-gradient(90deg, var(--tk-surface-2) 25%, var(--tk-border) 50%, var(--tk-surface-2) 75%); background-size: 200% 100%; animation: tk-shimmer 1.4s linear infinite; }
.skeleton + .skeleton { margin-top: 8px; }
.skeleton-lg { height: 28px; width: 40%; }

/* ---------- Auth shell: main.auth > .auth-card ---------- */
.auth { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; background: var(--tk-bg); }
.auth-card { width: 100%; max-width: 400px; background: var(--tk-surface); border: 1px solid var(--tk-border); border-radius: var(--tk-radius); box-shadow: var(--tk-shadow-2); padding: 28px 24px; }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-bottom: 20px; text-align: center; }
.auth-brand .brand-mark { width: 44px; height: 44px; border-radius: 10px; }
.auth-brand .brand-mark .icon { width: 26px; height: 26px; }
.auth-brand h1 { margin: 0; font-size: 20px; }
.auth-foot { margin-top: 16px; text-align: center; font-size: 13px; color: var(--tk-muted); }

/* ---------- Legal links (templates/_legal.html) and the consent line of the sign-up form ---------- */
.legal { margin: 14px 0 0; text-align: center; font-size: 13px; color: var(--tk-muted); }
.legal a { padding: 4px 2px; }
.legal-sep { margin: 0 8px; }
.consent { margin: 0 0 12px; font-size: 13px; line-height: 1.5; color: var(--tk-muted); }
.app-footer { padding: 12px 24px 20px; border-top: 1px solid var(--tk-border); }
.app-footer .legal { margin: 0; text-align: left; }

/* ---------- Small screens: sidebar becomes a top bar ---------- */
@media (max-width: 800px) {
  .app { flex-direction: column; }
  .sidebar { position: static; width: 100%; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; overflow: visible; }
  .brand { padding: 10px 12px; }
  .nav { flex-direction: row; flex-wrap: wrap; padding: 0 8px 8px; flex: 1 1 100%; order: 3; }
  .nav-label { display: none; }
  .nav-item { width: auto; padding: 6px 10px; }
  .sidebar-foot { margin: 0 0 0 auto; border: 0; padding: 4px 8px; display: flex; align-items: center; gap: 4px; }
  .sidebar-user { display: none; }
  .topbar { position: static; padding: 8px 16px; }
  .content { padding: 16px; }
  .toast-region { right: 8px; bottom: 8px; }
}

@keyframes tk-spin { to { transform: rotate(360deg); } }
@keyframes tk-shimmer { to { background-position: -200% 0; } }
@keyframes tk-in { from { opacity: 0; transform: translateY(8px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
  .skeleton { background: var(--tk-surface-2); }
}
