/*
 * InstantHub admin panel — Phase 3A.10.
 *
 * Visual brief: dense, utilitarian, Linear-settings-page aesthetic. Distinct
 * from the marketing pages: tighter padding, smaller type, more greys, less
 * whitespace. Stays in light mode (matches the rest of the post-3A.7 app)
 * but leans cooler — borders + chips do the heavy lifting instead of cards
 * with big drop-shadows.
 *
 * Lives in its own stylesheet so the marketing/app style.css doesn't bloat
 * with rules nobody but the founder ever loads.
 */

* { box-sizing: border-box; }

/*
 * Phase 3A.12 — universal [hidden] override.
 *
 * The browser's UA stylesheet defines `[hidden] { display: none }`, but any
 * class selector with a `display:` rule has equal-or-higher specificity and
 * wins the cascade. That caused .admin-loading (display: grid; position:
 * fixed; inset: 0) to stay covering the viewport even after bootstrap() set
 * `loadingEl.hidden = true` — the page looked stuck at "Loading…" while the
 * shell rendered invisibly underneath.
 *
 * `!important` here is load-bearing: any future rule that sets `display`
 * on a hidden element would re-introduce the bug. This is the canonical
 * way to make `hidden` mean what its name says.
 */
[hidden] { display: none !important; }

:root {
  --admin-bg:        #f5f7fb;
  --admin-surface:   #ffffff;
  --admin-surface-2: #f8fafc;
  --admin-border:    #e2e8f0;
  --admin-border-2:  #cbd5e1;
  --admin-text:      #08090e;
  --admin-text-2:    #475569;
  --admin-text-mute: #94a3b8;
  --admin-brand:     #3b82f6;
  --admin-brand-2:   #2563eb;
  --admin-good:      #10b981;
  --admin-bad:       #ef4444;
  --admin-warn:      #f59e0b;

  --admin-font-head: 'Syne', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --admin-font-body: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html, body { height: 100%; }
body.admin-body {
  margin: 0;
  background: var(--admin-bg);
  color: var(--admin-text);
  font-family: var(--admin-font-body);
  font-size: 14px;
  line-height: 1.5;
}

.admin-loading {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--admin-text-mute);
  font-size: 14px;
}

/* ---- Header ----
   Top bar styling now lives in style.css (.topbar / .brand / .user-chip).
   admin.html shares that pattern with /app and /account; the only
   admin-specific addition is the small .brand-context-tag chip, also
   defined in style.css. */

/* ---- Main ---- */
.admin-main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ---- Stat cards ---- */
.admin-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.admin-stat-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--admin-surface);
  border: 1px solid var(--admin-border);
  border-radius: 10px;
  padding: 16px 18px;
}
.admin-stat-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--admin-text-mute);
}
.admin-stat-value {
  font-family: var(--admin-font-head);
  font-size: 32px;
  font-weight: 700;
  color: var(--admin-text);
  letter-spacing: -0.02em;
  line-height: 1.1;
}

@media (max-width: 1000px) {
  .admin-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 540px) {
  .admin-stats { grid-template-columns: 1fr; }
}

/* ---- Two-column row (users + activity) ---- */
.admin-columns {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  gap: 24px;
}
.admin-col {
  background: var(--admin-surface);
  border: 1px solid var(--admin-border);
  border-radius: 10px;
  padding: 18px 20px 14px;
}
@media (max-width: 1000px) {
  .admin-columns { grid-template-columns: 1fr; }
}

/* ---- Section heads + toolbars ---- */
.admin-section-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 14px;
}
.admin-section-title {
  margin: 0;
  font-family: var(--admin-font-head);
  font-size: 16px;
  font-weight: 700;
  color: var(--admin-text);
  letter-spacing: -0.01em;
}
.admin-section-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  padding: 0 6px;
  height: 20px;
  background: var(--admin-surface-2);
  border: 1px solid var(--admin-border);
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--admin-text-2);
}
.admin-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

/* ---- Inputs ---- */
.admin-input {
  font-family: var(--admin-font-body);
  font-size: 13px;
  color: var(--admin-text);
  background: var(--admin-surface);
  border: 1px solid var(--admin-border-2);
  border-radius: 6px;
  padding: 7px 10px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.admin-input:focus {
  border-color: var(--admin-brand);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.18);
}
.admin-input[type="search"] { min-width: 220px; flex: 1; max-width: 320px; }
.admin-select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 28px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' stroke='%2364748b' stroke-width='1.4' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 8px center;
}
.admin-input-sm { padding: 4px 8px; font-size: 12px; }

/* ---- Tables ---- */
.admin-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--admin-border);
  border-radius: 8px;
}
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.admin-table th,
.admin-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--admin-border);
  white-space: nowrap;
}
.admin-table th {
  background: var(--admin-surface-2);
  color: var(--admin-text-mute);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: var(--admin-surface-2); }
.admin-empty {
  padding: 22px 12px !important;
  text-align: center;
  color: var(--admin-text-mute);
  font-size: 13px;
}

