/**
 * SMART-THESIS RESPONSIVE DESIGN SYSTEM & PRESENTATION HARDENING (UX-0)
 * Canonical Responsive Rules, Design Tokens, Anti-Overflow System & Components
 */

/* =========================================================
   1. DESIGN TOKENS (Standardized CSS Custom Properties)
   ========================================================= */
:root {
    --content-max-width: 1440px;
    --page-padding: clamp(1rem, 3vw, 2.5rem);
    --card-gap: 1.5rem;
    --radius-sm: 0.75rem;
    --radius-md: 1.25rem;
    --radius-lg: 1.5rem;
    --radius-xl: 2.5rem;
    --radius: 1.5rem;
    --sidebar-width: 18rem; /* 288px */
    --header-height: 5rem;   /* 80px */
    --touch-target-min: 44px;
    --transition-standard: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* =========================================================
   2. GLOBAL ANTI-OVERFLOW & CONTAINER FOUNDATION
   ========================================================= */
*, *::before, *::after {
    box-sizing: border-box;
}

/* Link & Button Reset: Triệt tiêu gạch dưới mặc định từ Bootstrap 5 Reboot */
a,
a:hover,
a:focus,
.btn,
button,
[role="button"] {
    text-decoration: none !important;
}

html {
    overflow-x: hidden;
    overflow-x: clip;
    max-width: 100%;
}

body {
    max-width: 100%;
    position: relative;
}

/* Flex and Grid Children Anti-Overflow (P0 Rule 36) */
main,
.main-content,
.flex-1,
.card,
.dashboard-panel,
.bento-card,
.glass-card {
    min-width: 0;
}

/* Media responsiveness (P0 Rule 30) */
img, video, canvas, svg {
    max-width: 100%;
    height: auto;
}

/* Standard Page Containers (P0 Rule 6) */
.page-container,
.content-wrapper,
.container-fluid {
    width: 100%;
    max-width: var(--content-max-width);
    margin-inline: auto;
    padding-inline: var(--page-padding);
}

/* Typography Fluid Scaling (P0 Rule 32) */
h1, .h1 {
    font-size: clamp(1.75rem, 4vw, 2.5rem);
    line-height: 1.2;
    overflow-wrap: break-word;
}

h2, .h2 {
    font-size: clamp(1.35rem, 3vw, 2rem);
    line-height: 1.25;
    overflow-wrap: break-word;
}

/* =========================================================
   3. CANONICAL TABLE SYSTEM (P0 Rules 12-19)
   ========================================================= */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1rem;
    position: relative;
    border-radius: inherit;
}

/* Mobile Table Scroll Affordance (DEF-TABLE-OVERFLOW-MOBILE) - Clean native indicator without touch interception */
@media (max-width: 767.98px) {
    .table-responsive,
    .overflow-x-auto {
        scrollbar-width: thin;
        scrollbar-color: rgba(148, 163, 184, 0.6) transparent;
    }
    
    .table-responsive::-webkit-scrollbar,
    .overflow-x-auto::-webkit-scrollbar {
        height: 6px;
    }
    
    .table-responsive::-webkit-scrollbar-thumb,
    .overflow-x-auto::-webkit-scrollbar-thumb {
        background-color: rgba(148, 163, 184, 0.6);
        border-radius: 9999px;
    }
}

/* Allow table to retain minimum width inside scroll container without clipping */
.table-responsive > table,
.table-responsive table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 0;
}

/* Cell Wrapping (Rule 16) - Never global white-space nowrap */
.table-responsive td,
.table-responsive th {
    overflow-wrap: anywhere;
    word-break: normal;
    vertical-align: middle;
}

/* Multi-line Headers (Rule 19) */
.table-responsive th {
    white-space: normal;
}

/* Table Actions Wrapper (Rule 17) */
.table-actions {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    justify-content: flex-end;
}

/* =========================================================
   4. MODALS & DRAWERS (P0 Rule 26)
   ========================================================= */
/* Bootstrap Modal Hardening */
.modal-dialog {
    max-width: min(calc(100vw - 32px), 800px) !important;
    margin: 1rem auto !important;
}

