/* ============================================================
   SMMS — Global Styles
   Built on Bootstrap 5 — yahaan sirf overrides + theme variables.
   :root variables layouts/header.php me Theme::cssVariablesTag() ne inject kiye hain.
   ============================================================ */

/* ---------- Base typography ---------- */
html, body {
    height: 100%;
    /* Defence against wide tables / long UDISE codes pushing the page
       sideways on mobile. Each .table-responsive still scrolls its own
       table; the document itself never scrolls horizontally. */
    max-width: 100%;
    overflow-x: hidden;
}

body {
    font-family: 'Noto Sans Devanagari', 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--smms-bg, #F5F7FA);
    color: var(--smms-text, #212529);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* English text inside body — render via system stack but keep Devanagari fallback */
.lang-en, .lang-en * {
    font-family: 'Segoe UI', 'Helvetica Neue', Arial, 'Noto Sans Devanagari', sans-serif;
}

a {
    color: var(--smms-primary);
    text-decoration: none;
}
a:hover {
    color: var(--smms-secondary);
    text-decoration: underline;
}

/* ---------- Bootstrap colour overrides via CSS vars ---------- */
.btn-primary,
.bg-primary {
    background-color: var(--smms-primary) !important;
    border-color: var(--smms-primary) !important;
}
.btn-primary:hover,
.btn-primary:focus {
    background-color: var(--smms-secondary) !important;
    border-color: var(--smms-secondary) !important;
}

.text-primary { color: var(--smms-primary) !important; }
.text-accent  { color: var(--smms-accent)  !important; }
.bg-accent    { background-color: var(--smms-accent) !important; color: #fff !important; }

/* ---------- Top navbar ---------- */
.smms-topbar {
    background: linear-gradient(135deg, var(--smms-primary), var(--smms-secondary));
    color: #fff;
    padding: 0.65rem 1rem;
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}
.smms-topbar a,
.smms-topbar .navbar-brand,
.smms-topbar .nav-link {
    color: #fff !important;
}
.smms-topbar .navbar-brand {
    font-weight: 700;
    font-size: 1.15rem;
}
.smms-topbar .smms-org {
    font-size: 0.85rem;
    opacity: 0.9;
}

/* ---------- Layout shell ---------- */
.smms-shell {
    display: flex;
    min-height: calc(100vh - 56px);
    position: relative;
}

/* Sidebar: offcanvas-md ke saath kaam karta hai.
   - < md (768px): Bootstrap apne aap is element ko offcanvas (slide-in) bana deta hai
   - >= md       : hum ise inline sidebar ki tarah dikhate hain */
.smms-sidebar {
    background: #fff;
}
.smms-sidebar .nav-link {
    color: var(--smms-text);
    padding: 0.65rem 1.25rem;
    border-left: 3px solid transparent;
    font-weight: 500;
}
.smms-sidebar .nav-link:hover {
    background: var(--smms-bg);
    color: var(--smms-primary);
    text-decoration: none;
}
.smms-sidebar .nav-link.active {
    background: var(--smms-bg);
    color: var(--smms-primary);
    border-left-color: var(--smms-accent);
}
.smms-sidebar .nav-link i {
    margin-right: 0.5rem;
    width: 1.2em;
    text-align: center;
}

/* Desktop: sidebar ko fixed-width inline panel ki tarah dikhao */
@media (min-width: 768px) {
    .smms-sidebar {
        width: 240px;
        flex-shrink: 0;
        border-right: 1px solid var(--smms-border);
        padding: 1rem 0;
    }
    .smms-sidebar .offcanvas-body {
        overflow: visible !important;
    }
}

/* Mobile offcanvas: width tighter than default 400px */
@media (max-width: 767.98px) {
    .smms-sidebar.offcanvas {
        width: 78%;
        max-width: 320px;
    }
    .smms-sidebar .offcanvas-header {
        background: var(--smms-bg);
        border-bottom: 1px solid var(--smms-border);
    }
    .smms-sidebar .offcanvas-title {
        color: var(--smms-primary);
        font-weight: 700;
    }
}

.smms-content {
    flex: 1;
    padding: 1.5rem;
    /* min-width:0 is critical: flex children default to min-width:auto
       which lets wide content (tables, long Hindi text) expand the
       parent beyond the viewport. With 0, the column shrinks and the
       inner .table-responsive takes over with its own horizontal scroll. */
    min-width: 0;
    max-width: 100%;
}
@media (max-width: 575.98px) {
    .smms-content {
        padding: 1rem 0.85rem;
    }
}

/* ---------- Responsive table defence ----------
   Bootstrap's .table-responsive gives the table its own scrollbar, but it
   only works when the WRAPPER is constrained. These rules ensure that:
   - the wrapper never exceeds its parent
   - long Hindi/English text inside cells wraps instead of pushing width
   - tables that forgot the wrapper still degrade gracefully (block scroll)
*/
.table-responsive {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.smms-content table {
    max-width: 100%;
}
.smms-content table td,
.smms-content table th {
    /* Allow long unbreakable strings (UDISE codes, monitor names, URLs)
       to break across lines on small screens instead of forcing the cell
       to widen. text-nowrap classes on individual cells still win. */
    overflow-wrap: anywhere;
    word-break: normal;
}
/* Cells the developer explicitly marked as no-wrap (action buttons,
   status badges) should NOT be affected by the rule above. */
.smms-content table td.text-nowrap,
.smms-content table th.text-nowrap {
    overflow-wrap: normal;
    word-break: normal;
    white-space: nowrap;
}

/* ---------- Action-button columns ----------
   Tables with several inline action buttons (`.btn-sm` + `<form class="d-inline">`)
   end up wide because each button forces minimum width AND text-nowrap on the
   cell prevents wrapping. On small screens we override that — buttons can wrap
   onto a second line inside the cell, but stay together as a group. The actions
   themselves keep `text-nowrap` (button labels don't break mid-word).
*/
@media (max-width: 575.98px) {
    .smms-content table td.text-end.text-nowrap,
    .smms-content table th.text-end.text-nowrap {
        white-space: normal;
    }
    .smms-content table td.text-end.text-nowrap .btn,
    .smms-content table td.text-end.text-nowrap form {
        margin-top: 0.15rem;
        margin-bottom: 0.15rem;
    }
}

/* ---------- Subtle scroll hint on .table-responsive ----------
   Adds a soft right-edge shadow only when the table actually overflows.
   `background-attachment: local` makes the scroll-tracked gradient slide
   away when the user reaches the end, naturally hiding the hint.
*/
.smms-content .table-responsive {
    background:
        linear-gradient(to right, rgba(255,255,255,1) 30%, rgba(255,255,255,0)) 0 0,
        linear-gradient(to right, rgba(255,255,255,0), rgba(255,255,255,1) 70%) 100% 0,
        radial-gradient(farthest-side at 0 50%, rgba(0,0,0,0.10), rgba(0,0,0,0)) 0 0,
        radial-gradient(farthest-side at 100% 50%, rgba(0,0,0,0.10), rgba(0,0,0,0)) 100% 0;
    background-repeat: no-repeat;
    background-size: 30px 100%, 30px 100%, 12px 100%, 12px 100%;
    background-attachment: local, local, scroll, scroll;
}

/* ---------- Page header + filter row wrapping ----------
   Many list pages have a "Page title left, action button right" header
   built with `.d-flex justify-content-between`. On small screens the
   right-side button can collide with a long Hindi page title. Add a
   forgiving gap + force wrap.
*/
.smms-content h2.smms-page-title {
    overflow-wrap: anywhere;
}
.smms-content .smms-page-title + .d-flex,
.smms-content > .d-flex.justify-content-between {
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* ---------- Form filter row buttons ----------
   Filter bars use `.row g-2` which already wraps. But the trailing Apply +
   Reset + (sometimes) Excel buttons sit in a single .col without min-width
   protection — on small screens they can overflow. This rule keeps them
   wrapping cleanly within the column.
*/
.smms-content form .row > .col-auto .btn,
.smms-content form .row > .col-12 .btn {
    margin-bottom: 0.25rem;
}

/* Hamburger button (mobile only) */
.smms-hamburger {
    color: #fff;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 0.25rem 0.55rem;
    border-radius: 0.35rem;
    font-size: 1.1rem;
    line-height: 1;
}
.smms-hamburger:hover,
.smms-hamburger:focus {
    background: rgba(255, 255, 255, 0.25);
    color: #fff;
}

/* ---------- Page heading ---------- */
.smms-page-title {
    font-weight: 700;
    color: var(--smms-primary);
    margin-bottom: 1.25rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--smms-border);
}

/* ---------- Card ---------- */
.card {
    border: 1px solid var(--smms-border);
    border-radius: 0.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.card-header {
    background: var(--smms-bg);
    border-bottom: 1px solid var(--smms-border);
    font-weight: 600;
    color: var(--smms-primary);
}

/* ---------- Chart card (dashboard widgets) ---------- */
.smms-chart-card {
    transition: box-shadow 0.18s ease;
}
.smms-chart-card:hover {
    box-shadow: 0 4px 14px rgba(121, 70, 31, 0.10);
}
.smms-chart-card .card-header {
    padding: 0.65rem 1rem;
}
.smms-chart-card .card-header .bi {
    color: var(--smms-primary);
    margin-right: 0.25rem;
}
.smms-chart-card .card-body {
    padding: 1rem 1.1rem;
}
/* Wrapper that gives Chart.js a fixed, responsive box to draw into.
   Without `position:relative` + a fixed height, responsive:true charts
   grow until the parent container does, then overflow on small screens. */
.smms-chart-wrap {
    position: relative;
    width: 100%;
    height: 280px;
}
.smms-chart-wrap canvas {
    max-width: 100%;
}
.smms-chart-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 220px;
    color: var(--smms-muted);
    font-size: 0.95rem;
    text-align: center;
}

/* ---------- Auth (login) screen ---------- */
.smms-auth-bg {
    min-height: 100vh;
    background: linear-gradient(135deg, var(--smms-primary), var(--smms-secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.smms-auth-card {
    width: 100%;
    max-width: 420px;
    background: #fff;
    border-radius: 0.75rem;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    overflow: hidden;
}
.smms-auth-header {
    padding: 1.5rem;
    text-align: center;
    background: var(--smms-bg);
    border-bottom: 1px solid var(--smms-border);
}
.smms-auth-header img {
    height: 56px;
    margin-bottom: 0.5rem;
}
.smms-auth-body {
    padding: 1.5rem;
}
.smms-auth-footer {
    text-align: center;
    padding: 0.75rem;
    font-size: 0.85rem;
    color: var(--smms-muted);
    background: var(--smms-bg);
    border-top: 1px solid var(--smms-border);
}

/* ---------- Role badge ---------- */
.smms-role-badge {
    display: inline-block;
    padding: 0.25rem 0.65rem;
    border-radius: 999px;
    background: var(--smms-accent);
    color: #fff;
    font-size: 0.8rem;
    font-weight: 600;
}

/* ---------- Footer ---------- */
.smms-footer {
    text-align: center;
    padding: 0.75rem;
    font-size: 0.85rem;
    color: var(--smms-muted);
    border-top: 1px solid var(--smms-border);
    background: #fff;
}

/* ---------- Lang switcher button ---------- */
.smms-lang-btn {
    background: rgba(255,255,255,0.15);
    color: #fff !important;
    border: 1px solid rgba(255,255,255,0.3);
    padding: 0.25rem 0.65rem;
    border-radius: 0.35rem;
    font-size: 0.85rem;
    text-decoration: none !important;
}
.smms-lang-btn:hover {
    background: rgba(255,255,255,0.25);
}

/* ---------- Monitoring form ---------- */
.smms-form-actions {
    bottom: 0;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.06);
    border-radius: 0 0 0.5rem 0.5rem;
    z-index: 10;
}

/* Section D: per-question card */
.smms-q {
    border: 1px solid var(--smms-border);
    border-radius: 0.4rem;
    padding: 0.65rem 0.85rem;
    margin-bottom: 0.6rem;
    background: #fff;
}
.smms-q.smms-q-error {
    border-color: var(--smms-danger);
    background: rgba(220, 53, 69, 0.04);
}
.smms-q-head {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}
.smms-q-num {
    background: var(--smms-primary);
    color: #fff;
    font-weight: 700;
    font-size: 0.78rem;
    padding: 0.15rem 0.5rem;
    border-radius: 0.3rem;
    flex-shrink: 0;
    margin-top: 0.1rem;
}
.smms-q-text {
    flex: 1;
    min-width: 0;
}
.smms-q-text-hi {
    font-weight: 500;
    color: var(--smms-text);
    line-height: 1.35;
}
.smms-q-text-en {
    margin-top: 0.15rem;
}
.smms-q-body {
    padding-left: 0.25rem;
}
.smms-q-options {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.smms-q-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 0.6rem;
    border: 1px solid var(--smms-border);
    border-radius: 0.3rem;
    cursor: pointer;
    background: var(--smms-bg);
    transition: background 0.1s;
    font-size: 0.92rem;
}
.smms-q-option:hover {
    background: #eef2f7;
}
.smms-q-option input[type="radio"] {
    flex-shrink: 0;
}
.smms-q-option-hi {
    font-weight: 500;
}

/* Stat card (used in dashboards) */
.smms-stat-card {
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.smms-stat-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
}
.smms-stat-icon {
    width: 3rem;
    height: 3rem;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1.5rem;
}
a.text-reset .smms-stat-card .card-footer { background: rgba(0, 0, 0, 0.02); }

/* Section D accordion polish */
.smms-q-accordion .accordion-button:not(.collapsed) {
    background: linear-gradient(90deg, rgba(31, 78, 121, 0.06), transparent);
    color: var(--smms-primary);
}
.smms-q-accordion .accordion-body {
    background: var(--smms-bg);
}
.smms-students td {
    vertical-align: middle;
}
.smms-students td:first-child {
    background: var(--smms-bg);
}
.smms-teachers input[type="text"],
.smms-teachers input[type="tel"],
.smms-teachers select {
    min-width: 0;
}
.smms-teachers .smms-srno {
    background: var(--smms-bg);
    font-weight: 600;
}

/* ---------- Master data tabs ---------- */
.smms-master-tabs .nav-link {
    color: var(--smms-muted);
    font-weight: 500;
}
.smms-master-tabs .nav-link.active {
    color: var(--smms-primary);
    border-bottom-color: var(--smms-accent);
    font-weight: 600;
}
.smms-master-tabs .nav-link i {
    font-size: 1.05rem;
}

/* Status badges in tables */
.table .badge {
    font-weight: 500;
    font-size: 0.78rem;
}

/* ---------- Tweaks for very small screens ---------- */
@media (max-width: 575.98px) {
    .smms-topbar {
        padding: 0.5rem 0.75rem;
    }
    .smms-topbar .navbar-brand img {
        height: 30px;
    }
    .smms-page-title {
        font-size: 1.3rem;
    }
    .smms-auth-card {
        max-width: 100%;
    }
}
