/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

/* ===== Login Screen ===== */
.login-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.login-card {
  width: 360px;
  padding: 40px 32px;
  background: var(--surface);
  border-radius: 16px;
  border: 1px solid var(--border);
  text-align: center;
}
.login-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text);
  margin-bottom: 4px;
}
.login-brand h1 { font-size: 24px; font-weight: 700; }
.login-brand svg { color: var(--primary); }
.login-subtitle { color: var(--text-muted); font-size: 14px; margin-bottom: 24px; }
.login-error {
  background: var(--danger-bg);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 16px;
  text-align: left;
}
#login-form { display: flex; flex-direction: column; gap: 12px; }
#login-form input {
  padding: 12px 14px;
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}
#login-form input:focus { border-color: var(--primary); }
#login-form input::placeholder { color: var(--text-muted); }
.btn-login {
  padding: 12px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}
.btn-login:hover { opacity: 0.9; }
.login-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: var(--text-muted);
  font-size: 13px;
}
.login-divider::before, .login-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.btn-google {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px;
  background: var(--surface-hover);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.btn-google:hover { border-color: var(--primary); background: var(--border); }

/* ===== Theme Variables ===== */
[data-theme="dark"] {
  --bg: #0f1117;
  --surface: #1a1c25;
  --surface-hover: #22252f;
  --border: #2a2d38;
  --text: #e4e6ed;
  --sidebar-active: rgba(108,92,231,0.15);
}

[data-theme="light"] {
  --primary-bg: rgba(108,92,231,0.12);
  --accent: #00cec9;
  --danger: #ff6b6b;
  --danger-bg: rgba(255,107,107,0.1);
  --success: #00b894;
  --warning: #fdcb6e;
  --sidebar-bg: #14161e;
  --sidebar-hover: #1e2030;
  --sidebar-active: rgba(108,92,231,0.15);
}

[data-theme="light"] {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-hover: #f0f1f4;
  --border: #e2e4ea;
  --text: #1a1c25;
  --text-muted: #6b7085;
  --text-heading: #0f1117;
  --primary: #6c5ce7;
  --primary-hover: #5a4bd5;
  --primary-bg: rgba(108,92,231,0.08);
  --accent: #00a89d;
  --danger: #e55555;
  --danger-bg: rgba(229,85,85,0.08);
  --success: #00a884;
  --warning: #e6b23e;
  --sidebar-bg: #ffffff;
  --sidebar-hover: #f0f1f4;
  --sidebar-active: rgba(108,92,231,0.1);
}

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

/* ===== Sidebar ===== */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 216px;
  height: 100vh;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 24px;
  font-size: 17px;
  font-weight: 700;
  color: var(--text-heading);
}

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0 12px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: none;
  border-radius: 8px;
  background: none;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
  width: 100%;
}

.nav-item:hover { background: var(--sidebar-hover); color: var(--text); }
.nav-item.active { background: var(--sidebar-active); color: var(--primary); font-weight: 500; }

.sidebar-footer {
  padding: 16px 12px;
  border-top: 1px solid var(--border);
}
.sidebar-user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  margin-bottom: 4px;
}
.sidebar-user-name {
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.admin-badge {
  display: inline-block;
  padding: 2px 8px;
  background: var(--primary);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}


/* ===== Main ===== */
.main {
  margin-left: 216px;
  flex: 1;
  min-height: 100vh;
}

.page { display: none; padding: 32px 40px; max-width: 1155px; }
.page.active { display: block; }

.page-header { margin-bottom: 28px; }
.page-header h1 { font-size: 24px; font-weight: 700; color: var(--text-heading); margin-bottom: 6px; }
.page-header p { font-size: 14px; color: var(--text-muted); }

/* ===== Card ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 20px;
}

.card h2 { font-size: 15px; font-weight: 600; color: var(--text-heading); margin-bottom: 16px; }
.card-error { border-color: var(--danger); }
.card-error h2 { color: var(--danger); }
.card-error p { color: var(--text-muted); }
.error-pre { white-space: pre-wrap; word-break: break-word; color: var(--danger); border-color: var(--danger); background: var(--danger-bg); }

.creative-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  padding: 24px;
}

.btn-copied { background: var(--success) !important; color: #fff !important; border-color: var(--success) !important; }

.card-header-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.card-header-row h2 { margin-bottom: 0; }
.card-actions { display: flex; gap: 8px; }

/* ===== Forms ===== */
.form-row { display: grid; gap: 20px; }
.form-row.two-col { grid-template-columns: 1fr 1fr; align-items: start;}
.form-row.three-col { grid-template-columns: 1fr 1fr auto; }

.fields-stack { display: flex; flex-direction: column; }

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

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
  resize: vertical;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: var(--primary); }
