:root {
  --bg: #f0f4ff;
  --surface: #ffffff;
  --card: #ffffff;
  --card2: #f5f7ff;
  --border: #e5e8f5;
  --border2: #edeef8;
  --primary: #5c35d4;
  --primary-light: #7c5ce8;
  --primary-dark: #3d1fa8;
  --primary-bg: #f0ebff;
  --accent: #f59e0b;
  --success: #059669;
  --error: #dc2626;
  --warn: #d97706;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --text-dim: #9ca3af;
  --fb: #1877f2; --ig: #e1306c; --tt: #ff0050; --yt: #ff0000; --tw: #1da1f2; --li: #0a66c2;
  --sidebar-w: 224px;
  --header-h: 58px;
  --bottom-nav-h: 64px;
  --shadow: 0 1px 8px rgba(80,60,200,0.08);
  --shadow-md: 0 4px 20px rgba(80,60,200,0.12);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { scroll-behavior: smooth; }
body { background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; font-size: 15px; line-height: 1.5; overflow: hidden; height: 100dvh; }

#app { display: flex; height: 100dvh; }

/* ── Sidebar ──────────────────────────────────────────────────────── */
#sidebar { width: var(--sidebar-w); background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; overflow: hidden; box-shadow: var(--shadow); }
.sidebar-header { display: flex; align-items: center; gap: 10px; padding: 16px 16px 14px; border-bottom: 1px solid var(--border); }
.sidebar-header img.sidebar-logo { height: 36px; object-fit: contain; }
.logo-mark { width: 36px; height: 36px; background: linear-gradient(135deg, var(--primary), var(--primary-light)); border-radius: 10px; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 0.85rem; color: white; flex-shrink: 0; }
.logo-title { font-weight: 700; font-size: 0.9rem; color: var(--text); }
.logo-sub { font-size: 0.7rem; color: var(--text-muted); }
.biz-selector { padding: 10px 12px; }
.biz-selector select { width: 100%; background: var(--card2); border: 1.5px solid var(--border); border-radius: 8px; color: var(--text); padding: 8px 10px; font-size: 0.82rem; cursor: pointer; outline: none; }
.biz-selector select:focus { border-color: var(--primary); }
.nav-links { flex: 1; padding: 8px; overflow-y: auto; }
.nav-link { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px; color: var(--text-muted); text-decoration: none; font-size: 0.87rem; font-weight: 500; transition: all 0.15s; margin-bottom: 2px; cursor: pointer; }
.nav-link:hover { background: var(--primary-bg); color: var(--primary); }
.nav-link.active { background: var(--primary-bg); color: var(--primary); font-weight: 600; }
.nav-icon { font-size: 1.1rem; width: 22px; text-align: center; }
.sidebar-footer { padding: 12px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 8px; }
.user-chip { flex: 1; font-size: 0.78rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-icon { background: none; border: none; cursor: pointer; font-size: 1rem; padding: 4px 6px; border-radius: 6px; transition: background 0.15s; color: var(--text-muted); }
.btn-icon:hover { background: var(--primary-bg); color: var(--primary); }

/* ── Main ─────────────────────────────────────────────────────────── */
#main { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: var(--bg); }
#mobile-header { display: none; align-items: center; gap: 10px; padding: 0 16px; height: var(--header-h); background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0; box-shadow: var(--shadow); }
.mobile-logo-img { height: 30px; object-fit: contain; }
.mobile-logo { font-weight: 700; font-size: 1rem; color: var(--primary); flex: 1; }
.mobile-biz-sel { background: var(--card2); border: 1.5px solid var(--border); border-radius: 8px; color: var(--text); padding: 6px 8px; font-size: 0.8rem; outline: none; max-width: 160px; }
#view-container { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 22px; padding-bottom: 22px; }
#bottom-nav { display: none; }

/* ── Bottom nav (mobile) ──────────────────────────────────────────── */
@media (max-width: 767px) {
  #sidebar { display: none; }
  #mobile-header { display: flex; }
  #view-container { padding: 16px; padding-bottom: calc(var(--bottom-nav-h) + 16px); }
  #bottom-nav { display: flex; align-items: center; justify-content: space-around; position: fixed; bottom: 0; left: 0; right: 0; height: var(--bottom-nav-h); background: var(--surface); border-top: 1px solid var(--border); z-index: 100; padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -2px 12px rgba(80,60,200,0.08); }
  .bn-btn { display: flex; flex-direction: column; align-items: center; gap: 2px; background: none; border: none; color: var(--text-muted); font-size: 0.68rem; cursor: pointer; padding: 6px 12px; border-radius: 10px; transition: color 0.15s; flex: 1; }
  .bn-btn.active { color: var(--primary); }
  .bn-icon { font-size: 1.3rem; }
  .bn-label { font-size: 0.62rem; font-weight: 500; }
  .compose-fab { background: linear-gradient(135deg, var(--primary), var(--primary-light)); color: white !important; border-radius: 50% !important; width: 52px; height: 52px; font-size: 1.5rem !important; padding: 0 !important; margin-top: -20px; box-shadow: 0 4px 20px rgba(92,53,212,0.4); flex: 0 0 52px; }
  .compose-fab .bn-label { display: none; }
}

/* ── Cards & Layout ───────────────────────────────────────────────── */
.view-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 10px; }
.view-title { font-size: 1.35rem; font-weight: 700; color: var(--text); }
.view-title span { color: var(--text-muted); font-weight: 400; font-size: 0.85rem; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 18px; box-shadow: var(--shadow); }
.card-sm { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 14px; box-shadow: var(--shadow); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 16px; box-shadow: var(--shadow); }
.stat-value { font-size: 2rem; font-weight: 800; line-height: 1; }
.stat-label { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }
.stat-icon { font-size: 1.4rem; margin-bottom: 8px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }

/* ── Buttons ──────────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 9px 16px; border-radius: 10px; font-size: 0.88rem; font-weight: 600; border: none; cursor: pointer; transition: all 0.15s; white-space: nowrap; }
.btn-primary { background: var(--primary); color: white; box-shadow: 0 2px 8px rgba(92,53,212,0.25); }
.btn-primary:hover { background: var(--primary-light); transform: translateY(-1px); }
.btn-secondary { background: var(--card2); border: 1.5px solid var(--border); color: var(--text); }
.btn-secondary:hover { border-color: var(--primary); color: var(--primary); }
.btn-success { background: rgba(5,150,105,0.1); border: 1px solid rgba(5,150,105,0.3); color: var(--success); }
.btn-danger { background: rgba(220,38,38,0.08); border: 1px solid rgba(220,38,38,0.2); color: var(--error); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; border-radius: 8px; }
.btn-lg { padding: 13px 24px; font-size: 1rem; border-radius: 12px; }
.btn:disabled { opacity: 0.5; cursor: default; transform: none !important; }

/* ── Forms ────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 0.82rem; color: var(--text-muted); margin-bottom: 6px; font-weight: 500; }
.form-control { width: 100%; background: var(--surface); border: 1.5px solid var(--border); border-radius: 10px; padding: 10px 14px; color: var(--text); font-size: 0.92rem; outline: none; transition: border-color 0.2s; font-family: inherit; }
.form-control:focus { border-color: var(--primary); background: white; }
textarea.form-control { resize: vertical; min-height: 100px; }
select.form-control { cursor: pointer; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .form-row { grid-template-columns: 1fr; } }

/* ── Platform badges ──────────────────────────────────────────────── */
.platform-badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 20px; font-size: 0.72rem; font-weight: 600; }
.badge-facebook { background: rgba(24,119,242,0.1); color: var(--fb); border: 1px solid rgba(24,119,242,0.2); }
.badge-instagram { background: rgba(225,48,108,0.1); color: var(--ig); border: 1px solid rgba(225,48,108,0.2); }
.badge-tiktok { background: rgba(255,0,80,0.1); color: var(--tt); border: 1px solid rgba(255,0,80,0.2); }
.badge-youtube { background: rgba(255,0,0,0.1); color: var(--yt); border: 1px solid rgba(255,0,0,0.2); }
.badge-twitter { background: rgba(29,161,242,0.1); color: var(--tw); border: 1px solid rgba(29,161,242,0.2); }
.badge-linkedin { background: rgba(10,102,194,0.1); color: var(--li); border: 1px solid rgba(10,102,194,0.2); }

