:root {
  --bg: #f0f2f5;
  --panel: #ffffff;
  --border: #dadde1;
  --text: #1c1e21;
  --muted: #65676b;
  --blue: #1877f2;
  --blue-dark: #166fe5;
  --green: #31a24c;
  --amber: #f0a000;
  --red: #e41e3f;
  --row-hover: #f5f6f7;
  --shadow: 0 1px 2px rgba(0,0,0,.1);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text); background: var(--bg); font-size: 13px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---- Login ---- */
.login { display: flex; align-items: center; justify-content: center; height: 100vh; }
.login-card {
  background: var(--panel); padding: 28px; border-radius: 10px; box-shadow: var(--shadow);
  width: 340px; display: flex; flex-direction: column; gap: 12px;
}
.login-card .brand { font-size: 20px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; }
.login-card input {
  padding: 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px;
}
.login-card button {
  margin-top: 6px; padding: 10px; background: var(--blue); color: #fff; border: 0;
  border-radius: 6px; font-size: 15px; font-weight: 700; cursor: pointer;
}
.login-card button:hover { background: var(--blue-dark); }
.error-msg { color: var(--red); font-size: 13px; }

/* ---- Logo ---- */
.logo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; background: var(--blue); color: #fff;
  border-radius: 6px; font-weight: 800; font-size: 13px;
}

/* ---- Topbar ---- */
.app { display: flex; flex-direction: column; height: 100vh; }
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--border);
  gap: 12px; flex-wrap: wrap;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.user-box { display: flex; align-items: center; gap: 6px; margin-left: 6px; }

.control {
  padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: #fff; font-size: 13px; cursor: pointer; color: var(--text);
}
button.control:hover { background: var(--row-hover); }
.control.grow { flex: 1; min-width: 180px; cursor: text; }
input.control { cursor: text; }

