/* ════════════════════════════════════════════════════════════
   touch-mode.css — Touch-friendly overrides for Surface tablet
   and other touch devices.

   Activated by the @media query `(pointer: coarse)` (no mouse) or
   when the user explicitly forces it via `<html data-touch="on">`.
   Mouse + desktop users get the compact, density-rich UI unchanged.

   Standards: 44×44 CSS pixels is the WCAG 2.5.5 minimum tap target.
   ════════════════════════════════════════════════════════════ */

/* ── Common rules: applied on touch devices ────────────────── */
@media (pointer: coarse) {

    :root {
        /* allows components to pick up touch sizes via the cascade */
        --sc-tap-min:  44px;
        --sc-tap-mid:  40px;
    }

    /* All interactive elements: kill 300ms tap delay, kill text select on UI */
    button, a, [role="button"], .csp-btn, .csp-icon-btn, .csp-back-btn,
    .csp-checkbox, .csp-link, .csp-tab, .csp-icon-btn, .csp-modal-close,
    .sc-app-tile, .sc-theme-toggle, .sc-user-profile, .al-pager-btn,
    .cfg-card, .cfg-nav-item, input[type="checkbox"], input[type="radio"] {
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }

    /* ── csp-* primary buttons ──────────────────────────────── */
    .csp-btn {
        min-height: var(--sc-tap-min) !important;
        padding: 8px 16px !important;
        font-size: 14px !important;
        gap: 8px !important;
    }

    .csp-icon-btn {
        width: var(--sc-tap-mid) !important;
        height: var(--sc-tap-mid) !important;
        border-radius: 8px;
    }
    .csp-icon-btn svg { width: 18px !important; height: 18px !important; }

    .csp-back-btn {
        width: var(--sc-tap-mid) !important;
        height: var(--sc-tap-mid) !important;
    }
    .csp-back-btn svg { width: 18px !important; height: 18px !important; }

    .csp-header { padding: 14px 20px !important; gap: 12px !important; }
    .csp-header-actions { gap: 10px !important; }

    /* ── csp-* search field ─────────────────────────────────── */
    .csp-search { height: var(--sc-tap-min) !important; padding: 0 14px !important; }
    .csp-search input { font-size: 14px !important; }
    .csp-search svg { width: 16px !important; height: 16px !important; }

    /* ── csp-* form inputs ──────────────────────────────────── */
    .csp-input,
    select.csp-input,
    .csp-form-group input,
    .csp-form-group select,
    .csp-form-group textarea {
        min-height: var(--sc-tap-min) !important;
        padding: 10px 14px !important;
        font-size: 14px !important;
    }

    /* ── csp-* checkboxes & radios — bigger hit area ────────── */
    .csp-checkbox,
    .csp-check-item input[type="checkbox"],
    .csp-check-item input[type="radio"],
    input.form-check-input {
        width: 20px !important;
        height: 20px !important;
    }
    .csp-check-item, .csp-check-row label { padding: 6px 4px; }

    /* ── csp-* tables — bigger rows, bigger row click target ── */
    .csp-table th { padding: 12px 14px !important; font-size: 12px !important; }
    .csp-table td { padding: 14px !important; font-size: 13.5px !important; }
    .csp-actions { gap: 6px !important; }

    /* ── csp-* modals: bigger close, bigger footer ──────────── */
    .csp-modal-close {
        width: var(--sc-tap-mid) !important;
        height: var(--sc-tap-mid) !important;
    }
    .csp-modal-header { padding: 14px 18px !important; }
    .csp-modal-footer { padding: 12px 18px !important; gap: 10px !important; }

    /* ── Pagination ─────────────────────────────────────────── */
    .al-pager-btn,
    .at-page-btn {
        min-width: var(--sc-tap-min) !important;
        height: var(--sc-tap-min) !important;
        padding: 0 10px !important;
        font-size: 14px !important;
    }
    .al-pager { gap: 6px !important; }
    .al-page-size { height: var(--sc-tap-min) !important; min-width: 130px !important; font-size: 14px !important; }

    /* ── Navbar controls ────────────────────────────────────── */
    .sc-theme-toggle {
        width: var(--sc-tap-min) !important;
        height: var(--sc-tap-min) !important;
        border-radius: 10px;
    }
    .sc-user-profile { padding: 6px 12px 6px 6px !important; gap: 10px !important; }
    .sc-user-avatar { width: 36px !important; height: 36px !important; font-size: 14px !important; }

    .app-navbar-item .btn-icon,
    .app-navbar-item > div[class*="w-35px"] {
        width: var(--sc-tap-min) !important;
        height: var(--sc-tap-min) !important;
    }

    /* ── App launcher tiles ─────────────────────────────────── */
    .sc-app-tile { padding: 14px 8px 12px !important; min-height: 90px; }
    .sc-app-tile-icon { width: 56px !important; height: 56px !important; }
    .sc-app-tile-name { font-size: 12px !important; }
    .sc-app-launcher-panel-wide { min-width: 420px !important; }

    /* ── Dashboard / Configurations cards ───────────────────── */
    .cfg-card { padding: 18px !important; min-height: 88px; }
    .cfg-nav-item { padding: 12px 16px !important; min-height: var(--sc-tap-min); }
    .cfg-card-name { font-size: 14.5px !important; }
    .cfg-card-desc { font-size: 12.5px !important; }

    .db-page { padding: 18px !important; }
    .db-stat-card { padding: 18px 20px 16px !important; }

    /* ── Bootstrap form-check (legacy menus) ────────────────── */
    .form-check { padding-left: 0 !important; min-height: var(--sc-tap-min); align-items: center; display: inline-flex; }
    .form-check-input { width: 20px !important; height: 20px !important; margin: 0 !important; }
    .form-check-label { font-size: 14px !important; padding-left: 8px; }

    /* ── User-account menu dropdown — bigger rows ──────────── */
    .menu-sub-dropdown .menu-item,
    .menu .menu-item .menu-link {
        min-height: var(--sc-tap-min);
        padding: 10px 14px !important;
        font-size: 14px !important;
    }

    /* ── Scroll: smooth + larger scrollbar ──────────────────── */
    html { scroll-behavior: smooth; -webkit-overflow-scrolling: touch; }
    ::-webkit-scrollbar { width: 10px !important; height: 10px !important; }

    /* ── Sticky toolbar — disable hover effect, use :active ── */
    .csp-btn:hover, .csp-icon-btn:hover, .csp-link:hover,
    .sc-app-tile:hover, .cfg-card:hover {
        background: inherit;
    }
    .csp-btn:active           { filter: brightness(0.92); }
    .csp-icon-btn:active      { background: var(--sc-surface-2) !important; }
    .sc-app-tile:active       { background: var(--sc-nav-hover-bg, var(--sc-bg4)) !important; }
    .cfg-card:active          { transform: scale(0.985); }
}

/* ── Manual force: opt-in even on a desktop with mouse ──────
   Add `data-touch="on"` to <html> to force touch mode for debugging
   or for kiosk-style installs that always run on Surface. */
[data-touch="on"] {
    --sc-tap-min: 44px;
    --sc-tap-mid: 40px;
}
[data-touch="on"] .csp-btn       { min-height: 44px !important; padding: 8px 16px !important; font-size: 14px !important; }
[data-touch="on"] .csp-icon-btn  { width: 40px !important; height: 40px !important; }
[data-touch="on"] .csp-back-btn  { width: 40px !important; height: 40px !important; }
[data-touch="on"] .csp-input     { min-height: 44px !important; padding: 10px 14px !important; font-size: 14px !important; }
[data-touch="on"] .csp-search    { height: 44px !important; }
[data-touch="on"] .sc-theme-toggle { width: 44px !important; height: 44px !important; }
[data-touch="on"] .al-pager-btn  { min-width: 44px !important; height: 44px !important; font-size: 14px !important; }
