/* ==========================================================================
   S2S Postback Dashboard — Shared Styles
   Light + Dark theme via data-theme attribute
   ========================================================================== */

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

:root {
  --azure: #3c7cfc;
  --seafoam: #59c0e8;
  --bg: #f8fafc;
  --bg-card: #ffffff;
  --bg-hover: #f1f5f9;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --gradient-blue: linear-gradient(135deg, #3c7cfc 0%, #59c0e8 100%);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
  --success: #10b981;
  --error: #ef4444;
  --warning: #f59e0b;
  --purple: #a855f7;
  --input-bg: #f8fafc;
}

[data-theme="dark"] {
  --bg: #0f1117;
  --bg-card: #181a20;
  --bg-hover: #1e2028;
  --border: #2a2d37;
  --text: #e8eaed;
  --text-muted: #8b8fa3;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.4);
  --success: #34d399;
  --error: #f87171;
  --warning: #fbbf24;
  --purple: #c084fc;
  --input-bg: #0f1117;
}

body {
  font-family: "Outfit", -apple-system, BlinkMacSystemFont, sans-serif;
  font-weight: 200;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* ==========================================================================
   Login Page
   ========================================================================== */

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

.login-card {
  background: var(--bg-card);
  border-radius: 20px;
  padding: 40px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  text-align: center;
  width: 100%;
  max-width: 400px;
}

.login-logo {
  width: 64px;
  height: 64px;
  margin: 0 auto 20px;
  background: var(--gradient-blue);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 20px rgba(60,124,252,0.3);
}

.login-logo svg { width: 32px; height: 32px; color: white; }

.login-title { font-size: 24px; font-weight: 300; margin-bottom: 8px; }
.login-subtitle { font-size: 14px; color: var(--text-muted); margin-bottom: 32px; }

.form-group { margin-bottom: 20px; text-align: left; }

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

.form-input {
  width: 100%;
  padding: 14px 18px;
  border: 2px solid var(--border);
  border-radius: 12px;
  font-size: 15px;
  font-family: inherit;
  font-weight: 200;
  transition: all 0.2s ease;
  background: var(--input-bg);
  color: var(--text);
}

.form-input:focus {
  outline: none;
  border-color: var(--azure);
  box-shadow: 0 0 0 4px rgba(60,124,252,0.1);
}

.error-message {
  background: rgba(239,68,68,0.1);
  border: 1px solid var(--error);
  border-radius: 10px;
  padding: 12px 16px;
  color: var(--error);
  font-size: 13px;
  margin-bottom: 20px;
  display: none;
}

.error-message.visible { display: block; }

.login-btn {
  width: 100%;
  padding: 16px;
  background: var(--gradient-blue);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 300;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.login-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(60,124,252,0.4);
}

.login-btn:disabled { opacity: 0.6; cursor: not-allowed; }

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: none;
}

.login-btn.loading .spinner { display: block; }
.login-btn.loading .btn-text { display: none; }

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

.login-footer { margin-top: 24px; font-size: 12px; color: var(--text-muted); }

/* ==========================================================================
   Dashboard Layout
   ========================================================================== */

.header {
  background: var(--gradient-blue);
  padding: 16px 24px;
  box-shadow: 0 4px 20px rgba(60,124,252,0.3);
}

.header-content {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-title {
  display: flex;
  align-items: center;
  gap: 12px;
  color: white;
  font-size: 18px;
  font-weight: 300;
}

.header-title svg { width: 24px; height: 24px; }

.header-nav {
  display: flex;
  gap: 8px;
  align-items: center;
}

.nav-btn {
  padding: 8px 16px;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 10px;
  color: white;
  text-decoration: none;
  font-size: 13px;
  font-weight: 300;
  font-family: inherit;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.nav-btn:hover { background: rgba(255,255,255,0.25); }
.nav-btn svg { width: 16px; height: 16px; }

.theme-toggle-nav {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 10px;
  padding: 8px;
  cursor: pointer;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.theme-toggle-nav:hover { background: rgba(255,255,255,0.25); }

.theme-toggle {
  position: fixed;
  top: 20px;
  right: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  z-index: 10;
}

.theme-toggle:hover { color: var(--azure); border-color: var(--azure); }

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

/* ==========================================================================
   Stats Cards
   ========================================================================== */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px 24px;
  box-shadow: var(--shadow-sm);
}

.stat-card h3 {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
  font-weight: 400;
  letter-spacing: 0.5px;
}

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

.stat-card .value.green { color: var(--success); }
.stat-card .value.blue { color: var(--azure); }
.stat-card .value.orange { color: var(--warning); }
.stat-card .value.red { color: var(--error); }
.stat-card .value.purple { color: var(--purple); }

/* ==========================================================================
   Section / Card
   ========================================================================== */

.section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  margin-bottom: 24px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.section-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg);
  flex-wrap: wrap;
  gap: 12px;
}

