/* ============================================================
   Admin Panel — Dark Dashboard Styles
   ============================================================ */

.admin-layout {
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Mobile hamburger toggle */
.admin-mobile-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 200;
  width: 40px;
  height: 40px;
  background: var(--void-light);
  border: 1px solid var(--void-lighter);
  border-radius: 6px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--gold);
  font-size: 1.25rem;
}

/* Sidebar overlay on mobile */
.admin-sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 90;
}

/* Sidebar */
.admin-sidebar {
  width: 260px;
  background: var(--void-light);
  border-right: 1px solid var(--void-lighter);
  padding: 24px 0;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  overflow-y: auto;
  z-index: 100;
  display: flex;
  flex-direction: column;
}

.admin-sidebar-logo {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--gold);
  padding: 0 24px;
  margin-bottom: 32px;
}

.admin-sidebar-logo small {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--gray-600);
  font-weight: 400;
  margin-top: 4px;
}

.admin-nav-section {
  margin-bottom: 24px;
}

.admin-nav-label {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--gray-600);
  padding: 0 24px;
  margin-bottom: 8px;
}

.admin-nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 24px;
  color: var(--gray-500);
  font-size: 0.9rem;
  transition: var(--transition);
}

.admin-nav-item:hover {
  color: var(--white);
  background: rgba(255, 255, 255, 0.03);
}

.admin-nav-item.active {
  color: var(--gold);
  background: var(--gold-dim);
  border-right: 2px solid var(--gold);
}

.admin-nav-item svg {
  width: 18px;
  height: 18px;
  opacity: 0.7;
  flex-shrink: 0;
}

.admin-sidebar-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--void-lighter);
  margin-top: auto;
}

.admin-user-info {
  font-size: 0.8rem;
  color: var(--gray-500);
  margin-bottom: 8px;
  word-break: break-all;
}

/* Main Content */
.admin-main {
  flex: 1;
  margin-left: 260px;
  padding: 32px;
  min-height: 100vh;
  min-width: 0;
}

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

.admin-title {
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 600;
}

.admin-subtitle {
  color: var(--gray-600);
  font-size: 0.9rem;
  margin-top: 4px;
}

/* Stats Cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--void-light);
  border: 1px solid var(--void-lighter);
  border-radius: 8px;
  padding: 20px;
}

.stat-card-label {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--gray-600);
  margin-bottom: 8px;
}

.stat-card-value {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 300;
}

.stat-card-sub {
  font-size: 0.75rem;
  color: var(--gray-500);
  margin-top: 4px;
}

/* Dashboard two-column layout */
.admin-two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

/* Tables */
.admin-table-wrapper {
  background: var(--void-light);
  border: 1px solid var(--void-lighter);
  border-radius: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 500px;
}

.admin-table th {
  text-align: left;
  padding: 12px 16px;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--gray-600);
  border-bottom: 1px solid var(--void-lighter);
  background: var(--void-light);
  white-space: nowrap;
}

.admin-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--void-lighter);
  font-size: 0.9rem;
  color: var(--gray-300);
}

.admin-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.admin-table .actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.admin-table .actions a,
.admin-table .actions button {
  padding: 4px 8px;
  color: var(--gray-600);
  transition: var(--transition);
  font-size: 0.85rem;
  white-space: nowrap;
}

.admin-table .actions a:hover { color: var(--gold); }
.admin-table .actions button:hover { color: #ef4444; }

/* Status Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.05em;
  padding: 3px 10px;
  border-radius: 4px;
  white-space: nowrap;
}

.badge-published { background: rgba(34, 197, 94, 0.1); color: #22c55e; }
.badge-draft { background: rgba(234, 179, 8, 0.1); color: #eab308; }
.badge-active { background: rgba(34, 197, 94, 0.1); color: #22c55e; }
.badge-bounced { background: rgba(239, 68, 68, 0.1); color: #ef4444; }
.badge-unsubscribed { background: rgba(156, 163, 175, 0.1); color: #9ca3af; }
.badge-complained { background: rgba(249, 115, 22, 0.1); color: #f97316; }
.badge-sent { background: rgba(59, 130, 246, 0.1); color: #3b82f6; }
.badge-sending { background: rgba(234, 179, 8, 0.1); color: #eab308; }
.badge-scheduled { background: rgba(168, 85, 247, 0.1); color: #a855f7; }
.badge-failed { background: rgba(239, 68, 68, 0.1); color: #ef4444; }
.badge-queued { background: rgba(156, 163, 175, 0.1); color: #9ca3af; }
.badge-delivered { background: rgba(34, 197, 94, 0.1); color: #22c55e; }
.badge-opened { background: rgba(59, 130, 246, 0.1); color: #3b82f6; }
.badge-clicked { background: rgba(168, 85, 247, 0.1); color: #a855f7; }
.badge-read { background: rgba(34, 197, 94, 0.1); color: #22c55e; }
.badge-unread { background: rgba(234, 179, 8, 0.1); color: #eab308; }

/* Forms */
.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--gray-600);
  margin-bottom: 6px;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  background: var(--void);
  border: 1px solid var(--void-lighter);
  color: var(--white);
  font-family: var(--font-body);
  font-size: 0.9rem;
  padding: 10px 14px;
  border-radius: 4px;
  outline: none;
  transition: var(--transition);
  box-sizing: border-box;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--gold);
}

