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

:root {
  --bg: #f4f3f0;
  --surface: #ffffff;
  --border: #e5e4e0;
  --border-mid: #d0cfc9;
  --text: #1a1a18;
  --text-muted: #6b6b67;
  --text-hint: #9f9f9a;
  --accent: #7c3aed;
  --accent-light: #faf5ff;
  --accent-mid: #ede9fe;
  --accent-text: #5b21b6;
  --accent-border: #c4b5fd;
  --success: #16a34a;
  --success-bg: #f0fdf4;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --radius: 8px;
  --radius-lg: 12px;
  --sidebar-w: 220px;
}

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

/* ============================================================
   APP SHELL
   ============================================================ */
.app { display: flex; min-height: 100vh; }

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: var(--sidebar-w);
  background: #0f0f0f;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
}

.sidebar-logo {
  padding: 22px 18px 18px;
  border-bottom: 0.5px solid rgba(255,255,255,0.08);
  margin-bottom: 8px;
}

.sidebar-logo-text {
  font-size: 16px;
  font-weight: 500;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 9px;
}

.sidebar-logo-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #a78bfa;
  flex-shrink: 0;
}

.sidebar-logo-sub {
  font-size: 10px;
  color: rgba(255,255,255,0.3);
  margin-top: 3px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.nav-links {
  list-style: none;
  padding: 6px 10px;
  flex: 1;
  overflow-y: auto;
}

.nav-section-label {
  font-size: 10px;
  color: rgba(255,255,255,0.55) !important;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 10px 10px 4px;
  margin-top: 4px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border-radius: var(--radius);
  color: #ffffff !important;
  text-decoration: none;
  font-size: 15px;
  font-weight: 600;
  transition: all 0.15s;
  margin-bottom: 2px;
}

.nav-link:hover {
  background: rgba(255,255,255,0.15);
  color: #ffffff !important;
}

.nav-link.active {
  background: rgba(167,139,250,0.3);
  color: #e9d5ff !important;
  font-weight: 700;
}

.nav-link i { font-size: 20px; }

.sidebar-footer {
  padding: 14px 12px;
  border-top: 0.5px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, #a78bfa, #7c3aed);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 500;
  color: #fff;
  flex-shrink: 0;
}

.sidebar-username {
  font-size: 13px;
  color: rgba(255,255,255,0.45);
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.page-topbar {
  background: var(--surface);
  border-bottom: 0.5px solid var(--border);
  padding: 14px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}

.page-topbar-left h1 {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
}

.page-topbar-left p {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 1px;
}

.page-topbar-right {
  display: flex;
  gap: 8px;
  align-items: center;
}

.page-body { padding: 28px 32px; }

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

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 14px;
  border-radius: var(--radius);
  border: 0.5px solid var(--border-mid);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  background: var(--surface);
  color: var(--text);
  white-space: nowrap;
}

.btn:hover { background: var(--bg); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-primary:hover { background: #6d28d9; border-color: #6d28d9; }

.btn-secondary {
  background: var(--bg);
  color: var(--text-muted);
  border-color: var(--border);
}

.btn-secondary:hover { color: var(--text); }

.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn-xs { height: 24px; padding: 0 8px; font-size: 11px; }

.btn-danger { color: var(--danger); border-color: #fca5a5; }
.btn-danger:hover { background: var(--danger-bg); }

/* ============================================================
   FORM ELEMENTS
   ============================================================ */
.field-group { display: flex; flex-direction: column; gap: 5px; }

.field-group label,
.field-label {
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}

select, input[type="text"], input[type="password"], textarea {
  border: 0.5px solid var(--border-mid);
  border-radius: var(--radius);
  padding: 0 10px;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  outline: none;
  font-family: inherit;
}

select { height: 34px; min-width: 160px; cursor: pointer; }
input[type="text"], input[type="password"] { height: 34px; }
textarea { padding: 8px 10px; resize: vertical; line-height: 1.6; }

select:focus, input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(124,58,237,0.1);
}

/* ============================================================
   CONTROLS BAR
   ============================================================ */
.controls-bar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 24px;
  padding: 16px 18px;
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
}

/* ============================================================
   PLATFORM TABS
   ============================================================ */
.platform-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.ptab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: 0.5px solid var(--border);
  border-radius: 20px;
  font-size: 12px;
  cursor: pointer;
  background: var(--surface);
  color: var(--text-muted);
  transition: all 0.15s;
}

.ptab:hover { border-color: var(--border-mid); color: var(--text); }

.ptab.active {
  background: var(--accent-mid);
  border-color: var(--accent-border);
  color: var(--accent-text);
  font-weight: 500;
}

/* ============================================================
   SAVE BAR
   ============================================================ */
.save-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--accent-light);
  border: 0.5px solid var(--accent-border);
  border-radius: var(--radius);
  margin-bottom: 20px;
}

.count-summary { font-size: 13px; color: var(--accent-text); font-weight: 500; }

/* ============================================================
   POST CARDS - 2 COLUMN GRID
   ============================================================ */
#posts-container .section-label {
  grid-column: 1 / -1;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-hint);
  margin: 16px 0 8px;
}

.posts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.post-card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.post-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.post-meta { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; }

