/* Responsive Design - Ponnuri Book */

/* Extra small devices (portrait phones, less than 576px) */
@media (max-width: 575.98px) {
    .container {
        padding-left: 10px;
        padding-right: 10px;
        max-width: 100%;
    }
    
    h1 { font-size: 1.8rem; }
    h2 { font-size: 1.5rem; }
    h3 { font-size: 1.3rem; }
    
    .navbar-brand span {
        display: none;
    }
    
    .table-responsive {
        font-size: 0.85rem;
        margin-bottom: 15px;
    }
    
    .card-body {
        padding: 1rem;
    }
    
    .btn-group {
        flex-wrap: wrap;
    }
    
    .btn-group .btn {
        margin-bottom: 5px;
        flex: 1 0 auto;
    }
    
    .modal-dialog {
        margin: 0.5rem;
    }
    
    /* Dashboard stats */
    .small-box .inner h3 {
        font-size: 1.8rem;
    }
    
    /* Forms */
    .form-label {
        font-size: 0.9rem;
    }
    
    .form-row {
        flex-direction: column;
    }
    
    .form-row .col {
        margin-bottom: 15px;
    }
    
    /* Sidebar */
    .sidebar {
        position: fixed;
        z-index: 1030;
        width: 250px;
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
        height: 100vh;
        top: 0;
        left: 0;
    }
    
    .sidebar.show {
        transform: translateX(0);
    }
    
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1029;
    }
    
    .sidebar-overlay.show {
        display: block;
    }
    
    .main-content {
        margin-left: 0 !important;
        width: 100%;
    }
    
    /* Chat specific */
    #chat-sidebar {
        width: 100%;
        position: fixed;
        z-index: 1040;
    }
    
    #chat-main {
        width: 100%;
        margin-top: 60px;
    }
    
    .message-bubble {
        max-width: 85%;
    }
    
    .conversation-name {
        max-width: 150px;
    }
}

/* Small devices (landscape phones, 576px and up) */
@media (min-width: 576px) and (max-width: 767.98px) {
    .container {
        max-width: 540px;
    }
    
    .navbar-brand span {
        display: inline;
    }
    
    .table-responsive {
        font-size: 0.9rem;
    }
    
    /* Cards */
    .card-columns {
        column-count: 1;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    /* Chat */
    #chat-sidebar {
        width: 200px;
    }
    
    .conversation-name {
        max-width: 120px;
    }
}

/* Medium devices (tablets, 768px and up) */
@media (min-width: 768px) and (max-width: 991.98px) {
    .container {
        max-width: 720px;
    }
    
    .card-columns {
        column-count: 2;
    }
    
    /* Forms */
    .form-inline .form-control {
        display: inline-block;
        width: auto;
        vertical-align: middle;
    }
    
    /* Tables */
    .table td, .table th {
        padding: 0.75rem;
    }
    
    /* Sidebar */
    .sidebar {
        width: 220px;
    }
    
    .main-content {
        margin-left: 220px;
    }
    
    /* Chat */
    #chat-sidebar {
        width: 250px;
    }
}

/* Large devices (desktops, 992px and up) */
@media (min-width: 992px) and (max-width: 1199.98px) {
    .container {
        max-width: 960px;
    }
    
    .card-columns {
        column-count: 3;
    }
    
    /* Sidebar */
    .sidebar {
        width: 250px;
    }
    
    .main-content {
        margin-left: 250px;
    }
    
    /* Chat */
    #chat-sidebar {
        width: 280px;
    }
}

/* Extra large devices (large desktops, 1200px and up) */
@media (min-width: 1200px) {
    .container {
        max-width: 1140px;
    }
    
    .card-columns {
        column-count: 4;
    }
    
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    
    /* Sidebar */
    .sidebar {
        width: 280px;
    }
    
    .main-content {
        margin-left: 280px;
    }
}

/* Container Queries */
@container (min-width: 400px) {
    .card-content {
        display: flex;
        gap: 20px;
    }
}

@container (min-width: 600px) {
    .card-content {
        flex-direction: column;
    }
}

/* Grid System Enhancements */
.row {
    --bs-gutter-x: 1.5rem;
    --bs-gutter-y: 1.5rem;
}

.col {
    padding: calc(var(--bs-gutter-x) / 2);
}

/* Utility Classes for Responsive */
.w-sm-100 {
    width: 100% !important;
}

@media (min-width: 576px) {
    .w-sm-100 {
        width: auto !important;
    }
}

.mobile-only {
    display: none;
}

@media (max-width: 768px) {
    .mobile-only {
        display: block;
    }
    
    .desktop-only {
        display: none;
    }
    
    .navbar-toggler {
        display: block;
    }
}

