/*
 * RetaDesk admin panel layout (docs/admin-panel/implementation_plan.md).
 * Built on the new design's stylesheet (/ui/rd.css: Bootstrap 5.3.8, AdminLTE 4 components, --rd-* tokens).
 * The top bar is slate, not RetaDesk Red, so an operator always sees that this is the platform panel and not a
 * client's RetaDesk. Chrome 109 floor: no color-mix(), no CSS nesting.
 */
:root {
  --pn-top: #1c2430;
  --pn-top-ink: #e8ecf1;
  --pn-top-muted: #9aa6b4;
  --pn-side-w: 236px;
  --pn-top-h: 54px;
}
[data-bs-theme="dark"] {
  --pn-top: #0e1218;
  --pn-top-ink: #e8ecf1;
  --pn-top-muted: #8b96a3;
}

body.pn { padding-top: var(--pn-top-h); }

/* ---- Top bar ---- */
.pn-top {
  position: fixed; inset: 0 0 auto 0; z-index: 1030;
  height: var(--pn-top-h);
  display: flex; align-items: center; gap: .75rem;
  padding: 0 1rem;
  background: var(--pn-top); color: var(--pn-top-ink);
  box-shadow: 0 1px 0 rgba(0, 0, 0, .25);
}
.pn-top a, .pn-top .btn-link { color: var(--pn-top-ink); text-decoration: none; }
.pn-brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.05rem; letter-spacing: .01em; }
.pn-brand img { width: 30px; height: 30px; border-radius: 7px; }
.pn-brand small { font-weight: 600; font-size: .72rem; text-transform: uppercase; letter-spacing: .08em;
  padding: .15rem .45rem; border-radius: 4px; background: rgba(255, 255, 255, .12); color: var(--pn-top-ink); }
.pn-env { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; padding: .2rem .5rem; border-radius: 4px; }
.pn-env-production { background: #c8121b; color: #fff; }
.pn-env-local, .pn-env-staging, .pn-env-test { background: #e09b0d; color: #1f262e; }
.pn-top .pn-spacer { flex: 1 1 auto; }
.pn-top .pn-icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px;
  border-radius: 8px; border: 0; background: transparent; color: var(--pn-top-ink); }
.pn-top .pn-icon-btn:hover, .pn-top .pn-icon-btn:focus-visible { background: rgba(255, 255, 255, .1); }
.pn-user { display: flex; align-items: center; gap: .5rem; border: 0; background: transparent; color: var(--pn-top-ink);
  padding: .25rem .5rem; border-radius: 8px; }
.pn-user:hover { background: rgba(255, 255, 255, .1); }
.pn-user .pn-avatar { width: 30px; height: 30px; border-radius: 50%; display: inline-flex; align-items: center;
  justify-content: center; background: #3b4757; font-weight: 700; font-size: .85rem; }
.pn-user .pn-user-role { color: var(--pn-top-muted); font-size: .75rem; }

/* ---- Side menu ---- */
.pn-side {
  --bs-offcanvas-width: 270px;
  background: var(--rd-surface);
  border-right: 1px solid var(--rd-border);
}
.pn-nav { list-style: none; margin: 0; padding: .75rem .5rem 2rem; }
.pn-nav .pn-section { padding: 1rem .75rem .35rem; font-size: .7rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--rd-muted); }
.pn-nav a { display: flex; align-items: center; gap: .7rem; padding: .5rem .75rem; border-radius: 8px;
  color: var(--rd-text); text-decoration: none; font-weight: 600; }
.pn-nav a .fa-solid { width: 1.1rem; text-align: center; color: var(--rd-muted); }
.pn-nav a:hover { background: var(--rd-surface-2); }
.pn-nav a.active { background: var(--rd-tint-primary); color: var(--rd-red-deep); }
.pn-nav a.active .fa-solid { color: var(--rd-red); }
@media (min-width: 992px) {
  .pn-side { position: fixed; top: var(--pn-top-h); bottom: 0; left: 0; width: var(--pn-side-w); overflow-y: auto; }
  /* Bootstrap's responsive offcanvas makes itself transparent from md up */
  .pn-side.offcanvas-md { background-color: var(--rd-surface) !important; }
  .pn-main { margin-left: var(--pn-side-w); }
  .pn-menu-btn { display: none !important; }
}

/* ---- Content ---- */
.pn-main { padding: 1.5rem 1.5rem 3rem; }
.pn-page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .75rem 1.5rem; margin-bottom: 1.25rem; }
.pn-page-head h1 { font-size: 1.6rem; font-weight: 700; margin: 0; }
.pn-page-head p { margin: .25rem 0 0; color: var(--rd-muted); }
.pn-page-head .pn-actions { margin-left: auto; display: flex; gap: .5rem; flex-wrap: wrap; }
.pn-main .card { border-color: var(--rd-border); }
.pn-main .card-header { background: transparent; font-weight: 700; border-bottom-color: var(--rd-border); }

