/* ==========================================================================
   MyHealthChapter (MHC) Design System - Universal WhatsApp Gateway Admin
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800;900&family=Inter:wght@400;500;600;700&display=swap');

:root {
  /* MHC Theme Tokens (Soft Off-White Soothing Medical Palette) */
  --theme-bg-gradient: linear-gradient(135deg, #F8FAFC 0%, #F1F5F9 100%);
  --theme-surface: #FFFFFF;
  --theme-surface-border: #E2E8F0;
  
  --theme-primary: #5BAAD7;
  --theme-primary-hover: #4593C2;
  --theme-accent: #6B9080;
  --theme-accent-hover: #527364;
  --theme-coral: #FC809F;
  --theme-coral-hover: #E06484;
  
  --theme-text-main: #0F172A;
  --theme-text-muted: #64748B;
  
  /* Status Badges */
  --badge-success-bg: #E2F0CB;
  --badge-success-text: #2D5A27;
  --badge-warning-bg: #FFF5BA;
  --badge-warning-text: #7A6915;
  --badge-danger-bg: #FFE9EF;
  --badge-danger-text: #C4385C;
  --badge-info-bg: #E6F3FA;
  --badge-info-text: #1C638D;
  --badge-teal-bg: rgba(20, 184, 166, 0.1);
  --badge-teal-text: #0f766e;

  --theme-card-shadow: 0 4px 20px -2px rgba(148, 163, 184, 0.15);
  --theme-radius-xl: 20px;
  --theme-radius-lg: 16px;
  --theme-radius-md: 10px;
  --theme-radius-sm: 6px;
}

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

body {
  font-family: 'Plus Jakarta Sans', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--theme-bg-gradient);
  color: var(--theme-text-main);
  min-height: 100vh;
  padding: 20px 16px;
  line-height: 1.5;
}

.container {
  max-width: 1240px;
  margin: 0 auto;
}

/* ─── Header & MHC Branding ────────────────────────── */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--theme-surface-border);
  flex-wrap: wrap;
  gap: 16px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}

.brand-logo-img {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  object-fit: cover;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  border: 1px solid rgba(226, 232, 240, 0.8);
}

.brand-title {
  font-size: 20px;
  font-weight: 900;
  color: var(--theme-text-main);
  letter-spacing: -0.5px;
  line-height: 1.1;
}

.brand-title span.highlight {
  color: var(--theme-primary);
}

.brand-subtitle-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.badge-beta {
  font-size: 9px;
  font-weight: 800;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 20px;
  background: var(--badge-teal-bg);
  color: var(--badge-teal-text);
  border: 1px solid rgba(20, 184, 166, 0.25);
  letter-spacing: 0.5px;
}

.brand-subtitle {
  font-size: 11px;
  color: var(--theme-text-muted);
  font-weight: 600;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ─── Cards & Grid ─────────────────────────────────── */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.card {
  background: var(--theme-surface);
  border: 1px solid var(--theme-surface-border);
  border-radius: var(--theme-radius-lg);
  box-shadow: var(--theme-card-shadow);
  padding: 22px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid #F1F5F9;
}

.card-title {
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--theme-text-main);
  letter-spacing: -0.2px;
}

/* ─── Status Badges ────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-success {
  background: var(--badge-success-bg);
  color: var(--badge-success-text);
}

.badge-warning {
  background: var(--badge-warning-bg);
  color: var(--badge-warning-text);
}

.badge-danger {
  background: var(--badge-danger-bg);
  color: var(--badge-danger-text);
}

.badge-info {
  background: var(--badge-info-bg);
  color: var(--badge-info-text);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  display: inline-block;
}

/* ─── WhatsApp Device Manager ──────────────────────── */
.device-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 8px 0;
}

.qr-container {
  background: #FFFFFF;
  padding: 12px;
  border-radius: 12px;
  border: 1px dashed var(--theme-primary);
  margin-bottom: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 220px;
  width: 240px;
}

.qr-container img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
}

.device-info {
  font-size: 13px;
  color: var(--theme-text-muted);
}

.device-phone {
  font-size: 20px;
  font-weight: 800;
  color: var(--theme-text-main);
  margin-top: 2px;
  letter-spacing: -0.3px;
}

/* ─── Buttons ──────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 700;
  border-radius: var(--theme-radius-md);
  border: none;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
}

.btn-primary {
  background: var(--theme-primary);
  color: white;
}
.btn-primary:hover {
  background: var(--theme-primary-hover);
}

.btn-accent {
  background: var(--theme-accent);
  color: white;
}
.btn-accent:hover {
  background: var(--theme-accent-hover);
}

.btn-secondary {
  background: #F1F5F9;
  color: var(--theme-text-main);
  border: 1px solid var(--theme-surface-border);
}
.btn-secondary:hover {
  background: #E2E8F0;
}

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

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

/* ─── Toggle Switches ──────────────────────────────── */
.toggle-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid #F8FAFC;
}

.toggle-item:last-child {
  border-bottom: none;
}

.toggle-info h4 {
  font-size: 13px;
  font-weight: 700;
  color: var(--theme-text-main);
}

.toggle-info p {
  font-size: 12px;
  color: var(--theme-text-muted);
}

/* Switch styling */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 22px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #CBD5E1;
  transition: .3s;
  border-radius: 24px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .3s;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

input:checked + .slider {
  background-color: var(--theme-primary);
}

input:checked + .slider:before {
  transform: translateX(22px);
}

/* ─── Dispatch Studio & Tabs ───────────────────────── */
.tab-header {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  border-bottom: 1px solid #F1F5F9;
  padding-bottom: 8px;
}

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

.tab-btn.active {
  background: #E6F3FA;
  color: var(--theme-primary);
}

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 5px;
  color: var(--theme-text-main);
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--theme-surface-border);
  border-radius: var(--theme-radius-md);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  background: #FFFFFF;
  transition: border-color 0.2s;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--theme-primary);
  box-shadow: 0 0 0 3px rgba(91, 170, 215, 0.15);
}

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

.format-bar {
  display: flex;
  gap: 4px;
  margin-bottom: 6px;
}

.format-btn {
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
  background: #F8FAFC;
  border: 1px solid var(--theme-surface-border);
  border-radius: 4px;
  cursor: pointer;
}
.format-btn:hover {
  background: #E2E8F0;
}

/* ─── Tables (API Keys & Audit Log) ─────────────────── */
.table-container {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 13px;
}

th {
  background: #F8FAFC;
  color: var(--theme-text-muted);
  font-weight: 700;
  padding: 10px 14px;
  border-bottom: 1px solid var(--theme-surface-border);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.5px;
}

td {
  padding: 12px 14px;
  border-bottom: 1px solid #F1F5F9;
  vertical-align: middle;
}

tr:hover td {
  background: #FAFCFE;
}

.key-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  background: #F1F5F9;
  padding: 3px 6px;
  border-radius: 6px;
  font-size: 12px;
  color: #334155;
  border: 1px solid #E2E8F0;
}

/* ─── Modal ────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

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

.modal {
  background: white;
  border-radius: var(--theme-radius-lg);
  padding: 24px;
  width: 90%;
  max-width: 520px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

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

.modal-title {
  font-size: 16px;
  font-weight: 800;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #0F172A;
  color: white;
  padding: 11px 18px;
  border-radius: var(--theme-radius-md);
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 10px 20px rgba(0,0,0,0.25);
  display: none;
  z-index: 2000;
  animation: slideUp 0.2s ease-out;
}

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

@media (max-width: 768px) {
  .grid-2, .form-grid-2 {
    grid-template-columns: 1fr;
  }
}
