/* ─── FinPay Admin Panel – Modern Dark Theme ─── */

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #232735;
  --border: #2d3248;
  --primary: #6c5ce7;
  --primary-hover: #7f70f0;
  --accent: #00cec9;
  --danger: #e74c3c;
  --danger-hover: #c0392b;
  --success: #00b894;
  --warning: #fdcb6e;
  --text: #e8e8ef;
  --text-muted: #8f93a5;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0,0,0,.35);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

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

/* ─── Layout ─── */
.layout {
  display: flex;
  min-height: 100vh;
}

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

.sidebar-brand {
  padding: 0 24px 24px;
  border-bottom: 1px solid var(--border);
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-brand span { font-size: 24px; }

.sidebar-nav { padding: 16px 12px; flex: 1; overflow-y: auto; }

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  transition: all .15s;
  margin-bottom: 4px;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
  background: var(--surface2);
  color: var(--text);
  text-decoration: none;
}

.sidebar-nav a.active {
  background: rgba(108,92,231,.15);
  color: var(--primary);
}

.sidebar-nav a .icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
}

.sidebar-footer {
  padding: 12px 12px 8px;
  border-top: 1px solid var(--border);
}

.logout-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  transition: all .15s;
}

.logout-link:hover {
  background: rgba(214,48,49,.12);
  color: var(--danger);
  text-decoration: none;
}

.logout-link .icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
}

/* ─── Sidebar sections (collapsible gateways) ─── */
.sidebar-section { margin-bottom: 2px; }

.sidebar-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  cursor: pointer;
  transition: background .15s;
  user-select: none;
}

.sidebar-section-title:hover {
  background: var(--surface2);
}

.sidebar-section-title .chevron {
  font-size: 12px;
  transition: transform .2s;
  color: var(--text-muted);
}

.sidebar-section.open .sidebar-section-title .chevron {
  transform: rotate(90deg);
}

.sidebar-section-items {
  display: none;
  padding-left: 8px;
}

.sidebar-section.open .sidebar-section-items {
  display: block;
}

.sidebar-section-items a {
  font-size: 13px;
  padding: 8px 16px;
}

.sidebar-divider {
  height: 1px;
  background: var(--border);
  margin: 8px 16px;
}

/* ─── Main ─── */
.main {
  margin-left: 260px;
  flex: 1;
  padding: 32px 40px;
  min-height: 100vh;
}

.page-header {
  margin-bottom: 32px;
}

.page-header h1 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 4px;
}

.page-header p {
  color: var(--text-muted);
  font-size: 14px;
}

/* ─── Cards ─── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}

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

.card-header h2 {
  font-size: 18px;
  font-weight: 600;
}

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

.stat-card {
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--border);
}

.stat-card .label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.stat-card .value {
  font-size: 28px;
  font-weight: 700;
}

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

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  transition: border-color .15s;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
}

.form-control::placeholder {
  color: var(--text-muted);
}

select.form-control {
  cursor: pointer;
}

textarea.form-control {
  resize: vertical;
  min-height: 80px;
}

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

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

.form-check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.form-check input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
}

.form-check label {
  font-size: 14px;
  cursor: pointer;
  margin-bottom: 0;
}

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover {
  background: var(--primary-hover);
  text-decoration: none;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover {
  background: var(--danger-hover);
}

.btn-success {
  background: var(--success);
  color: #fff;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-outline:hover {
  background: var(--surface2);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

.btn-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ─── Table ─── */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

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

thead th {
  text-align: left;
  padding: 12px 16px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 12px 16px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

tbody tr:hover {
  background: rgba(108,92,231,.06);
}

/* ─── Badges ─── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.badge-success {
  background: rgba(0,184,148,.15);
  color: var(--success);
}
.badge-danger {
  background: rgba(231,76,60,.15);
  color: var(--danger);
}
.badge-warning {
  background: rgba(253,203,110,.15);
  color: var(--warning);
}
.badge-info {
  background: rgba(0,206,201,.15);
  color: var(--accent);
}
.badge-primary {
  background: rgba(108,92,231,.15);
  color: var(--primary);
}

/* ─── Alerts ─── */
.alert {
  padding: 14px 18px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 14px;
}
.alert-success {
  background: rgba(0,184,148,.1);
  border: 1px solid rgba(0,184,148,.3);
  color: var(--success);
}
.alert-danger {
  background: rgba(231,76,60,.1);
  border: 1px solid rgba(231,76,60,.3);
  color: var(--danger);
}
.alert-info {
  background: rgba(0,206,201,.1);
  border: 1px solid rgba(0,206,201,.3);
  color: var(--accent);
}

/* ─── Modal ─── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal-overlay.show { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  min-width: 400px;
  max-width: 90vw;
  box-shadow: var(--shadow);
}

.modal h3 {
  margin-bottom: 20px;
  font-size: 18px;
}

/* ─── Misc ─── */
.text-muted { color: var(--text-muted); }
.text-right { text-align: right; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.gap-8 { gap: 8px; }
.d-flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }

pre.response-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  font-size: 13px;
  overflow-x: auto;
  max-height: 300px;
  white-space: pre-wrap;
  word-break: break-all;
}

