:root {
  --brand: #6C5CE7;
  --sidebar-bg: #1e1b3a;
  --bg: #f4f5fb;
  --card: #ffffff;
  --text: #1f2333;
  --muted: #6b7088;
  --radius: 14px;
  --bs-primary: var(--brand);
}
* { box-sizing: border-box; }
html, body { overflow-x: hidden; }
body { font-family: 'IBM Plex Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); }

.btn-primary { --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-hover-bg: color-mix(in srgb, var(--brand) 85%, #000); --bs-btn-hover-border-color: color-mix(in srgb, var(--brand) 85%, #000); --bs-btn-active-bg: color-mix(in srgb, var(--brand) 75%, #000); --bs-btn-disabled-bg: var(--brand); --bs-btn-disabled-border-color: var(--brand); }
.btn-outline-primary { --bs-btn-color: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-hover-bg: var(--brand); --bs-btn-hover-border-color: var(--brand); --bs-btn-active-bg: var(--brand); }
.text-brand { color: var(--brand) !important; }
a { color: var(--brand); }
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }

/* Layout */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 250px; flex-shrink: 0; background: var(--sidebar-bg); color: #fff; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; z-index: 1040; }
.sidebar-brand { display: flex; gap: .75rem; align-items: center; padding: 1.25rem 1.25rem 1rem; }
.brand-mark { width: 40px; height: 40px; border-radius: 12px; background: linear-gradient(135deg, var(--brand), #fd79a8); display: grid; place-items: center; font-weight: 700; color: #fff; font-size: 1.2rem; }
.sidebar .nav-link { color: rgba(255,255,255,.75); display: flex; align-items: center; gap: .65rem; padding: .55rem 1.25rem; margin: 1px .6rem; border-radius: 10px; font-size: .94rem; }
.sidebar .nav-link:hover { background: rgba(255,255,255,.07); color: #fff; }
.sidebar .nav-link.active { background: var(--brand); color: #fff; }
.sidebar .nav-link.is-future { opacity: .55; }
.nav-section { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: rgba(255,255,255,.4); padding: 1rem 1.6rem .3rem; }
.sidebar-foot { margin-top: auto; padding: 1rem 1.25rem; border-top: 1px solid rgba(255,255,255,.08); }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: .75rem; padding: .85rem 1.5rem; background: #fff; border-bottom: 1px solid #eceef5; position: sticky; top: 0; z-index: 1020; }
.content { padding: 1.5rem; flex: 1; }
.sidebar-backdrop { display: none; }

@media (max-width: 991.98px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .sidebar-backdrop.open { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 1030; }
  .content { padding: 1rem; }
  .topbar { padding: .7rem 1rem; }
}

/* Cards */
.card { border: 0; border-radius: var(--radius); box-shadow: 0 1px 2px rgba(20,20,50,.05), 0 4px 16px rgba(20,20,50,.04); }
.card-header { background: transparent; border-bottom: 1px solid #f0f1f6; font-weight: 600; padding: .9rem 1.1rem; }
.stat-card { padding: 1rem 1.1rem; height: 100%; }
.stat-card .label { color: var(--muted); font-size: .82rem; }
.stat-card .value { font-size: 1.7rem; font-weight: 700; line-height: 1.2; }
.stat-card .icon { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: color-mix(in srgb, var(--brand) 12%, #fff); color: var(--brand); }
.quick-actions .btn { white-space: nowrap; }

/* Product cards */
.product-card { overflow: hidden; height: 100%; display: flex; flex-direction: column; }
.product-card .thumb { aspect-ratio: 1/1; background: #eef0f7 center/cover no-repeat; position: relative; }
.product-card .thumb .select { position: absolute; top: .5rem; left: .5rem; transform: scale(1.25); }
.product-card .thumb .badges { position: absolute; top: .5rem; right: .5rem; display: flex; flex-direction: column; gap: .25rem; align-items: flex-end; }
.product-card .body { padding: .8rem .9rem; flex: 1; display: flex; flex-direction: column; }
.product-card .name { font-weight: 600; font-size: .95rem; line-height: 1.3; }
.thumb-placeholder { display: grid; place-items: center; color: #b4b8cc; font-size: 2rem; height: 100%; }

.img-tile { position: relative; border-radius: 10px; overflow: hidden; aspect-ratio: 1/1; background: #eef0f7 center/cover; }
.img-tile .tools { position: absolute; inset: auto 0 0 0; display: flex; gap: .25rem; padding: .3rem; background: linear-gradient(transparent, rgba(0,0,0,.55)); }
.img-tile .primary-flag { position: absolute; top: .3rem; left: .3rem; }

/* Content preview */
.content-card { display: grid; grid-template-columns: 110px 1fr auto; gap: 1rem; padding: 1rem; align-items: start; }
.content-card .preview { width: 110px; aspect-ratio: 1/1; border-radius: 10px; background: #eef0f7 center/cover; position: relative; }
.content-card .preview .media-flag { position: absolute; bottom: .3rem; right: .3rem; }
.content-card .caption { white-space: pre-wrap; font-size: .9rem; max-height: 9.5em; overflow: hidden; }
.content-card .actions { display: flex; flex-direction: column; gap: .35rem; min-width: 120px; }
@media (max-width: 767.98px) {
  .content-card { grid-template-columns: 80px 1fr; }
  .content-card .preview { width: 80px; }
  .content-card .actions { grid-column: 1 / -1; flex-direction: row; flex-wrap: wrap; min-width: 0; }
}
.hashtags { color: var(--brand); font-size: .85rem; }

/* Status badges */
.st { font-weight: 500; font-size: .75rem; padding: .3em .6em; border-radius: 999px; display: inline-block; white-space: nowrap; }
.st-draft, .st-cancelled, .st-rejected { background: #eceef4; color: #5b6075; }
.st-generating { background: #e8e4ff; color: #5541d6; }
.st-ready_for_review { background: #fff4d6; color: #946200; }
.st-approved, .st-scheduled, .st-queued { background: #dff1ff; color: #0b62a8; }
.st-publishing, .st-awaiting_callback { background: #e8e4ff; color: #5541d6; }
.st-published { background: #dcf7e6; color: #137a3b; }
.st-failed { background: #ffe1e1; color: #b42318; }
.st-paused { background: #ffe9d6; color: #a14a00; }
.st-manual_required { background: #fff0f6; color: #b0246b; }
.st-connected { background: #dcf7e6; color: #137a3b; }
.st-error { background: #ffe1e1; color: #b42318; }
.st-not_configured, .st-disconnected { background: #eceef4; color: #5b6075; }
.st-manual { background: #fff0f6; color: #b0246b; }

.pf { font-size: .72rem; padding: .2em .5em; border-radius: 6px; background: #f1f2f8; color: #3e4258; white-space: nowrap; }
.pf-facebook { background: #e7efff; color: #1d4ed8; }
.pf-tiktok { background: #111; color: #fff; }
.pf-tiktok_shop { background: #ffe4ec; color: #be123c; }
.pf-shopee { background: #fff1e6; color: #c2410c; }

/* Calendar */
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; background: #e6e8f0; border-radius: 12px; overflow: hidden; }
.cal-head { background: #f8f9fc; text-align: center; font-size: .8rem; color: var(--muted); padding: .5rem 0; }
.cal-cell { background: #fff; min-height: 110px; padding: .35rem; display: flex; flex-direction: column; gap: .25rem; min-width: 0; }
.cal-cell.other { background: #fafbfd; color: #b0b4c5; }
.cal-cell.today { box-shadow: inset 0 0 0 2px var(--brand); }
.cal-cell.drop { background: color-mix(in srgb, var(--brand) 10%, #fff); }
.cal-day { font-size: .8rem; font-weight: 600; }
.cal-item { font-size: .72rem; border-radius: 6px; padding: .2rem .35rem; background: #f3f4fa; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border-left: 3px solid #c9cde0; }
.cal-item[draggable="true"] { cursor: grab; }
.cal-item.s-ready_for_review { border-left-color: #f0b400; }
.cal-item.s-scheduled, .cal-item.s-approved { border-left-color: #2a8be0; }
.cal-item.s-published { border-left-color: #22a55a; }
.cal-item.s-failed { border-left-color: #e5484d; }
.cal-item.s-generating { border-left-color: #7c6cf0; }
.cal-item.s-paused { border-left-color: #f08a24; }
.week-grid { display: grid; grid-template-columns: repeat(7, minmax(140px, 1fr)); gap: .5rem; overflow-x: auto; }
.week-col { background: #fff; border-radius: 12px; padding: .5rem; min-height: 300px; }
@media (max-width: 767.98px) {
  .cal-cell { min-height: 70px; }
  .cal-item .t-name { display: none; }
}

/* Wizard */
.wizard-steps { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.wizard-steps .step { padding: .35rem .8rem; border-radius: 999px; background: #eceef5; font-size: .85rem; color: var(--muted); }
.wizard-steps .step.active { background: var(--brand); color: #fff; }
.wizard-steps .step.done { background: color-mix(in srgb, var(--brand) 18%, #fff); color: var(--brand); }
.pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .75rem; }
.pick-item { border: 2px solid transparent; border-radius: 12px; background: #fff; padding: .5rem; cursor: pointer; position: relative; }
.pick-item.selected { border-color: var(--brand); }
.pick-item .ph { aspect-ratio: 1/1; border-radius: 8px; background: #eef0f7 center/cover; margin-bottom: .4rem; }
.pick-item .focus-toggle { position: absolute; top: .9rem; right: .9rem; }

/* Login */
.login-body { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(circle at top, #ece9ff, var(--bg)); padding: 16px; }
.login-card { width: 100%; max-width: 400px; background: #fff; padding: 2rem; border-radius: 20px; box-shadow: 0 10px 40px rgba(40,30,120,.12); }

.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty i { font-size: 2.5rem; display: block; margin-bottom: .5rem; opacity: .5; }
.table > :not(caption) > * > * { vertical-align: middle; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em; }
.sticky-actions { position: sticky; bottom: 0; background: rgba(244,245,251,.95); backdrop-filter: blur(6px); padding: .75rem 0; z-index: 5; }
pre.code { background: #f6f7fb; border-radius: 8px; padding: .75rem; font-size: .8rem; white-space: pre-wrap; word-break: break-all; }
.data-source { font-size: .7rem; padding: .15em .45em; border-radius: 5px; }
.ds-actual { background: #dcf7e6; color: #137a3b; }
.ds-manual { background: #dff1ff; color: #0b62a8; }
.ds-estimated { background: #fff4d6; color: #946200; }
.progress-thin { height: 6px; }
