/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root,
[data-theme="dark"] {
  --bg: #0f1117;
  --bg2: #1a1d27;
  --bg3: #22263a;
  --border: #2e3348;
  --accent: #6c63ff;
  --accent2: #5a52e0;
  --accent-glow: rgba(108,99,255,0.18);
  --text: #e8eaf6;
  --text2: #9095b0;
  --text3: #5c6180;
  --success: #22d3a0;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #38bdf8;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --transition: 0.18s ease;
  --code-bg: #0d0f1a;
}

[data-theme="light"] {
  --bg: #f0f2f9;
  --bg2: #ffffff;
  --bg3: #e8eaf4;
  --border: #d0d4e8;
  --accent: #6c63ff;
  --accent2: #5a52e0;
  --accent-glow: rgba(108,99,255,0.12);
  --text: #1a1d2e;
  --text2: #5c6180;
  --text3: #9095b0;
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --info: #0284c7;
  --shadow: 0 4px 24px rgba(0,0,0,0.1);
  --code-bg: #f3f4f8;
}

html, body { height: 100%; font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.6; }

a { color: var(--accent); text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, textarea, select { font-family: inherit; }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ===== LAYOUT ===== */
#app { display: flex; height: 100vh; overflow: hidden; }

/* ===== SIDEBAR ===== */
.sidebar {
  width: 240px; min-width: 240px; background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  transition: width var(--transition);
  overflow: hidden;
}
.sidebar-logo {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.sidebar-logo .logo-icon {
  width: 34px; height: 34px; background: var(--accent);
  border-radius: 9px; display: flex; align-items: center; justify-content: center;
  font-size: 16px; flex-shrink: 0;
}
.sidebar-logo span { font-weight: 700; font-size: 15px; color: var(--text); white-space: nowrap; }
.sidebar-logo small { display: block; font-size: 10px; color: var(--text2); font-weight: 400; }

.sidebar-nav { flex: 1; padding: 12px 10px; overflow-y: auto; }
.sidebar-section { margin-bottom: 6px; }
.sidebar-section-title {
  font-size: 10px; font-weight: 600; color: var(--text3);
  text-transform: uppercase; letter-spacing: 1px;
  padding: 6px 10px; margin-bottom: 2px;
}
.sidebar-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--text2); font-size: 13.5px; font-weight: 500;
  cursor: pointer; transition: all var(--transition);
  border: 1px solid transparent; user-select: none;
  white-space: nowrap; overflow: hidden;
}
.sidebar-item:hover { background: var(--bg3); color: var(--text); }
.sidebar-item.active { background: var(--accent-glow); color: var(--accent); border-color: rgba(108,99,255,0.2); }
.sidebar-item .icon { font-size: 16px; flex-shrink: 0; }
.sidebar-item .badge {
  margin-left: auto; background: var(--accent); color: #fff;
  font-size: 10px; font-weight: 700; padding: 1px 6px;
  border-radius: 20px; flex-shrink: 0;
}
.sidebar-item .label { overflow: hidden; text-overflow: ellipsis; }

.sidebar-footer {
  padding: 12px 10px; border-top: 1px solid var(--border);
}

/* ===== MAIN CONTENT ===== */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.topbar {
  height: 56px; min-height: 56px;
  background: var(--bg2); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 24px; gap: 12px;
}
.topbar-title { font-size: 16px; font-weight: 700; flex: 1; }
.topbar-actions { display: flex; gap: 8px; }
.breadcrumb { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text2); }
.breadcrumb span { color: var(--text3); }

.content { flex: 1; overflow-y: auto; padding: 28px; }

/* ===== PAGES ===== */
.page { display: none; }
.page.active { display: block; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 16px; border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight: 600; border: none;
  transition: all var(--transition); white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent2); box-shadow: 0 0 20px var(--accent-glow); }
