﻿/* ============================================
   Capital CST - Enhanced Responsive CSS
   Mobile-First Design System
   ============================================ */

/* ============================================
   Mobile First Base Styles
   ============================================ */

/* Ensure viewport meta is respected */
html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

/* Touch-friendly tap targets */
button, 
.btn, 
a.nav-link,
input[type="submit"],
input[type="button"] {
    min-height: 44px;
    min-width: 44px;
}

/* Fluid images */
img {
    max-width: 100%;
    height: auto;
}

/* ============================================
   Mobile Styles (Default - Mobile First)
   ============================================ */

/* Container adjustments */
.container {
    padding-left: 15px;
    padding-right: 15px;
}

/* Full-width inputs on mobile */
.form-control,
.form-select,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="tel"],
textarea,
select {
    width: 100%;
    font-size: 16px; /* Prevents zoom on iOS */
}

/* Stack buttons on mobile */
.btn-group-mobile {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btn-group-mobile .btn {
    width: 100%;
}

/* ============================================
   Responsive Tables - Card View on Mobile
   ============================================ */

/* Hide table on mobile, show cards */
@media (max-width: 768px) {
    .table-responsive-cards thead {
        display: none;
    }
    
    .table-responsive-cards tbody tr {
        display: block;
        background: var(--bg-white, #fff);
        border: 1px solid var(--border-color, #e5e7eb);
        border-radius: 12px;
        margin-bottom: 15px;
        padding: 15px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    }
    
    .table-responsive-cards tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 10px 0;
        border: none;
        border-bottom: 1px solid var(--border-color, #e5e7eb);
    }
    
    .table-responsive-cards tbody td:last-child {
        border-bottom: none;
    }
    
    .table-responsive-cards tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-dark, #1f2937);
        flex: 1;
    }
    
    .table-responsive-cards tbody td .btn {
        padding: 8px 12px;
        font-size: 0.85rem;
    }
}

/* Horizontal scroll for complex tables */
.table-scroll-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -15px;
    padding: 0 15px;
}

.table-scroll-wrapper table {
    min-width: 600px;
}

/* ============================================
   Off-Canvas Sidebar
   ============================================ */

/* Mobile overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* Hamburger Menu Button */
.hamburger-btn {
    display: none;
    width: 44px;
    height: 44px;
    background: var(--primary, #059669);
    border: none;
    border-radius: 10px;
    cursor: pointer;
    position: relative;
    z-index: 1001;
}

.hamburger-btn span {
    display: block;
    width: 22px;
    height: 2px;
    background: white;
    margin: 5px auto;
    transition: all 0.3s ease;
}

.hamburger-btn.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}

.hamburger-btn.active span:nth-child(2) {
    opacity: 0;
}

.hamburger-btn.active span:nth-child(3) {
    transform: rotate(-45deg) translate(5px, -5px);
}

@media (max-width: 992px) {
    .hamburger-btn {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
    }
}

/* ============================================
   Responsive Grid System Enhancements
   ============================================ */

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 15px;
}

@media (min-width: 576px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 992px) {
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 20px;
    }
}

/* Dashboard Cards Grid */
.dashboard-cards {
    display: grid;
    grid-template-columns: 1fr;
    gap: 15px;
}

@media (min-width: 768px) {
    .dashboard-cards {
        grid-template-columns: repeat(2, 1fr);
        gap: 20px;
    }
}

