/* =============================================================================
   BlunxAI Administration Panel - stylesheet
   =============================================================================
   Self-hosted on purpose: no CDN, no build step, no external font. The panel
   must stay renderable with a strict Content-Security-Policy ('self' only).

   The tokens mirror the visual identity of the BlunxAI application (dark
   surfaces, solid cards, purple accent) so the two interfaces feel like the
   same product, while the layout is denser: an operator scans tables, not
   marketing pages.
   ============================================================================= */

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

:root {
  --bg:        #08080d;
  --surface:   #14141f;
  --surface-2: #1b1b28;
  --surface-3: #22222f;
  --border:    #232334;
  --border-2:  #2f2f45;

  --text:      #eaeaf4;
  --text-2:    #b8b8d0;
  --text-3:    #8a8aa0;
  --muted:     #5a5a72;

  --accent:    #6c5ce7;
  --accent-2:  #a29bfe;
  --green:     #00b894;
  --red:       #e17055;
  --red-2:     #ff6b6b;
  --yellow:    #fdcb6e;
  --blue:      #74b9ff;

  --radius:    10px;
  --radius-sm: 7px;
  --radius-lg: 14px;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
}

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

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

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }

.mono { font-family: var(--mono); font-size: 12.5px; color: var(--text-2); }
.link { color: var(--accent-2); }

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--accent); color: #fff; padding: 8px 14px; border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus { left: 0; }

/* ============================= Brand ============================= */

.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; }

.brand-mark {
  display: grid; place-items: center;
  width: 34px; height: 34px; flex: 0 0 34px;
  border-radius: 9px;
  background: linear-gradient(140deg, var(--accent), #b14fd6);
  color: #fff; font-weight: 700; font-size: 16px;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-name { font-weight: 600; font-size: 14px; }
.brand-sub { font-size: 11.5px; color: var(--muted); }

/* ============================= Auth layout ============================= */

.auth-body { display: grid; place-items: center; min-height: 100%; padding: 24px; }

.auth-shell {
  width: 100%; max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 22px 18px;
  box-shadow: var(--shadow);
}

.auth-title { font-size: 19px; margin-bottom: 4px; }
.auth-desc { color: var(--text-3); margin: 0 0 18px; font-size: 13px; }
.auth-hint { color: var(--muted); font-size: 12px; margin: 16px 0 0; }
.auth-foot { text-align: center; color: var(--muted); font-size: 11.5px; margin-top: 18px; }

/* ============================= Application shell ============================= */

.shell { display: flex; min-height: 100vh; }

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

.nav { display: flex; flex-direction: column; padding: 0 10px 24px; gap: 2px; }

.nav-section {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin: 18px 8px 6px;
}

.nav-title {
  font-size: 10.5px; letter-spacing: .09em; text-transform: uppercase;
  color: var(--muted); font-weight: 600;
}

.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text-2); font-size: 13.5px;
  border-left: 2px solid transparent;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link.is-active {
  background: var(--surface-2);
  color: var(--text);
  border-left-color: var(--accent);
  font-weight: 500;
}
.ico { width: 16px; height: 16px; fill: currentColor; flex: 0 0 16px; }

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

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-size: 15px; font-weight: 600; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }

.user-chip { display: flex; flex-direction: column; line-height: 1.25; text-align: right; }
.user-name { font-size: 13px; }
.user-mail { font-size: 11.5px; color: var(--muted); }

.inline-form { display: inline; }

.icon-btn {
  display: none;
  background: transparent; border: 1px solid var(--border);
  color: var(--text-2); border-radius: var(--radius-sm);
  padding: 6px; cursor: pointer;
}
.icon-btn:hover { color: var(--text); border-color: var(--border-2); }

.content { padding: 20px; display: flex; flex-direction: column; gap: 16px; }

/* ============================= Grid & cards ============================= */

.grid { display: grid; gap: 14px; }
.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)); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.card-title { font-size: 13.5px; font-weight: 600; }
.card-body { padding: 16px; }
.card-foot {
  margin: 0; padding: 10px 16px;
  border-top: 1px solid var(--border);
  color: var(--muted); font-size: 12px;
}

.stat {
  display: flex; flex-direction: column; gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.stat-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.stat-value { font-size: 26px; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-hint { font-size: 12px; color: var(--text-3); }

/* Trend badge: the colour follows the OUTCOME, not the direction - a rising
   error rate must read as bad news. */
.stat-trend {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums;
  margin-top: 2px;
}
.stat-trend.is-good { color: var(--green); }
.stat-trend.is-bad  { color: var(--red-2); }

/* Card accents: used to draw the eye when a figure needs attention. */
.stat-ok .stat-value     { color: var(--green); }
.stat-warn .stat-value   { color: var(--yellow); }
.stat-danger .stat-value { color: var(--red-2); }
.stat-accent .stat-value { color: var(--accent-2); }
.stat-ok     { border-color: rgba(0, 184, 148, .32); }
.stat-warn   { border-color: rgba(253, 203, 110, .32); }
.stat-danger { border-color: rgba(225, 112, 85, .34); }

/* ============================= Tables ============================= */

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 16px; text-align: left; border-bottom: 1px solid var(--border); }
.table th {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); font-weight: 600; background: var(--surface-2);
}
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: none; }

