/**
 * SocializeTogether - Responsive Stylesheet
 * Mobile-first responsive design with Bootstrap 5
 */

/* --------------------------------------------------------
   Root Variables for Theming
   -------------------------------------------------------- */
:root {
    --primary-color: #667eea;
    --secondary-color: #764ba2;
    --success-color: #48bb78;
    --danger-color: #f56565;
    --warning-color: #ed8936;
    --info-color: #4299e1;
    --light-color: #f7fafc;
    --dark-color: #2d3748;
    --text-color: #2d3748;
    --border-radius: 0.5rem;
    --box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    --transition: all 0.3s ease;
}

/* --------------------------------------------------------
   Base Styles
   -------------------------------------------------------- */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
                 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
    color: var(--text-color);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

* {
    box-sizing: border-box;
}

/* --------------------------------------------------------
   Typography Responsive Scaling
   -------------------------------------------------------- */
h1 {
    font-size: clamp(1.75rem, 5vw, 2.5rem);
    font-weight: 700;
    margin-bottom: 1rem;
}

h2 {
    font-size: clamp(1.5rem, 4vw, 2rem);
    font-weight: 600;
    margin-bottom: 0.875rem;
}

h3 {
    font-size: clamp(1.25rem, 3vw, 1.75rem);
    font-weight: 600;
    margin-bottom: 0.75rem;
}

h4 {
    font-size: clamp(1.125rem, 2.5vw, 1.5rem);
    font-weight: 500;
}

p {
    font-size: clamp(0.875rem, 2vw, 1rem);
}

/* --------------------------------------------------------
   Navigation Responsive
   -------------------------------------------------------- */
.navbar-brand {
    font-weight: 700;
    font-size: clamp(1.25rem, 3vw, 1.5rem);
}

/* Mobile menu improvements */
@media (max-width: 991.98px) {
    .navbar-collapse {
        background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
        padding: 1rem;
        border-radius: var(--border-radius);
        margin-top: 1rem;
    }

    .navbar-nav .nav-link {
        padding: 0.75rem 1rem;
        border-radius: 0.25rem;
        margin: 0.25rem 0;
    }

    .navbar-nav .nav-link:hover {
        background: rgba(255, 255, 255, 0.1);
    }
}

/* --------------------------------------------------------
   Card Components
   -------------------------------------------------------- */
.card {
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    border: none;
    transition: var(--transition);
    margin-bottom: 1.5rem;
}

.card:hover {
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.15);
    transform: translateY(-2px);
}

.card-header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
    font-weight: 600;
    border-radius: var(--border-radius) var(--border-radius) 0 0 !important;
}

/* --------------------------------------------------------
   Buttons Responsive
   -------------------------------------------------------- */
.btn {
    border-radius: var(--border-radius);
    padding: 0.625rem 1.25rem;
    font-weight: 500;
    transition: var(--transition);
    white-space: nowrap;
}

/* Mobile button adjustments */
@media (max-width: 575.98px) {
    .btn {
        padding: 0.5rem 1rem;
        font-size: 0.875rem;
    }

    .btn-group-sm .btn {
        padding: 0.375rem 0.75rem;
        font-size: 0.8125rem;
    }

    /* Stack buttons vertically on small screens */
    .btn-toolbar .btn-group {
        width: 100%;
        margin-bottom: 0.5rem;
    }

    .btn-toolbar .btn {
        width: 100%;
    }
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    border: none;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

/* --------------------------------------------------------
   Forms Responsive
   -------------------------------------------------------- */
.form-control, .form-select {
    border-radius: 0.375rem;
    border: 1px solid #e2e8f0;
    padding: 0.75rem 1rem;
    transition: var(--transition);
    font-size: 1rem;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
}

/* Mobile form improvements */
@media (max-width: 575.98px) {
    .form-control, .form-select {
        font-size: 16px; /* Prevents iOS zoom on focus */
        padding: 0.625rem 0.875rem;
    }

    .form-label {
        font-size: 0.875rem;
        font-weight: 500;
    }
}

/* --------------------------------------------------------
   Tables Responsive
   -------------------------------------------------------- */
.table-responsive {
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
}

/* Improve table on mobile */
@media (max-width: 767.98px) {
    .table {
        font-size: 0.875rem;
    }

    .table thead {
        display: none;
    }

    .table tbody tr {
        display: block;
        margin-bottom: 1rem;
        border: 1px solid #e2e8f0;
        border-radius: var(--border-radius);
        box-shadow: var(--box-shadow);
    }

    .table tbody td {
        display: flex;
        justify-content: space-between;
        padding: 0.75rem;
        border: none;
        border-bottom: 1px solid #f7fafc;
    }

    .table tbody td:last-child {
        border-bottom: none;
    }

    .table tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        margin-right: 1rem;
    }

    /* Button groups in tables */
    .table .btn-group {
        display: flex;
        gap: 0.25rem;
    }
}

