/* Backoffice admin UI — light theme matching webapp's design tokens. */

:root {
  --bg-page: #ffffff;
  --bg-inset: #f9fafb;
  --bg-hover: rgba(0, 0, 0, 0.04);
  --text-primary: #101828;
  --text-secondary: #364153;
  --text-muted: #6a7282;
  --text-tertiary: #99a1af;
  --border-default: #f3f4f6;
  --border-strong: #e5e7eb;
  --border-hover: #d1d5db;
  --primary-500: #1a56db;
  --primary-600: #1e40af;
  --primary-700: #1d4ed8;
  --primary-50: #eff6ff;
  --primary-100: #dbeafe;
  --ok-500: #16a34a;
  --ok-700: #15803d;
  --ok-50: #f0fdf4;
  --ok-100: #dcfce7;
  --bad-500: #dc2626;
  --bad-600: #b91c1c;
  --bad-50: #fef2f2;
  --bad-100: #fee2e2;
  --warn-500: #d97706;
  --warn-700: #b45309;
  --warn-50: #fffbeb;
  --warn-100: #fef3c7;
}

* { box-sizing: border-box; }

/* `hidden` must win over any class-level `display` rule. Without this,
   `.state-block { display: flex }` etc. override the UA `[hidden]` rule
   (same specificity, source order) and JS toggling .hidden has no effect. */
[hidden] { display: none !important; }

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-page);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

::selection { background: var(--primary-100); color: var(--text-primary); }

button, input, select {
  font-family: inherit;
}

/* ===============================================================
   Boot splash / login / forbidden screens
   =============================================================== */

.boot-splash {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg-page);
  z-index: 200;
}

.boot-spinner {
  width: 22px;
  height: 22px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--primary-500);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.login-screen,
.forbidden-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: linear-gradient(160deg, #f6f8ff 0%, #ffffff 60%, #eef2ff 100%);
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-page);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 28px;
  box-shadow:
    0 25px 50px -12px rgba(16, 24, 40, 0.10),
    0 0 0 1px rgba(16, 24, 40, 0.02);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

.login-brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #1d4ed8 0%, #1a56db 100%);
  color: #ffffff;
  display: grid;
  place-items: center;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 16px;
  font-weight: 600;
}

.login-brand-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.login-brand-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 1px;
}

#descope-flow-container { min-height: 320px; }

descope-wc {
  display: block;
  width: 100%;
}

.forbidden-card {
  width: 100%;
  max-width: 440px;
  background: var(--bg-page);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 28px;
  text-align: center;
  box-shadow: 0 25px 50px -12px rgba(16, 24, 40, 0.10);
}

.forbidden-card h1 {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.forbidden-card p {
  margin: 0 0 8px;
  color: var(--text-secondary);
  font-size: 13.5px;
  line-height: 1.55;
}

.forbidden-link {
  color: var(--primary-500);
  text-decoration: none;
  font-weight: 500;
}

.forbidden-link:hover {
  color: var(--primary-700);
  text-decoration: underline;
}

.forbidden-card .btn {
  margin-top: 18px;
}

/* ===============================================================
   Page shell
   =============================================================== */

.page {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  width: 100%;
  background: var(--bg-page);
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border-default);
  flex-shrink: 0;
}

.page-header-left {
  display: flex;
  align-items: center;
}

.page-header-icon {
  display: inline-flex;
  width: 16px;
  height: 16px;
  color: var(--text-primary);
}

.page-header-icon svg {
  width: 100%;
  height: 100%;
}

.page-header-title {
  margin-left: 10px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.076px;
  color: var(--text-primary);
}

.page-header-divider {
  margin-left: 14px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--border-hover);
}

.page-header-count {
  margin-left: 14px;
  font-size: 11px;
  letter-spacing: 0.064px;
  color: var(--text-muted);
}

.page-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.btn-icon:hover {
  background: var(--bg-inset);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.btn-icon svg { width: 16px; height: 16px; }

/* Add button — pill, primary blue, matches MembersHeader's */
.btn-add {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 16px 0 12px;
  border: none;
  border-radius: 9999px;
  background: var(--primary-500);
  color: #ffffff;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  box-shadow:
    0 1px 1.5px rgba(26, 86, 219, 0.25),
    0 1px 1px rgba(26, 86, 219, 0.25);
  transition: background-color 0.15s ease;
}

.btn-add:hover { background: var(--primary-600); }
.btn-add:focus-visible {
  outline: none;
  box-shadow:
    0 0 0 2px #ffffff,
    0 0 0 4px rgba(26, 86, 219, 0.4);
}

.btn-add-glyph {
  font-size: 16px;
  font-weight: 500;
  line-height: 1;
  margin-top: -1px;
}

/* ===============================================================
   Body + table
   =============================================================== */

.page-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 24px 32px 32px;
}