.form-textarea {
  resize: vertical;
  min-height: 120px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* Admin Login */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.login-box {
  width: 100%;
  max-width: 400px;
  padding: 40px;
  background: var(--void-light);
  border: 1px solid var(--void-lighter);
  border-radius: 8px;
}

.login-title {
  font-family: var(--font-display);
  font-size: 1.5rem;
  text-align: center;
  margin-bottom: 8px;
}

.login-subtitle {
  text-align: center;
  color: var(--gray-600);
  font-size: 0.85rem;
  margin-bottom: 32px;
}

.login-error {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #ef4444;
  padding: 10px 14px;
  border-radius: 4px;
  font-size: 0.85rem;
  margin-bottom: 20px;
}

/* Pagination */
.pagination {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 24px;
  flex-wrap: wrap;
}

.pagination a,
.pagination span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 8px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  border: 1px solid var(--void-lighter);
  border-radius: 4px;
  color: var(--gray-500);
  transition: var(--transition);
}

.pagination a:hover { border-color: var(--gold); color: var(--gold); }
.pagination .current { background: var(--gold); color: var(--void); border-color: var(--gold); }

/* Editor */
.editor-toolbar {
  display: flex;
  gap: 4px;
  padding: 8px 12px;
  background: var(--void);
  border: 1px solid var(--void-lighter);
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  flex-wrap: wrap;
}

.editor-toolbar button {
  padding: 4px 8px;
  color: var(--gray-600);
  font-size: 0.85rem;
  border-radius: 3px;
  transition: var(--transition);
}

.editor-toolbar button:hover {
  color: var(--gold);
  background: var(--void-lighter);
}

.editor-toolbar .sep {
  width: 1px;
  background: var(--void-lighter);
  margin: 0 4px;
}

.editor-preview {
  background: var(--void);
  border: 1px solid var(--void-lighter);
  border-radius: 0 0 4px 4px;
  padding: 16px;
  min-height: 300px;
  color: var(--gray-300);
  line-height: 1.8;
}

.editor-word-count {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--gray-600);
  padding: 4px 12px;
  border: 1px solid var(--void-lighter);
  border-top: none;
}

/* Campaign HTML Editor */
.html-editor-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.html-preview-frame {
  background: #fff;
  border-radius: 4px;
  min-height: 400px;
}

.html-preview-frame iframe {
  width: 100%;
  height: 400px;
  border: none;
  border-radius: 4px;
}

/* Tabs */
.admin-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--void-lighter);
  margin-bottom: 24px;
}

.admin-tab {
  padding: 10px 20px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gray-600);
  border-bottom: 2px solid transparent;
  transition: var(--transition);
  cursor: pointer;
}

.admin-tab:hover { color: var(--gray-300); }
.admin-tab.active { color: var(--gold); border-color: var(--gold); }

/* Back link */
.post-back {
  color: var(--gold);
  font-size: 0.85rem;
  text-decoration: none;
  display: inline-block;
  margin-bottom: 4px;
}

.post-back:hover { text-decoration: underline; }

/* Alert / Flash */
.alert {
  padding: 12px 16px;
  border-radius: 4px;
  font-size: 0.85rem;
  margin-bottom: 20px;
}