.btn-secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-ghost { background: transparent; color: var(--text2); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg3); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.85; }
.btn-success { background: var(--success); color: #000; }
.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn-icon { padding: 7px; gap: 0; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== CARDS ===== */
.card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-title { font-size: 15px; font-weight: 700; }
.card-subtitle { font-size: 12px; color: var(--text2); margin-top: 2px; }

/* ===== PROJECT CARDS (DASHBOARD) ===== */
.projects-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px;
}
.project-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
  cursor: pointer; transition: all var(--transition);
  position: relative; overflow: hidden;
}
.project-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--accent);
}
.project-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow); }
.project-card-name { font-size: 16px; font-weight: 700; margin-bottom: 6px; }
.project-card-desc { font-size: 12.5px; color: var(--text2); margin-bottom: 14px; min-height: 36px; }
.project-card-meta { display: flex; gap: 12px; font-size: 11.5px; color: var(--text3); }
.project-card-meta span { display: flex; align-items: center; gap: 4px; }
.project-card-actions {
  position: absolute; top: 12px; right: 12px;
  display: flex; gap: 4px;
  opacity: 0; transition: opacity var(--transition);
}
.project-card:hover .project-card-actions { opacity: 1; }
.project-add-card {
  background: transparent; border: 2px dashed var(--border);
  border-radius: var(--radius); padding: 20px;
  cursor: pointer; transition: all var(--transition);
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 10px; min-height: 140px;
  color: var(--text3);
}
.project-add-card:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-glow); }
.project-add-card .add-icon { font-size: 28px; }