.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Progress bar ─── */
.progress-bar-bg {
  width: 100%;
  height: 12px;
  background: var(--bg);
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.progress-bar-fill {
  height: 100%;
  border-radius: 6px;
  transition: width .4s ease;
}

.progress-active {
  background: linear-gradient(90deg, var(--primary), var(--primary-hover));
  animation: pulse-bar 1.5s ease-in-out infinite;
}

.progress-success {
  background: linear-gradient(90deg, var(--success), #2ecc71);
}

.progress-mixed {
  background: linear-gradient(90deg, var(--warning), #f39c12);
}

@keyframes pulse-bar {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* ─── Code block ─── */
code {
  background: rgba(108,92,231,.1);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
}

/* ─── Mobile top bar & hamburger ─── */
.mobile-topbar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 200;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  align-items: center;
  gap: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,.3);
}

.mobile-topbar .hamburger {
  background: none;
  border: none;
  color: var(--text);
  font-size: 28px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
}
.mobile-topbar .hamburger:active {
  background: var(--surface2);
}

.mobile-topbar .topbar-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 299;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.sidebar-overlay.show { display: block; }

/* hide old toggle */
.sidebar-toggle { display: none; }

/* ─── Responsive: Tablet (≤1024) ─── */
@media (max-width: 1024px) {
  .main { padding: 24px 20px; }
  .stats-row { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
  .stat-card { padding: 16px; }
  .stat-card .value { font-size: 22px; }
  .page-header h1 { font-size: 24px; }
}

/* ═══════════════════════════════════════════════════════
   MOBILE  (≤768px)
   ═══════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* ── Top bar ── */
  .mobile-topbar { display: flex; }

  /* ── Sidebar → slide-over drawer ── */
  .sidebar {
    width: 85vw;
    max-width: 320px;
    transform: translateX(-100%);
    transition: transform .3s cubic-bezier(.4,0,.2,1);
    z-index: 300;
    padding-top: 16px;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 30px rgba(0,0,0,.5);
  }
  .sidebar-brand {
    padding: 8px 20px 20px;
    font-size: 18px;
  }
  .sidebar-nav a {
    padding: 14px 18px;
    font-size: 15px;
    min-height: 48px;
  }
  .sidebar-section-title {
    padding: 14px 18px;
    font-size: 14px;
    min-height: 48px;
  }
  .sidebar-section-items a {
    font-size: 14px;
    padding: 12px 18px 12px 28px;
    min-height: 44px;
  }
  .logout-link {
    padding: 14px 18px;
    font-size: 15px;
  }

  /* ── Main content ── */
  .main {
    margin-left: 0;
    padding: 72px 14px 24px;
    min-height: 100vh;
    width: 100%;
  }

  /* ── Page header ── */
  .page-header { margin-bottom: 16px; }
  .page-header h1 { font-size: 20px; line-height: 1.3; }
  .page-header p { font-size: 12px; line-height: 1.4; }

  /* ── Stats → 2 columns ── */
  .stats-row {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 16px;
  }
  .stat-card {
    padding: 14px;
    border-radius: 10px;
  }
  .stat-card .label {
    font-size: 9px;
    letter-spacing: .6px;
    margin-bottom: 4px;
  }
  .stat-card .value { font-size: 22px; }

  /* ── Cards ── */
  .card {
    padding: 14px;
    margin-bottom: 12px;
    border-radius: 10px;
  }
  .card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 12px;
  }
  .card-header h2 { font-size: 15px; }
  .card-header .btn { align-self: stretch; text-align: center; justify-content: center; }

  /* ── Forms ── */
  .form-row,
  .form-row-3 {
    grid-template-columns: 1fr;
    gap: 0;
  }
  .form-group { margin-bottom: 14px; }
  .form-group label { font-size: 12px; margin-bottom: 5px; }
  .form-control {
    padding: 12px 14px;
    font-size: 16px; /* prevents iOS zoom */
    border-radius: 10px;
  }
  select.form-control {
    padding: 12px 14px;
    font-size: 16px;
    min-height: 48px;
  }
  textarea.form-control {
    font-size: 14px;
    min-height: 100px;
  }
  .form-check {
    padding: 10px 0;
    gap: 10px;
  }
  .form-check input[type="checkbox"] {
    width: 22px;
    height: 22px;
  }
  .form-check label {
    font-size: 14px;
  }

  /* ── Buttons (large touch targets) ── */
  .btn {
    padding: 13px 18px;
    font-size: 14px;
    border-radius: 10px;
    min-height: 48px;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
  }
  .btn-sm {
    padding: 10px 14px;
    font-size: 12px;
    min-height: 40px;
  }
  /* Primary form buttons full width */
  form > .btn,
  form > .btn-group > .btn:first-child {
    width: 100%;
  }
  .btn-group {
    flex-wrap: wrap;
    gap: 8px;
  }
  .btn-group .btn {
    flex: 1 1 calc(50% - 4px);
    min-width: 0;
  }

  /* ── Tables → Card list on mobile ── */
  .table-wrap {
    margin: 0 -14px;
    padding: 0 14px;
  }
  /* Default: scrollable table with visible hint */
  table {
    font-size: 13px;
    min-width: 600px; /* forces scroll */
  }
  thead th {
    padding: 10px 12px;
    font-size: 10px;
    position: sticky;
    top: 0;
    background: var(--surface);
    z-index: 1;
  }
  tbody td {
    padding: 10px 12px;
    font-size: 13px;
  }

  /* Card-mode tables: add class .mobile-cards to table-wrap */
  .mobile-cards table {
    min-width: 0;
  }
  .mobile-cards thead { display: none; }
  .mobile-cards tbody tr {
    display: block;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    margin-bottom: 8px;
  }
  .mobile-cards tbody tr:hover {
    background: var(--surface2);
  }
  .mobile-cards tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    border-bottom: none;
    font-size: 13px;
    gap: 8px;
  }
  .mobile-cards tbody td:before {
    content: attr(data-label);
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .3px;
    min-width: 80px;
    flex-shrink: 0;
  }
  .mobile-cards tbody td:last-child {
    padding-top: 8px;
    margin-top: 4px;
    border-top: 1px solid var(--border);
  }

  /* ── Modal ── */
  .modal-overlay {
    align-items: flex-end;
  }
  .modal {
    min-width: 0;
    width: 100vw;
    max-width: 100vw;
    padding: 20px 16px 28px;
    border-radius: 16px 16px 0 0;
    max-height: 85vh;
    overflow-y: auto;
  }
  .modal h3 { font-size: 17px; }

  /* ── Response box ── */
  pre.response-box {
    font-size: 11px;
    padding: 10px;
    max-height: 200px;
    border-radius: 8px;
    -webkit-overflow-scrolling: touch;
  }

  /* ── Badges ── */
  .badge { font-size: 10px; padding: 3px 8px; }

  /* ── Alerts ── */
  .alert {
    padding: 12px 14px;
    font-size: 13px;
    border-radius: 10px;
  }

  /* ── Code ── */
  code {
    font-size: 11px;
    word-break: break-all;
  }

  /* ── Pagination ── */
  .pagination-wrap {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px;
    margin-top: 16px;
  }
  .pagination-wrap .btn {
    min-width: 40px;
    padding: 10px 8px;
    flex: 0;
  }

  /* ── Misc mobile helpers ── */
  .desktop-only { display: none !important; }
  .mobile-full { width: 100% !important; }
}

/* ═══════════════════════════════════════════════════════
   SMALL PHONES  (≤420px)
   ═══════════════════════════════════════════════════════ */
@media (max-width: 420px) {
  .mobile-topbar { height: 50px; padding: 0 10px; }
  .mobile-topbar .topbar-title { font-size: 14px; }
  .main { padding: 62px 10px 16px; }
  .card { padding: 12px; }
  .stats-row { gap: 6px; }
  .stat-card { padding: 10px; }
  .stat-card .value { font-size: 20px; }
  .stat-card .label { font-size: 8px; }
  .page-header h1 { font-size: 18px; }
  .btn { padding: 11px 12px; font-size: 13px; min-height: 44px; }
  .btn-sm { padding: 8px 10px; font-size: 11px; min-height: 36px; }
  .form-control { padding: 11px 12px; }
  .mobile-cards tbody tr { padding: 12px; }
  .mobile-cards tbody td { font-size: 12px; }
  .mobile-cards tbody td:before { font-size: 10px; min-width: 70px; }
}