.form-group input::placeholder,
.form-group textarea::placeholder { color: var(--text-muted); opacity: 0.5; }

/* Upload */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  min-height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.upload-area:hover,
.upload-area.dragover { border-color: var(--primary); background: var(--primary-bg); }

.upload-placeholder { color: var(--text-muted); }
.upload-placeholder p { margin: 8px 0 4px; font-size: 14px; }
.upload-placeholder span { font-size: 12px; opacity: 0.6; }

.image-preview { max-width: 100%; max-height: 400px; border-radius: 8px; object-fit: contain; }
.image-previews-container { display: flex; flex-direction: column; gap: 12px; width: 100%; }
.preview-item { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.image-preview-multi { max-width: 100%; max-height: 250px; border-radius: 8px; object-fit: contain; }
.main-image-label { font-size: 13px; color: var(--text-heading); display: flex; align-items: center; gap: 6px; cursor: pointer; }

/* ===== Radio Group ===== */
.radio-group { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.radio-option {
  display: flex;
  flex-direction: column;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s;
  background: var(--bg);
}
.radio-option:hover { border-color: var(--primary); }
.radio-option.active { border-color: var(--primary); background: var(--primary-bg); }
.radio-option input { display: none; }
.radio-label { font-size: 14px; font-weight: 600; color: var(--text-heading); margin-bottom: 2px; }
.radio-desc { font-size: 12px; color: var(--text-muted); }

.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.checkbox-option {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  transition: all 0.15s;
  user-select: none;
}
.checkbox-option:hover { border-color: var(--primary); }
.checkbox-option:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-bg);
  color: var(--primary);
}
.checkbox-option input[type="checkbox"] {
  accent-color: var(--primary);
  width: 15px;
  height: 15px;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn:active { transform: scale(0.97); }
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-lg { width: 100%; padding: 14px; font-size: 15px; margin-top: 8px; }

.spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Pipeline ===== */
.pipeline { display: flex; gap: 8px; }

.pipeline-step {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--bg);
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-muted);
  transition: all 0.3s;
}

.step-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
  transition: all 0.3s;
}

.pipeline-step.active { color: var(--text); }
.pipeline-step.active .step-dot { background: var(--warning); box-shadow: 0 0 8px var(--warning); animation: pulse 1s ease infinite; }
.pipeline-step.done { color: var(--success); }
.pipeline-step.done .step-dot { background: var(--success); box-shadow: 0 0 8px var(--success); animation: none; }

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

/* ===== Results ===== */
.tags-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }

.tag {
  padding: 5px 12px;
  background: var(--primary-bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  color: var(--accent);
}

details summary { cursor: pointer; font-size: 13px; color: var(--text-muted); padding: 8px 0; }

pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.5;
  color: var(--accent);
}

.ad-copy-preview { background: var(--bg); border-radius: 10px; padding: 24px; }
.ad-copy-preview .headline { font-size: 20px; font-weight: 700; margin-bottom: 12px; color: var(--text-heading); }
.ad-copy-preview .primary-text { font-size: 14px; line-height: 1.7; margin-bottom: 16px; color: var(--text-muted); }
.ad-copy-preview .description { font-size: 13px; color: var(--text-muted); padding-top: 12px; border-top: 1px solid var(--border); margin-bottom: 12px; }
.ad-copy-preview .cta-badge { display: inline-block; padding: 6px 16px; background: var(--primary); color: #fff; border-radius: 6px; font-size: 13px; font-weight: 500; }

.creatives-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.creative-card { text-align: center; }
.creative-card img { width: 100%; border-radius: 8px; border: 1px solid var(--border); margin-bottom: 8px; }
.creative-card .label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; }

/* ===== Switch Model Page ===== */
.active-model-display {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--primary-bg);
  border: 1px solid var(--primary);
  border-radius: 8px;
  margin-bottom: 14px;
  font-size: 14px;
  color: var(--primary);
  font-weight: 500;
}

.active-model-display::before { content: "Active:"; color: var(--text-muted); font-weight: 400; }

.model-options {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 4px 0;
}

.model-opt-btn {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}

.model-opt-btn:hover { border-color: var(--primary); color: var(--primary); }
.model-opt-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); cursor: default; }