/* ---- Tier + status badges ---- */
.admin-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid transparent;
  text-transform: capitalize;
}
.admin-badge-free     { background: #f1f5f9; border-color: #e2e8f0; color: #475569; }
.admin-badge-starter  { background: #ecfeff; border-color: #a5f3fc; color: #0e7490; }
.admin-badge-pro      { background: #eef2ff; border-color: #c7d2fe; color: #3730a3; }
.admin-badge-producer { background: #fef3c7; border-color: #fde68a; color: #92400e; }
.admin-badge-founder  { background: #fce7f3; border-color: #fbcfe8; color: #9d174d; }

.admin-status {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.admin-status-new     { background: #fef3c7; color: #92400e; }
.admin-status-replied { background: #e0e7ff; color: #3730a3; }
.admin-status-closed  { background: #f1f5f9; color: #475569; }

/* ---- Manage button in tables ---- */
.admin-row-btn {
  background: transparent;
  border: 1px solid var(--admin-border-2);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
  color: var(--admin-text);
  cursor: pointer;
  font-family: var(--admin-font-body);
  transition: background 0.15s, border-color 0.15s;
}
.admin-row-btn:hover {
  background: var(--admin-surface-2);
  border-color: var(--admin-text-mute);
}

/* ---- Activity feed ---- */
.admin-activity-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 540px;
  overflow-y: auto;
}
.admin-activity-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 8px;
  border-radius: 6px;
}
.admin-activity-item:hover { background: var(--admin-surface-2); }
.admin-activity-icon {
  flex: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--admin-surface-2);
  display: grid;
  place-items: center;
  font-size: 12px;
  color: var(--admin-brand);
}
.admin-activity-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.admin-activity-text {
  font-size: 13px;
  color: var(--admin-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.admin-activity-meta {
  font-size: 11px;
  color: var(--admin-text-mute);
}

/* ---- Tickets section ---- */
.admin-tickets {
  background: var(--admin-surface);
  border: 1px solid var(--admin-border);
  border-radius: 10px;
  padding: 18px 20px 14px;
}
.admin-ticket-preview {
  color: var(--admin-text-2);
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Modal ---- */
.admin-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 9, 14, 0.55);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 24px;
}
.admin-modal-backdrop[hidden] { display: none; }
.admin-modal {
  background: var(--admin-surface);
  border-radius: 12px;
  max-width: 520px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px 26px;
  position: relative;
  box-shadow: 0 20px 60px rgba(8, 9, 14, 0.25);
}
.admin-modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  color: var(--admin-text-mute);
  cursor: pointer;
  border-radius: 6px;
}
.admin-modal-close:hover { background: var(--admin-surface-2); color: var(--admin-text); }
.admin-modal-title {
  margin: 0 0 16px;
  font-family: var(--admin-font-head);
  font-size: 18px;
  font-weight: 700;
  color: var(--admin-text);
  letter-spacing: -0.01em;
}
.admin-modal-details {
  margin: 0 0 18px;
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 6px 14px;
  font-size: 13px;
}
.admin-modal-details dt {
  color: var(--admin-text-mute);
  font-weight: 500;
}
.admin-modal-details dd {
  margin: 0;
  color: var(--admin-text);
  word-break: break-word;
}
.admin-modal-details .admin-message-block {
  grid-column: 1 / -1;
  margin-top: 6px;
  padding: 12px 14px;
  background: var(--admin-surface-2);
  border: 1px solid var(--admin-border);
  border-radius: 8px;
  white-space: pre-wrap;
  font-size: 13px;
  line-height: 1.55;
  color: var(--admin-text);
}
.admin-modal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.admin-action-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.admin-action-label {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  color: var(--admin-text-2);
}
.admin-btn {
  background: var(--admin-text);
  color: #ffffff;
  border: none;
  border-radius: 6px;
  padding: 9px 14px;
  font-family: var(--admin-font-body);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.15s;
}
.admin-btn:hover { background: #1e293b; }
.admin-btn-link {
  background: var(--admin-surface-2);
  color: var(--admin-text);
  border: 1px solid var(--admin-border-2);
}
.admin-btn-link:hover { background: var(--admin-border); }
.admin-btn-danger {
  background: var(--admin-bad);
  color: #ffffff;
}
.admin-btn-danger:hover { background: #dc2626; }
.admin-btn-danger:disabled {
  background: var(--admin-border);
  color: var(--admin-text-mute);
  cursor: not-allowed;
}
.admin-modal-danger-zone {
  margin-top: 6px;
  padding-top: 12px;
  border-top: 1px dashed var(--admin-border);
  display: flex;
  justify-content: flex-end;
}

/* Phase 3A.11 — cancel-pending tier chip variant. The base tier badge
   still shows ("pro", "starter", etc.) but with a strikethrough + amber
   tint so a glance at the users table tells the founder which paid users
   are on their way out. */
.admin-badge.is-cancel-pending {
  background: #fef3c7;
  border-color: #fde68a;
  color: #92400e;
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}
.admin-modal-status {
  margin: 14px 0 0;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
}
.admin-modal-status.is-ok { background: rgba(16, 185, 129, 0.10); color: #065f46; }
.admin-modal-status.is-err { background: rgba(239, 68, 68, 0.10); color: #991b1b; }