.modal-content {
    max-height: calc(100vh - 32px) !important;
    overflow-y: auto !important;
    border-radius: var(--radius-lg) !important;
}

.modal-footer {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

/* Custom Tailwind Modals */
.custom-modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 150;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(8px);
}

.modal-responsive,
.custom-modal-card {
    width: 100%;
    max-width: min(calc(100vw - 32px), 720px);
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    border-radius: var(--radius-xl);
}

/* =========================================================
   5. TOOLBARS & SEARCH HUBS (P0 Rule 22)
   ========================================================= */
.responsive-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
    width: 100%;
}

.responsive-toolbar > * {
    min-width: 0;
}

@media (max-width: 767.98px) {
    .responsive-toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    
    .responsive-toolbar .flex-1,
    .responsive-toolbar form,
    .responsive-toolbar input,
    .responsive-toolbar select {
        width: 100% !important;
    }
}

/* =========================================================
   6. FORM GRIDS (P0 Rules 23-25)
   ========================================================= */
.form-grid {
    display: grid;
    gap: 1.5rem;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

@media (max-width: 575.98px) {
    .form-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem;
    }
}

/* File Upload Wrapping (Rule 25) */
.file-upload-zone {
    width: 100%;
    overflow: hidden;
    word-break: break-all;
}

/* =========================================================
   7. PAGINATION (P0 Rule 21)
   ========================================================= */
.pagination-wrapper {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    width: 100%;
}

/* =========================================================
   8. TOUCH TARGETS (P0 Rule 33)
   ========================================================= */
@media (pointer: coarse) {
    button,
    .btn,
    input[type="button"],
    input[type="submit"],
    input[type="reset"],
    .touch-target {
        min-height: var(--touch-target-min);
        min-width: var(--touch-target-min);
    }
}

/* =========================================================
   9. AI-READY & BLOCKCHAIN-READY UI SLOTS (Rules 57-58)
   ========================================================= */
/* Future AI Components Slot */
.ai-slot-container {
    width: 100%;
    min-width: 0;
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.ai-recommendation-panel {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
    width: 100%;
}

.ai-evidence-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 700;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Future Blockchain Components Slot */
.blockchain-slot-container {
    width: 100%;
    min-width: 0;
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.blockchain-qr-box {
    aspect-ratio: 1 / 1;
    max-width: 240px;
    width: 100%;
    margin-inline: auto;
    object-contain: contain;
}

.blockchain-hash-display {
    font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace);
    font-size: 0.8rem;
    overflow-wrap: anywhere;
    word-break: break-all;
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    background: rgba(0, 0, 0, 0.05);
}

/* =========================================================
   10. MOBILE BREAKPOINT SPECIALIZATIONS (< 480px, < 768px)
   ========================================================= */
@media (max-width: 767.98px) {
    /* Main Layout Padding Symmetrization */
    main {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }
    
    /* Sticky sidebars collapse to regular flow on mobile */
    .sidebar-sticky {
        height: auto !important;
        position: static !important;
    }

    /* Page Header Stack */
    .page-header-actions {
        flex-direction: column;
        align-items: stretch !important;
        width: 100%;
    }
}

@media (max-width: 479.98px) {
    :root {
        --page-padding: 0.75rem;
    }

    /* Prevent padding-induced horizontal scroll */
    .p-8, .p-10, .p-12, .p-16, .p-20, .p-24 {
        padding: 1.25rem !important;
    }
    
    .px-8, .px-10, .px-12, .px-14, .px-16 {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }
}

@media (min-width: 768px) and (max-width: 1023.98px) {
    /* When sidebar is present on tablet viewports (768px), main content width is ~432px */
    .md\:grid-cols-3,
    .md\:grid-cols-4 {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)) !important;
    }
}

/* =========================================================
   11. PROPORTIONAL VIEWPORT BUTTON & TAB PILL SCALING
   Scales oversized Tailwind button/CTA padding & radii
   proportionally across desktop, laptop, tablet, and mobile.
   ========================================================= */