/* ============================= Badges ============================= */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: .02em;
  background: var(--surface-3); color: var(--text-2);
  border: 1px solid var(--border-2);
  white-space: nowrap;
}
.badge-ok     { background: rgba(0, 184, 148, .12); color: var(--green);   border-color: rgba(0, 184, 148, .35); }
.badge-danger { background: rgba(225, 112, 85, .12); color: var(--red-2);  border-color: rgba(225, 112, 85, .35); }
.badge-warn   { background: rgba(253, 203, 110, .12); color: var(--yellow); border-color: rgba(253, 203, 110, .35); }
.badge-accent { background: rgba(108, 92, 231, .16); color: var(--accent-2); border-color: rgba(108, 92, 231, .4); }
.badge-muted  { background: transparent; color: var(--muted); }

/* ============================= Forms ============================= */

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

.input, .select, .textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 9px 11px;
  font-family: inherit;
  font-size: 13.5px;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(108, 92, 231, .18);
}
.input::placeholder { color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-2);
  background: var(--surface-2); color: var(--text);
  font-family: inherit; font-size: 13px; font-weight: 500;
  cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #7d6cf0; border-color: #7d6cf0; }
.btn-danger { background: rgba(225, 112, 85, .14); border-color: rgba(225, 112, 85, .45); color: var(--red-2); }
.btn-danger:hover { background: rgba(225, 112, 85, .22); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; }

