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

:root {
  --font-sans: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  
  /* Light theme */
  --bg: #f8fafc;
  --bg-subtle: #f1f5f9;
  --card: #ffffff;
  --card-hover: #fafafa;
  --card-border: #e2e8f0;
  --fg: #0f172a;
  --fg-muted: #64748b;
  --line: #e2e8f0;
  
  /* Brand Colors */
  --accent: #10b981;
  --accent-hover: #059669;
  --accent-light: rgba(16, 185, 129, 0.12);
  --accent-border: rgba(16, 185, 129, 0.25);
  
  /* Status Colors */
  --ok: #10b981;
  --ok-bg: rgba(16, 185, 129, 0.1);
  --warn: #f59e0b;
  --warn-bg: rgba(245, 158, 11, 0.1);
  --err: #ef4444;
  --err-bg: rgba(239, 68, 68, 0.1);
  
  /* Shadows & Glass */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.08), 0 4px 8px rgba(0, 0, 0, 0.04);
  --glass-bg: rgba(255, 255, 255, 0.85);
  --glass-backdrop: blur(12px);
  
  /* WA Chat Preview */
  --wa-bg: #efeae2;
  --wa-bubble-bg: #dcf8c6;
  --wa-bubble-fg: #111b21;
  --radius-card: 16px;
  --radius-btn: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f19;
    --bg-subtle: #111827;
    --card: #1e293b;
    --card-hover: #243347;
    --card-border: rgba(255, 255, 255, 0.08);
    --fg: #f8fafc;
    --fg-muted: #94a3b8;
    --line: rgba(255, 255, 255, 0.08);
    
    --accent: #10b981;
    --accent-hover: #34d399;
    --accent-light: rgba(16, 185, 129, 0.18);
    --accent-border: rgba(16, 185, 129, 0.3);
    
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 6px 16px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
    --glass-bg: rgba(30, 41, 59, 0.8);
    
    --wa-bg: #0b141a;
    --wa-bubble-bg: #005c4b;
    --wa-bubble-fg: #e9edef;
  }
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* App Header & Layout */
.app-shell {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.75rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--line);
}

.brand-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--accent), #059669);
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: #fff;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.brand-text h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--fg);
}

.brand-text p {
  font-size: 0.8125rem;
  color: var(--fg-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

/* Dashboard Metrics Grid */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.metric-card {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-backdrop);
  -webkit-backdrop-filter: var(--glass-backdrop);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-card);
  padding: 1.25rem 1.4rem;
  box-shadow: var(--shadow-md);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.metric-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.metric-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.metric-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.metric-icon-total {
  background: rgba(59, 130, 246, 0.12);
  color: #3b82f6;
  border: 1px solid rgba(59, 130, 246, 0.25);
}

.metric-icon-monthly {
  background: var(--accent-light);
  color: var(--accent);
  border: 1px solid var(--accent-border);
}

.metric-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.metric-month-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 0.5rem;
}

.month-select {
  width: auto !important;
  padding: 0.25rem 0.6rem !important;
  font-size: 0.8125rem !important;
  border-radius: 8px !important;
  background: var(--bg-subtle) !important;
  color: var(--fg) !important;
  border: 1px solid var(--line) !important;
  cursor: pointer;
}

.metric-body {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.metric-value {
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--fg);
  line-height: 1.2;
}

.metric-subtext {
  font-size: 0.8125rem;
  color: var(--fg-muted);
}

/* Dashboard Grid Layout */
.dashboard-grid {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 900px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

.full-width {
  grid-column: 1 / -1;
}

/* Cards & Sections */
.card {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-backdrop);
  -webkit-backdrop-filter: var(--glass-backdrop);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-card);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-md);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

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

.card-title {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.card-title svg {
  color: var(--accent);
}

h2 {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--fg);
}

/* Tabs Navigation Component */
.tabs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.75rem;
  margin-bottom: 1.25rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.tabs-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-subtle);
  padding: 0.3rem;
  border-radius: 12px;
  border: 1px solid var(--line);
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 1.1rem;
  border-radius: 9px;
  border: 0;
  background: transparent;
  color: var(--fg-muted);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.tab-btn:hover {
  color: var(--fg);
  background: rgba(255, 255, 255, 0.05);
}

