/* PageFlow — design system "professional SaaS console"
   Token: indigo primary, slate surfaces, 8px rhythm, system fonts, subtle motion. */
:root {
  --bg: #f4f6fb; --panel: #ffffff; --line: #e4e9f2; --line-strong: #d4dbe8;
  --text: #101828; --text-2: #344054; --muted: #667085;
  --primary: #4f46e5; --primary-dark: #4338ca; --primary-soft: #eef2ff;
  --danger: #d92d20; --danger-soft: #fee4e2; --ok: #067647; --ok-soft: #d1fadf;
  --warn: #b54708; --warn-soft: #fef0c7;
  --sidebar-bg: #0f172a; --sidebar-text: #cbd5e1; --sidebar-active: #1e293b;
  --radius: 12px; --radius-sm: 8px;
  --shadow-1: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.1);
  --shadow-2: 0 4px 12px -2px rgba(16,24,40,.1), 0 2px 6px -2px rgba(16,24,40,.06);
  --ring: 0 0 0 3px rgba(79,70,229,.25);
  --font: "Inter", "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "Cascadia Code", "JetBrains Mono", Consolas, monospace;
}
* { box-sizing: border-box; }
html { font-size: 15px; }
body { margin: 0; font-family: var(--font); background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
#app { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
#sidebar { width: 232px; background: var(--sidebar-bg); color: var(--sidebar-text); padding: 18px 12px; display: flex; flex-direction: column; gap: 14px; position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 10px; color: #fff; letter-spacing: .01em; }
.logo { background: linear-gradient(135deg, #6366f1, #4f46e5); color: #fff; border-radius: 9px; padding: 4px 8px; font-size: 12px; font-weight: 800; letter-spacing: .04em; }
#nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; margin: 0 -4px; }
#nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--radius-sm); color: var(--sidebar-text); text-decoration: none; font-size: 14px; font-weight: 500; transition: background .18s, color .18s; position: relative; }
#nav a svg { width: 17px; height: 17px; flex: none; opacity: .75; }
#nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
#nav a.active { background: var(--sidebar-active); color: #fff; }
#nav a.active::before { content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px; border-radius: 3px; background: #818cf8; }
#nav a.active svg { opacity: 1; color: #a5b4fc; }
.side-user { border-top: 1px solid rgba(255,255,255,.09); padding-top: 12px; font-size: 12.5px; color: var(--sidebar-text); display: flex; flex-direction: column; gap: 4px; }
.side-user b { color: #fff; font-weight: 600; }
.side-user .muted { color: #8ea0b8; font-size: 11.5px; }
.side-user .row-btns { display: flex; gap: 6px; margin-top: 4px; }
.side-user button { flex: 1; background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.12); color: #e2e8f0; font-size: 11.5px; padding: 5px 6px; border-radius: 7px; cursor: pointer; transition: background .18s; }
.side-user button:hover { background: rgba(255,255,255,.14); }

/* ---------- Main ---------- */
#main { flex: 1; padding: 26px 30px; max-width: 1240px; min-width: 0; }
h1 { font-size: 22px; font-weight: 700; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 15px; font-weight: 650; margin: 22px 0 10px; color: var(--text); }
h3, h4, h5, h6 { margin: 0; font-weight: 600; }
.sub { color: var(--muted); margin: 0 0 18px; font-size: 13.5px; }
.hidden { display: none !important; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--mono); font-size: 12px; background: var(--primary-soft); color: var(--primary-dark); padding: 1px 6px; border-radius: 5px; }

/* ---------- Cards & panels ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); gap: 12px; margin-bottom: 20px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow-1); transition: box-shadow .18s; }
.card:hover { box-shadow: var(--shadow-2); }
.card .label { font-size: 12px; font-weight: 550; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.card b { display: block; font-size: 24px; margin-top: 6px; font-weight: 700; letter-spacing: -.02em; }
.card.good b { color: var(--ok); } .card.warn b { color: var(--warn); } .card.bad b { color: var(--danger); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-1); margin-bottom: 16px; }
.panel > b { display: block; font-size: 14.5px; font-weight: 650; margin-bottom: 6px; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-1); }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; font-size: 13.5px; }
th { color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; background: #f8fafd; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #f8faff; }
td .muted { font-size: 12px; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2.5px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.gray { background: #eef1f6; color: #475467; }
.badge.blue { background: #e0eaff; color: #1d4ed8; }
.badge.green { background: var(--ok-soft); color: var(--ok); }
.badge.red { background: var(--danger-soft); color: var(--danger); }
.badge.orange { background: var(--warn-soft); color: var(--warn); }
.badge.purple { background: #ecebff; color: #5b3fc4; }

/* ---------- Forms ---------- */
input, textarea, select { font: inherit; padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); width: 100%; background: #fff; color: var(--text); transition: border-color .15s, box-shadow .15s; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
input[type="checkbox"], input[type="radio"] { accent-color: var(--primary); }
input[type="file"] { padding: 7px; background: #f8fafd; }
input:disabled, textarea:disabled, select:disabled { background: #f1f4f9; color: var(--muted); }
textarea { min-height: 120px; resize: vertical; line-height: 1.55; }
label { display: block; margin: 12px 0 5px; font-weight: 600; font-size: 13px; color: var(--text-2); }
::placeholder { color: #98a2b3; }

/* ---------- Buttons ---------- */
button { font: inherit; font-weight: 550; padding: 8px 15px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong); background: #fff; color: var(--text-2); cursor: pointer; transition: background .16s, border-color .16s, box-shadow .16s, color .16s; }
button:hover { background: #f6f8fc; border-color: #c3cddf; }
button:focus-visible { outline: none; box-shadow: var(--ring); }
button.primary { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 1px 2px rgba(79,70,229,.35); }
button.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
button.danger { color: var(--danger); border-color: #f2b8b5; background: #fff; }
button.danger:hover { background: var(--danger-soft); border-color: #e69f9c; }
button.small { padding: 4.5px 11px; font-size: 12.5px; border-radius: 7px; }
button:disabled { opacity: .55; cursor: not-allowed; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1 1 180px; min-width: 0; }
.row > button, .row > .fixed { flex: 0 0 auto; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 7px; }
.checks label { display: flex; align-items: center; gap: 9px; font-weight: 450; margin: 0; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; cursor: pointer; transition: border-color .15s, background .15s; }
.checks label:hover { border-color: #c3cddf; background: #f8faff; }
.checks input { width: auto; flex: none; }
.radios { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.radios label { display: flex; gap: 7px; align-items: center; font-weight: 450; margin: 0; cursor: pointer; }
.radios input { width: auto; }
.err { color: var(--danger); margin-top: 8px; font-size: 13px; }
.muted { color: var(--muted); font-size: 12.5px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
details { margin: 10px 0; }
details summary { cursor: pointer; color: var(--primary-dark); font-weight: 600; font-size: 13.5px; }
.empty { color: var(--muted); text-align: center; padding: 30px 0; font-size: 13.5px; }

/* ---------- Toast ---------- */
.toast { position: fixed; bottom: 20px; right: 20px; background: #101828; color: #fff; padding: 11px 18px; border-radius: 10px; box-shadow: 0 12px 32px rgba(16,24,40,.35); z-index: 50; font-size: 13.5px; max-width: 380px; animation: toast-in .22s ease-out; }
.toast.err { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Calendar ---------- */
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 7px; }
.cal-head { text-align: center; font-weight: 650; color: var(--muted); font-size: 11.5px; padding: 4px 0; text-transform: uppercase; letter-spacing: .05em; }
.cal-cell { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; min-height: 92px; padding: 7px; font-size: 12px; transition: border-color .15s; }
.cal-cell:hover { border-color: #c3cddf; }
.cal-cell.dim { opacity: .4; }
.cal-cell .day { font-weight: 700; color: var(--text-2); }
.chip { display: block; margin-top: 4px; padding: 3px 7px; border-radius: 6px; font-size: 11px; font-weight: 550; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border: 1px solid transparent; }
.chip.scheduled { background: #e0eaff; color: #1d4ed8; }
.chip.published { background: var(--ok-soft); color: var(--ok); }
.chip.failed_retryable, .chip.failed_permanent { background: var(--danger-soft); color: var(--danger); }
.chip.processing { background: var(--warn-soft); color: var(--warn); }
.chip.outcome_unknown { background: #ecebff; color: #5b3fc4; }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; gap: 9px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar select, .toolbar input { width: auto; }

/* ---------- Modal ---------- */
div[role="dialog"], .panel.modal-open { animation: modal-in .2s ease-out; }
@keyframes modal-in { from { opacity: 0; transform: translateY(10px) scale(.985); } to { opacity: 1; transform: none; } }

/* ---------- Bars (stats) ---------- */
.bar-row { display: flex; align-items: center; gap: 10px; margin: 6px 0; }
.bar-row .bar-label { width: 140px; flex: none; font-size: 12.5px; color: var(--text-2); }
.bar-row .bar-track { flex: 1; height: 10px; background: #eef1f6; border-radius: 99px; overflow: hidden; }
.bar-row .bar-fill { height: 100%; background: linear-gradient(90deg, #6366f1, #4f46e5); border-radius: 99px; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  #sidebar { width: 64px; padding: 14px 8px; }
  .brand span, #nav a span, .side-user > *:not(.row-btns) { display: none; }
  #nav a { justify-content: center; padding: 10px; }
  #nav a.active::before { display: none; }
  #main { padding: 18px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- Topbar / nav-section / login (khớp markup hiện tại) ---------- */
#topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 22px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
#topbar .eyebrow { display: block; font-size: 10.5px; font-weight: 650; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
#topbar #workspace-label { font-size: 15px; font-weight: 650; color: var(--text); }
#topbar .primary-link { background: var(--primary); color: #fff; padding: 8px 15px; border-radius: var(--radius-sm); font-weight: 600; font-size: 13.5px; text-decoration: none; transition: background .16s; box-shadow: 0 1px 2px rgba(79,70,229,.35); }
#topbar .primary-link:hover { background: var(--primary-dark); text-decoration: none; }
#nav .nav-section { display: block; font-size: 10px; font-weight: 650; letter-spacing: .09em; text-transform: uppercase; color: #64748b; padding: 14px 12px 5px; }
#nav .nav-icon { display: inline-flex; }
.brand span:not(.logo) { display: flex; flex-direction: column; line-height: 1.15; }
.brand small { font-size: 8.5px; font-weight: 650; letter-spacing: .14em; text-transform: uppercase; color: #64748b; }
body.login-page { background: radial-gradient(1200px 500px at 50% -10%, #e0e7ff, var(--bg)); }
body.login-page #main { display: flex; align-items: flex-start; justify-content: center; }
body.login-page .panel { max-width: 400px; width: 100%; margin-top: 9vh; box-shadow: var(--shadow-2); }
body.login-page h1 { font-size: 20px; }
.panel .err { color: var(--danger); }

/* ---------- Page heading / eyebrow / quiet link ---------- */
.eyebrow { display: block; font-size: 10.5px; font-weight: 650; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); margin: 0 0 4px; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.page-heading h1 { margin: 0; }
.quiet-link { color: var(--muted); font-weight: 550; font-size: 13.5px; text-decoration: none; transition: color .15s; }
.quiet-link:hover { color: var(--primary); text-decoration: none; }
.section-note { font-size: 12.5px; color: var(--muted); margin: 6px 0 12px; }
.text-button { background: none; border: none; color: var(--primary); padding: 0; font-weight: 550; cursor: pointer; }
.text-button:hover { text-decoration: underline; background: none; }
.btn { font: inherit; font-weight: 550; cursor: pointer; }

/* ---------- Login ---------- */
.login-panel { padding: 30px 30px 26px; }
.login-mark { width: 52px; height: 52px; border-radius: 14px; background: linear-gradient(135deg, #6366f1, #4f46e5); color: #fff; font-size: 22px; font-weight: 800; display: flex; align-items: center; justify-content: center; margin-bottom: 16px; }

/* ---------- Activity timeline (dashboard) ---------- */
.activity-row { display: flex; gap: 12px; padding: 9px 0; border-bottom: 1px dashed var(--line); align-items: flex-start; }
.activity-row:last-child { border-bottom: none; }
.activity-dot { width: 9px; height: 9px; border-radius: 99px; background: linear-gradient(135deg, #818cf8, #4f46e5); flex: none; margin-top: 5px; }
.activity-row strong { font-size: 13px; font-weight: 600; color: var(--text-2); display: block; }
.activity-row p { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }
.activity-row time { margin-left: auto; font-size: 11.5px; color: var(--muted); white-space: nowrap; flex: none; }

/* ---------- Composer: bố cục 2 cột ---------- */
.compose-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; align-items: start; }
.compose-preview { position: sticky; top: 20px; display: flex; flex-direction: column; gap: 8px; }
@media (max-width: 1080px) { .compose-layout { grid-template-columns: 1fr; } .compose-preview { position: static; } }
.compose-editor textarea { min-height: 180px; }
.editor-tools { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; margin: 0 0 8px; padding: 8px; background: #f8fafd; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.editor-tools button { padding: 5px 11px; font-size: 12.5px; border-radius: 7px; }
.editor-tools .muted { margin-left: auto; font-size: 11.5px; }
.emoji-picker { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; padding: 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #f8fafd; margin-bottom: 10px; }
.emoji-picker button { font-size: 18px; padding: 5px; border: none; background: none; border-radius: 7px; }
.emoji-picker button:hover { background: var(--primary-soft); }
.art-panel { border: 1px solid var(--line); border-radius: var(--radius-sm); background: #f8fafd; padding: 12px; margin-bottom: 10px; }

/* ---------- Upload zone ---------- */
.upload-zone { border: 2px dashed var(--line-strong); border-radius: var(--radius); padding: 26px 18px; text-align: center; color: var(--muted); background: #f8fafd; transition: border-color .18s, background .18s; cursor: pointer; }
.upload-zone:hover, .upload-zone.dragging { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-dark); }
.upload-zone.dragging { transform: none; }

/* ---------- Media thumbnails ---------- */
.media-thumb, .cp-asset { border-radius: 8px; }
.cp-asset video { width: 46px; height: 46px; object-fit: cover; border-radius: 8px; }
.selected-media { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 8px; }
.selected-item { border-color: var(--primary) !important; background: var(--primary-soft) !important; }

/* ---------- Preview post (giống Facebook) ---------- */
.preview-post { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-1); padding: 14px; }
.preview-author { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.preview-avatar { width: 38px; height: 38px; border-radius: 99px; background: linear-gradient(135deg, #6366f1, #4f46e5); color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center; flex: none; }
.preview-author strong { font-size: 13.5px; display: block; }
.preview-author .muted { font-size: 11.5px; }
.preview-media { display: grid; gap: 6px; margin: 10px 0; }
.preview-media img, .preview-media video { width: 100%; border-radius: 9px; display: block; }
.preview-post .preserve-lines { font-size: 13.5px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.preview-footer { display: flex; justify-content: space-between; border-top: 1px solid var(--line); margin-top: 12px; padding-top: 8px; color: var(--muted); font-size: 12.5px; }
.preview-footer span { flex: 1; text-align: center; }
.preserve-lines { white-space: pre-wrap; word-break: break-word; }

/* ---------- Carousel ---------- */
.carousel-review { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.carousel-card { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px; background: #f8fafd; }
.carousel-card strong { display: block; margin-bottom: 4px; font-size: 13px; }

/* ---------- Misc ---------- */
.preserve-lines { word-break: break-word; }
input[type="file"] + .muted { display: inline-block; }

/* ---------- Compose options (switch hàng ngang) / cloud sources / layout helper ---------- */
.compose-option { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; margin: 8px 0; }
.compose-option label { margin: 0; font-weight: 550; font-size: 13px; cursor: pointer; }
.compose-option input[role="switch"] { width: 38px; height: 21px; appearance: none; position: relative; background: #d0d5dd; border-radius: 99px; cursor: pointer; transition: background .18s; flex: none; padding: 0; border: none; }
.compose-option input[role="switch"]::after { content: ""; position: absolute; top: 2.5px; left: 2.5px; width: 16px; height: 16px; border-radius: 99px; background: #fff; transition: transform .18s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.compose-option input[role="switch"]:checked { background: var(--primary); }
.compose-option input[role="switch"]:checked::after { transform: translateX(17px); }
.ui-layout-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.ui-layout-5 { margin-top: 10px; }
.cloud-sources { display: flex; gap: 8px; align-items: center; margin: 10px 0 6px; flex-wrap: wrap; }
.cloud-sources button:disabled { opacity: .45; }
.cloud-help { margin-top: 10px; }
.cloud-help summary { font-weight: 600; }
.cloud-help h3 { margin: 12px 0 4px; font-size: 13px; }
.cloud-help ol, .cloud-help ul { padding-left: 20px; margin: 6px 0; color: var(--text-2); font-size: 13px; }
.cloud-help code { user-select: all; }

/* ---------- Trạng thái active chung ---------- */
.active-ring { box-shadow: var(--ring); }
