
/* =====================================================================
   Againsoft UI fixes — fonts, devices, layout, mobile usability
   Loaded LAST via app/Views/includes/custom_head.php with ?v=<file mtime>
   (cache-busting). Neither file is overwritten by Rise core updates, so all
   global UI fixes live here.
   Documented in docs/CRM_SYSTEM_DOCUMENTATION.md §1 (UI layer).
   ===================================================================== */

/* ---------- 1. Fonts ---------- */

/* Same Open Sans files as stock, plus font-display: swap so text shows
   immediately with a fallback font instead of staying invisible. */
@font-face { font-family: 'Open Sans'; font-style: normal; font-weight: 300; font-display: swap;
    src: local('Open Sans Light'), local('OpenSans-Light'), url('fonts/opensans/opensans-light.woff') format('woff'); }
@font-face { font-family: 'Open Sans'; font-style: normal; font-weight: 400; font-display: swap;
    src: local('Open Sans'), local('OpenSans'), url('fonts/opensans/opensans.woff') format('woff'); }
@font-face { font-family: 'Open Sans'; font-style: normal; font-weight: 700; font-display: swap;
    src: local('Open Sans Bold'), local('OpenSans-Bold'), url('fonts/opensans/opensans-bold.woff') format('woff'); }

/* Open Sans has no Bengali letters. Without this, Bengali text (task titles,
   daily account descriptions, notes) falls back to whatever the device picks,
   e.g. the old "Vrinda" font on Windows. These are good system Bengali fonts:
   Nirmala UI (Windows), Noto Sans Bengali (Android/Linux), Kohinoor Bangla (iOS/macOS). */
:root {
    --app-font-family: "Open Sans", "Nirmala UI", "Noto Sans Bengali", "Kohinoor Bangla", "Hind Siliguri", "Bangla MN", "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
    --bs-font-sans-serif: var(--app-font-family);
    --bs-body-font-family: var(--app-font-family);
}

body,
button, input, select, textarea, optgroup,
.select2-container, .select2-drop, .select2-results,
.popover, .tooltip, .dropdown-menu, .modal,
.daterangepicker, .datepicker, .fc {
    font-family: var(--app-font-family);
}

html {
    /* stop iOS/Android from enlarging text on rotation */
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* ---------- 2. Layout safety (all screen sizes) ---------- */

/* Long URLs, emails, or unbroken text must wrap instead of pushing the layout wider */
.card-body, .modal-body, .dataTable td, .list-group-item, .comment-container,
.dropdown-menu, .popover-body, .box-content {
    overflow-wrap: break-word;
    word-wrap: break-word;
}

/* Images pasted into descriptions, notes, comments, tickets never exceed their box */
#page-content img,
.modal-body img {
    max-width: 100%;
}
#page-content img:not([height]),
.modal-body img:not([height]) {
    height: auto;
}

/* Embedded media stay inside their container */
#page-content iframe,
#page-content video {
    max-width: 100%;
}

/* ---------- 3. Phones and small tablets (Rise treats < 800px as mobile) ---------- */

@media (max-width: 767.98px) {

    /* iPhone/iPad zoom into any input with text under 16px; 16px stops that zoom */
    input.form-control,
    select.form-control,
    textarea.form-control,
    .form-select,
    input[type="text"], input[type="search"], input[type="email"], input[type="number"],
    input[type="password"], input[type="tel"], input[type="url"], input[type="date"],
    textarea,
    .select2-container .select2-choice,
    .select2-container .select2-choices .select2-search-field input,
    .select2-search input,
    .dataTables_filter input {
        font-size: 16px !important;
    }

    /* Minimum readable size for small labels and badges */
    .text-off, .badge, small, .small, .font-11, .font-12 {
        font-size: 12px !important;
    }

    /* Modals use nearly the full screen width */
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }
    .modal-footer .btn {
        min-width: 96px;
    }

    /* Table cells: a little more vertical room so rows are easier to tap */
    table.dataTable > tbody > tr > td {
        padding-top: 10px;
        padding-bottom: 10px;
    }

    /* Page titles wrap instead of being cut off */
    .page-title h1, .page-title h4, .title-tab h4 {
        white-space: normal;
        word-break: normal; /* QA 2026-11-18: break-word squeezed titles to one letter per line beside tabs */
        overflow-wrap: break-word;
        min-width: 7em;
        flex-shrink: 0;
    }

    /* Keep the last content clear of the fixed bottom menu */
    #page-content {
        padding-bottom: 16px;
    }
}