/* --------------------------------------------------------
   Modals Responsive
   -------------------------------------------------------- */
@media (max-width: 575.98px) {
    .modal-dialog {
        margin: 0.5rem;
    }

    .modal-content {
        border-radius: var(--border-radius);
    }

    .modal-header, .modal-footer {
        padding: 1rem;
    }

    .modal-body {
        padding: 1.25rem;
    }
}

/* --------------------------------------------------------
   Stats Cards
   -------------------------------------------------------- */
.stat-card {
    background: white;
    border-radius: var(--border-radius);
    padding: 1.5rem;
    box-shadow: var(--box-shadow);
    text-align: center;
    transition: var(--transition);
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.15);
}

.stat-card .stat-value {
    font-size: clamp(2rem, 5vw, 3rem);
    font-weight: 700;
    color: var(--primary-color);
}

.stat-card .stat-label {
    font-size: clamp(0.875rem, 2vw, 1rem);
    color: #718096;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* --------------------------------------------------------
   Alerts Responsive
   -------------------------------------------------------- */
.alert {
    border-radius: var(--border-radius);
    border-left: 4px solid;
    padding: 1rem 1.25rem;
}

@media (max-width: 575.98px) {
    .alert {
        font-size: 0.875rem;
        padding: 0.875rem 1rem;
    }
}

/* --------------------------------------------------------
   Badge Enhancements
   -------------------------------------------------------- */
.badge {
    padding: 0.375rem 0.625rem;
    border-radius: 0.25rem;
    font-weight: 500;
    font-size: 0.8125rem;
}

@media (max-width: 575.98px) {
    .badge {
        font-size: 0.75rem;
        padding: 0.3125rem 0.5rem;
    }
}

/* --------------------------------------------------------
   Grid System Improvements
   -------------------------------------------------------- */
@media (max-width: 767.98px) {
    .row > [class*='col-'] {
        margin-bottom: 1rem;
    }

    .row > [class*='col-']:last-child {
        margin-bottom: 0;
    }
}

/* --------------------------------------------------------
   Utility Classes
   -------------------------------------------------------- */

/* Responsive spacing */
.section-padding {
    padding: clamp(2rem, 5vw, 4rem) 0;
}

.container-padding {
    padding: clamp(1rem, 3vw, 2rem);
}

/* Responsive text alignment */
@media (max-width: 767.98px) {
    .text-md-start {
        text-align: start !important;
    }

    .text-md-center {
        text-align: center !important;
    }

    .text-md-end {
        text-align: end !important;
    }
}

/* Hide on mobile */
.hide-mobile {
    display: block;
}

@media (max-width: 767.98px) {
    .hide-mobile {
        display: none !important;
    }
}

/* Show only on mobile */
.show-mobile {
    display: none;
}

@media (max-width: 767.98px) {
    .show-mobile {
        display: block !important;
    }
}

/* --------------------------------------------------------
   Loading States
   -------------------------------------------------------- */
.spinner-border-sm {
    width: 1rem;
    height: 1rem;
    border-width: 0.15em;
}

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

/* --------------------------------------------------------
   Animation Classes
   -------------------------------------------------------- */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in {
    animation: fadeIn 0.5s ease-out;
}

@keyframes slideDown {
    from {
        max-height: 0;
        opacity: 0;
    }
    to {
        max-height: 500px;
        opacity: 1;
    }
}

.slide-down {
    animation: slideDown 0.3s ease-out;
}

/* --------------------------------------------------------
   Print Styles
   -------------------------------------------------------- */
@media print {
    .no-print {
        display: none !important;
    }

    body {
        font-size: 12pt;
    }

    .card {
        box-shadow: none;
        border: 1px solid #000;
        page-break-inside: avoid;
    }

    a[href]:after {
        content: " (" attr(href) ")";
    }
}

/* --------------------------------------------------------
   Accessibility Improvements
   -------------------------------------------------------- */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Focus styles */
*:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

button:focus,
a:focus {
    outline-offset: 4px;
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* --------------------------------------------------------
   Dark Mode Support (Optional)
   -------------------------------------------------------- */
@media (prefers-color-scheme: dark) {
    /* Uncomment to enable dark mode
    :root {
        --text-color: #f7fafc;
        --light-color: #2d3748;
        --dark-color: #f7fafc;
    }

    body {
        background: #1a202c;
        color: var(--text-color);
    }

    .card {
        background: #2d3748;
        color: var(--text-color);
    }

    .form-control, .form-select {
        background: #1a202c;
        color: var(--text-color);
        border-color: #4a5568;
    }
    */
}

/* ========================================================
   Chapter Customization Styles
   ======================================================== */

/* CSS Variables for Chapter Theming */
:root {
    --custom-background: #ffffff;
    --custom-button: #667eea;
    --custom-text: #2d3748;
    --custom-header: #667eea;
}

/* Chapter-specific theme application */
body.chapter-page {
    background-color: var(--custom-background);
    color: var(--custom-text);
}

body.chapter-page .chapter-header {
    background: linear-gradient(135deg, var(--custom-header) 0%, var(--custom-button) 100%);
}

body.chapter-page .btn-primary {
    background-color: var(--custom-button);
    border-color: var(--custom-button);
}

body.chapter-page .btn-primary:hover {
    background-color: color-mix(in srgb, var(--custom-button) 85%, black);
    border-color: color-mix(in srgb, var(--custom-button) 85%, black);
}

body.chapter-page .btn-primary:focus {
    box-shadow: 0 0 0 0.25rem rgba(from var(--custom-button) r g b / 25%);
}

/* Additional theme elements */
body.chapter-page .card {
    border-color: color-mix(in srgb, var(--custom-button) 30%, transparent);
}

body.chapter-page .card-header {
    background-color: color-mix(in srgb, var(--custom-header) 10%, white);
    border-bottom-color: color-mix(in srgb, var(--custom-header) 20%, transparent);
}

body.chapter-page .nav-link.active {
    color: var(--custom-button) !important;
}

body.chapter-page .text-primary {
    color: var(--custom-button) !important;
}

body.chapter-page .btn-outline-primary {
    color: var(--custom-button);
    border-color: var(--custom-button);
}

body.chapter-page .btn-outline-primary:hover {
    background-color: var(--custom-button);
    border-color: var(--custom-button);
    color: white;
}

body.chapter-page h1, body.chapter-page h2, body.chapter-page h3,
body.chapter-page h4, body.chapter-page h5, body.chapter-page h6 {
    color: var(--custom-header);
}

body.chapter-page .stat-card {
    border-left-color: var(--custom-button) !important;
}

/* Background Image Support (MySpace-style) */
body.chapter-page.has-background-image {
    position: relative;
}

/* Background container - starts at bottom of banner, scrolls with page */
body.chapter-page.has-background-image .chapter-background-layer {
    position: absolute;
    left: 0;
    width: 100%;
    bottom: 0;
    z-index: -1;
    background-color: var(--custom-background);
    background-image: var(--custom-background-image);
    background-position: center top;
    pointer-events: none;
    /* Top position set by JS based on banner height - bottom: 0 ensures full coverage */
}

/* Stretch mode - cover entire viewport */
body.chapter-page.bg-mode-cover .chapter-background-layer {
    background-size: cover;
    background-repeat: no-repeat;
}

/* Tile mode - repeat pattern */
body.chapter-page.bg-mode-tile .chapter-background-layer {
    background-size: auto;
    background-repeat: repeat;
}

/* Dark overlay for better text readability */
body.chapter-page.has-background-image.bg-overlay .chapter-background-layer::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    pointer-events: none;
}

/* Ensure content is readable over background */
body.chapter-page.has-background-image .card {
    background-color: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(5px);
}

/* Keep navbar solid - no background behind it */
body.chapter-page.has-background-image .navbar {
    background-color: #ffffff !important;
    position: relative;
    z-index: 10;
}

/* Keep banner/header area solid white to cover background */
body.chapter-page.has-background-image .chapter-header {
    position: relative;
    z-index: 5;
    background-color: #ffffff;
}

/* The banner image itself should show */
body.chapter-page.has-background-image .chapter-banner {
    position: relative;
    z-index: 6;
}

/* Dark theme adjustments for background images */
body.chapter-page.has-background-image.bg-overlay .card {
    background-color: rgba(255, 255, 255, 0.9);
}

/* Logo styling - Prominent sidebar display */
.chapter-logo-container {
    margin-bottom: 2rem;
    text-align: center;
}

.chapter-logo-container .card-body {
    padding: 0;
}

.chapter-logo {
    max-width: 100%;
    width: 100%;
    height: auto;
    border-radius: 8px;
    object-fit: cover;
    display: block;
    margin: 0 auto;
}

/* Sidebar spacing for left-side layout */
@media (min-width: 992px) {
    .col-lg-4.order-lg-1 {
        padding-right: 2rem;
    }
}

/* Banner styling - Full width hero image */
.chapter-banner {
    width: 100vw;
    height: auto;
    max-height: 400px;
    object-fit: cover;
    object-position: center;
    display: block;
    margin: 0;
    padding: 0;
    position: relative;
    left: 50%;
    right: 50%;
    margin-left: -50vw;
    margin-right: -50vw;
}

/* Cropper modal styles */
#cropper-modal .modal-dialog {
    max-width: 800px;
}