.badge { font-size: 11px; padding: 3px 9px; border-radius: 20px; font-weight: 500; }
.badge-fb { background: #dbeafe; color: #1e40af; }
.badge-li { background: #dbeafe; color: #1e40af; }
.badge-tw { background: #f3f4f6; color: #374151; }
.badge-bs { background: #ede9fe; color: #5b21b6; }
.badge-product { background: var(--bg); color: var(--text-muted); }

.char-count { font-size: 11px; color: var(--text-hint); }
.char-over { color: var(--danger); }

.post-body {
  font-size: 13px;
  line-height: 1.75;
  color: var(--text-muted);
  white-space: pre-wrap;
  border-left: 2px solid var(--accent-border);
  padding-left: 12px;
  flex: 1;
}

.post-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ============================================================
   IMAGE PROMPT
   ============================================================ */
.image-prompt-box {
  background: var(--accent-light);
  border: 0.5px solid var(--accent-border);
  border-radius: var(--radius);
  padding: 10px 12px;
}

.image-prompt-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #a78bfa;
  margin-bottom: 5px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.image-prompt-text {
  font-size: 12px;
  line-height: 1.6;
  color: var(--accent-text);
  margin-bottom: 8px;
  font-style: italic;
}

.image-prompt-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.image-attach-box {
  border-top: 0.5px solid var(--border);
  padding-top: 10px;
}

.image-attach-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.image-preview { margin-bottom: 8px; }

/* ============================================================
   SECTION LABEL (standalone)
   ============================================================ */
.section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-hint);
  margin: 20px 0 10px;
}

/* ============================================================
   EMPTY & LOADING STATES
   ============================================================ */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.loading-state {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border-mid);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

.error-box {
  background: var(--danger-bg);
  border: 0.5px solid #fca5a5;
  border-radius: var(--radius);
  padding: 12px 16px;
  color: var(--danger);
  font-size: 13px;
  margin-bottom: 12px;
}

/* ============================================================
   SCHEDULE
   ============================================================ */
.schedule-nav {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 10px;
  margin-bottom: 24px;
}

.cal-day {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px;
  min-height: 120px;
}

.cal-today { border-color: var(--accent); }

.cal-day-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  padding-bottom: 7px;
  border-bottom: 0.5px solid var(--border);
}

.cal-day-name {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 500;
}

.cal-day-num { font-size: 14px; font-weight: 500; color: var(--text); }

.cal-today-num {
  background: var(--accent);
  color: #fff;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}

.cal-post-item {
  background: var(--accent-light);
  border: 0.5px solid var(--accent-border);
  border-radius: 6px;
  padding: 6px 8px;
  margin-bottom: 6px;
  font-size: 11px;
}

.cal-post-top {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}

.cal-remove-btn {
  margin-left: auto;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0;
  font-size: 12px;
  line-height: 1;
}

.cal-remove-btn:hover { color: var(--danger); }

.cal-post-preview {
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.4;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.cal-post-collapsed { cursor: pointer; }
.cal-post-collapsed:hover { color: var(--accent); }
.cal-post-full { margin-top: 6px; }

/* ============================================================
   LIBRARY
   ============================================================ */
.batch-card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 12px;
  overflow: hidden;
}

.batch-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  cursor: pointer;
}

.batch-header:hover { background: var(--bg); }
.batch-title { font-weight: 500; font-size: 14px; }
.batch-date { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.batch-body {
  border-top: 0.5px solid var(--border);
  padding: 16px 18px;
  display: none;
}

.batch-body.open { display: block; }

/* ============================================================
   SETTINGS
   ============================================================ */
.settings-card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  max-width: 620px;
}

.settings-card h2 {
  font-size: 15px;
  font-weight: 500;
  margin-bottom: 6px;
}

.help-text {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 5px;
  line-height: 1.6;
}

.help-text a { color: var(--accent); }
.divider { border: none; border-top: 0.5px solid var(--border); margin: 24px 0; }

.products-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.product-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: 20px;
  font-size: 12px;
  color: var(--text-muted);
}

.settings-msg { margin-top: 12px; font-size: 13px; }
.settings-msg.ok { color: var(--success); }
.settings-msg.err { color: var(--danger); }

/* ============================================================
   GROUPS
   ============================================================ */
.group-dropdown {
  position: fixed;
  z-index: 2000;
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 24px rgba(0,0,0,0.1);
  min-width: 240px;
  overflow: hidden;
}

.group-dropdown-item {
  display: block;
  padding: 11px 16px;
  font-size: 13px;
  color: var(--text);
  text-decoration: none;
  border-bottom: 0.5px solid var(--border);
}

.group-dropdown-item:last-child { border-bottom: none; }
.group-dropdown-item:hover { background: var(--bg); }

.group-list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 6px;
}

/* ============================================================
   TOAST
   ============================================================ */
.toast {
  position: fixed;
  bottom: 28px;
  right: 28px;
  background: #1a1a18;
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.25s;
  pointer-events: none;
  z-index: 999;
}

.toast.show { opacity: 1; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1000px) {
  .posts-grid { grid-template-columns: 1fr; }
  .calendar-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 700px) {
  .main { margin-left: 0; }
  .sidebar { display: none; }
  .page-body { padding: 16px; }
  .page-topbar { padding: 12px 16px; }
  .calendar-grid { grid-template-columns: 1fr 1fr; }
  .controls-bar { flex-direction: column; align-items: stretch; }
}