.pn-stat { display: block; padding: 1rem 1.1rem; border: 1px solid var(--rd-border); border-radius: 10px;
  background: var(--rd-surface); color: var(--rd-text); text-decoration: none; height: 100%; }
.pn-stat:hover { border-color: var(--rd-muted); text-decoration: none; }
.pn-stat .pn-stat-label { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--rd-muted); }
.pn-stat .pn-stat-value { font-size: 1.9rem; font-weight: 700; line-height: 1.15; margin-top: .2rem; font-variant-numeric: tabular-nums; }
.pn-stat .pn-stat-sub { font-size: .85rem; color: var(--rd-muted); }
.pn-stat.pn-stat-alert .pn-stat-value { color: var(--bs-danger); }

.pn-table { margin: 0; }
.pn-table th { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--rd-muted); font-weight: 700;
  white-space: nowrap; }
.pn-table td { vertical-align: middle; }
.pn-mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em; }
.pn-msg { max-width: 60ch; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2;
  -webkit-box-orient: vertical; word-break: break-word; }
.pn-level { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: .2rem .45rem; border-radius: 4px; }
.pn-level-fatal, .pn-level-exception, .pn-level-error { background: var(--rd-tint-danger); color: var(--bs-danger); }
.pn-level-warning { background: var(--rd-tint-warning); color: #8a5a00; }
[data-bs-theme="dark"] .pn-level-warning { color: #f3c262; }
.pn-level-notice, .pn-level-deprecated { background: var(--rd-tint-info); color: var(--bs-info); }

/* ---- Sign-in pages ---- */
body.pn-auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 2rem 1rem;
  background: var(--pn-top); }
.pn-auth-card { width: 100%; max-width: 420px; background: var(--rd-surface); color: var(--rd-text); border-radius: 14px;
  padding: 2rem; box-shadow: 0 20px 50px rgba(0, 0, 0, .35); }
.pn-auth-card.pn-wide { max-width: 560px; }
.pn-auth-brand { display: flex; align-items: center; gap: .75rem; margin-bottom: 1.5rem; }
.pn-auth-brand img { width: 44px; height: 44px; border-radius: 10px; }
.pn-auth-brand strong { display: block; font-size: 1.15rem; }
.pn-auth-brand span { color: var(--rd-muted); font-size: .85rem; }
.pn-auth-card h1 { font-size: 1.35rem; font-weight: 700; margin: 0 0 .35rem; }
.pn-auth-card .pn-lead { color: var(--rd-muted); margin-bottom: 1.25rem; }
.pn-code-input { font-size: 1.6rem; letter-spacing: .35em; text-align: center; font-variant-numeric: tabular-nums; }
.pn-qr { width: 200px; height: 200px; margin: 0 auto; padding: 6px; background: #fff; border-radius: 8px; }
.pn-qr svg { width: 100%; height: 100%; display: block; }
.pn-secret { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 1rem; letter-spacing: .05em;
  word-break: break-all; padding: .5rem .75rem; border-radius: 6px; background: var(--rd-surface-2); border: 1px solid var(--rd-border); }
.pn-codes { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; padding: 0; list-style: none; }
.pn-codes li { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 1.05rem; text-align: center;
  padding: .45rem; border-radius: 6px; background: var(--rd-surface-2); border: 1px solid var(--rd-border); }
.pn-auth-foot { margin-top: 1.5rem; text-align: center; font-size: .8rem; color: var(--pn-top-muted); }

@media (max-width: 767.98px) {
  .pn-main { padding: 1rem .75rem 3rem; }
  .pn-page-head h1 { font-size: 1.35rem; }
  .pn-user .pn-user-text { display: none; }
  .pn-brand small { display: none; }
  .pn-auth-card { padding: 1.5rem 1.25rem; }
}
@media print {
  .pn-top, .pn-side { display: none !important; }
  body.pn { padding-top: 0; }
  .pn-main { margin: 0; }
}

/* ---- Errors: trend chart (stacked bars, 2px gaps, 4px rounded tops), sparkline, trace ---- */
:root { --pn-sev-severe: #d03b3b; --pn-sev-other: #2f7fc1; }
[data-bs-theme="dark"] { --pn-sev-severe: #e05252; --pn-sev-other: #4a8fd6; }
.pn-sev-severe { background: var(--pn-sev-severe); }
.pn-sev-other { background: var(--pn-sev-other); }
.pn-legend { display: inline-flex; align-items: center; gap: .4rem; font-size: .85rem; }
.pn-swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
.pn-trend-plot { position: relative; display: flex; align-items: stretch; gap: 2px;
  border-bottom: 1px solid var(--rd-border); padding-top: 14px; }
.pn-trend-max { position: absolute; top: -2px; left: 0; font-size: .7rem; color: var(--rd-muted); line-height: 1; }
.pn-trend-plot::before { content: ""; position: absolute; left: 0; right: 0; top: 14px; border-top: 1px dashed var(--rd-border-soft); }
.pn-trend-day { flex: 1 1 0; display: flex; align-items: flex-end; justify-content: center; cursor: default; min-width: 0; }
.pn-trend-day:hover { background: var(--rd-surface-2); }
.pn-trend-stack { width: 100%; max-width: 22px; display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; position: relative; }
.pn-trend-stack > span { display: block; width: 100%; }
.pn-trend-stack > span:first-child { border-radius: 4px 4px 0 0; }
.pn-trend-axis { display: flex; justify-content: space-between; font-size: .72rem; color: var(--rd-muted); margin-top: .25rem; }
.pn-spark { display: flex; align-items: flex-end; gap: 2px; height: 48px; border-bottom: 1px solid var(--rd-border); }
.pn-spark > span { flex: 1 1 0; display: flex; align-items: flex-end; height: 100%; }
.pn-spark > span:hover { background: var(--rd-surface-2); }
.pn-spark i { display: block; width: 100%; background: var(--pn-sev-other); border-radius: 2px 2px 0 0; }
.pn-tip { position: fixed; z-index: 2000; pointer-events: none; padding: .3rem .55rem; border-radius: 6px; font-size: .8rem;
  background: var(--rd-text); color: var(--rd-surface); box-shadow: var(--rd-shadow-pop); white-space: nowrap; }
.pn-error-title { font-size: 1.25rem !important; line-height: 1.35; word-break: break-word; }
.pn-trace { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .8rem; white-space: pre-wrap;
  word-break: break-all; max-height: 420px; overflow: auto; }
details.card > summary { cursor: pointer; list-style: none; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::before { content: "\25B8"; display: inline-block; margin-right: .5rem; transition: transform .15s; }
details.card[open] > summary::before { transform: rotate(90deg); }
.pn-json { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .78rem; white-space: pre-wrap;
  word-break: break-all; margin: 0; max-height: 240px; overflow: auto; }
.pn-log { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .78rem; white-space: pre-wrap;
  word-break: break-all; margin: 0; max-height: 70vh; overflow: auto; background: var(--rd-surface-2); padding: .75rem; border-radius: 8px; }
.pn-table tr.pn-row-strong > td { background: var(--rd-surface-2); }

/* ---- Permission editor (roles and templates) ---- */
.pn-perm-bar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; margin-bottom: .5rem; }
.pn-perm-bar input[type="search"] { max-width: 280px; }
.pn-perm-tree ul { list-style: none; margin: 0; padding: 0; }
.pn-perm-tree ul ul { padding-left: 1.4rem; border-left: 1px dashed var(--rd-border); margin-left: .55rem; }
.pn-perm-item { display: flex; align-items: center; gap: .5rem; padding: .25rem .4rem; border-radius: 6px; cursor: pointer;
  margin: 1px 0; }
.pn-perm-item:hover { background: var(--rd-surface-2); }
.pn-perm-item .form-check-input { margin: 0; flex: 0 0 auto; }
.pn-perm-tree > ul > li > .pn-perm-item .pn-perm-label { font-weight: 700; }
.pn-perm-restriction { background: var(--rd-tint-warning); }
.pn-perm-flag { font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: .05rem .35rem;
  border-radius: 4px; background: var(--rd-tint-warning); color: #8a5a00; border: 1px solid rgba(138, 90, 0, .25); }
[data-bs-theme="dark"] .pn-perm-flag { color: #f3c262; }
.pn-perm-added { background: var(--rd-tint-success); box-shadow: inset 3px 0 0 var(--bs-success); }
.pn-perm-removed { background: var(--rd-tint-danger); box-shadow: inset 3px 0 0 var(--bs-danger); }
.pn-perm-removed .pn-perm-label { text-decoration: line-through; }
.pn-perm-match .pn-perm-label { background: var(--rd-tint-warning); border-radius: 3px; }
.pn-perm [hidden] { display: none !important; }
.pn-savebar { position: sticky; bottom: 0; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: .75rem;
  padding: .75rem 1rem; margin: 1rem -.25rem 0; background: var(--rd-surface); border: 1px solid var(--rd-border);
  border-radius: 10px; box-shadow: 0 -6px 18px rgba(0, 0, 0, .08); }
.pn-diff-list { columns: 2 260px; font-size: .85rem; padding-left: 1.1rem; }
/* AdminLTE's clearfix ::after would become a third flex item and push a header link to the middle */
.pn-main .card-header.d-flex::after { display: none; }

/* Schema status (phase 4) */
.pn-schema th, .pn-schema td { white-space: nowrap; }
.pn-schema thead th { text-transform: none; letter-spacing: 0; font-size: .82rem; color: var(--rd-text); vertical-align: bottom; min-width: 7.5rem; }
.pn-schema tbody th { position: sticky; left: 0; background: var(--rd-surface); z-index: 1; text-transform: none; letter-spacing: 0;
  font-size: .85rem; color: var(--rd-text); }
.pn-schema tr.pn-schema-diff > th { box-shadow: inset 4px 0 0 var(--bs-warning); }
.pn-schema-sub { font-size: .75rem; color: var(--rd-muted); font-weight: 400; }
.pn-schema-none { color: var(--rd-muted); opacity: .6; }
.pn-schema-level-mark { display: inline-block; margin-left: .35rem; padding: 0 .35rem; border-radius: 4px; font-size: .65rem;
  font-weight: 700; text-transform: uppercase; letter-spacing: .05em; background: var(--rd-tint-info); color: var(--bs-info); vertical-align: middle; }
.pn-schema-diff-mark { display: inline-block; width: 4px; height: .9em; background: var(--bs-warning); vertical-align: -.1em; margin-right: .2rem; }

/* Provisioning jobs (phase 5) */
.pn-joblog { max-height: 70vh; min-height: 18rem; overflow: auto; padding: 1rem; font-size: .78rem; line-height: 1.45;
  background: var(--rd-surface-2); color: var(--rd-text); white-space: pre-wrap; word-break: break-word; border-radius: 0 0 var(--bs-border-radius) var(--bs-border-radius); }
[data-step][data-state="todo"] { color: var(--rd-muted); }
[data-step][data-state="running"] { font-weight: 600; }
.pn-scroll-list { max-height: 18rem; overflow: auto; }
.pn-dl dd { margin-bottom: .3rem; }

/* Module switches (phase 6) */
.pn-modules thead th { text-transform: none; letter-spacing: 0; font-size: .82rem; color: var(--rd-text); vertical-align: bottom; min-width: 6.5rem; }
.pn-modules tr > :first-child { position: sticky; left: 0; background: var(--rd-surface); z-index: 1; min-width: 15rem; max-width: 22rem; }
.pn-modules td:first-child .small { font-size: .75rem; }

/* Billing */
.pn-charge { border: 1px solid var(--rd-border); border-radius: 10px; padding: .75rem .9rem; margin-bottom: .75rem; }
.pn-charge.pn-charge-empty { border-style: dashed; background: transparent; }
.pn-charge.pn-charge-empty .form-label { color: var(--rd-muted); }
.pn-price-rows td { padding-top: .35rem; padding-bottom: .35rem; }
.pn-money { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pn-chips { display: flex; flex-wrap: wrap; gap: .25rem; }
.pn-chip { display: inline-block; padding: .1rem .45rem; border-radius: 999px; font-size: .78rem; background: var(--rd-surface-2);
  border: 1px solid var(--rd-border); white-space: nowrap; }
.pn-note-input { width: 13rem; max-width: 100%; }
@media (max-width: 575.98px) { .pn-note-input { width: 100%; } }
.pn-preview { border: 1px solid var(--rd-border); border-radius: 10px; padding: .75rem .9rem .25rem; margin-bottom: .9rem; }
.pn-preview .table { --bs-table-bg: transparent; }
.pn-preview tfoot td { border-bottom: 0; }