.table-wrap {
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--bg-page);
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
}

.col-name { width: 28%; }
.col-owner { width: 24%; }
.col-num { width: 90px; }
.col-date { width: 140px; }
.col-status { width: 1%; white-space: nowrap; }
.col-actions { width: 56px; }

thead th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
  padding: 10px 16px;
  background: var(--bg-inset);
  border-bottom: 1px solid var(--border-strong);
}

thead th.num { text-align: right; }

tbody tr {
  border-bottom: 1px solid var(--border-default);
  transition: background-color 0.12s ease;
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: rgba(0, 0, 0, 0.018); }

tbody td {
  padding: 12px 16px;
  vertical-align: middle;
  color: var(--text-primary);
  font-size: 13px;
}

td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}

/* Name cell */
.row-name {
  font-weight: 500;
  color: var(--text-primary);
  letter-spacing: -0.005em;
}

.row-id {
  margin-top: 2px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11px;
  color: var(--text-tertiary);
  letter-spacing: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Owner cell */
.owner-cell { color: var(--text-secondary); }
.owner-cell .owner-empty { color: var(--text-tertiary); }
.owner-cell .row-pending {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  font-size: 10.5px;
  font-weight: 500;
  border-radius: 9999px;
  color: var(--warn-700);
  background: var(--warn-50);
  border: 1px solid var(--warn-100);
  text-transform: capitalize;
}

td.date-cell {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  white-space: nowrap;
}

/* Actions cell */
td.actions-cell { text-align: right; padding-right: 12px; }

.row-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s ease, background-color 0.12s ease, color 0.12s ease;
}

tbody tr:hover .row-action { opacity: 1; }
.row-action:focus-visible { opacity: 1; outline: none; box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.25); }

.row-action:hover {
  background: var(--bad-50);
  color: var(--bad-500);
}

.row-action svg { width: 16px; height: 16px; }

/* ===============================================================
   Status pills (Railway / Webapp / Descope)
   =============================================================== */

.status-cell {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  padding: 0 9px 0 8px;
  border-radius: 9999px;
  background: var(--bg-inset);
  border: 1px solid var(--border-strong);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: -0.005em;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.12s, border-color 0.12s, color 0.12s;
}

.status-pill .pill-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-tertiary);
}

.status-pill .pill-arrow {
  width: 10px;
  height: 10px;
  margin-left: 1px;
  opacity: 0.7;
  transition: transform 0.12s ease;
}

.status-pill .pill-arrow svg { width: 100%; height: 100%; }

a.status-pill { cursor: pointer; }
a.status-pill:hover .pill-arrow { transform: translate(1px, -1px); opacity: 1; }

.status-pill.ok {
  background: var(--ok-50);
  border-color: var(--ok-100);
  color: var(--ok-700);
}
.status-pill.ok .pill-dot { background: var(--ok-500); }

.status-pill.missing {
  background: var(--bad-50);
  border-color: var(--bad-100);
  color: var(--bad-600);
}
.status-pill.missing .pill-dot { background: var(--bad-500); }

.status-pill.error {
  background: var(--warn-50);
  border-color: var(--warn-100);
  color: var(--warn-700);
}
.status-pill.error .pill-dot { background: var(--warn-500); }

.status-pill.loading .pill-dot {
  animation: pulse 1.3s infinite ease-in-out;
}

@keyframes pulse {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}

/* ===============================================================
   Banners + state blocks
   =============================================================== */

.banner {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 16px;
  border: 1px solid;
}

.banner-error {
  background: var(--bad-50);
  border-color: var(--bad-100);
  color: var(--bad-600);
}

.state-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 64px 20px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--bg-page);
}

.state-block-empty { border-style: dashed; background: var(--bg-inset); }

.state-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-hover);
  border-top-color: var(--primary-500);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 10px;
}

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

.state-text {
  font-size: 13px;
  color: var(--text-muted);
}

.state-title {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
}

.state-sub {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
  max-width: 300px;
}

/* ===============================================================
   Modals
   =============================================================== */

