/* DeenCircle Admin on a phone, and as an installed app (phase 48).
   Everything here is additive: the desktop layout stays as it is; under 900 px wide the console becomes an app —
   a sticky top bar, a bottom tab bar, a slide-in menu with a scrim, tables as cards, dialogs as bottom sheets — and
   every page shows a thin progress bar and skeletons while it loads. */

:root { --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px); --mnav-h: 64px;
  --sk1: rgba(127,127,127,.10); --sk2: rgba(127,127,127,.20); }

/* ---------------------------------------------------------------- page loading: progress bar, skeletons */
#dc-progress { position: fixed; top: var(--safe-t); left: 0; right: 0; height: 3px; z-index: 100; pointer-events: none; opacity: 0;
  transition: opacity .25s ease .1s; }
#dc-progress.on { opacity: 1; transition-delay: 0s; }
#dc-progress i { display: block; height: 100%; width: 100%; transform-origin: 0 50%; transform: scaleX(0);
  background: linear-gradient(90deg, #2ecc71, #1b8a55 60%, #c8962e); box-shadow: 0 0 10px rgba(46,204,113,.7);
  transition: transform .3s ease; border-radius: 0 3px 3px 0; }

.is-skel { color: transparent !important; position: relative; min-height: 112px; overflow: hidden; user-select: none; }
.is-skel * { visibility: hidden; }
.is-skel::before { content: ""; position: absolute; inset: 16px 18px; border-radius: 10px;
  background:
    linear-gradient(var(--sk1), var(--sk1)) 0 0 / 62% 14px no-repeat,
    linear-gradient(var(--sk1), var(--sk1)) 0 28px / 92% 12px no-repeat,
    linear-gradient(var(--sk1), var(--sk1)) 0 52px / 80% 12px no-repeat,
    linear-gradient(var(--sk1), var(--sk1)) 0 76px / 46% 12px no-repeat; }
.is-skel::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, var(--sk2), transparent); animation: skel 1.2s ease-in-out infinite; }
td.is-skel { height: 132px; }
@keyframes skel { to { transform: translateX(100%); } }
@media (prefers-reduced-motion: reduce) { .is-skel::after { animation: none; } }

.page:not(.hidden) { animation: pageIn .2s ease-out; }
@keyframes pageIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------------------------------------------------------------- install the app */
.install-app { display: inline-flex; align-items: center; gap: 6px; }
.install-app .ic { width: 16px; height: 16px; }
.side-foot .install-app { width: 100%; justify-content: center; margin-bottom: 8px; }
.ios-hint { position: fixed; left: 12px; right: 12px; bottom: calc(var(--mnav-h) + 14px + var(--safe-b)); z-index: 45;
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 18px; padding: 14px 16px;
  box-shadow: 0 18px 50px rgba(0,0,0,.28); display: flex; gap: 12px; align-items: flex-start; animation: sheetUp .25s ease-out; }
.ios-hint img { width: 44px; height: 44px; border-radius: 11px; flex: none; }
.ios-hint p { margin: 2px 0 0; font-size: 13px; color: var(--sub); }
.ios-hint button { margin-left: auto; border: 0; background: none; color: var(--sub); font-size: 18px; line-height: 1; padding: 0 2px; }
.offline-card .btn { display: block; text-align: center; text-decoration: none; margin-top: 16px; }

/* ---------------------------------------------------------------- the bottom tab bar (phones) */
.mnav { display: none; }
.side-scrim { display: none; }
.ptr { display: none; }

