:root {
  --bg-body: #f5f5f7;
  --bg-card: #ffffff;
  --border-subtle: #dde1e6;
  --text-main: #1f2430;
  --text-muted: #6b7280;
  --accent: #2563eb;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  background: var(--bg-body);
  color: var(--text-main);
}

.shell { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid var(--border-subtle);
  background: #ffffff;
}

.topbar-left { display: flex; align-items: center; gap: 10px; }
.logo-mark {
  width: 28px; height: 28px; border-radius: 8px;
  border: 1px solid var(--border-subtle);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px; color: var(--accent);
}
.logo-text-title { font-size: 15px; font-weight: 600; }
.logo-text-sub { font-size: 11px; color: var(--text-muted); }
.topbar-right { display: flex; align-items: center; gap: 12px; font-size: 12px; color: var(--text-muted); }
.status-dot { width: 8px; height: 8px; border-radius: 999px; background: var(--success); margin-right: 4px; }

.btn-logout {
  margin-left: 1rem;
  padding: 0.5rem 1rem;
  background: var(--accent);
  border: 1px solid var(--accent);
  color: white;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.2s;
}

.btn-logout:hover {
  background: #1d4ed8;
  border-color: #1d4ed8;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

.nav-tabs {
  display: flex; gap: 4px; background: #ffffff;
  padding: 8px 24px 0; border-bottom: 1px solid var(--border-subtle);
}
.nav-tab {
  border: none; background: transparent; padding: 8px 12px;
  border-radius: 999px 999px 0 0; font-size: 13px; cursor: pointer;
  color: var(--text-muted); border-bottom: 2px solid transparent;
}
.nav-tab.active { color: var(--accent); border-color: var(--accent); background: #ffffff; }

.content {
  flex: 1;
  padding: 18px 24px 24px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

.page { display: none; }
.page.active { display: block; }
.page-header { margin-bottom: 16px; }
.page-title { margin: 0 0 4px; font-size: 20px; }
.page-subtitle { margin: 0; font-size: 13px; color: var(--text-muted); }

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1.6fr);
  gap: 16px;
}

.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border-subtle);
  padding: 14px 16px 16px;
}

.card-header {
  display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px;
}
.card-title { font-size: 14px; font-weight: 600; }
.card-subtext { font-size: 12px; color: var(--text-muted); }

.badge-soft {
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: #f3f4f6; color: var(--text-muted); border: 1px solid #e5e7eb;
}

.field-group { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.field { display: flex; flex-direction: column; gap: 3px; font-size: 13px; }
.field label { color: var(--text-muted); }
.field input, .field select, .field textarea {
  font: inherit; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--border-subtle); background: #ffffff;
}
.field textarea { resize: vertical; min-height: 70px; }
.toggle-row {
  flex-direction: row;
  align-items: flex-start;
  gap: 10px;
}
.toggle-row label {
  margin: 0;
  color: var(--text-main);
}
.toggle-row input[type="checkbox"] {
  margin-top: 2px;
}
.toggle-row .hint {
  margin: 0;
  color: var(--text-muted);
  font-size: 12px;
}

.btn-primary {
  border: none; border-radius: 999px; background: var(--accent);
  color: #ffffff; padding: 9px 16px; font-size: 13px; cursor: pointer;
}
.btn-secondary {
  border-radius: 999px; border: 1px solid var(--border-subtle);
  background: #ffffff; color: var(--text-main); padding: 8px 12px; font-size: 12px; cursor: pointer;
}
.btn-primary:disabled { opacity: 0.7; cursor: default; }

.stats-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.stat-card {
  flex: 1 1 120px; min-width: 120px; padding: 8px 10px;
  border-radius: 10px; border: 1px solid var(--border-subtle); background: #f9fafb;
}
.stat-label { font-size: 11px; color: var(--text-muted); margin-bottom: 2px; }
.stat-value { font-size: 18px; font-weight: 600; }
.stat-value.success { color: var(--success); }
.stat-value.warning { color: var(--warning); }
.stat-value.danger { color: var(--danger); }