.modal[hidden] { display: none; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(6px);
  animation: fade-in 0.2s ease;
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
  position: relative;
  width: 100%;
  max-width: 480px;
  background: var(--bg-page);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 24px;
  box-shadow:
    0 25px 50px -12px rgba(0, 0, 0, 0.25),
    0 0 0 1px rgba(0, 0, 0, 0.02);
  animation: rise 0.2s ease;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-title {
  margin: 0 0 4px;
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.modal-sub {
  margin: 0 0 16px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-muted);
}

.modal-sub:last-of-type { margin-bottom: 8px; }

/* Form bits */
.form { display: flex; flex-direction: column; gap: 14px; }

.field { display: block; }

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.field input {
  display: block;
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-page);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-primary);
  transition: border-color 0.12s, box-shadow 0.12s;
}

.field input::placeholder { color: var(--text-tertiary); }

.field input:focus {
  outline: none;
  border-color: var(--primary-500);
  box-shadow: 0 0 0 3px rgba(26, 86, 219, 0.15);
}

.form-error {
  margin: 0;
  font-size: 12.5px;
  color: var(--bad-600);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

/* Modal buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 0.12s, border-color 0.12s, color 0.12s, transform 0.08s;
}

.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(26, 86, 219, 0.2); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-primary {
  background: var(--primary-500);
  color: #ffffff;
  border-color: var(--primary-500);
  box-shadow:
    0 1px 1.5px rgba(26, 86, 219, 0.25),
    0 1px 1px rgba(26, 86, 219, 0.25);
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-600);
  border-color: var(--primary-600);
}

.btn-danger {
  background: var(--bad-500);
  color: #ffffff;
  border-color: var(--bad-500);
  box-shadow:
    0 1px 1.5px rgba(220, 38, 38, 0.25),
    0 1px 1px rgba(220, 38, 38, 0.25);
}
.btn-danger:hover:not(:disabled) {
  background: var(--bad-600);
  border-color: var(--bad-600);
}

.confirm-token {
  display: inline-block;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--bad-50);
  color: var(--bad-600);
  border: 1px solid var(--bad-100);
  font-weight: 500;
}

/* ===============================================================
   Progress stages — clean, light, no log dots
   =============================================================== */

.stages {
  list-style: none;
  padding: 14px 16px;
  margin: 16px 0;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--bg-inset);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stages li {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  gap: 10px;
  align-items: center;
  font-size: 13px;
  color: var(--text-muted);
  padding: 5px 0;
}

.stages li .stage-marker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1.5px solid var(--border-hover);
  background: var(--bg-page);
  flex-shrink: 0;
  transition: background-color 0.15s, border-color 0.15s;
}

.stages li .stage-marker::after {
  content: "";
  display: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.stages li .stage-time {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11px;
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}

.stages li.pending .stage-time { visibility: hidden; }

.stages li.active {
  color: var(--text-primary);
  font-weight: 500;
}
.stages li.active .stage-marker {
  border-color: var(--primary-500);
  color: var(--primary-500);
}
.stages li.active .stage-marker::after {
  display: block;
  animation: pulse-dot 1s infinite ease-in-out;
}
.stages li.active .stage-time { color: var(--primary-700); }

@keyframes pulse-dot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(0.6); opacity: 0.6; }
}

.stages li.done { color: var(--text-secondary); }
.stages li.done .stage-marker {
  background: var(--ok-500);
  border-color: var(--ok-500);
  color: #ffffff;
}
.stages li.done .stage-marker::after {
  display: block;
  width: 8px;
  height: 8px;
  background: transparent;
  border: 1.5px solid currentColor;
  border-top: 0;
  border-right: 0;
  border-radius: 0;
  transform: rotate(-45deg) translate(1px, -1px);
}

.stages li.failed { color: var(--bad-600); }
.stages li.failed .stage-marker {
  background: var(--bad-500);
  border-color: var(--bad-500);
  color: #ffffff;
}
.stages li.failed .stage-marker::after {
  display: block;
  width: 8px;
  height: 1.5px;
  background: currentColor;
  border-radius: 1px;
  position: relative;
}

.result {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 12.5px;
  line-height: 1.5;
  margin-bottom: 4px;
}

.result.ok {
  background: var(--ok-50);
  border: 1px solid var(--ok-100);
  color: var(--ok-700);
}

.result.fail {
  background: var(--bad-50);
  border: 1px solid var(--bad-100);
  color: var(--bad-600);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-word;
}

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

@media (max-width: 720px) {
  .page-header { padding: 0 16px; }
  .page-body { padding: 16px; }
  .modal-card { padding: 20px; }
  .col-num, .col-date { display: none; }
  thead th:nth-child(3), thead th:nth-child(4),
  tbody td:nth-child(3), tbody td:nth-child(4) { display: none; }
}