/* Loading States */
.loading {
    position: relative;
    pointer-events: none;
    opacity: 0.7;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 20px;
    height: 20px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Smooth Scrolling */
html {
    scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
}

/* Focus States for Accessibility */
:focus {
    outline: 3px solid rgba(52, 152, 219, 0.5);
    outline-offset: 2px;
}

:focus:not(:focus-visible) {
    outline: none;
}

:focus-visible {
    outline: 3px solid rgba(52, 152, 219, 0.5);
    outline-offset: 2px;
}

/* Custom Scrollbar for Webkit */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Firefox Scrollbar */
* {
    scrollbar-width: thin;
    scrollbar-color: #c1c1c1 #f1f1f1;
}

/* Print styles */
@media print {
    .no-print {
        display: none !important;
    }
    
    .sidebar,
    .navbar,
    .footer,
    .btn,
    .form-control,
    .dropdown,
    .pagination,
    .badge {
        display: none !important;
    }
    
    .card {
        border: none !important;
        box-shadow: none !important;
        break-inside: avoid;
    }
    
    .table {
        border-collapse: collapse !important;
        break-inside: avoid;
    }
    
    .table th,
    .table td {
        border: 1px solid #000 !important;
        padding: 5px !important;
    }
    
    a {
        text-decoration: none !important;
        color: #000 !important;
    }
    
    a[href]::after {
        content: " (" attr(href) ")";
    }
    
    body {
        font-size: 12pt !important;
        line-height: 1.5 !important;
        color: #000 !important;
        background: #fff !important;
    }
    
    .container {
        width: 100% !important;
        max-width: 100% !important;
        padding: 0 !important;
    }
    
    h1, h2, h3, h4, h5, h6 {
        page-break-after: avoid;
    }
    
    img {
        max-width: 100% !important;
        page-break-inside: avoid;
    }
    
    ul, ol, dl {
        page-break-before: avoid;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
    }
    
    body {
        background-color: #121212;
        color: #e0e0e0;
    }
    
    .card {
        background-color: #1e1e1e;
        border-color: #333;
    }
    
    .table {
        color: #e0e0e0;
    }
    
    .table th,
    .table td {
        border-color: #333;
        background-color: #1e1e1e;
    }
    
    .table thead th {
        background-color: #2d2d2d;
        border-color: #404040;
    }
    
    .form-control {
        background-color: #2d2d2d;
        border-color: #404040;
        color: #e0e0e0;
    }
    
    .modal-content {
        background-color: #1e1e1e;
        color: #e0e0e0;
    }
    
    /* Custom scrollbar for dark mode */
    ::-webkit-scrollbar-track {
        background: #2d2d2d;
    }
    
    ::-webkit-scrollbar-thumb {
        background: #555;
    }
    
    ::-webkit-scrollbar-thumb:hover {
        background: #666;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .btn-primary {
        background-color: #004085;
        border-color: #002752;
        color: #fff;
    }
    
    .btn-secondary {
        background-color: #545b62;
        border-color: #3a4046;
        color: #fff;
    }
    
    .text-muted {
        color: #6c757d !important;
    }
    
    a {
        color: #0000ee;
        text-decoration: underline;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    
    .fade-in,
    .card:hover,
    .btn:hover {
        transform: none !important;
        transition: none !important;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .btn,
    .form-control,
    .dropdown-toggle,
    .nav-link {
        min-height: 44px;
        min-width: 44px;
    }
    
    .nav-link {
        padding: 0.75rem 1rem;
    }
    
    /* Increase tap targets */
    input[type="checkbox"],
    input[type="radio"] {
        width: 24px;
        height: 24px;
    }
    
    .table td,
    .table th {
        padding: 12px;
    }
    
    .dropdown-item {
        padding: 12px 20px;
    }
}

/* Orientation specific */
@media (orientation: portrait) {
    .landscape-only {
        display: none !important;
    }
    
    .video-container {
        padding-bottom: 56.25%; /* 16:9 */
    }
}

@media (orientation: landscape) {
    .portrait-only {
        display: none !important;
    }
}

/* Device pixel ratio */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    /* High resolution assets */
    .logo img {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* Screen height */
@media (max-height: 600px) {
    .modal-dialog {
        margin: 0.5rem auto;
        max-height: calc(100vh - 1rem);
    }
    
    .modal-content {
        max-height: calc(100vh - 1rem);
        overflow-y: auto;
    }
    
    .navbar {
        padding: 0.5rem 1rem;
    }
    
    .sidebar {
        overflow-y: auto;
    }
}

/* Custom breakpoints for specific components */
@media (max-width: 400px) {
    .btn {
        padding: 0.375rem 0.5rem;
        font-size: 0.875rem;
    }
    
    .display-1 { font-size: 2.5rem; }
    .display-2 { font-size: 2rem; }
    .display-3 { font-size: 1.75rem; }
    .display-4 { font-size: 1.5rem; }
    
    .conversation-name {
        max-width: 100px;
    }
}

/* Grid adjustments for very small screens */
@media (max-width: 350px) {
    .row {
        margin-left: -5px;
        margin-right: -5px;
    }
    
    [class*="col-"] {
        padding-left: 5px;
        padding-right: 5px;
    }
    
    .btn {
        padding: 0.25rem 0.5rem;
        font-size: 0.8rem;
    }
}

/* Chat specific responsive styles */
@media (max-width: 768px) {
    #chat-container {
        height: calc(100vh - 60px);
    }
    
    .chat-messages {
        max-height: calc(100vh - 200px);
    }
    
    .emoji-picker {
        bottom: 70px;
        right: 10px;
        max-width: 180px;
    }
}

@media (max-width: 480px) {
    .message-bubble {
        max-width: 90%;
        padding: 8px 12px;
    }
    
    .conversation-avatar {
        width: 40px;
        height: 40px;
    }
    
    #message-input {
        font-size: 0.9rem;
    }
}

/* Animation for mobile menu */
@keyframes slideIn {
    from {
        transform: translateX(-100%);
    }
    to {
        transform: translateX(0);
    }
}

@keyframes slideOut {
    from {
        transform: translateX(0);
    }
    to {
        transform: translateX(-100%);
    }
}

/* Responsive typography */
html {
    font-size: 16px;
}

@media (max-width: 768px) {
    html {
        font-size: 15px;
    }
}

@media (max-width: 576px) {
    html {
        font-size: 14px;
    }
}