:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --primary: #111827;
  --primary-hover: #0b1024;
  --accent: #2563eb;
  --accent-soft: #e0e7ff;
  --border: #e5e7eb;
  --shadow: 0 14px 48px rgba(17, 24, 39, 0.08);
  --radius-lg: 16px;
  --radius-sm: 8px;
  --font: "Inter", "Helvetica Neue", Arial, sans-serif;
}

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

body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  color: var(--text);
  background: radial-gradient(circle at 20% 20%, rgba(37, 99, 235, 0.06), transparent 35%), var(--bg);
}

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

a:hover {
  text-decoration: underline;
}

.page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 16px;
}

.wrap {
  width: 100%;
  max-width: 1100px;
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 32px;
}

/* Admin-specific layout: top-aligned dashboard style */
body.app-body .page {
  align-items: flex-start;
  justify-content: center;
}

body.app-body .wrap {
  max-width: 1200px;
}

.app-shell {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.app-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 18px;
}

.app-logo {
  font-size: 20px;
}

.app-nav {
  display: inline-flex;
  gap: 8px;
}

.app-main {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.tab-panel .card {
  margin-bottom: 18px;
}

.tab-panel h2 {
  margin-bottom: 10px;
}

.tab-panel h3 {
  margin-top: 10px;
  margin-bottom: 10px;
}

.top-links {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}

/* Unified page header */
.page-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 20px;
}

.page-title h1 {
  margin: 0 0 6px;
}

.page-subtitle {
  margin: 0;
  font-size: 18px;
  color: var(--muted);
}

.page-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

/* Base button */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 18px;
  border: none;
  border-radius: 12px;
  font-weight: 700;
  color: #fff;
  background: #111827;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
  text-decoration: none;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 30px rgba(17, 24, 39, 0.25);
  background: #020617;
}

.btn:disabled {
  background: #6b7280;
  cursor: not-allowed;
  box-shadow: none;
  opacity: 0.7;
}

.btn-secondary {
  background: #111827;
  color: #ffffff;
}

.btn-small {
  padding: 6px 12px;
  font-size: 13px;
  border-radius: 999px;
  background: #111827;
  color: #ffffff;
}

.copy-btn {
  padding: 8px 12px;
  font-size: 12px;
  background: var(--accent);
}

h1,
h2,
h3,
h4 {
  margin: 0 0 12px;
}

h1 {
  font-size: 26px;
  letter-spacing: -0.3px;
}

h2 {
  font-size: 20px;
  margin-top: 12px;
}

p {
  margin: 0 0 12px;
  color: var(--text);
}

label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
textarea,
select {
  width: 100%;
  max-width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #f8fafc;
  font-family: var(--font);
  margin-bottom: 16px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18);
  outline: none;
  background: #fff;
}

textarea {
  resize: vertical;
}

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  background: var(--card);
  box-shadow: 0 10px 30px rgba(17, 24, 39, 0.04);
}

.card form {
  width: 100%;
}

.card input[type="text"],
.card input[type="email"],
.card input[type="password"],
.card input[type="number"],
.card textarea,
.card select {
  display: block;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

/* Summary strip for User Management */
.card-summary {
  margin-bottom: 16px;
}

.summary-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  align-items: center;
}

.summary-item {
  min-width: 220px;
}

.summary-label {
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 4px;
  font-size: 13px;
}

.summary-value {
  font-weight: 700;
  color: var(--text);
}

/* Tabs */
.tab-container {
  margin-top: 8px;
}

/* Horizontal scrolling wrapper for tab nav on smaller widths */
.tab-nav-wrapper {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
}

.tab-nav-wrapper::-webkit-scrollbar {
  height: 6px;
}

.tab-nav-wrapper::-webkit-scrollbar-track {
  background: #e5e7eb;
}

.tab-nav-wrapper::-webkit-scrollbar-thumb {
  background: #9ca3af;
  border-radius: 999px;
}

/* Tab navigation – iOS segmented control style */
.tab-nav {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0;
  padding: 4px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.16); /* soft slate bg */
  margin: 12px 0 18px;
  flex-wrap: nowrap;           /* always one row; overflow handled by wrapper */
  min-width: max-content;      /* can be wider than viewport so it scrolls */
}