/* ── Platform checkboxes ──────────────────────────────────────────── */
.platform-pills { display: flex; flex-wrap: wrap; gap: 8px; }
.platform-pill { display: flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 20px; border: 1.5px solid var(--border); background: var(--card2); cursor: pointer; font-size: 0.82rem; font-weight: 500; transition: all 0.15s; user-select: none; }
.platform-pill input { display: none; }
.platform-pill.sel-facebook { border-color: var(--fb); background: rgba(24,119,242,0.08); color: var(--fb); }
.platform-pill.sel-instagram { border-color: var(--ig); background: rgba(225,48,108,0.08); color: var(--ig); }
.platform-pill.sel-tiktok { border-color: var(--tt); background: rgba(255,0,80,0.08); color: var(--tt); }
.platform-pill.sel-youtube { border-color: var(--yt); background: rgba(255,0,0,0.08); color: var(--yt); }

/* ── Status badges ────────────────────────────────────────────────── */
.status { display: inline-block; padding: 3px 8px; border-radius: 20px; font-size: 0.72rem; font-weight: 600; }
.status-draft { background: #f3f4f6; color: var(--text-muted); }
.status-scheduled { background: rgba(245,158,11,0.12); color: var(--warn); }
.status-published { background: rgba(5,150,105,0.1); color: var(--success); }
.status-failed { background: rgba(220,38,38,0.1); color: var(--error); }
.status-processing { background: var(--primary-bg); color: var(--primary); }

/* ── Cards: idea / post / video ───────────────────────────────────── */
.idea-card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 14px; margin-bottom: 10px; cursor: pointer; transition: all 0.15s; box-shadow: var(--shadow); }
.idea-card:hover { border-color: var(--primary); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.idea-title { font-weight: 600; margin-bottom: 4px; color: var(--text); }
.idea-hook { font-size: 0.82rem; color: var(--text-muted); margin-bottom: 8px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.idea-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.trend-bar { flex: 1; height: 4px; background: var(--border); border-radius: 2px; min-width: 60px; }
.trend-fill { height: 100%; border-radius: 2px; background: linear-gradient(90deg, var(--primary), var(--accent)); }

.post-card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 14px; margin-bottom: 10px; box-shadow: var(--shadow); }
.post-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.post-content { font-size: 0.88rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.post-footer { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

.video-card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; display: flex; gap: 12px; margin-bottom: 10px; padding: 12px; box-shadow: var(--shadow); }
.video-thumb { width: 80px; height: 80px; background: var(--card2); border-radius: 8px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 1.8rem; overflow: hidden; }
.video-thumb img { width: 100%; height: 100%; object-fit: cover; }
.video-info { flex: 1; min-width: 0; }
.video-title { font-weight: 600; margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.video-meta { font-size: 0.78rem; color: var(--text-muted); margin-bottom: 8px; }

/* ── AI loading ───────────────────────────────────────────────────── */
.ai-loading { display: flex; align-items: center; gap: 12px; padding: 20px; color: var(--text-muted); font-size: 0.9rem; }
.spin { width: 20px; height: 20px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; flex-shrink: 0; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Script display ───────────────────────────────────────────────── */
.script-box { background: var(--card2); border: 1px solid var(--border); border-radius: 12px; padding: 16px; font-size: 0.88rem; line-height: 1.8; white-space: pre-wrap; max-height: 400px; overflow-y: auto; color: var(--text); }
.section-tag { display: inline-block; background: var(--primary-bg); color: var(--primary); font-size: 0.7rem; padding: 2px 8px; border-radius: 4px; margin-bottom: 4px; font-weight: 600; text-transform: uppercase; }

/* ── Calendar ─────────────────────────────────────────────────────── */
.cal-header { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; font-size: 0.75rem; color: var(--text-muted); margin-bottom: 8px; font-weight: 600; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-day { min-height: 70px; background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 4px 6px; font-size: 0.75rem; }
.cal-day.other-month { opacity: 0.35; }
.cal-day.today { border-color: var(--primary); background: var(--primary-bg); }
.cal-day-num { font-weight: 600; margin-bottom: 2px; color: var(--text-muted); }
.cal-day.today .cal-day-num { color: var(--primary); }
.cal-event { background: var(--primary); color: white; border-radius: 4px; padding: 1px 4px; font-size: 0.65rem; margin-bottom: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }

/* ── Upload zone ──────────────────────────────────────────────────── */
.upload-zone { border: 2px dashed var(--border); border-radius: 16px; padding: 40px; text-align: center; cursor: pointer; transition: all 0.2s; background: var(--card2); }
.upload-zone:hover, .upload-zone.drag { border-color: var(--primary); background: var(--primary-bg); }
.upload-icon { font-size: 3rem; margin-bottom: 12px; }
.upload-text { font-size: 1rem; font-weight: 600; margin-bottom: 4px; color: var(--text); }
.upload-sub { font-size: 0.82rem; color: var(--text-muted); }

/* ── Progress bar ─────────────────────────────────────────────────── */
.progress { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.progress-bar { height: 100%; background: linear-gradient(90deg, var(--primary), var(--primary-light)); border-radius: 3px; transition: width 0.3s; }

/* ── Modal ────────────────────────────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(30,20,80,0.4); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 16px; backdrop-filter: blur(4px); }
.modal-overlay.hidden { display: none; }
.modal-box { background: var(--card); border: 1px solid var(--border); border-radius: 20px; width: 100%; max-width: 560px; max-height: 90dvh; overflow-y: auto; padding: 24px; position: relative; box-shadow: var(--shadow-md); }
.modal-close { position: absolute; top: 16px; right: 16px; background: var(--card2); border: 1px solid var(--border); color: var(--text-muted); width: 32px; height: 32px; border-radius: 50%; cursor: pointer; font-size: 0.9rem; display: flex; align-items: center; justify-content: center; }
.modal-title { font-size: 1.15rem; font-weight: 700; margin-bottom: 20px; padding-right: 40px; color: var(--text); }

/* ── Toast ────────────────────────────────────────────────────────── */
#toast-container { position: fixed; top: 20px; right: 20px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 16px; font-size: 0.88rem; max-width: 320px; animation: slide-in 0.3s ease; pointer-events: all; box-shadow: var(--shadow-md); color: var(--text); }
.toast-success { border-left: 3px solid var(--success); }
.toast-error { border-left: 3px solid var(--error); }
.toast-info { border-left: 3px solid var(--primary); }
@keyframes slide-in { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes slide-out { to { transform: translateX(120%); opacity: 0; } }

/* ── Misc ─────────────────────────────────────────────────────────── */
.sep { height: 1px; background: var(--border); margin: 16px 0; }
.tag { display: inline-block; background: var(--primary-bg); color: var(--primary); border-radius: 20px; padding: 2px 8px; font-size: 0.75rem; margin: 2px; }
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-text { font-size: 1rem; font-weight: 600; margin-bottom: 4px; color: var(--text); }
.copy-btn { background: none; border: 1px solid var(--border); border-radius: 6px; color: var(--text-muted); padding: 3px 8px; font-size: 0.75rem; cursor: pointer; transition: all 0.15s; }
.copy-btn:hover { border-color: var(--primary); color: var(--primary); }
.flex { display: flex; } .flex-1 { flex: 1; } .gap-8 { gap: 8px; } .gap-12 { gap: 12px; }
.items-center { align-items: center; } .justify-between { justify-content: space-between; }
.mb-8 { margin-bottom: 8px; } .mb-12 { margin-bottom: 12px; } .mb-16 { margin-bottom: 16px; } .mb-20 { margin-bottom: 20px; }
.text-muted { color: var(--text-muted); } .text-sm { font-size: 0.82rem; } .text-xs { font-size: 0.72rem; } .fw-700 { font-weight: 700; } .fw-600 { font-weight: 600; }
.section-title { font-size: 0.95rem; font-weight: 700; margin-bottom: 12px; color: var(--text); }
.tabs { display: flex; gap: 4px; background: var(--card2); padding: 4px; border-radius: 12px; margin-bottom: 16px; overflow-x: auto; border: 1px solid var(--border); }
.tab { padding: 8px 14px; border-radius: 9px; border: none; background: none; color: var(--text-muted); font-size: 0.85rem; font-weight: 500; cursor: pointer; white-space: nowrap; transition: all 0.15s; }
.tab.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow); font-weight: 600; }
.hashtag-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.char-counter { font-size: 0.75rem; color: var(--text-muted); text-align: right; margin-top: 4px; }
.account-chip { display: flex; align-items: center; gap: 8px; background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; box-shadow: var(--shadow); }
.account-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--primary); display: flex; align-items: center; justify-content: center; font-size: 0.8rem; font-weight: 700; color: white; flex-shrink: 0; overflow: hidden; }
.account-avatar img { width: 100%; height: 100%; object-fit: cover; }