/* ===== TABS ===== */
.tabs {
  display: flex; gap: 2px; border-bottom: 1px solid var(--border);
  margin-bottom: 24px; overflow-x: auto;
}
.tab {
  padding: 10px 18px; font-size: 13.5px; font-weight: 600;
  color: var(--text2); cursor: pointer; border-bottom: 2px solid transparent;
  white-space: nowrap; transition: all var(--transition);
  margin-bottom: -1px; display: flex; align-items: center; gap: 7px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* Sub-tabs */
.subtabs { display: flex; gap: 8px; margin-bottom: 20px; }
.subtab {
  padding: 7px 14px; border-radius: 20px; font-size: 13px; font-weight: 600;
  color: var(--text2); cursor: pointer; transition: all var(--transition);
  border: 1px solid transparent;
}
.subtab:hover { color: var(--text); }
.subtab.active { background: var(--accent); color: #fff; }

/* ===== TABLE ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: 11px; font-weight: 700;
  color: var(--text3); text-transform: uppercase; letter-spacing: 0.5px;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td { padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.02); }

/* ===== BADGE/STATUS ===== */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 600;
}
.badge-draft { background: rgba(148,163,184,0.15); color: #94a3b8; }
.badge-scheduled { background: rgba(245,158,11,0.15); color: var(--warning); }
.badge-sent { background: rgba(34,211,160,0.15); color: var(--success); }
.badge-active { background: rgba(34,211,160,0.15); color: var(--success); }
.badge-paused { background: rgba(245,158,11,0.15); color: var(--warning); }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  display: none; align-items: center; justify-content: center;
  z-index: 1000; padding: 20px; backdrop-filter: blur(4px);
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); width: 100%; max-width: 600px;
  max-height: 90vh; display: flex; flex-direction: column;
  box-shadow: var(--shadow);
}
.modal-lg { max-width: 860px; }
.modal-xl { max-width: 1100px; }
.modal-header {
  padding: 20px 24px 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.modal-title { font-size: 16px; font-weight: 700; }
.modal-close {
  width: 30px; height: 30px; border-radius: 6px; background: var(--bg3);
  border: none; color: var(--text2); display: flex;
  align-items: center; justify-content: center; cursor: pointer;
  flex-shrink: 0;
}
.modal-close:hover { background: var(--border); color: var(--text); }
.modal-close svg { pointer-events: none; }
.modal-body { padding: 20px 24px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 16px 24px; border-top: 1px solid var(--border);
  display: flex; gap: 10px; justify-content: flex-end; flex-shrink: 0;
}

/* ===== FORM ===== */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text2); margin-bottom: 6px; }
.form-control {
  width: 100%; padding: 9px 13px; background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); font-size: 13.5px; transition: border-color var(--transition);
  outline: none;
}
.form-control:focus { border-color: var(--accent); }
.form-control::placeholder { color: var(--text3); }
textarea.form-control { resize: vertical; min-height: 90px; }
select.form-control { cursor: pointer; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-hint { font-size: 11.5px; color: var(--text3); margin-top: 5px; }

/* ===== CODE EDITOR ===== */
.code-editor {
  background: var(--code-bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px;
  font-family: 'Fira Code', 'Consolas', monospace; font-size: 12.5px;
  line-height: 1.7; color: #a8b4e8; min-height: 200px;
  width: 100%; resize: vertical; outline: none;
}
.code-editor:focus { border-color: var(--accent); }

/* ===== AI GENERATE AREA ===== */
.ai-box {
  background: linear-gradient(135deg, rgba(108,99,255,0.08), rgba(108,99,255,0.03));
  border: 1px solid rgba(108,99,255,0.25); border-radius: var(--radius);
  padding: 18px;
}
.ai-box-header { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.ai-box-header .ai-badge {
  background: var(--accent); color: #fff; font-size: 11px; font-weight: 700;
  padding: 2px 8px; border-radius: 20px;
}
.ai-box-title { font-weight: 700; font-size: 14px; }

/* ===== EMPTY STATE ===== */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 60px 20px; text-align: center;
}
.empty-state .empty-icon { font-size: 48px; margin-bottom: 14px; opacity: 0.5; }
.empty-state h3 { font-size: 16px; font-weight: 700; margin-bottom: 6px; }
.empty-state p { font-size: 13px; color: var(--text2); max-width: 320px; margin-bottom: 20px; }

/* ===== STATS CARDS ===== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.stat-label { font-size: 11.5px; color: var(--text2); font-weight: 600; margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-value { font-size: 28px; font-weight: 800; }
.stat-change { font-size: 11px; color: var(--success); margin-top: 3px; }

/* ===== CONTACT IMPORT ===== */
.drop-zone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 40px 20px; text-align: center; cursor: pointer;
  transition: all var(--transition); color: var(--text2);
}
.drop-zone:hover, .drop-zone.dragover { border-color: var(--accent); background: var(--accent-glow); color: var(--accent); }
.drop-zone .drop-icon { font-size: 36px; margin-bottom: 10px; }
.drop-zone p { font-size: 13px; }
.drop-zone strong { color: var(--accent); }

/* ===== SEARCH ===== */
.search-bar {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 7px 13px;
}
.search-bar input { background: none; border: none; outline: none; color: var(--text); flex: 1; font-size: 13.5px; }
.search-bar .search-icon { color: var(--text3); font-size: 14px; }

/* ===== CHECKBOX ===== */
.checkbox-wrap { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.checkbox-wrap input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

/* ===== TOGGLE ===== */
.toggle-wrap { display: flex; align-items: center; gap: 12px; }
.toggle {
  position: relative; width: 40px; height: 22px;
  background: var(--border); border-radius: 11px; cursor: pointer;
  transition: background var(--transition);
}
.toggle.on { background: var(--accent); }
.toggle::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 16px; height: 16px; border-radius: 50%; background: #fff;
  transition: transform var(--transition);
}
.toggle.on::after { transform: translateX(18px); }

/* ===== LOADER ===== */
.loader {
  display: inline-block; width: 18px; height: 18px;
  border: 2px solid rgba(108,99,255,0.3); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== NOTIFICATIONS ===== */
.notifications {
  position: fixed; bottom: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 8px; z-index: 9999;
}
.notif {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 16px;
  display: flex; align-items: center; gap: 10px;
  font-size: 13.5px; box-shadow: var(--shadow); min-width: 260px;
  animation: slideIn 0.2s ease;
}
.notif-success { border-left: 3px solid var(--success); }
.notif-error { border-left: 3px solid var(--danger); }
.notif-info { border-left: 3px solid var(--info); }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }

/* ===== COLOR DOT ===== */
.color-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* ===== TEMPLATE PREVIEW ===== */
.template-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px;
}
.template-card {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; cursor: pointer;
  transition: all var(--transition);
}
.template-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.template-card-preview {
  height: 140px; overflow: hidden; background: #fff;
  position: relative;
}
.template-card-preview iframe {
  width: 200%; height: 200%; transform: scale(0.5); transform-origin: top left;
  border: none; pointer-events: none;
}
.template-card-info { padding: 12px; }
.template-card-name { font-size: 13px; font-weight: 700; margin-bottom: 4px; }
.template-card-meta { font-size: 11.5px; color: var(--text2); }
.template-card-actions { display: flex; gap: 6px; margin-top: 10px; }