.tab-btn {
  position: relative;
  border: none;
  background: transparent;
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
  transition:
    background 0.16s ease,
    color 0.16s ease,
    box-shadow 0.16s ease,
    transform 0.06s ease;
  white-space: nowrap;
}

.tab-btn:hover {
  color: var(--text);
}

.tab-btn.is-active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.35);
  transform: translateY(-1px);
}

.user-filters {
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
  margin-bottom: 12px;
}

.user-filters .filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
}

.user-filters .filter-group {
  flex: 1 1 180px;
}

.user-filters .filter-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* Icon / text labels inside tabs */
.tab-label-desktop {
  display: inline;
}
.tab-label-mobile {
  display: none;
}

.tab-panel {
  display: none;
}

.tab-panel.is-active {
  display: block;
}

/* Mobile: smaller pills, same scrolling behavior via wrapper */
@media (max-width: 640px) {
  .tab-nav {
    gap: 6px;
    justify-content: flex-start;
    /* NOTE: no width/overflow/flex-wrap here;
       the wrapper handles scrolling */
  }

  .tab-btn {
    flex: 0 0 auto;      /* size to content */
    white-space: nowrap; /* keep label in one line per pill */
    font-size: 13px;
    padding: 8px 12px;
    line-height: 1.2;
    text-align: center;
  }

  .tab-label-desktop {
    display: none;
  }

  .tab-label-mobile {
    display: inline;
  }
}



/* Generic table styling */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.table th,
.table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.table thead th {
  font-weight: 700;
  color: #111827;
  background: #f3f4f6;
}

.table tbody tr:nth-child(even) {
  background: #f9fafb;
}

.table tbody tr:hover {
  background: #eef2ff;
}

/* Scroll container so wide tables don't blow past the card */
.table-scroll {
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch; /* smooth scrolling on iOS */
    white-space: nowrap;
}

.table-scroll::-webkit-scrollbar {
  height: 8px;
}

.table-scroll::-webkit-scrollbar-track {
  background: #e5e7eb;
}

.table-scroll::-webkit-scrollbar-thumb {
  background: #9ca3af;
  border-radius: 999px;
}

.section {
  margin-top: 24px;
}

.item {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 12px;
  background: #fff;
  box-shadow: 0 4px 16px rgba(17, 24, 39, 0.06);
}

.item h3 {
  margin: 0 0 6px;
}

.meta {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}

.note {
  background: var(--accent-soft);
  color: #1f2937;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid #c7d2fe;
  margin-bottom: 16px;
}

.error {
  background: #fee2e2;
  color: #991b1b;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid #fecdd3;
  margin-bottom: 12px;
}

.success {
  background: #ecfdf3;
  color: #065f46;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid #bbf7d0;
  margin-bottom: 16px;
}

.hidden {
  display: none !important;
}

.pill {
  display: inline-flex;
  padding: 6px 12px;
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  font-size: 13px;
  margin-left: 8px;
}