.model-opt-wrap {
  display: inline-flex;
  align-items: center;
  position: relative;
}
.model-opt-hide {
  position: absolute;
  right: -6px;
  top: -6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: none;
  background: var(--danger);
  color: #fff;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.model-opt-wrap:hover .model-opt-hide { display: flex; }

.btn-show-all {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 12px;
  cursor: pointer;
  padding: 4px 8px;
  text-decoration: underline;
}
.btn-show-all:hover { color: var(--primary-hover); }

.model-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.model-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  color: var(--text);
}

.model-chip .chip-remove {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0;
}

.chip-cap {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 500;
  background: var(--primary-bg);
  color: var(--primary);
  margin-left: 2px;
}

/* ===== Logs Page ===== */
.stats-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 20px; }

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 24px;
  text-align: center;
}

.stat-value { font-size: 28px; font-weight: 700; color: var(--text-heading); }
.stat-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; margin-top: 4px; }

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

.log-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 13px;
}

.log-table th {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-table td {
  overflow: hidden;
  text-overflow: ellipsis;
}

.log-table th {
  text-align: left;
  padding: 8px 10px;
  background: var(--bg);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.log-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 12px;
}

.log-table tr:hover td { background: var(--surface-hover); }

.log-table .empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 14px;
}

.log-table .badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
}

.badge-vision { background: rgba(0,206,201,0.15); color: var(--accent); }
.badge-text { background: rgba(108,92,231,0.15); color: var(--primary); }
.badge-image { background: rgba(253,203,110,0.15); color: var(--warning); }
.badge-provider-openai { background: rgba(0,166,126,0.15); color: #00a67e; }
.badge-provider-openrouter { background: rgba(108,92,231,0.15); color: var(--primary); }
.badge-provider-xai { background: rgba(29,161,242,0.15); color: #1da1f2; }
.badge-provider-unknown { background: rgba(139,143,163,0.15); color: var(--text-muted); }
.badge-scrape { background: rgba(0,184,148,0.15); color: var(--success); }

/* ===== PropertyGuru Results ===== */
.pguru-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 0; }
.pguru-field {
  display: flex;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.pguru-field:nth-child(odd) { background: var(--bg); }
.pguru-label { font-size: 13px; color: var(--text-muted); font-weight: 500; min-width: 140px; }
.pguru-value { font-size: 13px; color: var(--text); text-align: right; word-break: break-word; }
.pguru-table { margin-bottom: 8px; }
.pguru-fallback { margin-top: 16px; }
.pguru-fallback summary { cursor: pointer; font-size: 13px; color: var(--text-muted); padding: 4px 0; }
.pguru-fallback summary:hover { color: var(--primary); }

@media (max-width: 768px) {
  .pguru-fields { grid-template-columns: 1fr; }
}

/* ===== Property Search Chat ===== */
.psearch-chat-card { padding: 0; display: flex; flex-direction: column; height: 60vh; min-height: 400px; }
.psearch-chat-history {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.psearch-chat-input {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  border-radius: 0 0 12px 12px;
}
.psearch-chat-input input {
  flex: 1;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.psearch-chat-input input:focus { border-color: var(--primary); }
.psearch-chat-input input::placeholder { color: var(--text-muted); opacity: 0.5; }
.psearch-chat-input .btn { flex-shrink: 0; padding: 10px 14px; }

.psearch-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
  word-wrap: break-word;
}
.psearch-bubble-user {
  align-self: flex-end;
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.psearch-bubble-bot {
  align-self: flex-start;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.psearch-bubble-thinking {
  align-self: flex-start;
  background: var(--bg);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  padding: 14px 20px;
}
.psearch-thinking { display: flex; gap: 4px; }
.psearch-thinking span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: psearchDot 1.4s ease-in-out infinite;
}
.psearch-thinking span:nth-child(2) { animation-delay: 0.2s; }
.psearch-thinking span:nth-child(3) { animation-delay: 0.4s; }
@keyframes psearchDot {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}
.psearch-meta {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  padding: 4px 0;
}

/* ===== Mobile Header ===== */
.mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 200;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
}
.mobile-hamburger {
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 8px;
  margin: -8px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.mobile-header-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-heading);
}
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}

/* ===== Mobile Card List (replaces tables) ===== */
.mobile-card-list { display: none; }

.mobile-card-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.mobile-card-item:active { border-color: var(--primary); }

.mobile-card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-heading);
  margin-bottom: 8px;
}

.mobile-card-rows {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 16px;
}