.alert {
  border-radius: var(--radius-sm);
  padding: 10px 13px;
  font-size: 13px;
  border: 1px solid var(--border-2);
  background: var(--surface-2);
  color: var(--text-2);
}
.alert-danger { background: rgba(225, 112, 85, .1); border-color: rgba(225, 112, 85, .4); color: #ffb4a2; }
.alert-info   { background: rgba(116, 185, 255, .1); border-color: rgba(116, 185, 255, .35); color: #bcdcff; }
.alert-ok     { background: rgba(0, 184, 148, .1);  border-color: rgba(0, 184, 148, .35);  color: #9be7d5; }

/* ============================= Secrets & codes ============================= */

.input-code {
  font-family: var(--mono);
  letter-spacing: .22em;
  font-size: 16px;
  text-align: center;
}

.secret-box {
  background: var(--bg);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 14px;
}
.secret-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.secret-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.secret-value {
  display: block;
  font-family: var(--mono);
  font-size: 15px;
  letter-spacing: .14em;
  color: var(--accent-2);
  word-break: break-all;
  user-select: all;
}
.secret-note { margin: 8px 0 0; font-size: 11.5px; color: var(--muted); }
.secret-uri { display: block; margin-top: 8px; font-family: var(--mono); font-size: 11.5px; color: var(--text-3); word-break: break-all; }

.details { margin-bottom: 16px; font-size: 12.5px; color: var(--text-3); }
.details summary { cursor: pointer; color: var(--text-2); }

.codes-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 16px 0;
}
.code-item {
  font-family: var(--mono);
  font-size: 14px;
  letter-spacing: .12em;
  padding: 9px 10px;
  text-align: center;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: pointer;
}
.code-item:hover { border-color: var(--accent); color: var(--accent-2); }

/* ============================= Inline step-up ============================= */

.stepup {
  border: 1px dashed var(--border-2);
  border-radius: var(--radius-sm);
  padding: 12px 14px 14px;
  margin: 4px 0 16px;
  background: rgba(253, 203, 110, .05);
}
.stepup-legend {
  padding: 0 6px;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 600;
  color: var(--yellow);
}
.stepup-hint { margin: 0 0 12px; font-size: 12.5px; color: var(--text-3); }

/* ============================= Forms layout ============================= */

.form-actions { display: flex; align-items: center; gap: 10px; }
.card-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.cell-actions { text-align: right; white-space: nowrap; }
.cell-clip { max-width: 18rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-right { text-align: right; font-variant-numeric: tabular-nums; }

/* ============================= Toolbar & pagination ============================= */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.toolbar .field { gap: 4px; }
.toolbar .field-label { font-size: 11px; }
.toolbar .input, .toolbar .select { padding: 6px 9px; font-size: 13px; }
.toolbar-spacer { flex: 1 1 auto; }

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
}
.pager-info { font-size: 12px; color: var(--muted); }
.pager-links { display: flex; align-items: center; gap: 4px; }
.pager-link {
  min-width: 30px;
  padding: 4px 8px;
  text-align: center;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  color: var(--text-2);
}
.pager-link:hover { border-color: var(--accent); color: var(--text); text-decoration: none; }
.pager-link.is-current { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.pager-link.is-disabled { opacity: .38; pointer-events: none; }
.pager-elision { padding: 0 4px; color: var(--muted); }

.empty-state { padding: 34px 16px; text-align: center; color: var(--text-3); font-size: 13.5px; }

/* Micro bar used inside a table cell to show a share without a chart. */
.micro-bar {
  display: block;
  height: 5px;
  border-radius: 3px;
  background: var(--surface-3);
  overflow: hidden;
  min-width: 60px;
}
.micro-bar > span { display: block; height: 100%; background: var(--accent); }
.micro-bar.is-warn > span { background: var(--yellow); }
.micro-bar.is-danger > span { background: var(--red); }
.micro-bar.is-ok > span { background: var(--green); }

/* ============================= Management screens ============================= */

.head-actions { display: flex; align-items: center; gap: 8px; }

.cell-strong { font-weight: 500; }
.cell-dim { color: var(--text-3); font-size: 12.5px; }

.check { display: flex; align-items: flex-start; gap: 8px; font-size: 13px; color: var(--text-2); }
.check input { margin-top: 3px; accent-color: var(--accent); }
.check-block { padding: 6px 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); }
.check-block:hover { border-color: var(--border-2); }
.check-row { display: flex; flex-direction: column; gap: 8px; }

.roles-fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.roles-fieldset legend { padding: 0 6px; }

.action-list { display: flex; flex-direction: column; gap: 16px; }
.action-item {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.action-text { display: flex; flex-direction: column; gap: 2px; }
.action-label { font-weight: 500; font-size: 13.5px; }
.action-hint { color: var(--text-3); font-size: 12.5px; }
.action-item .stepup { margin: 0; }
.action-item .btn { align-self: flex-start; }

.matrix { display: flex; flex-direction: column; gap: 18px; margin: 8px 0 4px; }
.matrix-group { display: flex; flex-direction: column; gap: 8px; }
.matrix-head { display: flex; flex-direction: column; gap: 2px; }
.matrix-title { font-size: 13px; font-weight: 600; }
.matrix-desc { margin: 0; font-size: 12px; color: var(--muted); }
.matrix-items { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }

.table-scroll { overflow-x: auto; }

.code-block {
  margin: 0;
  padding: 14px 16px;
  background: var(--bg);
  color: var(--text-2);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  overflow-x: auto;
  max-height: 26rem;
}

/* ============================= Roadmap list ============================= */
.roadmap { list-style: none; margin: 0; padding: 6px 16px 14px; display: flex; flex-direction: column; gap: 8px; }
.roadmap li { display: flex; align-items: center; gap: 10px; color: var(--text-2); font-size: 13px; }

/* ============================= Modal ============================= */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center;
  background: rgba(4, 4, 8, .72);
  padding: 20px;
}
.modal-backdrop[hidden] { display: none; }

.modal {
  width: 100%; max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
  animation: modal-in .14s ease-out;
}
@keyframes modal-in { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }

.modal-title { font-size: 15px; margin-bottom: 8px; }
.modal-text { color: var(--text-2); font-size: 13px; margin: 0 0 18px; white-space: pre-line; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ============================= Toasts ============================= */

.toast-root {
  position: fixed; right: 18px; bottom: 18px; z-index: 70;
  display: flex; flex-direction: column; gap: 8px;
  max-width: min(360px, calc(100vw - 36px));
}
.toast {
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 10px 13px;
  font-size: 13px;
  color: var(--text);
  box-shadow: var(--shadow);
  animation: toast-in .16s ease-out;
}
.toast-ok      { border-left-color: var(--green); }
.toast-danger  { border-left-color: var(--red); }
.toast-warn    { border-left-color: var(--yellow); }
@keyframes toast-in { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }

/* ============================= Responsive ============================= */

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

@media (max-width: 820px) {
  .shell { flex-direction: column; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 50;
    transform: translateX(-102%);
    transition: transform .18s ease-out;
    box-shadow: var(--shadow);
  }
  body.nav-open .sidebar { transform: none; }
  .icon-btn { display: inline-flex; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .matrix-items { grid-template-columns: minmax(0, 1fr); }
  .codes-grid { grid-template-columns: minmax(0, 1fr); }
  .user-mail { display: none; }
  .table th, .table td { padding: 9px 12px; }
}