@media (max-width: 900px) {
  html { -webkit-text-size-adjust: 100%; }
  body { overscroll-behavior-y: contain; -webkit-tap-highlight-color: transparent; }
  .main { padding: 0 14px calc(var(--mnav-h) + 24px + var(--safe-b)); }

  /* top app bar */
  .top { position: sticky; top: 0; z-index: 15; margin: 0 -14px 14px; padding: calc(8px + var(--safe-t)) 10px 8px;
    min-height: calc(56px + var(--safe-t)); gap: 8px;
    background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: saturate(1.6) blur(14px);
    -webkit-backdrop-filter: saturate(1.6) blur(14px); border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent); }
  .top h2 { font-size: 18px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .top .menu { width: 40px; height: 40px; padding: 0; border-radius: 12px; display: grid; place-items: center; font-size: 18px; border-color: transparent; }
  .top .menu:active { background: rgba(127,127,127,.12); }
  .top-right { gap: 8px; }
  .top-right .live { padding: 4px 8px; font-size: 11px; }
  #updated { display: none; }
  .top .install-app { padding: 7px 11px; font-size: 12.5px; border-radius: 10px; }

  /* slide-in menu with a scrim; swipe it away */
  .side { box-shadow: none; }
  body.nav-open .side { box-shadow: 10px 0 40px rgba(0,0,0,.28); }
  .side { width: min(86vw, 320px); padding-top: calc(16px + var(--safe-t)); padding-bottom: calc(12px + var(--safe-b));
    transition: transform .26s cubic-bezier(.2,.8,.2,1); will-change: transform; touch-action: pan-y; }
  .side.dragging { transition: none; }
  .side nav a { min-height: 44px; }
  .side-scrim { display: block; position: fixed; inset: 0; z-index: 29; background: rgba(5,12,9,.5); opacity: 0; pointer-events: none;
    transition: opacity .2s; backdrop-filter: blur(1px); }
  body.nav-open .side-scrim { opacity: 1; pointer-events: auto; }
  body.nav-open { overflow: hidden; }

  /* bottom tab bar */
  .mnav { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
    padding: 6px 8px calc(6px + var(--safe-b)); min-height: calc(var(--mnav-h) + var(--safe-b));
    background: color-mix(in srgb, var(--panel) 86%, transparent); backdrop-filter: saturate(1.6) blur(16px);
    -webkit-backdrop-filter: saturate(1.6) blur(16px); border-top: 1px solid color-mix(in srgb, var(--line) 80%, transparent);
    box-shadow: 0 -8px 30px rgba(0,0,0,.06); }
  .mnav a, .mnav button { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    min-height: 50px; border: 0; background: none; color: var(--sub); text-decoration: none; font-size: 10.5px; font-weight: 700;
    border-radius: 14px; letter-spacing: .1px; padding: 4px 2px; }
  .mnav .ic { width: 22px; height: 22px; transition: transform .15s; }
  .mnav .lbl { max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .mnav a.active { color: var(--green); }
  .mnav a.active .pill-bg { position: absolute; top: 3px; width: 56px; height: 30px; border-radius: 99px; background: rgba(46,204,113,.16); z-index: -1; }
  .mnav a:active .ic, .mnav button:active .ic { transform: scale(.88); }
  .mnav .mb { position: absolute; top: 2px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 99px;
    background: var(--red); color: #fff; font-size: 10.5px; font-weight: 800; display: grid; place-items: center; border: 2px solid var(--panel); }
  .mnav .mb.dot { min-width: 10px; width: 10px; height: 10px; padding: 0; }

  /* pull down to refresh */
  .ptr { display: grid; place-items: center; position: fixed; left: 50%; top: calc(56px + var(--safe-t)); z-index: 14;
    width: 38px; height: 38px; margin-left: -19px; border-radius: 50%; background: var(--panel); box-shadow: 0 6px 20px rgba(0,0,0,.18);
    transform: translateY(-60px) scale(.6); opacity: 0; transition: transform .2s, opacity .2s; pointer-events: none; }
  .ptr.pulling { transition: none; }
  .ptr svg { width: 20px; height: 20px; fill: none; stroke: var(--green); stroke-width: 2.4; stroke-linecap: round; }
  .ptr.spin svg { animation: ptrspin .8s linear infinite; }
  @keyframes ptrspin { to { transform: rotate(360deg); } }

  /* touch-friendly controls; 16 px text in fields so iPhones don't zoom in */
  .btn { min-height: 40px; }
  .btn.sm { min-height: 34px; }
  input, select, textarea, .search, .select { font-size: 16px; }
  .chip { padding: 9px 14px; }
  .toolbar { gap: 8px; }
  .toolbar .search { flex-basis: 100%; }
  .chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -14px; padding: 0 14px 2px; }
  .chips::-webkit-scrollbar { display: none; }
  .chip { flex: none; }
  .card { border-radius: 18px; padding: 14px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 12px 14px; border-radius: 16px; gap: 2px; }
  .kpi-i { font-size: 16px; }
  .kpi-v, .db-overview .kpi-v { font-size: 23px; line-height: 1.15; overflow-wrap: anywhere; }
  .kpi-l { font-size: 12px; }
  .kpi::after { width: 64px; height: 64px; inset: auto -22px -22px auto; }
  .db-q-n { font-size: 30px; }

  /* dialogs as bottom sheets, the details drawer full screen */
  .modal-bg { place-items: end center; }
  .modal { width: 100%; max-width: 640px; border-radius: 22px 22px 0 0; max-height: 92vh; overflow: auto;
    padding: 10px 18px calc(18px + var(--safe-b)); animation: sheetUp .24s cubic-bezier(.2,.8,.2,1); }
  .modal::before { content: ""; display: block; width: 40px; height: 5px; border-radius: 99px; background: var(--line); margin: 0 auto 12px; }
  .modal-actions { flex-wrap: wrap; position: sticky; bottom: calc(-18px - var(--safe-b)); background: var(--panel); padding: 10px 0 2px; }
  .modal-actions .btn { flex: 1 1 120px; }
  .drawer { width: 100vw; padding-top: calc(16px + var(--safe-t)); padding-bottom: calc(30px + var(--safe-b)); }
  .toast { bottom: calc(var(--mnav-h) + 16px + var(--safe-b)); max-width: calc(100vw - 32px); text-align: center; }
  .idle { bottom: calc(var(--mnav-h) + 16px + var(--safe-b)); }

  /* wide tables scroll sideways inside their card instead of squashing */
  .card.flush, .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
}
@keyframes sheetUp { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }

/* ---------------------------------------------------------------- tables as cards on narrow phones */
@media (max-width: 640px) {
  .table.m-cards, .table.m-cards tbody { display: block; width: 100%; }
  .table.m-cards thead { display: none; }
  .table.m-cards tr { display: block; padding: 12px 14px; border-bottom: 1px solid var(--line); }
  .table.m-cards tr:active { background: rgba(46,204,113,.06); }
  .table.m-cards td { display: flex !important; align-items: center; justify-content: space-between; gap: 14px; padding: 5px 0;
    border: 0; text-align: right; min-width: 0; word-break: break-word; }
  .table.m-cards td::before { content: attr(data-label); flex: none; max-width: 45%; text-align: left; color: var(--sub);
    font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; }
  .table.m-cards td[data-label=""]::before, .table.m-cards td.m-first::before { display: none; }
  .table.m-cards td.m-first { justify-content: flex-start; text-align: left; padding-bottom: 8px; font-size: 15px; }
  .table.m-cards td.empty { justify-content: center; }
  .table.m-cards td.empty::before { display: none; }
  .table.m-cards td[colspan] { display: block !important; text-align: center; }
  .table.m-cards td[colspan]::before { display: none; }
  .card.flush:has(.table.m-cards) { overflow: hidden; }
  .table.m-cards td.is-skel { display: block !important; position: relative; }
  .table.m-cards td.is-skel::before { display: block; content: ""; }
}

/* ---------------------------------------------------------------- installed app: no browser bars around it */
@media (display-mode: standalone), (display-mode: window-controls-overlay) {
  .install-app { display: none !important; }
  body { user-select: none; -webkit-user-select: none; }
  input, textarea, [contenteditable], .mono, pre, td, p, b, small, code { user-select: text; -webkit-user-select: text; }
}

/* ---------------------------------------------------------------- phase 49: swipeable cards, "Who they are", account cards */
.us-cards { display: none; }
.m-dots { display: none; }

@media (max-width: 900px) {
  /* number cards in a row you swipe sideways, snapping card by card, with dots under them */
  .m-carousel { display: flex !important; grid-template-columns: none !important; overflow-x: auto; overscroll-behavior-x: contain;
    scroll-snap-type: x mandatory; scroll-padding: 0 14px; gap: 10px; margin: 0 -14px 4px !important; padding: 4px 14px 10px;
    scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .m-carousel::-webkit-scrollbar { display: none; }
  .m-carousel > * { flex: 0 0 auto; scroll-snap-align: start; }
  #kpis.m-carousel > .kpi, #us-kpis.m-carousel > .kpi { width: 42%; min-width: 148px; max-width: 200px; min-height: 124px; align-content: start; }
  #db-kpis.m-carousel > * { width: 46%; min-width: 160px; max-width: 220px; }
  #db-queues.m-carousel > * { width: 84%; max-width: 380px; }
  .m-carousel .kpi .kpi-i { width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; font-size: 17px;
    background: color-mix(in srgb, currentColor 13%, transparent); margin-bottom: 6px; }
  .m-carousel .kpi .kpi-v { font-size: 24px; }
  .m-carousel .kpi .us-share { font-size: 11.5px; color: var(--sub); font-weight: 600; }
  .m-carousel .kpi.sel { box-shadow: 0 0 0 2px var(--blue), var(--shadow); border-color: transparent; }
  .m-dots { display: flex; justify-content: center; gap: 6px; margin: 0 0 14px; min-height: 6px; }
  .m-dots i { width: 6px; height: 6px; border-radius: 99px; background: var(--line); transition: width .2s, background .2s; }
  .m-dots i.on { width: 18px; background: var(--green); }

  /* section titles: title on one line, the hint under it */
  .db-sec-h { display: block; margin: 18px 0 8px; }
  .db-sec-h h3 { font-size: 17px; margin: 0; letter-spacing: -.2px; }
  .db-sec-h .muted.tiny { display: block; margin-top: 2px; }

  /* "Who they are": activity, status, gender, platform, countries as tabs */
  .us-bd { padding: 14px 0 12px; margin-top: 14px; overflow: hidden; }
  .us-bd-h { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 0 14px 10px; }
  .us-bd-h h3 { margin: 0; font-size: 15px; }
  .us-bd-tabs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 0 14px 12px; border-bottom: 1px solid var(--line); }
  .us-bd-tabs::-webkit-scrollbar { display: none; }
  .us-bd-tabs button { flex: none; display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel);
    color: var(--sub); border-radius: 99px; padding: 8px 13px; font-weight: 700; font-size: 13px; min-height: 38px; }
  .us-bd-tabs button .ic { width: 16px; height: 16px; }
  .us-bd-tabs button.on { background: var(--green); border-color: var(--green); color: #fff; }
  .us-bd-panes { display: flex; align-items: flex-start; overflow-x: auto; overflow-y: hidden; scroll-snap-type: x mandatory;
    scrollbar-width: none; overscroll-behavior-x: contain; transition: height .25s ease; }
  .us-bd-panes::-webkit-scrollbar { display: none; }
  .us-bd .us-bd-pane { flex: 0 0 100%; scroll-snap-align: start; border: 0; box-shadow: none; background: none; border-radius: 0;
    padding: 14px 14px 4px; margin: 0; min-height: 180px; }
  .us-bd .us-bd-pane .card-h h3 { display: none; }
  .us-bd .us-bd-pane .card-h { margin-bottom: 6px; }
  .us-bd .dc-bars { gap: 12px; }
  .us-bd .dc-brow { grid-template-columns: 1fr auto; grid-template-areas: "n v" "t t"; row-gap: 6px; font-size: 14px; }
  .us-bd .dc-bname { grid-area: n; font-weight: 600; }
  .us-bd .dc-bval { grid-area: v; }
  .us-bd .dc-btrack { grid-area: t; height: 8px; border-radius: 99px; }
  .us-bd .dc-bfill { border-radius: 99px; }
}

/* ---------------------------------------------------------------- account cards (the Users list on phones) */
@media (max-width: 700px) {
  .us-listcard { padding: 0; background: none; border: 0; box-shadow: none; }
  .us-listcard .toolbar { padding: 0; }
  .us-listcard .chips { padding: 0 14px 2px; }
  .us-listcard .us-tablewrap { display: none; }
  .us-cards { display: grid; gap: 12px; margin-top: 4px; }
  .us-cards > .empty { padding: 28px 12px; }
  .ucard { position: relative; display: grid; gap: 12px; padding: 14px; border-radius: 18px; border: 1px solid var(--line);
    background: var(--panel); box-shadow: 0 1px 2px rgba(0,0,0,.03); cursor: pointer; transition: transform .12s, box-shadow .12s; }
  .ucard:active { transform: scale(.985); }
  .ucard:focus-visible { outline: 2px solid var(--green2); outline-offset: 2px; }
  .ucard.is-banned { border-color: color-mix(in srgb, var(--red) 40%, var(--line)); }
  .ucard-h { display: flex; align-items: center; gap: 12px; min-width: 0; }
  .ucard-h .av { font-size: 20px; box-shadow: 0 0 0 2px var(--panel), 0 0 0 3.5px color-mix(in srgb, var(--green2) 55%, transparent); }
  .ucard-id { flex: 1; min-width: 0; }
  .ucard-id b, .ucard-id small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .ucard-id b { font-size: 15.5px; }
  .ucard-id small { color: var(--sub); font-size: 13px; margin-top: 1px; }
  .ucard-st { flex: none; align-self: flex-start; }
  .ucard-st .pill { font-size: 11px; }
  .ucard-contact { display: flex; align-items: center; gap: 8px; padding: 9px 11px; border-radius: 12px; background: rgba(127,127,127,.06);
    font-size: 13.5px; min-width: 0; }
  .ucard-contact .ic { width: 16px; height: 16px; color: var(--green); }
  .ucard-contact span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .ucard-stats { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
  .ucard-stats > div { display: grid; justify-items: center; gap: 1px; padding: 9px 4px; }
  .ucard-stats > div + div { border-left: 1px solid var(--line); }
  .ucard-stats .ic { width: 17px; height: 17px; color: var(--sub); }
  .ucard-stats b { font-size: 16px; font-variant-numeric: tabular-nums; }
  .ucard-stats small { font-size: 11px; color: var(--sub); font-weight: 600; }
  .ucard-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; margin: 0; }
  .ucard-meta > div { min-width: 0; }
  .ucard-meta dt { display: flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 700; color: var(--sub); text-transform: uppercase; letter-spacing: .3px; }
  .ucard-meta dt .ic { width: 13px; height: 13px; }
  .ucard-meta dd { margin: 2px 0 0; font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
  .ucard-meta dd small { display: block; color: var(--sub); font-weight: 500; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .ucard-f { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding-top: 10px; border-top: 1px dashed var(--line); }
  .ucard-open { margin-left: auto; display: inline-flex; align-items: center; gap: 2px; color: var(--green); font-weight: 700; font-size: 13px; }
  .ucard-open .ic { width: 15px; height: 15px; }
  .us-listcard .pager { padding: 12px 2px 2px; flex-wrap: wrap; gap: 8px; }
}