.mobile-card-field {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.mobile-card-label {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.mobile-card-value {
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mobile-card-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

/* ===== Responsive: Tablet ===== */
@media (max-width: 900px) {
  .sidebar { width: 110px; }
  .sidebar-brand { padding: 14px 8px 16px; font-size: 14px; gap: 6px; }
  .sidebar-nav { padding: 0 6px; }
  .nav-item { font-size: 11px; padding: 8px 6px; gap: 6px; }
  .nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }
  .main { margin-left: 110px; }
  .page { padding: 24px 16px; }
  .sidebar-footer { padding: 10px 6px; }
  .sidebar-user-info { padding: 6px 6px; }
  .sidebar-user-name { font-size: 11px; }
}

/* ===== Responsive: Mobile ===== */
@media (max-width: 768px) {
  /* Show mobile header, hide sidebar */
  .mobile-header { display: flex; }

  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    width: 280px;
    z-index: 300;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }

  .main {
    margin-left: 0;
    padding-top: 56px;
  }

  .page {
    padding: 16px;
    max-width: 100%;
  }

  .page-header { margin-bottom: 16px; }
  .page-header h1 { font-size: 20px; }
  .page-header p { font-size: 13px; }

  /* Cards */
  .card { padding: 16px; margin-bottom: 12px; border-radius: 10px; }
  .card h2 { font-size: 14px; margin-bottom: 12px; }
  .card-header-row { flex-wrap: wrap; gap: 8px; }

  /* Tables → Card list on mobile */
  .mobile-card-list { display: block; }
  .table-wrap { display: none; }

  /* Forms */
  .form-row.two-col { grid-template-columns: 1fr; }
  .form-row.three-col { grid-template-columns: 1fr; }
  .form-group { margin-bottom: 12px; }
  .form-group input, .form-group select, .form-group textarea { font-size: 16px; padding: 12px 14px; }

  /* Buttons — larger touch targets */
  .btn { padding: 12px 20px; font-size: 15px; min-height: 44px; }
  .btn-sm { padding: 8px 14px; font-size: 13px; min-height: 36px; }
  .btn-lg { padding: 16px; font-size: 16px; }

  /* Creatives grid single column */
  .creatives-grid { grid-template-columns: 1fr; }

  /* Pipeline steps vertical */
  .pipeline { flex-direction: column; }

  /* Stats row single column */
  .stats-row { grid-template-columns: 1fr; }

  /* Radio/checkbox groups */
  .radio-group { grid-template-columns: 1fr; }
  .checkbox-group { gap: 6px; }
  .checkbox-option { padding: 10px 14px; font-size: 14px; }

  /* Upload area smaller */
  .upload-area { min-height: 160px; padding: 16px; }

  /* Chat sidebar */
  .chat-sidebar { width: 80px; }
  .contact-details { display: none; }
  .chat-bubble { max-width: 90%; }

  /* PGuru fields single col */
  .pguru-fields { grid-template-columns: 1fr; }

  /* Meta ads previews */
  .meta-ads-preview-tabs { gap: 6px; }
  .meta-ads-preview-tabs .preview-tab { padding: 8px 12px; font-size: 12px; }
}

/* ===== WhatsApp Chat Interface ===== */
.chat-container {
  display: flex;
  height: 100vh;
  width: 100%;
  background-color: var(--surface);
  overflow: hidden;
}

/* Contact Sidebar */
.chat-sidebar {
  width: 320px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background-color: var(--bg);
}

.chat-sidebar-header {
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
}

.chat-sidebar-header h3 {
  font-size: 16px;
  margin: 0;
}

.contact-list {
  flex: 1;
  overflow-y: auto;
}

.contact-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: background 0.2s;
}

.contact-item:hover, .contact-item.active {
  background: var(--surface-hover);
}

.contact-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
}

.contact-details { flex: 1; overflow: hidden; }
.contact-number { font-weight: 600; font-size: 14px; margin-bottom: 2px; }
.contact-preview { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Main Chat Window */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: #efeae2;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='400' viewBox='0 0 800 800'%3E%3Cg fill='none' stroke='%23000' stroke-opacity='0.03' stroke-width='1'%3E%3Cpath d='M769 229L1037 260.9M927 880L731 737 520 660 309 538 40 599 46 442 105 288 190 151 346 59 519 5 695 33 852 103 982 210 1018 322 1011 448 958 584 851 713 626 820 460 765'/%3E%3Cpath d='M233 452L23 422.5 70 80L334 1.5 540 115 470 455 125 464 233 452z'/%3E%3Cpath d='M633 352L833 322.5 880 80 1134 1.5 1340 115 1270 455 925 464 1033 452z'/%3E%3C/g%3E%3C/svg%3E");
  background-attachment: fixed;
  position: relative;
}