.email-body,
.post-body {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #f9fafb;
  margin-top: 8px;
  font-size: 14px;
  line-height: 1.6;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

/* Users table layout */
.users-table {
  min-width: 1100px;
  table-layout: fixed;   /* force columns to obey width assignments */
}

/* Let the fixed layout and per-column widths drive sizing */
.users-table th,
.users-table td {
  /* no generic min-width here */
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ID column (col 1) – very compact */
.users-table th:nth-child(1),
.users-table td:nth-child(1) {
  width: 40px;
  max-width: 40px;
  text-align: left;
}

/* Actions (col 2) – compact gear cell */
.users-table th:nth-child(2),
.users-table td:nth-child(2) {
  width: 70px;
  max-width: 70px;
  white-space: nowrap;
}

/* Email (col 3) */
.users-table th:nth-child(3),
.users-table td:nth-child(3) {
  width: 22%;
  word-break: break-word;
}

/* Name (col 4) – more room than Role */
.users-table th:nth-child(4),
.users-table td:nth-child(4) {
  width: 18%;
  word-break: break-word;
}

/* Role (col 5) – narrow */
.users-table th:nth-child(5),
.users-table td:nth-child(5) {
  width: 7%;
}

/* Status (col 6) */
.users-table th:nth-child(6),
.users-table td:nth-child(6) {
  width: 7%;
}

/* License (col 7) */
.users-table th:nth-child(7),
.users-table td:nth-child(7) {
  width: 8%;
}

/* Reg Code (col 8) */
.users-table th:nth-child(8),
.users-table td:nth-child(8) {
  width: 12%;
  word-break: break-word;
}

/* Created (col 9) */
.users-table th:nth-child(9),
.users-table td:nth-child(9) {
  width: 13%;
  white-space: nowrap;
}

/* Last Login (col 10) */
.users-table th:nth-child(10),
.users-table td:nth-child(10) {
  width: 14%;
  white-space: nowrap;
}

.table .table-actions {
  display: inline-flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.table .table-actions .btn,
.table .table-actions .btn-small {
  padding: 8px 12px;
  font-size: 13px;
  border-radius: 10px;
}

/* Make Manage button in table clearly visible */
.users-table .btn,
.users-table .btn-small {
  background: #111827;
  color: #ffffff;
}

/* Masked key display */
.masked-key {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.4;
}

.masked-key-value {
  display: block;
  word-break: break-all;
  overflow-wrap: anywhere;
  font-family: 'SFMono-Regular', Menlo, Consolas, monospace;
  font-size: 13px;
  margin-top: 2px;
}

/* Loading overlay */
#loading-indicator {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  backdrop-filter: blur(2px);
  flex-direction: column;
  gap: 12px;
  text-align: center;
  padding: 20px;
}

.is-loading #loading-indicator {
  display: flex !important;
}

.is-loading {
  cursor: progress;
}

.spinner {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 5px solid rgba(37, 99, 235, 0.15);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
  box-shadow: 0 10px 30px rgba(37, 99, 235, 0.25);
}

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

.loading-text {
  font-size: 16px;
  color: var(--text);
  font-weight: 600;
  text-align: center;
}

/* ===== User management modal ===== */

.user-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10000;
}

.user-modal.is-open {
  display: block;
}

/* Stronger, darker backdrop with fade-in */
.user-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-modal-card {
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 18px 55px rgba(15, 23, 42, 0.45);
  padding: 24px 28px;
  width: min(640px, 95vw);
  max-height: 85vh;
  overflow-y: auto;
  border: 1px solid #e5e7eb;
  line-height: 1.5;

  /* NEW: allow long content (like emails) to wrap instead of forcing the card to grow */
  word-break: break-word;
  overflow-wrap: anywhere;
}