.pill {
  padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: #e4e6eb; color: var(--muted);
}
.pill.ok { background: #e3f3e8; color: var(--green); }
.pill.bad { background: #fde7ea; color: var(--red); }

/* ---- Tabs ---- */
.tabs { display: flex; align-items: center; gap: 4px; padding: 0 14px; background: var(--panel); border-bottom: 1px solid var(--border); }
.tab {
  padding: 12px 16px; border: 0; background: none; cursor: pointer; font-size: 14px;
  font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent;
}
.tab.active { color: var(--blue); border-bottom-color: var(--blue); }
.chip {
  margin-left: 10px; padding: 4px 10px; background: #e7f0fe; color: var(--blue-dark);
  border-radius: 999px; font-size: 12px; cursor: pointer; font-weight: 600;
}
.chip::after { content: " ✕"; opacity: .6; }

/* ---- Toolbar ---- */
.toolbar { display: flex; gap: 8px; padding: 10px 14px; background: var(--bg); align-items: center; }
.cols-wrap { position: relative; }
.cols-menu {
  position: absolute; top: 110%; left: 0; z-index: 20; background: #fff;
  border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow);
  padding: 8px; min-width: 200px; max-height: 320px; overflow: auto;
}
.cols-menu label { display: flex; gap: 8px; align-items: center; padding: 4px 6px; font-size: 13px; cursor: pointer; }
.cols-menu label:hover { background: var(--row-hover); border-radius: 4px; }

/* ---- Table ---- */
.table-wrap { flex: 1; overflow: auto; padding: 0 14px 14px; position: relative; }
.grid { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--panel); }
.grid th, .grid td {
  padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap;
}
.grid th {
  position: sticky; top: 0; background: #f7f8fa; z-index: 5; font-weight: 600; color: var(--muted);
  cursor: pointer; user-select: none; border-top: 1px solid var(--border);
}
.grid th.col-name, .grid td.col-name { text-align: left; }
.grid th:first-child, .grid td:first-child { text-align: left; }
.grid th .arrow { font-size: 10px; opacity: .5; }
.grid tbody tr:hover { background: var(--row-hover); }
.grid tfoot td { font-weight: 700; background: #f7f8fa; position: sticky; bottom: 0; }

.name-cell { display: flex; align-items: center; gap: 8px; max-width: 360px; }
.name-cell .thumb { width: 34px; height: 34px; border-radius: 4px; object-fit: cover; background: #e4e6eb; flex: none; }
.name-text { overflow: hidden; text-overflow: ellipsis; }
.name-text .sub { font-size: 11px; color: var(--muted); }
.linkish { color: var(--blue-dark); cursor: pointer; font-weight: 600; }
.linkish:hover { text-decoration: underline; }

/* On/Off pseudo-toggle (read-only) */
.toggle { width: 30px; height: 16px; border-radius: 999px; background: #ccd0d5; position: relative; display: inline-block; }
.toggle.on { background: var(--blue); }
.toggle::after { content: ""; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; background: #fff; border-radius: 50%; transition: left .1s; }
.toggle.on::after { left: 16px; }

/* Delivery badges */
.badge { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 12px; }
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.badge.active::before { background: var(--green); }
.badge.learning::before { background: var(--amber); }
.badge.learning-limited::before { background: var(--amber); }
.badge.off::before, .badge.campaign-off::before, .badge.ad-set-off::before { background: #bcc0c4; }
.badge.rejected::before, .badge.issues::before { background: var(--red); }
.badge.in-review::before, .badge.scheduled::before { background: var(--blue); }

/* States */
.state { padding: 40px; text-align: center; color: var(--muted); font-size: 14px; }
.state.error { color: var(--red); }
.spinner {
  width: 22px; height: 22px; border: 3px solid var(--border); border-top-color: var(--blue);
  border-radius: 50%; display: inline-block; animation: spin .8s linear infinite; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Pager */
.pager { display: flex; justify-content: space-between; align-items: center; padding: 8px 14px; background: var(--panel); border-top: 1px solid var(--border); }
.pager-controls { display: flex; gap: 8px; align-items: center; }

/* Row actions under the name (Edit / View post / Details) — Meta-style, reveal on hover */
.name-text .nm { line-height: 1.3; }
.rowacts { margin-top: 2px; font-size: 11px; opacity: 0; transition: opacity .08s; }
.grid tbody tr:hover .rowacts { opacity: 1; }
.rowact { color: var(--blue-dark); cursor: pointer; }
.rowact:hover { text-decoration: underline; }
.rowacts .dot { color: var(--border); margin: 0 5px; }

/* Quality / engagement / conversion ranking */
.rank { font-weight: 600; font-size: 12px; }
.rank.rk-good { color: var(--green); }
.rank.rk-mid { color: var(--muted); }
.rank.rk-bad { color: var(--red); }

/* ---- Read-only edit/details flyout ---- */
.flyout-scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); opacity: 0; pointer-events: none; transition: opacity .15s; z-index: 40; }
.flyout-scrim.open { opacity: 1; pointer-events: auto; }
.flyout {
  position: fixed; top: 0; right: 0; height: 100vh; width: 440px; max-width: 92vw;
  background: var(--panel); box-shadow: -2px 0 16px rgba(0,0,0,.18); z-index: 41;
  transform: translateX(100%); transition: transform .18s ease; display: flex; flex-direction: column;
}
.flyout.open { transform: translateX(0); }
.flyout-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; padding: 16px; border-bottom: 1px solid var(--border); }
.flyout-title { font-size: 16px; font-weight: 700; max-width: 340px; }
.flyout-body { padding: 8px 16px 24px; overflow: auto; }
.ro-banner { background: #fff7e6; border: 1px solid #ffe1a8; color: #8a6d3b; border-radius: 6px; padding: 8px 10px; font-size: 12px; margin: 12px 0; }
.dsec { font-size: 13px; font-weight: 700; color: var(--text); margin: 16px 0 6px; }
.drow { display: flex; gap: 12px; padding: 7px 0; border-bottom: 1px solid #f0f1f3; font-size: 13px; }
.drow .dk { flex: 0 0 150px; color: var(--muted); }
.drow .dv { flex: 1; word-break: break-word; }
.dthumb { margin: 8px 0; }
.dthumb img { max-width: 100%; border-radius: 8px; border: 1px solid var(--border); }