:root {
    --btn-py-lg: clamp(0.5rem, 0.38rem + 0.35vw, 0.72rem);
    --btn-py-xl: clamp(0.55rem, 0.42rem + 0.4vw, 0.8rem);
    --btn-px-lg: clamp(0.875rem, 0.65rem + 0.65vw, 1.25rem);
    --btn-px-xl: clamp(1rem, 0.75rem + 0.8vw, 1.45rem);
    --btn-font-scale: clamp(0.6875rem, 0.64rem + 0.14vw, 0.75rem);
    --btn-radius-scale: clamp(0.75rem, 0.6rem + 0.35vw, 1rem);
}

/* Tame oversized vertical padding (py-3, py-3.5, py-4, py-5, py-6) on buttons and CTA links across all portals */
:is(button, a, [role="button"]):is(.py-3, .py-3\.5, .py-4, .sm\:py-3\.5, .sm\:py-4, .md\:py-4) {
    padding-top: var(--btn-py-lg) !important;
    padding-bottom: var(--btn-py-lg) !important;
}

:is(button, a, [role="button"]):is(.py-5, .py-6, .sm\:py-5, .sm\:py-6, .md\:py-5, .md\:py-6) {
    padding-top: var(--btn-py-xl) !important;
    padding-bottom: var(--btn-py-xl) !important;
}

/* Tame oversized horizontal padding (px-6, px-7, px-8, px-10, px-12) on buttons and CTA links */
:is(button, a, [role="button"]):is(.px-5, .px-6, .px-7, .px-8, .sm\:px-6, .sm\:px-8, .md\:px-8) {
    padding-left: var(--btn-px-lg) !important;
    padding-right: var(--btn-px-lg) !important;
}

:is(button, a, [role="button"]):is(.px-10, .px-12, .px-14, .px-16, .sm\:px-10, .sm\:px-12, .md\:px-10, .md\:px-12) {
    padding-left: var(--btn-px-xl) !important;
    padding-right: var(--btn-px-xl) !important;
}

/* Proportionally scale border-radius and typography on large buttons */
:is(button, a, [role="button"]):is(.py-3, .py-3\.5, .py-4, .py-5, .py-6, .px-7, .px-8, .px-10, .px-12) {
    font-size: var(--btn-font-scale) !important;
    line-height: 1.25 !important;
    border-radius: var(--btn-radius-scale) !important;
    gap: 0.45rem !important;
}

:is(button, a, [role="button"]):is(.py-3, .py-3\.5, .py-4, .py-5, .py-6, .px-6, .px-8, .px-10, .px-12) .material-symbols-outlined {
    font-size: clamp(16px, 0.9rem + 0.2vw, 18px) !important;
}

/* Compact square icon action buttons (w-12 h-12 -> proportional 36px-40px on desktop) */
:is(button, a, [role="button"]).w-12.h-12 {
    width: clamp(2.15rem, 1.95rem + 0.35vw, 2.45rem) !important;
    height: clamp(2.15rem, 1.95rem + 0.35vw, 2.45rem) !important;
    border-radius: 0.75rem !important;
}

/* Apple-style primary CTA buttons in Student Portal */
.apple-btn-primary {
    padding: var(--btn-py-lg) var(--btn-px-lg) !important;
    font-size: var(--btn-font-scale) !important;
    border-radius: var(--btn-radius-scale) !important;
}

/* Laptop / Compact Desktop (<= 1366px): tighten button footprint further */
@media (max-width: 1366px) {
    :root {
        --btn-py-lg: 0.48rem;
        --btn-py-xl: 0.55rem;
        --btn-px-lg: 0.9rem;
        --btn-px-xl: 1.05rem;
        --btn-font-scale: 0.6875rem;
        --btn-radius-scale: 0.75rem;
    }
}

/* Tablet & Mobile (<= 768px): compact buttons that fit narrow screens */
@media (max-width: 767.98px) {
    :root {
        --btn-py-lg: 0.45rem;
        --btn-py-xl: 0.5rem;
        --btn-px-lg: 0.8rem;
        --btn-px-xl: 0.95rem;
        --btn-font-scale: 0.6875rem;
        --btn-radius-scale: 0.7rem;
    }
}

