:root {
  --navy: #191E3B; --navy-2: #252C55; --yellow: #FDDB32; --blue: #1668E3; --blue-hover: #0D4EAF; --surface: #F3F3F5; --border: #DFE0E4;
  --text: #1F2340; --muted: #676A7D; --success: #227950; --error: #C70A0B;
  --bs-primary: #1668E3; --bs-primary-rgb: 22,104,227; --bs-body-font-family: "Inter", system-ui, sans-serif; --bs-body-color: #1F2340; --bs-link-color: #1668E3; --bs-link-color-rgb: 22,104,227;
}
body { background: var(--surface); font-size: 14.5px; }
.admin-shell { display: flex; min-height: 100vh; }
.sidebar { width: 252px; background: var(--navy); color: #fff; flex-shrink: 0; }
@media (min-width: 992px) { .sidebar, .sidebar.offcanvas-lg { position: sticky; top: 0; height: 100vh; overflow-y: auto; background-color: var(--navy) !important; } }
.sidebar.offcanvas-lg { --bs-offcanvas-bg: var(--navy); --bs-offcanvas-width: 260px; }
.sidebar-brand { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand { color: #fff; font-weight: 800; font-size: 1.05rem; display: flex; align-items: center; gap: 8px; text-decoration: none; }
.brand:hover { color: #fff; }
.brand small { font-weight: 600; color: var(--yellow); font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; }
.logo-mark { width: 28px; height: 28px; border-radius: 7px; background: var(--yellow); color: var(--navy); display: inline-grid; place-items: center; font-size: .85rem; }
.sidebar { display: flex; flex-direction: column; }
.sidebar-search { position: relative; margin: 12px 12px 4px; }
.sidebar-search .bi { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: rgba(255,255,255,.45); font-size: .8rem; pointer-events: none; }
.sidebar-search input { width: 100%; background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.12); border-radius: 8px; color: #fff; font-size: .85rem; padding: 7px 10px 7px 30px; outline: 0; }
.sidebar-search input::placeholder { color: rgba(255,255,255,.45); }
.sidebar-search input:focus { border-color: rgba(255,255,255,.35); background: rgba(255,255,255,.1); }
.sidebar-nav { padding: 8px 10px 24px; flex: 1; }
.sidebar-nav .nav-link-item { display: flex; align-items: center; gap: 10px; color: rgba(255,255,255,.82); padding: 7px 10px; border-radius: 7px; text-decoration: none; font-size: .9rem; line-height: 1.25; }
.sidebar-nav .nav-link-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.sidebar-nav .nav-link-item.active { background: var(--blue); color: #fff; font-weight: 600; }
.sidebar-nav .nav-link-item > .bi { width: 18px; text-align: center; flex-shrink: 0; }
/* Collapsible groups */
.nav-group { margin-top: 2px; }
.nav-group:first-of-type { margin-top: 10px; padding-top: 10px; border-top: 1px solid rgba(255,255,255,.08); }
.nav-group-toggle { width: 100%; display: flex; align-items: center; gap: 10px; background: none; border: 0; color: rgba(255,255,255,.92); font-size: .86rem; font-weight: 600; padding: 8px 10px; border-radius: 7px; text-align: left; }
.nav-group-toggle:hover { background: rgba(255,255,255,.07); }
.nav-group-toggle > .bi:first-child { width: 18px; text-align: center; color: var(--yellow); flex-shrink: 0; }
.nav-group-toggle span { flex: 1; }
.nav-group-toggle .chev { font-size: .7rem; opacity: .6; transition: transform .2s; }
.nav-group-toggle.collapsed .chev { transform: rotate(-90deg); }
.nav-group.has-active > .nav-group-toggle { color: #fff; }
.nav-group-links { margin: 2px 0 6px 19px; padding-left: 10px; border-left: 1px solid rgba(255,255,255,.12); }
.nav-group-links .nav-link-item { font-size: .86rem; padding: 6px 10px; color: rgba(255,255,255,.72); }
.nav-group-links .nav-link-item > .bi { opacity: .8; }
/* Filter mode: show every matching link, hide the rest */
.sidebar-nav.filtering .collapse { display: block !important; height: auto !important; }
.sidebar-nav.filtering .chev { visibility: hidden; }
.sidebar-nav .is-hidden { display: none !important; }
.nav-empty { color: rgba(255,255,255,.5); font-size: .85rem; padding: 8px 10px; margin: 0; }
@media (prefers-reduced-motion: reduce) { .nav-group-toggle .chev { transition: none; } }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { background: #fff; border-bottom: 1px solid var(--border); padding: 10px 20px; display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 100; }
.content { padding: 22px; }
@media (max-width: 575px) { .content { padding: 14px; } }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 16px; }
.page-head h1 { font-size: 1.45rem; font-weight: 700; margin: 0; }
.page-head p { color: var(--muted); margin: 2px 0 0; }
.card { border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 1px 3px rgba(25,30,59,.05); }
.card-header { background: #fff; font-weight: 600; border-bottom: 1px solid var(--border); }
.btn { border-radius: 8px; font-weight: 600; }
.btn-primary { background: var(--blue); border-color: var(--blue); }
.btn-primary:hover { background: var(--blue-hover); border-color: var(--blue-hover); }
.kpi { padding: 16px 18px; }
.kpi .label { color: var(--muted); font-size: .82rem; }
.kpi .value { font-size: 1.6rem; font-weight: 800; line-height: 1.2; }
.kpi .bi { font-size: 1.3rem; width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; }
.table { --bs-table-bg: #fff; margin: 0; }
.table thead th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: #fafbfc; white-space: nowrap; }
.table td { vertical-align: middle; }
.table-card { overflow: hidden; }
/* RS-05: tables become card lists on mobile */
@media (max-width: 767px) {
  .table-stack thead { display: none; }
  .table-stack, .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
  .table-stack tr { border-bottom: 1px solid var(--border); padding: 8px 0; }
  .table-stack td { border: 0; padding: 3px 12px; }
  .table-stack td[data-label]::before { content: attr(data-label) ": "; font-weight: 600; color: var(--muted); font-size: .8rem; }
}
.status { border-radius: 999px; padding: .2rem .6rem; font-size: .75rem; font-weight: 700; white-space: nowrap; }
.s-ok { background: #E6F4EC; color: var(--success); }
.s-bad { background: #FDECEC; color: var(--error); }
.s-warn { background: #FFF6D6; color: #7a5b00; }
.s-info { background: #E8F0FD; color: var(--blue); }
.s-muted { background: #eef0f3; color: var(--muted); }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 8px 0 8px 18px; border-left: 2px solid var(--border); position: relative; font-size: .88rem; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 13px; width: 10px; height: 10px; border-radius: 50%; background: var(--blue); }
.form-label { font-weight: 600; font-size: .85rem; }
.matrix th, .matrix td { text-align: center; }
.matrix td:first-child, .matrix th:first-child { text-align: left; }
.block-item { border: 1px solid var(--border); border-radius: 10px; background: #fff; margin-bottom: 10px; }
.block-item .block-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; cursor: grab; border-bottom: 1px solid transparent; }
.block-item.open .block-head { border-bottom-color: var(--border); }
.block-item .block-body { padding: 12px; display: none; }
.block-item.open .block-body { display: block; }
.sortable-ghost { opacity: .4; }
.serp { font-family: Arial, sans-serif; max-width: 600px; }
.serp .u { color: #202124; font-size: 14px; }
.serp .t { color: #1a0dab; font-size: 20px; line-height: 1.3; }
.serp .d { color: #4d5156; font-size: 14px; }
.preview-frame { border: 1px solid var(--border); border-radius: 10px; background: #fff; height: 75vh; transition: width .2s; max-width: 100%; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.media-tile { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: #fff; cursor: pointer; }
.media-tile img { width: 100%; height: 110px; object-fit: cover; background: #f0f1f4; }
.media-tile .meta { padding: 6px 8px; font-size: .75rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.char-count { font-size: .75rem; color: var(--muted); }
.char-count.bad { color: var(--error); }
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(160deg, #191E3B, #2C2F63); padding: 16px; }
.ck-editor__editable { min-height: 180px; }

/* ================= Responsive refinements ================= */
img, video, iframe { max-width: 100%; }
.content { min-width: 0; overflow-wrap: break-word; }
/* Page headers, toolbars and filter bars wrap instead of pushing the page sideways. */
.page-head > div:last-child:not(:first-child), .page-head .d-flex, .page-head .btn-group { flex-wrap: wrap; }
.page-head .btn-group > .btn { flex: 0 0 auto; }
form.card.d-flex.flex-row { flex-wrap: wrap; align-items: center; }
form.card.d-flex.flex-row > .form-control { flex: 1 1 220px; width: auto; min-width: 0; }
.nav-tabs { flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.nav-tabs::-webkit-scrollbar { display: none; }
.nav-tabs .nav-link { white-space: nowrap; }
.card-header.d-flex { flex-wrap: wrap; gap: 6px; }
@media (max-width: 991.98px) {
  .topbar { padding: 8px 12px; }
  .content { padding: 16px; }
}
@media (max-width: 767.98px) {
  .page-head h1 { font-size: 1.25rem; }
  .kpi { padding: 12px 14px; }
  .kpi .value { font-size: 1.05rem !important; overflow-wrap: anywhere; }
  .kpi > div { min-width: 0; }
  .kpi.flex-row { gap: 10px !important; }
  .kpi .bi { width: 34px; height: 34px; font-size: 1.05rem; flex-shrink: 0; }
  /* Stacked table rows: inline inputs/forms fill the row instead of fixed widths. */
  .table-stack td input.form-control, .table-stack td select.form-select { width: 100% !important; max-width: 100%; }
  .table-stack td .d-flex { flex-wrap: wrap; }
  .table-stack td.text-end { text-align: left !important; }
  .table-stack td:empty { display: none; }
  .modal-dialog { margin: .5rem; }
  .preview-frame { height: 60vh; }
}
@media (max-width: 575.98px) {
  .content { padding: 12px; }
  .page-head { align-items: flex-start; }
  .page-head > a.btn, .page-head > div > .btn { flex: 0 0 auto; }
  form.card.d-flex.flex-row > .btn { flex: 1 1 100%; }
  form.card.d-flex.flex-row > .form-select { flex: 1 1 100%; width: 100% !important; }
  .card.p-3, .card.p-4 { padding: 12px !important; }
  .login-wrap .card { padding: 18px !important; }
  #sidebar .sidebar-nav .nav-link-item { padding: 9px 10px; }
}