/* Modal animations */
@keyframes modal-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes modal-slide-down {
  from {
    opacity: 0;
    transform: translateY(-12px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.user-modal.is-open .user-modal-backdrop {
  animation: modal-fade-in 0.22s ease-out;
}

.user-modal.is-open .user-modal-card {
  animation: modal-slide-down 0.22s ease-out;
}

.user-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.user-modal-header h3 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
}

.user-modal-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.user-modal-body .success,
.user-modal-body .error {
  margin-bottom: 4px;
}

/* Dashboard tabs and history layout */
.tabs {
  display: flex;
  gap: 8px;
  margin: 12px 0 16px;
  border-bottom: 1px solid #e5e7eb;
}

.tab-link {
  padding: 10px 14px;
  text-decoration: none;
  font-weight: 700;
  color: #4b5563;
  border-bottom: 2px solid transparent;
}

.tab-link.is-active {
  color: #111827;
  border-bottom-color: #111827;
}

.campaign-form,
.campaign-output {
  margin-top: 12px;
}

.campaign-output {
  padding: 16px 18px;
  background: #f9fafb;
  border-radius: 12px;
  border: 1px solid #e5e7eb;
}

.campaign-output-actions {
  margin-top: 12px;
}

.history-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.history-search {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.history-search input[type="text"] {
  flex: 1 1 240px;
}

.history-search-note {
  font-size: 13px;
  color: #6b7280;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.history-table {
  width: 100%;
}

.pagination {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.page-link {
  text-decoration: none;
  font-size: 0.875rem;
  color: #2563eb;
}

.page-info {
  font-size: 0.875rem;
  color: #6b7280;
}

.history-detail {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid #e5e7eb;
}

@media (max-width: 640px) {
  .tabs {
    overflow-x: auto;
  }

  .history-search {
    flex-direction: column;
    align-items: stretch;
  }
}

.user-modal-body p {
  margin-bottom: 6px;
}

.user-modal-body label {
  font-weight: 600;
  color: #111827;
}

/* Two-column layout on wider screens */
.user-modal-body-grid {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.user-modal-col {
  background: #f9fafb;
  border-radius: 12px;
  padding: 14px 16px;
  border: 1px solid #e5e7eb;
}

.user-modal-col-summary {
  background: #eff6ff;
  /* NEW: apply wrapping at container level */
  word-break: break-word;
  overflow-wrap: anywhere;
}

/* Optional: keep for extra safety, but now redundant */
.user-modal-col-summary p,
.user-modal-col-summary span,
.user-modal-col-summary strong {
  word-break: break-word;
  overflow-wrap: anywhere;
}

.user-modal-section-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 6px;
}

.compact-form .form-group {
  margin-bottom: 10px;
}

.compact-form .form-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 6px;
}

/* Close button stands out (red pill) */
.user-modal-close {
  background: #dc2626;
  color: #ffffff;
}

.masked-key-label {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
  max-width: 100%;
}

.masked-key-value {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}


/* Responsive tweaks */


@media (max-width: 640px) {
  .wrap {
    padding: 20px;
  }

  .top-links {
    flex-direction: column;
  }

  .table {
    font-size: 13px;
  }

  .table th,
  .table td {
    padding: 6px 8px;
  }

  .users-table {
    min-width: 720px;
  }

  .user-modal-card {
    width: 94vw;
    max-height: 88vh;
  }
}

/* --- Campaign history filters (admin) --- */
.campaigns-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
}

.campaigns-filter .input-text,
.campaigns-filter input[type="text"] {
  width: 100%;
  max-width: 320px;
}

.filter-note {
  font-size: 0.875rem;
  color: #4b5563;
  margin-bottom: 0.5rem;
}

.filter-note .filter-clear {
  font-size: 0.875rem;
  color: #2563eb;
  text-decoration: none;
}

.filter-note .filter-clear:hover {
  text-decoration: underline;
}

@media (max-width: 640px) {
  .campaigns-filter {
    flex-direction: column;
    align-items: stretch;
  }
}

/* --- Activity log filters (admin) --- */
.activity-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
}

.activity-filter .input-text,
.activity-filter input[type="text"] {
  width: 100%;
  max-width: 320px;
}

@media (max-width: 640px) {
  .activity-filter {
    flex-direction: column;
    align-items: stretch;
  }
}

.error-page {
  max-width: 520px;
}

.error-page h1 {
  margin-top: 0;
  font-size: 22px;
}

.error-page p {
  margin-bottom: 0.75rem;
}

/* --- Badges --- */
.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1.4;
    white-space: nowrap;
}

.badge-success {
    background-color: #d1fae5; /* soft green */
    color: #065f46;
}

.badge-warning {
    background-color: #fef3c7; /* soft amber */
    color: #92400e;
}

.badge-danger {
    background-color: #fee2e2; /* soft red */
    color: #991b1b;
}

.badge-muted {
    background-color: #e5e7eb; /* soft gray */
    color: #374151;
}

/* Optional: summary strip layout */
.card-summary {
    margin-bottom: 1.5rem;
}

.card-summary .summary-row {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: space-between;
    align-items: center;
}

.card-summary .summary-item {
    min-width: 200px;
}

.card-summary .summary-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #6b7280;
    margin-bottom: 0.15rem;
}

.card-summary .summary-value {
    font-size: 0.875rem;
    color: #111827;
}