/* Dark mode override for the chat background */
[data-theme="dark"] .chat-main { 
  background-color: #0b141a; 
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='400' viewBox='0 0 800 800'%3E%3Cg fill='none' stroke='%23fff' stroke-opacity='0.03' stroke-width='1'%3E%3Cpath d='M769 229L1037 260.9M927 880L731 737 520 660 309 538 40 599 46 442 105 288 190 151 346 59 519 5 695 33 852 103 982 210 1018 322 1011 448 958 584 851 713 626 820 460 765'/%3E%3Cpath d='M233 452L23 422.5 70 80L334 1.5 540 115 470 455 125 464 233 452z'/%3E%3Cpath d='M633 352L833 322.5 880 80 1134 1.5 1340 115 1270 455 925 464 1033 452z'/%3E%3C/g%3E%3C/svg%3E");
}

.chat-header {
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  justify-content: space-between;
  flex-shrink: 0;
  z-index: 1;
}

.chat-header h3 { margin: 0; font-size: 16px; }

.chat-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  text-align: center;
  padding: 40px;
}

.chat-history {
  flex: 1;
  overflow-y: auto;
  padding: 10px 5% 20px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-bubble {
  max-width: 85%;
  min-width: 60px;
  padding: 5px 8px 3px;
  border-radius: 7.5px;
  font-size: 14.2px;
  line-height: 1.5;
  position: relative;
  word-wrap: break-word;
  white-space: pre-wrap;
  box-shadow: 0 1px 0.5px rgba(0,0,0,0.13);
}

.bubble-inbound {
  background: var(--surface);
  align-self: flex-start;
  border-top-left-radius: 0;
  margin-left: 8px;
}

/* Inbound tail */
.bubble-inbound::before {
  content: "";
  position: absolute;
  top: 0;
  left: -8px;
  width: 0;
  height: 0;
  border-top: 8px solid var(--surface);
  border-left: 8px solid transparent;
}

.bubble-outbound {
  background: #dcf8c6;
  color: #111b21;
  align-self: flex-end;
  border-top-right-radius: 0;
  margin-right: 8px;
}

/* Outbound tail */
.bubble-outbound::before {
  content: "";
  position: absolute;
  top: 0;
  right: -8px;
  width: 0;
  height: 0;
  border-top: 8px solid #dcf8c6;
  border-right: 8px solid transparent;
}

[data-theme="dark"] .bubble-outbound { background: #005c4b; color: #e9edef; }
[data-theme="dark"] .bubble-outbound::before { border-top-color: #005c4b; }

[data-theme="dark"] .bubble-inbound { background: #202c33; color: #e9edef; }
[data-theme="dark"] .bubble-inbound::before { border-top-color: #202c33; }

.bubble-system {
  background: rgba(0,0,0,0.3);
  color: white;
  align-self: center;
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 7px;
  max-width: 90%;
  text-align: center;
  box-shadow: none;
  margin: 6px 0;
  font-weight: 500;
  backdrop-filter: blur(2px);
}

.bubble-system::before { display: none; }

.bubble-time {
  float: right;
  font-size: 11px;
  color: #667781;
  margin: 4px 0 0 8px;
  position: relative;
  bottom: -2px;
}

.bubble-outbound .bubble-time { color: #667781; }
[data-theme="dark"] .bubble-outbound .bubble-time { color: rgba(255,255,255,0.6); }

/* Message input bar */
.chat-input-area {
  min-height: 62px;
  background: var(--surface);
  padding: 10px 16px;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
  border-top: 1px solid var(--border);
}

.chat-input-area input {
  flex: 1;
  height: 42px;
  border-radius: 8px;
  border: none;
  padding: 0 16px;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

.chat-input-area .btn { 
  border-radius: 50%; 
  width: 42px; 
  height: 42px; 
  padding: 0; 
  display: flex; 
  align-items: center; 
  justify-content: center;
  background: var(--primary);
  color: white;
}

/* Media rendering in bubbles */
.chat-media-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 6px;
  border-radius: 4px;
  overflow: hidden;
}

.chat-media-grid img {
  width: 100%;
  max-height: 300px;
  object-fit: cover;
  border-radius: 4px;
  cursor: pointer;
  background: #f0f0f0;
}

.bubble-text {
  clear: both;
}

/* (mobile rules consolidated into main mobile block above) */

/* Meta Ads Preview */
.meta-ads-preview-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.meta-ads-preview-tabs .preview-tab {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s;
}
.meta-ads-preview-tabs .preview-tab:hover {
  border-color: var(--primary);
  color: var(--text);
}
.meta-ads-preview-tabs .preview-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.meta-ads-preview-frame {
  display: flex;
  justify-content: center;
  min-height: 200px;
}
.meta-ads-preview-frame iframe {
  border: none;
  max-width: 100%;
}

/* ====== Create New Ads Wizard ====== */
.wizard-progress {
  display: flex;
  align-items: center;
  margin-bottom: 24px;
  padding: 0 16px;
}
.wizard-progress-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.wizard-progress-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.2s;
}
.wizard-progress-step.active .wizard-progress-dot {
  background: var(--primary);
  color: #fff;
}
.wizard-progress-step.done .wizard-progress-dot {
  background: #27ae60;
  color: #fff;
}
.wizard-progress-label {
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 500;
}
.wizard-progress-step.active .wizard-progress-label {
  color: var(--primary);
}
.wizard-progress-line {
  flex: 1;
  height: 2px;
  background: var(--border);
  margin: 0 8px;
  margin-bottom: 18px;
}
.wizard-progress-line.done {
  background: #27ae60;
}

.wizard-choice {
  display: flex;
  gap: 20px;
  justify-content: center;
  margin: 32px 0;
}
.wizard-choice-btn {
  flex: 1;
  max-width: 260px;
  padding: 28px 20px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--card-bg);
  cursor: pointer;
  text-align: center;
  transition: all 0.2s;
}
.wizard-choice-btn:hover {
  border-color: var(--primary);
  box-shadow: 0 4px 12px rgba(108, 92, 231, 0.15);
}
.wizard-choice-btn svg {
  margin-bottom: 12px;
  color: var(--primary);
}
.wizard-choice-btn h3 {
  margin: 0 0 6px;
  font-size: 15px;
  color: var(--text-primary);
}
.wizard-choice-btn p {
  margin: 0;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.wizard-image-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}
.wizard-image-option {
  position: relative;
  border: 3px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.2s;
}
.wizard-image-option.selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(108, 92, 231, 0.3);
}
.wizard-image-option img {
  width: 100%;
  height: 140px;
  object-fit: cover;
  display: block;
}
.wizard-image-option .wizard-image-radio {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: rgba(0,0,0,0.3);
}
.wizard-image-option.selected .wizard-image-radio {
  background: var(--primary);
  border-color: #fff;
}

/* Wizard creative card actions */
.wizard-creative-card {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--card-bg);
}
.wizard-creative-card img {
  width: 100%;
  object-fit: contain;
  display: block;
}
.wizard-creative-card .creative-format-label {
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  background: var(--bg);
}
.wizard-creative-actions {
  display: flex;
  gap: 4px;
  padding: 6px;
  background: var(--bg);
  flex-wrap: wrap;
}
.wizard-creative-actions button {
  flex: 1;
  min-width: 0;
  padding: 5px 8px;
  font-size: 11px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--card-bg);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}
.wizard-creative-actions button:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* Wizard overlay edit form inline */
.wizard-overlay-edit {
  padding: 8px;
  background: var(--bg);
  border-top: 1px solid var(--border);
}
.wizard-overlay-edit .form-group {
  margin-bottom: 6px;
}
.wizard-overlay-edit label {
  font-size: 11px;
}
.wizard-overlay-edit input {
  font-size: 12px;
  padding: 4px 8px;
}

/* Ad copy display in wizard */
.wizard-ad-copy-field {
  margin-bottom: 12px;
}
.wizard-ad-copy-field .wizard-field-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  margin-bottom: 2px;
}
.wizard-ad-copy-field .wizard-field-value {
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.5;
}

.wizard-meta-copy {
  white-space: pre-wrap;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-primary);
}

/* Hidden file input for image replacement */
.wizard-hidden-input {
  display: none;
}

@media (max-width: 768px) {
  .wizard-choice {
    flex-direction: column;
    align-items: center;
  }
  .wizard-choice-btn {
    max-width: 100%;
    width: 100%;
  }
  .wizard-image-gallery {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  }
  .wizard-progress-label {
    font-size: 10px;
  }
  .wizard-progress-dot {
    width: 26px;
    height: 26px;
    font-size: 12px;
  }
}