/* ===== WEBHOOK ITEM ===== */
.webhook-item {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px;
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 10px;
}
.webhook-url { flex: 1; font-family: monospace; font-size: 12.5px; color: var(--text2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== SECTION HEADER ===== */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }
.section-title { font-size: 18px; font-weight: 800; }
.section-subtitle { font-size: 13px; color: var(--text2); margin-top: 2px; }

/* ===== TAG ===== */
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--bg3); border: 1px solid var(--border);
  padding: 3px 9px; border-radius: 20px; font-size: 11.5px; color: var(--text2);
}

/* ===== PROGRESS ===== */
.progress-bar { background: var(--bg3); border-radius: 10px; height: 6px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 10px; transition: width 0.4s ease; }

/* ===== LIGHT MODE OVERRIDES ===== */
[data-theme="light"] .sidebar { background: #ffffff; }
[data-theme="light"] .topbar  { background: #ffffff; }
[data-theme="light"] .code-editor { color: #3730a3; }
[data-theme="light"] pre { color: #3730a3 !important; }
[data-theme="light"] .template-card-preview { background: #f3f4f8; }
[data-theme="light"] .modal { background: #ffffff; }
[data-theme="light"] .notif  { background: #ffffff; }

/* ===== SVG ICON COLORING ===== */
/* Buttons inherit their own text color; SVGs follow currentColor */
.btn svg { flex-shrink: 0; }

/* Ghost/secondary buttons: icons use text color */
.btn-ghost svg,
.btn-secondary svg { color: inherit; }

/* Primary buttons: always white icon */
.btn-primary svg { color: #fff; }

/* Danger buttons: always white icon */
.btn-danger svg  { color: #fff; }

/* Standalone icon buttons (icon-only, no label) */
.btn-icon { color: var(--text2); }
.btn-icon:hover { color: var(--text); }

/* Sidebar icons */
.sidebar-item svg { color: inherit; }

/* Topbar action icons — match button color */
#topbar-actions .btn svg { color: inherit; }

/* Theme toggle icon */
.theme-toggle svg { color: var(--text2); }
.theme-toggle:hover svg { color: var(--text); }

/* Light-mode: ghost/secondary icon buttons get accent color */
[data-theme="light"] .btn-ghost svg,
[data-theme="light"] .btn-secondary svg { color: var(--accent); }
[data-theme="light"] .btn-icon { color: var(--accent); }
[data-theme="light"] .btn-icon:hover { color: var(--accent2); }
[data-theme="light"] .sidebar-item svg { color: inherit; }
[data-theme="light"] .sidebar-item.active svg { color: var(--accent); }

/* ===== THEME TOGGLE ===== */
.theme-toggle {
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--bg3); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all var(--transition);
}
.theme-toggle:hover { background: var(--border); }

/* ===== LABEL ROW ===== */
.label-row:hover { background: var(--bg3); }
.label-row:hover .label-row-actions { opacity: 1 !important; }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .sidebar { width: 200px; min-width: 200px; }
  .content { padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
