/* ===== Admin app shell ===== */
.app { display: flex; min-height: 100vh; }
.sidebar { flex: 0 0 264px; width: 264px; background: var(--mx-sidebar); color: #aab6cc; display: flex; flex-direction: column; padding: 20px 14px 16px; position: sticky; top: 0; height: 100vh; overflow-y: auto; z-index: 1040; }
.sidebar-brand { display: flex; align-items: center; gap: 11px; padding: 4px 10px 22px; color: #fff; text-decoration: none; }
.sidebar-brand img { width: 34px; height: 34px; border-radius: 9px; }
.sidebar-brand span { font-size: 1.2rem; font-weight: 700; letter-spacing: -.02em; }
.side-label { font-size: .68rem; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: #6b7a96; padding: 14px 12px 8px; }
.side-link { display: flex; align-items: center; gap: 12px; padding: 9px 12px; margin-bottom: 2px; border-radius: 10px; color: #b4bfd3; font-weight: 500; font-size: .9rem; text-decoration: none; position: relative; transition: background-color .15s, color .15s; }
.side-link .icon { opacity: .85; }
.side-link:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.side-link.active { background: rgba(91, 124, 250, .18); color: #fff; }
.side-link.active .icon { color: #9fb2ff; opacity: 1; }
.side-link.active::before { content: ""; position: absolute; left: -14px; top: 9px; bottom: 9px; width: 4px; border-radius: 0 4px 4px 0; background: #7b94ff; }
.side-user { margin-top: auto; padding-top: 14px; border-top: 1px solid rgba(255, 255, 255, .08); }
.side-user-card { display: flex; align-items: center; gap: 11px; padding: 6px 8px 12px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: linear-gradient(135deg, #5b7cfa, #2747b8); color: #fff; display: grid; place-items: center; font-weight: 650; font-size: .85rem; flex: none; }
.side-user-name { color: #fff; font-weight: 600; font-size: .875rem; line-height: 1.2; }
.side-user-role { font-size: .75rem; color: #7f8da8; text-transform: capitalize; }
.side-user .side-link { margin-bottom: 0; width: 100%; background: none; border: 0; text-align: left; }
.sidebar form { margin: 0; }

.app-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.topbar-mobile { display: none; align-items: center; gap: 12px; padding: 10px 16px; background: var(--mx-surface); border-bottom: 1px solid var(--mx-border); position: sticky; top: 0; z-index: 1030; }
.topbar-mobile .brand { display: flex; align-items: center; gap: 9px; font-weight: 700; color: var(--mx-ink); text-decoration: none; letter-spacing: -.02em; }
.topbar-mobile .brand img { width: 28px; height: 28px; border-radius: 8px; }
.nav-toggle { border: 1px solid var(--mx-border); background: var(--mx-surface); border-radius: 9px; width: 40px; height: 40px; display: grid; place-items: center; color: var(--mx-ink); }
.nav-backdrop { display: none; position: fixed; inset: 0; background: rgba(12, 20, 38, .55); z-index: 1035; }
.content { width: 100%; max-width: 1240px; margin: 0 auto; padding: 30px 36px 56px; }

@media (max-width: 991.98px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-102%); transition: transform .22s ease; box-shadow: 8px 0 32px rgba(0, 0, 0, .3); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .nav-backdrop { display: block; }
  .topbar-mobile { display: flex; }
  .content { padding: 22px 16px 48px; }
  .side-link.active::before { left: -14px; }
}

/* ===== Page header ===== */
.page-header { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 14px; margin-bottom: 24px; }
.page-title { font-size: 1.55rem; font-weight: 680; letter-spacing: -.02em; margin: 0; color: var(--mx-ink); display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.page-sub { color: var(--mx-muted); margin: 5px 0 0; font-size: .9rem; }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--mx-muted); text-decoration: none; font-size: .85rem; font-weight: 500; margin-bottom: 8px; }
.back-link:hover { color: var(--mx-primary); }

/* ===== Flash messages ===== */
.flash { display: flex; align-items: flex-start; gap: 10px; }
.flash .icon { margin-top: 2px; }
.flash .btn-close { margin-left: auto; padding: .9rem; }
.alert-dismissible .btn-close { position: static; padding: .4rem; flex: none; }

/* ===== KPI cards ===== */
.kpi { padding: 18px 18px 16px; height: 100%; }
.kpi-top { display: flex; align-items: center; justify-content: space-between; }
.kpi-label { color: var(--mx-muted); font-size: .8125rem; font-weight: 550; }
.kpi-icon { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; }
.kpi-blue .kpi-icon { background: var(--mx-primary-50); color: var(--mx-primary); }
.kpi-green .kpi-icon { background: var(--mx-success-bg); color: var(--mx-success); }
.kpi-amber .kpi-icon { background: var(--mx-warning-bg); color: #d97706; }
.kpi-violet .kpi-icon { background: #f1ebff; color: #6d44d8; }
.kpi-value { font-size: 1.85rem; font-weight: 700; letter-spacing: -.025em; color: var(--mx-ink); line-height: 1.15; margin-top: 10px; font-variant-numeric: tabular-nums; }
.kpi-sub { color: var(--mx-muted); font-size: .8125rem; margin-top: 4px; }

/* ===== Chart ===== */
.chart { width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .bar { fill: #c3d0fb; transition: fill .15s; }
.chart .bar.today { fill: var(--mx-primary); }
.chart g:hover .bar { fill: var(--mx-primary); }
.chart .axis, .chart .grid { stroke: var(--mx-border); stroke-width: 1; }
.chart text { fill: var(--mx-muted); font-size: 10px; font-family: var(--bs-font-sans-serif); }

/* ===== Section cards & tables ===== */
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--mx-border); }
.section-head h2 { font-size: 1rem; margin: 0; font-weight: 650; }
.section-body { padding: 20px; }
.table-card { padding: 0; overflow: hidden; }
.table td .cell-title { font-weight: 600; color: var(--mx-ink); text-decoration: none; }
.table td a.cell-title:hover { color: var(--mx-primary); }
.cell-sub { color: var(--mx-muted); font-size: .8125rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; align-items: center; }
.empty { text-align: center; padding: 52px 20px; }
.empty-icon { width: 56px; height: 56px; border-radius: 16px; background: var(--mx-primary-50); color: var(--mx-primary); display: grid; place-items: center; margin: 0 auto 14px; }
.empty h3 { font-size: 1.05rem; margin-bottom: 4px; }
.mini-list { list-style: none; margin: 0; padding: 0; }
.mini-list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px; border-top: 1px solid var(--mx-border); }
.mini-list li:first-child { border-top: 0; }
.mini-list a { text-decoration: none; color: var(--mx-ink); font-weight: 550; }
.mini-list a:hover { color: var(--mx-primary); }

/* ===== Filters ===== */
.filter-bar { padding: 16px 18px; margin-bottom: 18px; }
.filter-bar .form-label { font-size: .75rem; color: var(--mx-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; margin-bottom: .25rem; }
.search-wrap { position: relative; }
.search-wrap .icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: #98a2b3; pointer-events: none; }
.search-wrap .form-control { padding-left: 2.2rem; }

/* ===== Definition rows (detail pages) ===== */
.kv { display: grid; grid-template-columns: 1fr; gap: 0; }
.kv-row { padding: 14px 20px; border-top: 1px solid var(--mx-border); }
.kv-row:first-child { border-top: 0; }
.kv-label { font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--mx-muted); margin-bottom: 3px; }
.kv-value { color: var(--mx-ink); word-break: break-word; }
.pay-attempt { border: 1px solid var(--mx-border); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; background: #fcfcfd; font-size: .85rem; }
.pay-attempt:last-child { margin-bottom: 0; }

/* ===== Builder ===== */
.builder-bar { position: sticky; top: 0; z-index: 25; margin: -30px -36px 22px; padding: 16px 36px; background: rgba(244, 246, 251, .88); backdrop-filter: saturate(160%) blur(10px); -webkit-backdrop-filter: saturate(160%) blur(10px); border-bottom: 1px solid var(--mx-border); }
@media (max-width: 991.98px) { .builder-bar { position: static; margin: -22px -16px 18px; padding: 14px 16px; } }
.builder-bar .page-header { margin: 0; }
.share-box { display: inline-flex; align-items: center; gap: 8px; background: var(--mx-surface); border: 1px solid var(--mx-border); border-radius: 9px; padding: 4px 10px; font-size: .8125rem; color: var(--mx-text); }
.q-card { border-left: 4px solid var(--mx-primary); transition: box-shadow .15s; }
.q-card:hover { box-shadow: var(--mx-shadow-sm); }
.q-card.q-heading { border-left-color: #98a2b3; }
.q-card.q-hidden-logic { border-left-style: dashed; }
.q-card .card-header { display: flex; align-items: center; gap: 10px; background: #fafbfc; font-weight: 500; }
.q-num { width: 26px; height: 26px; border-radius: 8px; background: var(--mx-primary-50); color: var(--mx-primary); display: grid; place-items: center; font-weight: 650; font-size: .8rem; flex: none; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 7px; font-size: .75rem; font-weight: 550; background: #f2f4f7; color: #475467; }
.chip-req { background: #fdecea; color: #b42318; }
.chip-logic { background: #f1ebff; color: #6d44d8; }
.chip-price { background: var(--mx-success-bg); color: #067647; }
.q-form .form-label { margin-bottom: .2rem; }
.logic-row select, .logic-row input { min-width: 0; }
.js-logic-panel { background: #f8f9fc !important; border-color: var(--mx-border) !important; border-radius: 10px !important; }
.add-card { border: 1.5px dashed #b8c4f0; background: #fbfcff; }
.add-card .card-header { background: var(--mx-primary-50); color: var(--mx-primary-600); border-bottom-color: #d5defa; }

/* ===== Settings page sections ===== */
.settings-grid { display: grid; gap: 18px; }
.set-section { padding: 0; }
.set-section .section-head { padding: 14px 20px; }
.set-section .section-head .icon { color: var(--mx-primary); }
.thumb { max-height: 90px; border-radius: 9px; border: 1px solid var(--mx-border); padding: 3px; background: #fff; }

/* ===== Auth screens ===== */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); }
.auth-aside { background: radial-gradient(1100px 600px at 10% -10%, #3b5fe0 0%, transparent 60%), radial-gradient(900px 500px at 110% 110%, #1d3a9e 0%, transparent 55%), #0c1426; color: #dbe3f5; padding: 48px 56px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.auth-aside::after { content: ""; position: absolute; width: 520px; height: 520px; right: -200px; bottom: -220px; border-radius: 50%; border: 1px solid rgba(255, 255, 255, .08); box-shadow: 0 0 0 60px rgba(255, 255, 255, .02), 0 0 0 120px rgba(255, 255, 255, .02); }
.auth-brand { display: flex; align-items: center; gap: 12px; color: #fff; font-weight: 700; font-size: 1.35rem; letter-spacing: -.02em; text-decoration: none; }
.auth-brand img { width: 38px; height: 38px; border-radius: 10px; }
.auth-aside h2 { color: #fff; font-size: 2.1rem; font-weight: 700; letter-spacing: -.03em; line-height: 1.2; max-width: 440px; margin-bottom: 26px; }
.auth-points { list-style: none; padding: 0; margin: 0; display: grid; gap: 14px; max-width: 420px; position: relative; z-index: 1; }
.auth-points li { display: flex; gap: 12px; align-items: flex-start; color: #c3cee6; }
.auth-points .tick { width: 26px; height: 26px; border-radius: 8px; background: rgba(123, 148, 255, .2); color: #a9b9ff; display: grid; place-items: center; flex: none; }
.auth-foot { font-size: .8rem; color: #7f8da8; position: relative; z-index: 1; }
.auth-main { display: flex; align-items: center; justify-content: center; padding: 32px 20px; background: var(--mx-bg); }
.auth-card { width: 100%; max-width: 410px; }
.auth-card .card-body { padding: 32px 30px; }
.auth-mobile-brand { display: none; align-items: center; justify-content: center; gap: 10px; margin-bottom: 22px; font-weight: 700; font-size: 1.25rem; color: var(--mx-ink); letter-spacing: -.02em; }
.auth-mobile-brand img { width: 34px; height: 34px; border-radius: 9px; }
@media (max-width: 899.98px) {
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-aside { display: none; }
  .auth-mobile-brand { display: flex; }
}
.auth-title { font-size: 1.4rem; font-weight: 700; letter-spacing: -.02em; margin-bottom: 4px; }
.auth-sub { color: var(--mx-muted); margin-bottom: 22px; font-size: .9rem; }
.mx-narrow { max-width: 540px; }

/* ===== misc helpers ===== */
.avatar-sm { width: 34px; height: 34px; font-size: .8rem; }
.text-ink { color: var(--mx-ink); }
.admin-manage { min-width: 330px; }

/* ===== Tables become stacked cards on phones ===== */
@media (max-width: 767.98px) {
  .table-stack thead { display: none; }
  .table-stack, .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
  .table-stack tr { padding: 14px 16px; border-bottom: 1px solid var(--mx-border); }
  .table-stack tbody tr:last-child { border-bottom: 0; }
  .table-stack > :not(caption) > * > * { padding: 5px 0; border: 0; box-shadow: none; background: none; }
  .table-stack td { display: flex; align-items: center; justify-content: space-between; gap: 14px; text-align: right; }
  .table-stack td::before { content: attr(data-label); flex: none; color: var(--mx-muted); font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; text-align: left; }
  .table-stack td[data-label=""]::before { display: none; }
  .table-stack td:first-child { display: block; text-align: left; padding-bottom: 8px; }
  .table-stack td:first-child::before { display: none; }
  .table-stack td[colspan] { display: block; text-align: center; }
  .table-stack .row-actions { justify-content: flex-start; flex-wrap: wrap; }
  .table-stack td[data-label=""] { justify-content: flex-start; padding-top: 10px; }
}