@media (min-width: 1200px) {
    .dashboard-cards {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ============================================
   Mobile Navigation
   ============================================ */

@media (max-width: 992px) {
    /* Sidebar transforms to off-canvas */
    .sidebar {
        transform: translateX(100%);
        width: 280px !important;
        transition: transform 0.3s ease;
    }
    
    .sidebar.active {
        transform: translateX(0);
    }
    
    /* Header adjustments */
    .header,
    .admin-header {
        right: 0 !important;
        padding: 0 15px;
    }
    
    /* Main content full width */
    .main-content,
    .admin-main {
        margin-right: 0 !important;
        padding: 15px;
    }
    
    /* Page title truncation */
    .page-title {
        max-width: 200px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

/* ============================================
   Form Responsive Layouts
   ============================================ */

/* Form row - stack on mobile */
.form-row {
    display: flex;
    flex-wrap: wrap;
    margin: 0 -10px;
}

.form-row > .form-group {
    padding: 0 10px;
    width: 100%;
}

@media (min-width: 768px) {
    .form-row > .form-group.col-md-6 {
        width: 50%;
    }
    
    .form-row > .form-group.col-md-4 {
        width: 33.333%;
    }
    
    .form-row > .form-group.col-md-3 {
        width: 25%;
    }
}

/* Filter section responsive */
.filter-section {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

@media (min-width: 768px) {
    .filter-section {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: flex-end;
    }
    
    .filter-section .form-group {
        flex: 1;
        min-width: 200px;
        margin-bottom: 0;
    }
}

/* ============================================
   Modal Responsive
   ============================================ */

.modal-dialog {
    margin: 10px;
    max-width: calc(100% - 20px);
}

@media (min-width: 576px) {
    .modal-dialog {
        margin: 30px auto;
        max-width: 500px;
    }
}

@media (min-width: 992px) {
    .modal-dialog.modal-lg {
        max-width: 800px;
    }
    
    .modal-dialog.modal-xl {
        max-width: 1140px;
    }
}

/* Modal body scroll on mobile */
.modal-body {
    max-height: calc(100vh - 200px);
    overflow-y: auto;
}

/* ============================================
   Card Responsive Styles
   ============================================ */

.card {
    margin-bottom: 15px;
}

.card-body {
    padding: 15px;
}

@media (min-width: 768px) {
    .card-body {
        padding: 25px;
    }
}

/* Stat card responsive */
.stat-card {
    padding: 15px;
}

.stat-card .stat-icon {
    width: 45px;
    height: 45px;
    font-size: 1.2rem;
}

.stat-card .stat-number {
    font-size: 1.5rem;
}

@media (min-width: 768px) {
    .stat-card {
        padding: 20px;
    }
    
    .stat-card .stat-icon {
        width: 55px;
        height: 55px;
        font-size: 1.5rem;
    }
    
    .stat-card .stat-number {
        font-size: 1.8rem;
    }
}

/* ============================================
   Button Responsive
   ============================================ */

/* Full width buttons on mobile */
@media (max-width: 576px) {
    .btn-mobile-full {
        width: 100%;
        margin-bottom: 10px;
    }
    
    .btn-group {
        flex-direction: column;
        width: 100%;
    }
    
    .btn-group .btn {
        width: 100%;
        border-radius: 8px !important;
        margin-bottom: 5px;
    }
}

/* Action buttons in tables */
.action-buttons {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
}

@media (max-width: 576px) {
    .action-buttons {
        flex-direction: column;
    }
    
    .action-buttons .btn {
        width: 100%;
        justify-content: center;
    }
}

/* ============================================
   Header Responsive
   ============================================ */

.header-content {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

@media (min-width: 768px) {
    .header-content {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }
}

.header-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

@media (max-width: 576px) {
    .header-actions {
        width: 100%;
    }
    
    .header-actions .btn {
        flex: 1;
        min-width: 0;
    }
    
    .header-actions .btn span {
        display: none;
    }
}

/* ============================================
   Search Box Responsive
   ============================================ */

.search-box {
    width: 100%;
}

@media (min-width: 768px) {
    .search-box {
        width: 300px;
    }
}

/* Section header responsive */
.section-header {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

@media (min-width: 768px) {
    .section-header {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }
}

/* ============================================
   Scanner Section Responsive
   ============================================ */

.scanner-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
}

@media (min-width: 992px) {
    .scanner-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 30px;
    }
}

.scanner-preview {
    min-height: 200px;
}

@media (min-width: 768px) {
    .scanner-preview {
        min-height: 280px;
    }
}

/* ============================================
   Attendance Log Responsive
   ============================================ */

.log-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
}

@media (min-width: 576px) {
    .log-item {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }
}

/* ============================================
   Print Styles
   ============================================ */

@media print {
    .sidebar,
    .header,
    .admin-header,
    .hamburger-btn,
    .btn,
    .no-print {
        display: none !important;
    }
    
    .main-content,
    .admin-main {
        margin: 0 !important;
        padding: 0 !important;
    }
    
    .card {
        box-shadow: none !important;
        border: 1px solid #ddd !important;
    }
    
    body {
        background: white !important;
    }
}

/* ============================================
   Utility Classes for Responsive
   ============================================ */

/* Hide on mobile */
@media (max-width: 767px) {
    .d-mobile-none {
        display: none !important;
    }
}

/* Show only on mobile */
@media (min-width: 768px) {
    .d-mobile-only {
        display: none !important;
    }
}

/* Full width on mobile */
@media (max-width: 576px) {
    .w-mobile-100 {
        width: 100% !important;
    }
}

/* Text alignment responsive */
@media (max-width: 576px) {
    .text-mobile-center {
        text-align: center !important;
    }
}

/* Padding adjustments */
@media (max-width: 576px) {
    .p-mobile-2 {
        padding: 0.5rem !important;
    }
    
    .px-mobile-2 {
        padding-left: 0.5rem !important;
        padding-right: 0.5rem !important;
    }
}

/* Margin adjustments */
@media (max-width: 576px) {
    .mb-mobile-3 {
        margin-bottom: 1rem !important;
    }
}

/* Font size responsive */
@media (max-width: 576px) {
    .fs-mobile-sm {
        font-size: 0.875rem !important;
    }
}