.alert-success { background: rgba(34, 197, 94, 0.1); border: 1px solid rgba(34, 197, 94, 0.3); color: #22c55e; }
.alert-error { background: rgba(239, 68, 68, 0.1); border: 1px solid rgba(239, 68, 68, 0.3); color: #ef4444; }
.alert-info { background: rgba(59, 130, 246, 0.1); border: 1px solid rgba(59, 130, 246, 0.3); color: #3b82f6; }

/* Buttons */
.btn { white-space: nowrap; }
.btn-sm { font-size: 0.75rem; padding: 6px 12px; }

/* ============================================================
   Responsive — Tablet
   ============================================================ */
@media (max-width: 1024px) {
  .admin-sidebar { width: 220px; }
  .admin-main { margin-left: 220px; padding: 24px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ============================================================
   Responsive — Mobile (< 768px)
   ============================================================ */
@media (max-width: 768px) {
  /* Lock down horizontal overflow */
  .admin-layout {
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
  }

  /* Show hamburger */
  .admin-mobile-toggle {
    display: flex;
  }

  /* Sidebar hidden off-screen */
  .admin-sidebar {
    width: 280px;
    transform: translateX(-100%);
    transition: transform 0.3s ease, visibility 0.3s ease;
    box-shadow: none;
    visibility: hidden;
    padding-top: 64px;
  }

  .admin-sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.5);
    visibility: visible;
  }

  /* Move hamburger inside sidebar when open */
  .admin-mobile-toggle {
    z-index: 200;
  }

  /* Overlay behind sidebar */
  .admin-sidebar-overlay.active {
    display: block;
  }

  /* Main content takes full width — NO left margin */
  .admin-main {
    margin-left: 0 !important;
    padding: 60px 16px 24px;
    width: 100%;
    max-width: 100vw;
    box-sizing: border-box;
  }

  /* Dashboard header stacks */
  .admin-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  /* Title shrinks */
  .admin-title {
    font-size: 1.35rem;
  }

  /* Stats: single column on mobile */
  .stats-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .stat-card {
    padding: 14px;
  }

  .stat-card-value {
    font-size: 1.5rem;
  }

  /* Dashboard two-column stacks */
  .admin-two-col {
    grid-template-columns: 1fr;
  }

  /* Forms stack */
  .form-row {
    grid-template-columns: 1fr;
  }

  .html-editor-split {
    grid-template-columns: 1fr;
  }

  /* -------------------------------------------------------
     CSS-only responsive tables → stacked card layout
     Each row becomes a card. Column headers become inline
     labels via data-label attributes (set in the PHP).
     For tables WITHOUT data-label, fall back to compact
     shrink mode so nothing breaks.
     ------------------------------------------------------- */

  /* Hide the <thead> row on mobile */
  .admin-table thead {
    display: none;
  }

  .admin-table,
  .admin-table tbody,
  .admin-table tr,
  .admin-table td {
    display: block;
    width: 100%;
  }

  .admin-table {
    min-width: 0;
  }

  .admin-table tr {
    padding: 14px 12px;
    border-bottom: 1px solid var(--void-lighter);
    position: relative;
  }

  .admin-table td {
    padding: 3px 0;
    border: none;
    font-size: 0.85rem;
    text-align: left;
  }

  /* If a td has a data-label, show it as an inline label */
  .admin-table td[data-label]::before {
    content: attr(data-label) ": ";
    font-family: var(--font-mono);
    font-size: 0.6rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--gray-600);
    margin-right: 6px;
  }

  /* Actions row: flex on mobile */
  .admin-table td.actions {
    padding-top: 10px;
    margin-top: 6px;
    border-top: 1px solid var(--void-lighter);
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
  }

  .admin-table td.actions a,
  .admin-table td.actions button {
    padding: 5px 10px;
    font-size: 0.75rem;
    border: 1px solid var(--void-lighter);
    border-radius: 4px;
  }

  /* Login box padding */
  .login-box {
    padding: 24px;
  }

  /* Modals: full-width on mobile */
  #create-modal > div,
  #add-modal > div,
  #import-modal > div {
    max-width: 100%;
    margin: 16px;
    max-height: 90vh;
    overflow-y: auto;
  }
}

/* ============================================================
   Responsive — Small phone (< 400px)
   ============================================================ */
@media (max-width: 400px) {
  .admin-main {
    padding: 56px 12px 20px;
  }

  .admin-title {
    font-size: 1.2rem;
  }
}