/* ---------- 4. Touch devices (phones, tablets, touch laptops) ---------- */

@media (pointer: coarse) {
    /* Comfortable touch targets (about 40px) */
    .btn,
    .page-link,
    .dataTables_paginate .paginate_button,
    .dropdown-item,
    .nav-tabs .nav-link {
        min-height: 40px;
    }
    .btn,
    .page-link {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    .dropdown-item {
        display: flex;
        align-items: center;
    }
    .page-link {
        min-width: 40px;
    }

    /* The "+" control that opens a collapsed table row: bigger icon */
    table.dataTable.dtr-inline.collapsed > tbody > tr > td.dtr-control:before,
    table.dataTable.dtr-inline.collapsed > tbody > tr > th.dtr-control:before {
        width: 16px;
        height: 16px;
        line-height: 16px;
    }

    /* Options icons in the last column (edit/delete) get room around them */
    table.dataTable td.option a {
        display: inline-block;
        padding: 6px;
    }
}

/* Module dashboards (plugins/Dashboards): card row at the top of module pages */
.md-cards .dashboard-icon-widget .card-body { min-height: 88px; display: flex; align-items: center; gap: 12px; }
.md-cards .dashboard-icon-widget .widget-icon { float: none; flex: 0 0 auto; }
.md-cards .dashboard-icon-widget .widget-details { position: static; flex: 1 1 auto; min-width: 0; text-align: right; }
.md-cards .dashboard-icon-widget .widget-details span { display: block; padding-left: 0; line-height: 1.3; }
.md-cards .md-value { font-size: 22px; word-break: break-word; }
.md-cards .md-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 4px 16px; }
.md-cards .md-list-item { min-width: 0; padding: 3px 0; }
.md-cards .widget-details span, .md-cards .md-value { word-break: normal; overflow-wrap: break-word; }
@media (max-width: 575px) {
    .md-cards .dashboard-icon-widget .card-body { flex-direction: column; align-items: flex-start; gap: 6px; padding: 10px 12px; min-height: 0; }
    .md-cards .dashboard-icon-widget .widget-icon { width: 34px; height: 34px; }
    .md-cards .dashboard-icon-widget .widget-icon .icon { width: 18px; height: 18px; }
    .md-cards .dashboard-icon-widget .widget-details { text-align: left; }
    .md-cards .md-value { font-size: 18px; margin: 0; }
    .md-cards .widget-details span { font-size: 13px; }
}

/* Accounts dashboard (Phase 9b): the big total */
.acc-total-amount { font-size: 34px; font-weight: 600; line-height: 1.2; word-break: break-word; }
@media (max-width: 575px) { .acc-total-amount { font-size: 26px; } }

/* money inputs (assets/js/againsoft-ui.js): a refused character flashes the field and a short hint */
input.as-money-bad { border-color: #e74c3c !important; box-shadow: 0 0 0 2px rgba(231, 76, 60, .15) !important; }
.as-money-tip { color: #e74c3c; font-size: 12px; margin-top: 3px; }

/* Bootstrap ".table" (used by plugin views for small static tables) sets a white cell background and light-grey lines in
   every theme. Rise's own tables take the card's colour, so in dark themes these tables showed white boxes.
   Follow Rise: transparent cells, the theme's text colour and a soft line that works on light and dark cards (2026-11-17). */
.table {
    --bs-table-bg: transparent;
    --bs-table-color: inherit;
    --bs-table-striped-bg: transparent;
    --bs-table-striped-color: inherit;
    --bs-table-hover-bg: rgba(128, 128, 128, 0.08);
    --bs-table-hover-color: inherit;
    color: inherit;
}
.table > :not(caption) > * > * {
    background-color: transparent;
    color: inherit;
    border-bottom-color: rgba(128, 128, 128, 0.18);
}
.table thead th {
    border-bottom-color: rgba(128, 128, 128, 0.28);
}

/* Againsoft (2026-11-18): when the open page has its own sub-menu item, that item is the highlighted one; its group only shows it is open */
.sidebar-menu li.main.ag-sub-open > a { background-color: transparent !important; }
.sidebar-menu li.main.ag-sub-open > ul > li.active > a { font-weight: 600; border-radius: 4px; }