.active-banner {
  margin-top: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  background: #fef3c7;
  border: 1px solid #fcd34d;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.active-banner.hidden { display: none; }
.active-banner .banner-title { font-weight: 700; font-size: 15px; }
.active-banner .banner-sub { font-size: 12px; color: var(--text-muted); }
.active-banner .banner-actions { display: flex; gap: 8px; }
.badge.live { background: #b91c1c; color: #fff; padding: 4px 10px; border-radius: 10px; font-size: 11px; font-weight: 700; text-transform: uppercase; }

.history-list { display: flex; flex-direction: column; gap: 10px; }
.history-item { border: 1px solid #e5e7eb; border-radius: 12px; padding: 10px 12px; background: #fff; }
.history-item-header { display:flex; align-items:center; justify-content:space-between; gap:10px; }
.history-item-title { font-weight:700; }
.history-item-sub { font-size:12px; color: var(--text-muted); }
.history-timeline { margin-top:6px; font-size:12px; color: var(--text-muted); }
.history-timeline div { margin-top:2px; }
.history-body { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.history-block { border: 1px solid #edf0f3; border-radius: 10px; padding: 8px 10px; background: #f9fafb; }
.history-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); margin-bottom: 4px; }
.history-text { font-size: 13px; color: var(--text-main); white-space: pre-wrap; }
.history-meta { display:flex; align-items:center; gap:6px; flex-wrap:wrap; }

.timeline { margin-top: 10px; font-size: 12px; border-top: 1px solid #edf0f3; padding-top: 8px; }
.timeline-item { display: flex; gap: 6px; margin-bottom: 4px; color: var(--text-muted); }
.timeline-item strong { color: var(--text-main); }

.table-wrapper { margin-top: 8px; border-radius: 10px; border: 1px solid var(--border-subtle); overflow: hidden; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
thead { background: #f9fafb; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid #edf0f3; }
th { color: var(--text-muted); font-weight: 500; }
tr:last-child td { border-bottom: none; }

.status-pill {
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  border: 1px solid #e5e7eb; background: #f9fafb;
}
.status-ok { color: var(--success); border-color: rgba(22,163,74,0.4); background: #ecfdf3; }
.status-pending { color: var(--warning); border-color: rgba(217,119,6,0.4); background: #fff7ed; }
.status-nack { color: var(--danger); border-color: rgba(220,38,38,0.4); }
.status-delivered { color: var(--success); border-color: rgba(22,163,74,0.4); background: #ecfdf3; }

.gateway-badge {
  padding: 4px 10px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 12px;
  border: 1px solid transparent;
}
.gateway-ready { color: #15803d; background: #dcfce7; border-color: #bbf7d0; }
.gateway-warning { color: #b45309; background: #fef9c3; border-color: #fcd34d; }
.gateway-error { color: #b91c1c; background: #fee2e2; border-color: #fecdd3; }
.gateway-unknown { color: #4b5563; background: #f3f4f6; border-color: #e5e7eb; }

.hint { margin-top: 8px; font-size: 11px; color: var(--text-muted); }

.admin-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
}

.pill-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.pill { font-size: 11px; padding: 3px 8px; border-radius: 999px; background: #f3f4f6; border: 1px solid #e5e7eb; color: var(--text-muted); }

/* Modal Styles */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}

.modal-overlay.hidden {
  display: none;
}

.modal-content {
  background: var(--bg-card);
  border-radius: var(--radius);
  max-width: 500px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
  animation: slideUp 0.3s ease;
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-title {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: background 0.2s;
}

.modal-close:hover {
  background: #f3f4f6;
}

.modal-body {
  padding: 20px 24px;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { 
    opacity: 0;
    transform: translateY(20px);
  }
  to { 
    opacity: 1;
    transform: translateY(0);
  }
}

/* Checkbox Cards */
.checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.checkbox-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 2px solid var(--border-subtle);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
  background: #ffffff;
}

.checkbox-card:hover {
  border-color: var(--accent);
  background: #f8fafc;
}

.checkbox-card.selected {
  border-color: var(--accent);
  background: #eff6ff;
}

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

.checkbox-card-content {
  flex: 1;
}

.checkbox-card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
}

.checkbox-card-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Enhanced Table */
.table-actions {
  display: flex;
  gap: 6px;
}

.btn-icon {
  background: none;
  border: none;
  padding: 6px;
  cursor: pointer;
  border-radius: 6px;
  color: var(--text-muted);
  transition: all 0.2s;
  font-size: 14px;
}

.btn-icon:hover {
  background: #f3f4f6;
  color: var(--text-main);
}

.btn-icon.delete:hover {
  background: #fee2e2;
  color: var(--danger);
}

/* Search Input */
.search-box {
  position: relative;
  margin-bottom: 12px;
}

.search-box input {
  width: 100%;
  padding: 10px 12px 10px 36px;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  font-size: 13px;
  background: #ffffff;
}

.search-box::before {
  content: "🔍";
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.5;
}

.empty-state-text {
  font-size: 14px;
  margin-bottom: 16px;
}

/* Button Variants */
.btn-danger {
  border: none;
  border-radius: 999px;
  background: var(--danger);
  color: #ffffff;
  padding: 9px 16px;
  font-size: 13px;
  cursor: pointer;
}

.btn-success {
  border: none;
  border-radius: 999px;
  background: var(--success);
  color: #ffffff;
  padding: 9px 16px;
  font-size: 13px;
  cursor: pointer;
}

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

/* Alert/Toast */
.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  max-width: 400px;
  z-index: 2000;
  animation: slideInRight 0.3s ease;
  display: flex;
  align-items: center;
  gap: 12px;
}

.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.warning { border-left: 4px solid var(--warning); }
.toast.info { border-left: 4px solid var(--accent); }

.toast-icon {
  font-size: 18px;
  font-weight: bold;
  flex-shrink: 0;
}

.toast.success .toast-icon { color: var(--success); }
.toast.error .toast-icon { color: var(--danger); }
.toast.warning .toast-icon { color: var(--warning); }
.toast.info .toast-icon { color: var(--accent); }

.toast-text {
  flex: 1;
  font-size: 14px;
  line-height: 1.4;
}

.toast-close {
  background: none;
  border: none;
  font-size: 20px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 0.2s;
  flex-shrink: 0;
}

.toast-close:hover {
  background: #f3f4f6;
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(100px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Data List with Actions */
.data-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.data-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: #f9fafb;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  transition: background 0.2s;
}

.data-item:hover {
  background: #f3f4f6;
}

.data-item-content {
  flex: 1;
}

.data-item-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
}

.data-item-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.data-item-actions {
  display: flex;
  gap: 4px;
}

@media (max-width: 900px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
  .admin-grid { grid-template-columns: minmax(0, 1fr); }
}

/* Loading Spinner */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 0.6s linear infinite;
}

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

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

@media (max-width: 640px) {
  .topbar { padding: 0 12px; }
  .nav-tabs { padding: 8px 12px 0; }
  .content { padding: 14px 12px 20px; }
  .modal-content { margin: 0 12px; }
  .toast { right: 12px; left: 12px; max-width: none; }
}
