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

:root {
  --bg:            var(--tg-theme-bg-color, #f2f2f7);
  --text:          var(--tg-theme-text-color, #1c1c1e);
  --hint:          var(--tg-theme-hint-color, #8e8e93);
  --link:          var(--tg-theme-link-color, #007aff);
  --button:        var(--tg-theme-button-color, #007aff);
  --button-text:   var(--tg-theme-button-text-color, #ffffff);
  --secondary-bg:  var(--tg-theme-secondary-bg-color, #ffffff);
  --accent:        var(--tg-theme-accent-text-color, #007aff);
  --section-bg:    var(--tg-theme-section-bg-color, #ffffff);
  --section-sep:   var(--tg-theme-section-separator-color, #c6c6c8);
  --section-header:var(--tg-theme-section-header-text-color, #6d6d71);
  --destructive:   var(--tg-theme-destructive-text-color, #ff3b30);

  /* Platform palette */
  --ig:    #e1306c;
  --yt:    #ff0000;
  --tg:    #229ed9;
  --tw:    #1da1f2;
  --tt:    #010101;
  --fb:    #1877f2;

  /* Status palette */
  --s-idea:      #8e8e93;
  --s-draft:     #ff9500;
  --s-ready:     #34c759;
  --s-scheduled: #007aff;
  --s-posted:    #34c759;
  --s-overdue:   #ff3b30;

  --radius:    14px;
  --radius-sm: 10px;
  --radius-xs: 7px;
  --nav-h:     56px;
  --safe-b:    env(safe-area-inset-bottom, 0px);
  --safe-t:    env(safe-area-inset-top, 0px);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ── App shell ───────────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* ── Scrollable tab area ─────────────────────────────────────────────────── */
.tab-content {
  flex: 1;
  overflow-y: auto;
  padding: 0 0 calc(var(--nav-h) + var(--safe-b) + 8px);
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

/* ── Page header ─────────────────────────────────────────────────────────── */
.page-header {
  padding: 14px 16px 8px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

/* ── Section group (iOS-style grouped list) ──────────────────────────────── */
.section {
  margin: 0 0 6px;
}

.section-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--section-header);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 14px 20px 6px;
}

.section-body {
  background: var(--section-bg);
  border-top: 0.5px solid var(--section-sep);
  border-bottom: 0.5px solid var(--section-sep);
}

/* ── Row (inside section-body) ───────────────────────────────────────────── */
.row {
  padding: 12px 16px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  cursor: pointer;
  transition: background 0.12s;
  position: relative;
}

.row:active { background: color-mix(in srgb, var(--hint) 10%, transparent); }

.row + .row::before {
  content: '';
  position: absolute;
  top: 0;
  left: 16px;
  right: 0;
  height: 0.5px;
  background: var(--section-sep);
}

.row-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-xs);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  flex-shrink: 0;
}

.row-content { flex: 1; min-width: 0; }
.row-title   { font-size: 15px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub     { font-size: 13px; color: var(--hint); margin-top: 2px; }
.row-right   { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.row-arrow   { color: var(--hint); font-size: 17px; line-height: 1; }

/* ── Standalone card (for dashboard items that aren't in a list) ─────────── */
.card {
  background: var(--section-bg);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin: 0 12px 10px;
}

.card-title { font-weight: 600; font-size: 15px; margin-bottom: 5px; }

/* ── Dashboard summary strip ─────────────────────────────────────────────── */
.summary-strip {
  display: flex;
  gap: 10px;
  padding: 12px 12px 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.summary-strip::-webkit-scrollbar { display: none; }

.summary-tile {
  background: var(--section-bg);
  border-radius: var(--radius);
  padding: 14px 16px;
  flex-shrink: 0;
  min-width: 110px;
  text-align: center;
}

.summary-tile .num {
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 4px;
}

.summary-tile .lbl {
  font-size: 12px;
  color: var(--hint);
  font-weight: 500;
}

.tile-overdue .num { color: var(--destructive); }
.tile-upcoming .num { color: var(--button); }
.tile-yt .num { color: var(--yt); }

/* ── Badge / pill ────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

/* Status badges */
.badge-idea      { background: color-mix(in srgb, var(--s-idea) 15%, transparent);      color: var(--s-idea); }
.badge-draft     { background: color-mix(in srgb, var(--s-draft) 15%, transparent);     color: var(--s-draft); }
.badge-ready     { background: color-mix(in srgb, var(--s-ready) 18%, transparent);     color: var(--s-ready); }
.badge-scheduled { background: color-mix(in srgb, var(--s-scheduled) 15%, transparent); color: var(--s-scheduled); }
.badge-posted    { background: color-mix(in srgb, var(--s-posted) 15%, transparent);    color: var(--s-posted); }
.badge-overdue   { background: color-mix(in srgb, var(--s-overdue) 13%, transparent);   color: var(--s-overdue); }

/* Source badges */
.badge-direct  { background: color-mix(in srgb, var(--button) 12%, transparent);      color: var(--button); }
.badge-queued  { background: color-mix(in srgb, var(--s-draft) 12%, transparent);     color: var(--s-draft); }
.badge-done    { background: color-mix(in srgb, var(--s-ready) 12%, transparent);     color: var(--s-ready); }
.badge-running { background: color-mix(in srgb, #007aff 12%, transparent);            color: #007aff; }
.badge-failed  { background: color-mix(in srgb, var(--destructive) 12%, transparent); color: var(--destructive); }
.badge-pending { background: color-mix(in srgb, var(--s-idea) 12%, transparent);      color: var(--s-idea); }

/* Platform dots */
.platform-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-instagram { background: var(--ig); }
.dot-youtube   { background: var(--yt); }
.dot-twitter   { background: var(--tw); }
.dot-tiktok    { background: var(--tt); }
.dot-facebook  { background: var(--fb); }
.dot-other     { background: var(--hint); }

/* ── Filter chips ────────────────────────────────────────────────────────── */
.chip-scroll {
  display: flex;
  gap: 8px;
  padding: 12px 16px 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.chip-scroll::-webkit-scrollbar { display: none; }

.chip {
  flex-shrink: 0;
  padding: 6px 14px;
  border-radius: 20px;
  border: 1.5px solid color-mix(in srgb, var(--hint) 30%, transparent);
  background: none;
  color: var(--hint);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.12s;
  white-space: nowrap;
}
.chip.active {
  border-color: var(--button);
  background: color-mix(in srgb, var(--button) 12%, transparent);
  color: var(--button);
  font-weight: 600;
}

/* ── Bottom nav ──────────────────────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: var(--section-bg);
  border-top: 0.5px solid var(--section-sep);
  display: flex;
  z-index: 100;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--hint);
  font-size: 10px;
  font-weight: 500;
  padding: 4px 0 0;
  transition: color 0.15s;
  position: relative;
}
.nav-btn.active { color: var(--button); }
.nav-btn.active::after {
  content: '';
  position: absolute;
  top: 0; left: 25%; right: 25%;
  height: 2px;
  background: var(--button);
  border-radius: 0 0 2px 2px;
}
.nav-icon { font-size: 21px; line-height: 1; }

/* ── FAB ─────────────────────────────────────────────────────────────────── */
.fab {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--safe-b) + 16px);
  right: 16px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--button);
  color: var(--button-text);
  border: none;
  font-size: 28px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 20px color-mix(in srgb, var(--button) 45%, transparent);
  z-index: 50;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: opacity 0.12s;
  white-space: nowrap;
}
.btn:active { opacity: 0.7; }
.btn-primary { background: var(--button);  color: var(--button-text); }
.btn-ghost   { background: color-mix(in srgb, var(--hint) 12%, transparent); color: var(--text); }
.btn-danger  { background: color-mix(in srgb, var(--destructive) 12%, transparent); color: var(--destructive); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-xs { padding: 4px 10px; font-size: 12px; border-radius: var(--radius-xs); }

/* ── Form inputs ─────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-label { font-size: 13px; color: var(--hint); font-weight: 500; margin-bottom: 5px; display: block; }

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  border: 1.5px solid color-mix(in srgb, var(--hint) 25%, transparent);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s;
  -webkit-appearance: none;
}
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--button); }
.form-textarea { resize: vertical; min-height: 80px; font-family: inherit; }

/* ── Sub-page overlay ────────────────────────────────────────────────────── */
.subpage {
  position: fixed;
  top: 0; left: 0; right: 0;
  bottom: calc(var(--nav-h) + var(--safe-b));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
  z-index: 150;
}
.subpage-header {
  position: sticky;
  top: 0;
  background: var(--section-bg);
  border-bottom: 0.5px solid var(--section-sep);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(var(--safe-t) + 10px) 12px 10px;
  z-index: 1;
}
.back-btn {
  background: none;
  border: none;
  font-size: 28px;
  line-height: 1;
  color: var(--button);
  cursor: pointer;
  padding: 0 4px;
  flex-shrink: 0;
}

/* ── Bottom sheet ────────────────────────────────────────────────────────── */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  display: flex;
  align-items: flex-end;
}

.sheet {
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-height: 88dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 16px calc(var(--safe-b) + 20px);
}

.sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: color-mix(in srgb, var(--hint) 30%, transparent);
  margin: 8px auto 16px;
}

.sheet-title { font-size: 18px; font-weight: 700; margin-bottom: 18px; }

/* ── Toast ───────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--safe-b) + 14px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  background: color-mix(in srgb, var(--text) 90%, transparent);
  color: var(--secondary-bg);
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  z-index: 300;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  white-space: nowrap;
  max-width: calc(100vw - 48px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty {
  text-align: center;
  padding: 56px 24px;
  color: var(--hint);
}
.empty-icon { font-size: 52px; margin-bottom: 12px; }
.empty p { font-size: 15px; line-height: 1.5; }

/* ── Spinner ─────────────────────────────────────────────────────────────── */
.spinner {
  width: 24px;
  height: 24px;
  border: 2.5px solid color-mix(in srgb, var(--button) 20%, transparent);
  border-top-color: var(--button);
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
  flex-shrink: 0;
}
.spin-center { display: flex; justify-content: center; padding: 48px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Sub-tabs ────────────────────────────────────────────────────────────── */
.subtab-row {
  display: flex;
  margin: 0 12px 12px;
  background: color-mix(in srgb, var(--hint) 12%, transparent);
  border-radius: var(--radius-sm);
  padding: 3px;
}
.subtab {
  flex: 1;
  padding: 7px;
  border: none;
  background: none;
  border-radius: var(--radius-xs);
  font-size: 13px;
  font-weight: 500;
  color: var(--hint);
  cursor: pointer;
  transition: all 0.15s;
}
.subtab.active {
  background: var(--section-bg);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* ── Timeline dot (for schedule list) ───────────────────────────────────── */
.timeline-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--section-bg);
  flex-shrink: 0;
  margin-top: 4px;
}

/* ── Collapsible rows ────────────────────────────────────────────────────── */
.collapsible-header {
  cursor: pointer;
  user-select: none;
}
.collapsible-header:active { opacity: 0.7; }
.chevron { transition: transform 0.2s; color: var(--hint); font-size: 14px; }
.chevron.open { transform: rotate(90deg); }

/* ── Idea body text ──────────────────────────────────────────────────────── */
.idea-body {
  font-size: 13px;
  color: var(--hint);
  line-height: 1.5;
  margin-top: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.idea-body.expanded {
  display: block;
  -webkit-line-clamp: unset;
}

/* ── Platform icon squares ───────────────────────────────────────────────── */
.icon-ig { background: linear-gradient(135deg, #f09433, #e6683c, #dc2743, #cc2366, #bc1888); }
.icon-yt { background: var(--yt); }
.icon-tg { background: var(--tg); }
.icon-tw { background: var(--tw); }
.icon-tt { background: #010101; }
.icon-fb { background: var(--fb); }
.icon-other { background: var(--hint); }

/* ── Misc utilities ──────────────────────────────────────────────────────── */
.flex-row  { display: flex; align-items: center; gap: 8px; }
.flex-col  { display: flex; flex-direction: column; gap: 6px; }
.flex-1    { flex: 1; min-width: 0; }
.gap-4     { gap: 4px; }
.gap-8     { gap: 8px; }
.mt-4      { margin-top: 4px; }
.mt-8      { margin-top: 8px; }
.mt-12     { margin-top: 12px; }
.mb-8      { margin-bottom: 8px; }
.px-16     { padding-left: 16px; padding-right: 16px; }
.text-hint { color: var(--hint); }
.text-sm   { font-size: 13px; }
.text-xs   { font-size: 11px; }
.text-bold { font-weight: 600; }
.text-danger { color: var(--destructive); }
.line-clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.nowrap    { white-space: nowrap; }

a { color: var(--link); text-decoration: none; }