#cropper-modal .cropper-container {
    max-height: 500px;
    margin: 0 auto;
}

.cropper-view-box {
    outline: 1px solid var(--primary-color);
}

/* Theme preset cards */
.theme-preset-card {
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s ease;
}

.theme-preset-card:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
}

.theme-preset-card.active {
    border-color: var(--primary-color);
    background-color: rgba(102, 126, 234, 0.05);
}

/* Color swatches */
.color-swatch {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    border: 2px solid #e2e8f0;
    display: inline-block;
}

/* Color picker display */
.color-picker-wrapper {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.color-picker-preview {
    width: 48px;
    height: 48px;
    border-radius: 6px;
    border: 2px solid #e2e8f0;
    cursor: pointer;
    transition: transform 0.2s;
}

.color-picker-preview:hover {
    transform: scale(1.05);
}

input[type="color"] {
    width: 60px;
    height: 48px;
    border-radius: 6px;
    border: 2px solid #e2e8f0;
    cursor: pointer;
}

/* Image preview containers */
.image-preview-container {
    position: relative;
    display: inline-block;
}

.image-preview-container img {
    max-width: 100%;
    border-radius: 8px;
    border: 2px solid #e2e8f0;
}

.image-preview-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
    border-radius: 8px;
}

.image-preview-container:hover .image-preview-overlay {
    opacity: 1;
}

/* Loading spinner */
#customization-loader {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    color: white;
}

#customization-loader.show {
    display: flex;
}

/* Customization modal tabs */
#customization-modal .nav-tabs .nav-link {
    color: #6c757d;
    border: none;
    border-bottom: 3px solid transparent;
}

#customization-modal .nav-tabs .nav-link:hover {
    border-bottom-color: var(--primary-color);
}

#customization-modal .nav-tabs .nav-link.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
    background: transparent;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .chapter-logo {
        max-width: 150px;
    }

    .chapter-logo-container {
        margin-bottom: 1.5rem;
    }

    .chapter-banner {
        max-height: 250px;
    }

    #cropper-modal .cropper-container {
        max-height: 300px;
    }

    .color-picker-wrapper {
        flex-direction: column;
        align-items: flex-start;
    }

    .theme-preset-card {
        margin-bottom: 1rem;
    }
}

@media (max-width: 576px) {
    .chapter-logo {
        max-width: 120px;
        padding: 0.75rem;
    }

    .chapter-logo-container {
        margin-bottom: 1rem;
    }

    .chapter-banner {
        max-height: 200px;
    }

    .color-swatch {
        width: 24px;
        height: 24px;
    }
}