.section-header h2 {
  font-size: 15px;
  font-weight: 400;
}

.section-tools {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

/* ==========================================================================
   Toolbar / Filters
   ========================================================================== */

.filter-input {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  font-weight: 200;
  background: var(--input-bg);
  color: var(--text);
  min-width: 200px;
  transition: border-color 0.2s;
}

.filter-input:focus {
  outline: none;
  border-color: var(--azure);
}

.filter-select {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  font-weight: 200;
  background: var(--input-bg);
  color: var(--text);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}

.btn {
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 13px;
  font-weight: 300;
  font-family: inherit;
  transition: all 0.2s;
  background: var(--bg-card);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn:hover { border-color: var(--azure); color: var(--azure); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn svg { width: 14px; height: 14px; }

.btn-primary {
  background: var(--gradient-blue);
  color: white;
  border-color: transparent;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(60,124,252,0.4);
  color: white;
}

.btn-danger {
  color: var(--error);
  border-color: var(--error);
}

.btn-danger:hover {
  background: var(--error);
  color: white;
}

/* ==========================================================================
   Table
   ========================================================================== */

.table-wrap { overflow-x: auto; }

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

th, td {
  padding: 10px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  white-space: nowrap;
}

th {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 400;
  letter-spacing: 0.5px;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 2;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-hover); }
tr { cursor: pointer; transition: background 0.1s; }

.truncate {
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ==========================================================================
   Status Badges
   ========================================================================== */

.badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 400;
}

.badge-sent { background: rgba(16,185,129,0.1); color: var(--success); }
.badge-failed { background: rgba(239,68,68,0.1); color: var(--error); }
.badge-retry { background: rgba(245,158,11,0.1); color: var(--warning); }
.badge-pending { background: rgba(60,124,252,0.1); color: var(--azure); }
.badge-test { background: rgba(168,85,247,0.1); color: var(--purple); }

/* ==========================================================================
   Pagination
   ========================================================================== */

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-muted);
}

.pagination-btns {
  display: flex;
  gap: 6px;
}

.page-btn {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-card);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

.page-btn:hover:not(:disabled) { border-color: var(--azure); color: var(--azure); }
.page-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.page-btn.active { background: var(--azure); color: white; border-color: var(--azure); }

/* ==========================================================================
   Empty & Loading States
   ========================================================================== */

.empty-state {
  padding: 48px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

.empty-state svg {
  width: 48px;
  height: 48px;
  margin-bottom: 16px;
  opacity: 0.4;
}

.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
  gap: 10px;
  color: var(--text-muted);
  font-size: 14px;
}

.loading-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--azure);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ==========================================================================
   Detail Modal
   ========================================================================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

[data-theme="dark"] .modal-overlay { background: rgba(0,0,0,0.7); }

.modal-overlay.active { display: flex; }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 600px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-head {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  background: var(--bg-card);
  z-index: 1;
}

.modal-head h3 { font-size: 16px; font-weight: 400; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all 0.15s;
}

.modal-close:hover { background: var(--bg-hover); color: var(--text); }

.modal-body { padding: 24px; }

.detail-section {
  font-size: 11px;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--azure);
  margin-top: 20px;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.detail-section:first-child { margin-top: 0; }

.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 13px;
  gap: 16px;
}

.detail-label {
  color: var(--text-muted);
  font-weight: 300;
  flex-shrink: 0;
}

.detail-value {
  text-align: right;
  word-break: break-all;
  max-width: 360px;
  font-weight: 300;
}

.detail-value pre {
  white-space: pre-wrap;
  font-size: 12px;
  font-family: "SF Mono", Monaco, monospace;
  background: var(--bg);
  padding: 8px 12px;
  border-radius: 8px;
  max-width: 360px;
  overflow-x: auto;
  text-align: left;
}

/* ==========================================================================
   Refresh Indicator
   ========================================================================== */

.refresh-info {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.refresh-dot {
  width: 6px;
  height: 6px;
  background: var(--success);
  border-radius: 50%;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 768px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .container { padding: 16px; }
  .header { padding: 12px 16px; }
  .header-title { font-size: 16px; }
  .section-header { flex-direction: column; align-items: flex-start; }
  .section-tools { width: 100%; }
  .filter-input { min-width: 0; flex: 1; }
  .login-card { padding: 28px; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { padding: 14px 16px; }
  .stat-card .value { font-size: 22px; }
  .header-nav { gap: 4px; }
  .nav-btn { padding: 6px 10px; font-size: 12px; }
}