.tab-btn.active {
  background: var(--card);
  color: var(--fg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--card-border);
}

.tab-btn.active svg {
  color: var(--accent);
}

.tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--line);
  color: var(--fg);
}

.tab-btn.active .tab-badge {
  background: var(--accent-light);
  color: var(--accent);
}

/* Toolbar & Search Bar */
.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.search-box {
  position: relative;
  flex: 1;
  max-width: 320px;
  min-width: 200px;
}

.search-box svg {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--fg-muted);
  pointer-events: none;
}

.search-box input {
  padding-left: 2.3rem !important;
}

/* Status Pill & Pulse */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.85rem;
  border-radius: 9999px;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: all 0.2s ease;
}

.dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: currentColor;
  position: relative;
}

.s-connected {
  color: var(--ok);
  background: var(--ok-bg);
  border: 1px solid rgba(16, 185, 129, 0.25);
}

.s-connected .dot::after {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.5;
  animation: pulse-ring 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.s-connecting, .s-qr {
  color: var(--warn);
  background: var(--warn-bg);
  border: 1px solid rgba(245, 158, 11, 0.25);
}

.s-disconnected {
  color: var(--err);
  background: var(--err-bg);
  border: 1px solid rgba(239, 68, 68, 0.25);
}

@keyframes pulse-ring {
  0% { transform: scale(1); opacity: 0.6; }
  100% { transform: scale(2.2); opacity: 0; }
}

/* Buttons */
button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.55rem 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-btn);
  background: var(--card);
  color: var(--fg);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

button:hover:not(:disabled) {
  background: var(--bg-subtle);
  border-color: var(--fg-muted);
  transform: translateY(-1px);
}

button:active:not(:disabled) {
  transform: translateY(0);
}

button.primary {
  background: linear-gradient(135deg, var(--accent), #059669);
  border-color: transparent;
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.25);
}

button.primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #059669, #047857);
  box-shadow: 0 6px 16px rgba(16, 185, 129, 0.35);
}

button.danger {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  border-color: transparent;
  color: #fff;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

.btn-icon-spin svg {
  animation: spin 1s linear infinite;
}

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

/* Forms & Inputs */
.form-group {
  margin-bottom: 1.1rem;
}

label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--fg-muted);
  margin-bottom: 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

input:not([type="file"]):not([type="checkbox"]):not([type="radio"]), textarea, select {
  width: 100%;
  padding: 0.65rem 0.85rem;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: var(--radius-btn);
  font-family: inherit;
  font-size: 0.9rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

textarea {
  min-height: 6rem;
  resize: vertical;
  line-height: 1.6;
}

/* Quick Template Variable Chips */
.variable-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.4rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.55rem;
  background: var(--accent-light);
  color: var(--accent);
  border: 1px solid var(--accent-border);
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  font-family: monospace;
  cursor: pointer;
  transition: all 0.15s ease;
}

.chip:hover {
  background: var(--accent);
  color: #fff;
  transform: translateY(-1px);
}

/* Custom File Upload Zone */
.file-drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.25rem 1rem;
  border: 2px dashed var(--line);
  border-radius: var(--radius-btn);
  background: var(--bg);
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}

.file-drop-zone:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.file-drop-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.drop-icon {
  color: var(--fg-muted);
  margin-bottom: 0.4rem;
}

.drop-text {
  font-size: 0.8125rem;
  color: var(--fg-muted);
}

.drop-text strong {
  color: var(--accent);
}

/* QR Code Section */
.qr-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-btn);
  margin-bottom: 1.25rem;
  text-align: center;
}

.qr-box {
  position: relative;
  padding: 10px;
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  margin: 0.75rem 0;
}

#qr-img {
  width: 200px;
  height: 200px;
  display: block;
  image-rendering: pixelated;
  border-radius: 4px;
}

.qr-instructions {
  font-size: 0.8125rem;
  color: var(--fg-muted);
  line-height: 1.4;
}

