:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --text-muted: #6b7280;
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

#app { min-height: 100vh; display: flex; flex-direction: column; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; }
.brand-mark {
  background: linear-gradient(135deg, var(--primary), #a855f7);
  color: white;
  width: 30px; height: 30px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
}

.client-switcher { display: flex; align-items: center; gap: 8px; }
.client-switcher select {
  padding: 8px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 14px;
  font-weight: 600;
  min-width: 160px;
}

.topbar-actions { margin-left: auto; }

/* ---------- Buttons ---------- */
.btn {
  border: none;
  border-radius: var(--radius);
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.05s ease, opacity 0.15s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #eef2ff; color: var(--primary-dark); }
.btn-secondary:hover { background: #e0e7ff; }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg); }
.btn-danger { background: #fee2e2; color: #b91c1c; }
.btn-danger:hover { background: #fecaca; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }

/* ---------- Layout ---------- */
.layout { display: flex; flex: 1; min-height: 0; }

.sidebar {
  width: 200px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border: none;
  background: transparent;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}
.nav-item:hover { background: var(--bg); color: var(--text); }
.nav-item.active { background: #eef2ff; color: var(--primary-dark); }
.nav-icon { font-size: 16px; }

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

/* ---------- Dashboard ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.stat-card .stat-value { font-size: 28px; font-weight: 800; }
.stat-card .stat-label { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

.section-title {
  font-size: 15px;
  font-weight: 700;
  margin: 0 0 12px;
  color: var(--text);
}

/* ---------- Post cards ---------- */
.post-list { display: flex; flex-direction: column; gap: 10px; }

.post-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.post-card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.post-badges { display: flex; gap: 6px; flex-wrap: wrap; }
.platform-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10.5px;
  font-weight: 700;
  color: white;
  border-radius: 5px;
  padding: 2px 6px;
  min-width: 22px;
  text-align: center;
}

.status-pill {
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.status-draft { background: #f3f4f6; color: #4b5563; }
.status-scheduled { background: #fef3c7; color: #92400e; }
.status-published { background: #dcfce7; color: #166534; }

.post-content { font-size: 14px; line-height: 1.5; white-space: pre-wrap; }
.post-media { max-width: 220px; border-radius: 8px; margin-top: 4px; }
.post-meta { font-size: 12.5px; color: var(--text-muted); }
.post-actions { display: flex; gap: 8px; margin-top: 4px; }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state .empty-emoji { font-size: 36px; margin-bottom: 10px; }

/* ---------- Calendar ---------- */
.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
}
.calendar-dow {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-align: center;
  padding-bottom: 4px;
}
.calendar-day {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 100px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.calendar-day.outside { opacity: 0.4; }
.calendar-day.today { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary) inset; }
.calendar-day-num { font-size: 12.5px; font-weight: 700; color: var(--text-muted); }
.calendar-post-chip {
  font-size: 11px;
  padding: 3px 6px;
  border-radius: 6px;
  background: #eef2ff;
  color: var(--primary-dark);
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.calendar-post-chip.published { background: #dcfce7; color: #166534; }

/* ---------- Accounts ---------- */
.account-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}
.account-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.account-card-top { display: flex; align-items: center; gap: 10px; }
.account-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 700; font-size: 12px;
}
.account-name { font-weight: 700; font-size: 14px; }
.account-handle { font-size: 12.5px; color: var(--text-muted); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal-overlay[hidden] { display: none; }

.modal {
  background: var(--surface);
  border-radius: 14px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-small { max-width: 400px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 0; font-size: 17px; }
.modal-close {
  border: none;
  background: transparent;
  font-size: 16px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px 8px;
}
.modal-close:hover { color: var(--text); }

.modal-body { padding: 18px 20px; display: flex; flex-direction: column; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

.field-label { font-size: 13px; font-weight: 700; margin: 14px 0 6px; }
.field-label:first-child { margin-top: 0; }
.field-hint { font-size: 12px; color: var(--text-muted); margin: 6px 0 0; }

input[type="text"], input[type="url"], input[type="datetime-local"], textarea, select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: var(--bg);
}
textarea { resize: vertical; }

.account-checklist { display: flex; flex-direction: column; gap: 8px; max-height: 160px; overflow-y: auto; }
.account-checklist label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: pointer;
}
.account-checklist label:hover { background: var(--bg); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: #111827;
  color: white;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 13.5px;
  box-shadow: var(--shadow-lg);
  z-index: 200;
}
.toast.error { background: #b91c1c; }
.toast.success { background: #166534; }
.toast[hidden] { display: none; }

@media (max-width: 720px) {
  .sidebar { width: 64px; }
  .nav-item span:last-child { display: none; }
  .topbar { flex-wrap: wrap; }
}