/* Live WhatsApp Chat Preview */
.wa-preview-card {
  margin-top: 1.25rem;
  background: var(--wa-bg);
  border-radius: 12px;
  padding: 1rem;
  border: 1px solid var(--line);
  position: relative;
}

.wa-preview-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fg-muted);
  margin-bottom: 0.75rem;
}

.wa-bubble {
  background: var(--wa-bubble-bg);
  color: var(--wa-bubble-fg);
  padding: 0.65rem 0.85rem;
  border-radius: 8px 8px 0px 8px;
  margin-left: auto;
  max-width: 88%;
  font-size: 0.875rem;
  line-height: 1.45;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
  position: relative;
  word-break: break-word;
}

.wa-bubble-media {
  max-width: 100%;
  max-height: 180px;
  border-radius: 6px;
  margin-bottom: 0.4rem;
  display: block;
  object-fit: cover;
}

.wa-bubble-time {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.25rem;
  font-size: 0.6875rem;
  opacity: 0.75;
  margin-top: 0.25rem;
}

/* Modern Data Tables */
.table-wrap {
  overflow-x: auto;
  border-radius: 12px;
  border: 1px solid var(--line);
  min-height: 240px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

th {
  background: var(--bg-subtle);
  color: var(--fg-muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line);
  color: var(--fg);
  white-space: nowrap;
  vertical-align: middle;
}

tbody tr {
  transition: background 0.15s ease;
}

tbody tr:hover {
  background: var(--card-hover);
}

tbody tr:last-child td {
  border-bottom: none;
}

.phone-badge {
  font-family: monospace;
  font-size: 0.8125rem;
  padding: 0.2rem 0.5rem;
  background: var(--bg-subtle);
  border-radius: 6px;
}

.stat-badge {
  font-weight: 600;
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  font-size: 0.8125rem;
}

.stat-total { background: rgba(99, 102, 241, 0.12); color: #6366f1; }
.stat-sent { background: rgba(59, 130, 246, 0.1); color: #3b82f6; }
.stat-delivered { background: rgba(16, 185, 129, 0.1); color: #10b981; }
.stat-read { background: rgba(139, 92, 246, 0.1); color: #8b5cf6; }
.stat-failed { background: rgba(239, 68, 68, 0.1); color: #ef4444; }

/* Pagination Controls Bar */
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 0.25rem 0.25rem;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: 0.84rem;
  color: var(--fg-muted);
}

.pagination-info {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.page-size-selector {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.page-size-selector select {
  width: auto;
  padding: 0.25rem 0.5rem;
  font-size: 0.8125rem;
  border-radius: 6px;
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.pagination-btn {
  min-width: 32px;
  height: 32px;
  padding: 0 0.5rem;
  font-size: 0.8125rem;
  border-radius: 6px;
}

.pagination-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 600;
}

/* Toast Notifications */
.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  background: var(--card);
  color: var(--fg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 0.75rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  animation: slide-up 0.25s ease-out;
}

@keyframes slide-up {
  from { opacity: 0; transform: translate(-50%, 1rem); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.muted {
  color: var(--fg-muted);
}

/* Alert boxes */
.alert-box {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-btn);
  font-size: 0.875rem;
  margin-top: 0.75rem;
  border: 1px solid transparent;
}

.alert-info {
  background: var(--accent-light);
  color: var(--accent);
  border-color: var(--accent-border);
}

/* Login Page Specific Styling */
.login-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  background: radial-gradient(circle at 50% 20%, rgba(16, 185, 129, 0.1), transparent 60%), var(--bg);
}

.login-card {
  width: 100%;
  max-width: 24rem;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-backdrop);
  -webkit-backdrop-filter: var(--glass-backdrop);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-card);
  padding: 2.25rem 2rem;
  box-shadow: var(--shadow-lg);
}

.login-header {
  text-align: center;
  margin-bottom: 1.75rem;
}

.login-header .brand-icon {
  margin: 0 auto 1rem;
  width: 48px;
  height: 48px;
}

.login-header h1 {
  font-size: 1.35rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

[hidden] {
  display: none !important;
}

/* Modal Overlay & Dialog */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.modal-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  width: 100%;
  max-width: 520px;
  box-shadow: var(--shadow-lg);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

