/**
 * ZAMIE Sunday School Portal - Common Styles
 * Shared base styles, typography, components, and utilities
 */

/* ============================================
   CSS RESET & BASE
   ============================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f5f7fa;
    min-height: 100vh;
}

/* Auth loading state - hide body until auth check completes */
body.auth-hidden {
    visibility: hidden;
}

body.auth-checked {
    visibility: visible;
}

/* ============================================
   NAVBAR BASE STYLES
   ============================================ */
.navbar {
    padding: 0.5rem 1rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.navbar-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
}

.navbar h1 {
    font-size: 1.125rem;
    font-weight: 600;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 15px;
}

.user-email {
    font-size: 14px;
    opacity: 0.9;
}

.logout-btn {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.25);
    color: white;
    padding: 0.375rem 0.75rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: background 0.2s, border-color 0.2s;
}

.logout-btn:hover {
    background: rgba(255,255,255,0.3);
}

/* ============================================
   CONTAINER & LAYOUT
   ============================================ */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem;
}

/* Standardized page width for navbar and content */
nav.navbar > .container,
body > .container,
.page-content > .container {
    max-width: 1000px;
}

/* ============================================
   CARDS & SECTIONS
   ============================================ */
.card {
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    border: 1px solid rgba(0,0,0,0.06) !important;
}

.dashboard-card {
    background: white;
    border-radius: 12px;
    padding: 1.25rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    border: 1px solid rgba(0,0,0,0.06);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    flex-direction: column;
    min-height: 240px;
}

.dashboard-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.1);
}

/* Card hover lift effect for grid cards */
.card.h-100 {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    will-change: transform;
}

.card.h-100:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 16px rgba(0,0,0,0.1) !important;
}

.card.h-100:focus-within {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.12) !important;
}

/* Keep cards visually narrower while retaining a 2x2 grid */
.row.g-0 .card.h-100,
.row.g-1 .card.h-100,
.row.g-2 .card.h-100,
.row.g-3 .card.h-100,
.row.g-4 .card.h-100 {
    max-width: 440px;
    margin-left: auto;
    margin-right: auto;
}

/* Dashboard cards alignment */
.dashboard-cards .card.h-100 {
    max-width: 440px;
    margin-left: auto;
    margin-right: auto;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    will-change: transform;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.dashboard-cards .card.h-100:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 16px rgba(0,0,0,0.1) !important;
}

.dashboard-cards .card.h-100:focus-within {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.12) !important;
}

.card-header-custom {
    display: flex;
    align-items: center;
    margin-bottom: 20px;
}

.card-icon {
    font-size: 24px;
    margin-right: 15px;
    padding: 10px;
    border-radius: 10px;
}

.card-title {
    font-size: 20px;
    color: #333;
    font-weight: 600;
}

.card-content {
    color: #666;
    line-height: 1.6;
    margin-bottom: 20px;
    flex-grow: 1;
    display: flex;
    align-items: center;
}

.card-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: auto;
    justify-content: center;
}

/* Card action buttons sizing */
.card .card-body .d-flex.gap-2 > .btn {
    flex: 1 1 0;
}

.card .card-body > div > .btn:only-child,
.card .card-body > .btn:only-child {
    display: block;
    width: 100%;
}

/* ============================================
   WELCOME & RESOURCES SECTIONS
   ============================================ */
.welcome-section {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    border: 1px solid rgba(0,0,0,0.06);
}

.welcome-section h2 {
    color: #1a1a1a;
    margin-bottom: 0.5rem;
    font-size: 1.5rem;
    font-weight: 600;
}

.welcome-section p {
    color: #666;
    font-size: 16px;
    line-height: 1.6;
}

.resources-section {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    border: 1px solid rgba(0,0,0,0.06);
}

.resources-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
}

.resources-header h3 {
    color: #333;
    font-size: 24px;
}

.resource-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 0;
    border-bottom: 1px solid #f0f0f0;
}

.resource-item:last-child {
    border-bottom: none;
}

.resource-info h4 {
    color: #333;
    margin-bottom: 5px;
}

.resource-info p {
    color: #666;
    font-size: 14px;
}

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

/* ============================================
   PAGE HEADERS
   ============================================ */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.page-header h2 {
    color: #333;
    font-size: 28px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.section-title {
    font-size: 24px;
    color: #333;
}

/* ============================================
   PAGE DESCRIPTION
   ============================================ */
.page-description {
    background: white;
    border-radius: 12px;
    padding: 1.25rem;
    margin-bottom: 1.25rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    border: 1px solid rgba(0,0,0,0.06);
}

.page-description p {
    color: #666;
    font-size: 16px;
    line-height: 1.6;
    margin: 0;
}

/* ============================================
   DASHBOARD GRID
   ============================================ */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 25px;
    margin-bottom: 30px;
    align-items: stretch;
}

/* ============================================
   FORMS
   ============================================ */
.form-group {
    margin-bottom: 1rem;
}

label {
    display: block;
    margin-bottom: 0.375rem;
    color: #1a1a1a;
    font-weight: 500;
    font-size: 0.875rem;
}

input[type="email"],
input[type="password"],
input[type="text"],
input[type="tel"] {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 0.9375rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: #fff;
}

input[type="email"]:focus,
input[type="password"]:focus,
input[type="text"]:focus,
input[type="tel"]:focus {
    outline: none;
    border-color: #4CAF50;
    box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.1);
}

input::placeholder {
    color: #9ca3af;
}

/* ============================================
   BUTTONS (Non-Bootstrap)
   ============================================ */
.btn-custom {
    width: 100%;
    padding: 0.75rem 1rem;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.btn-custom:hover {
    transform: translateY(-1px);
}

.btn-custom:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Back button styles */
.back-btn:not(.btn) {
    background: #f0f0f0;
    border: none;
    padding: 8px 16px;
    border-radius: 5px;
    color: #333;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: background 0.3s;
    text-decoration: none;
}

.back-btn:not(.btn):hover {
    background: #e0e0e0;
}

.back-to-lessons-btn:not(.btn) {
    margin-bottom: 15px;
    font-size: 14px;
    padding: 8px 16px;
}

.back-to-lessons-btn:not(.btn):hover {
    background: #e9ecef;
    transform: translateX(-2px);
}

/* ============================================
   MESSAGES & ALERTS
   ============================================ */
.error-message {
    color: #e74c3c;
    background: #fdf2f2;
    padding: 10px;
    border-radius: 5px;
    margin-bottom: 20px;
    display: none;
}

.success-message {
    color: #27ae60;
    background: #f2fdf2;
    padding: 10px;
    border-radius: 5px;
    margin-bottom: 20px;
    display: none;
}

.placeholder-text {
    color: #999;
    font-style: italic;
    text-align: center;
    padding: 40px 20px;
}

/* ============================================
   LOADING STATES
   ============================================ */
.loading {
    display: none;
    text-align: center;
    margin: 20px 0;
}

.spinner {
    border: 3px solid #f3f3f3;
    border-top: 3px solid #4CAF50;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    animation: spin 1s linear infinite;
    margin: 0 auto 10px;
}

.loading-spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #2196F3;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-text {
    color: #666;
    font-size: 16px;
    font-weight: 500;
}

/* Auth loading screen */
.auth-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: #f5f7fa;
}

.auth-loading.hide {
    display: none;
}

/* Page content loading state */
.page-content {
    display: none;
}

.page-content.show {
    display: block;
}

/* ============================================
   ANNOUNCEMENTS
   ============================================ */
.announcement-card {
    background: linear-gradient(135deg, #fff3e0 0%, #ffe0b2 100%);
    border-left: 4px solid #ff9800;
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 20px;
}

.announcement-card h4 {
    color: #e65100;
    margin-bottom: 10px;
}

.announcement-card p {
    color: #bf360c;
}

/* ============================================
   TABS
   ============================================ */
.tabs {
    display: flex;
    margin-bottom: 20px;
    border-bottom: 1px solid #e0e0e0;
}

.tab {
    padding: 12px 24px;
    cursor: pointer;
    font-weight: 600;
    color: #757575;
    transition: all 0.3s;
    border-bottom: 2px solid transparent;
}

.tab.active {
    color: #4CAF50;
    border-bottom: 2px solid #4CAF50;
}

.tab:hover:not(.active) {
    color: #333;
    background: #f5f5f5;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ============================================
   TABLES
   ============================================ */
table {
    width: 100%;
    border-collapse: collapse;
}

th {
    text-align: left;
    padding: 12px;
    border-bottom: 1px solid #e0e0e0;
    color: #757575;
    font-weight: 600;
}

td {
    padding: 12px;
    border-bottom: 1px solid #f5f5f5;
}

tr:hover {
    background: #f9f9f9;
}

/* ============================================
   STATUS BADGES
   ============================================ */
.status-badge {
    display: inline-block;
    padding: 5px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.status-pending {
    background: #FFF3E0;
    color: #E65100;
}

.status-approved {
    background: #E8F5E9;
    color: #2E7D32;
}

.status-rejected {
    background: #FFEBEE;
    color: #C62828;
}

/* ============================================
   NAV LINKS
   ============================================ */
.nav-links {
    display: flex;
    gap: 15px;
}

.nav-link-custom {
    color: #4CAF50;
    text-decoration: none;
    font-weight: 600;
    padding: 8px 0;
    transition: all 0.3s;
}

.nav-link-custom:hover {
    color: #2E7D32;
}

/* ============================================
   ROLE INDICATORS
   ============================================ */
.role-indicator {
    text-align: center;
    margin: 15px 0;
    padding: 10px;
    border-radius: 5px;
    font-weight: 500;
    display: none;
}

.role-teacher {
    background: #e8f5e8;
    color: #2e7d32;
}

.role-parent {
    background: #e3f2fd;
    color: #1565c0;
}

/* ============================================
   CUSTOM DIALOGS
   ============================================ */
.custom-dialog {
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: none;
    justify-content: center;
    align-items: center;
}

.dialog-content {
    background: white;
    border-radius: 10px;
    padding: 30px;
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    animation: dialogSlideIn 0.3s ease-out;
}

@keyframes dialogSlideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.dialog-icon {
    font-size: 48px;
    margin-bottom: 15px;
}

.dialog-icon.success {
    color: #4CAF50;
}

.dialog-icon.error {
    color: #f44336;
}

.dialog-icon.warning {
    color: #FF9800;
}

.dialog-title {
    font-size: 20px;
    font-weight: 600;
    color: #333;
    margin-bottom: 10px;
}

.dialog-message {
    color: #666;
    margin-bottom: 25px;
    line-height: 1.5;
}

.dialog-button {
    background: #4CAF50;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 500;
    transition: background 0.3s;
}

.dialog-button:hover {
    background: #45a049;
}

/* ============================================
   RESPONSIVE BREAKPOINTS
   ============================================ */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }
    
    .navbar-content {
        flex-direction: column;
        gap: 0.75rem;
        text-align: center;
    }
    
    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .resources-header {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }
    
    .resource-item {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }
    
    .resource-actions {
        flex-direction: column;
        gap: 0.75rem;
        align-items: stretch;
    }
    
    /* Fix navbar overflow on mobile */
    .navbar-brand {
        font-size: 0.9375rem !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: calc(100vw - 120px);
    }
    
    .navbar .ms-auto {
        flex-shrink: 0;
    }
    
    .navbar .ms-auto .text-white,
    .navbar .ms-auto .text-white-50 {
        font-size: 0.75rem;
        max-width: 100px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    
    /* Ensure consistent button sizing in cards */
    .card .d-flex.gap-2 {
        flex-direction: column;
        gap: 0.5rem !important;
    }
    
    .card .d-flex.gap-2 .btn {
        width: 100%;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        min-height: 38px;
        font-size: 0.875rem;
    }
    
    /* Card body padding on mobile */
    .card-body {
        padding: 1rem !important;
    }
    
    /* Page header adjustments */
    .page-header {
        flex-direction: column;
        gap: 0.75rem;
        align-items: flex-start;
    }
    
    .page-header h2 {
        font-size: 1.25rem;
    }
}

/* Align cards inward on md+ when horizontal gutters are 0 */
@media (min-width: 768px) {
    .row.g-0 > *:nth-child(odd) .card.h-100,
    .row.gx-0 > *:nth-child(odd) .card.h-100 {
        margin-left: auto;
        margin-right: 0;
    }
    .row.g-0 > *:nth-child(even) .card.h-100,
    .row.gx-0 > *:nth-child(even) .card.h-100 {
        margin-left: 0;
        margin-right: auto;
    }
}

/* Phones: stack navbar, show full title and email without truncation */
@media (max-width: 576px) {
    nav.navbar > .container {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.375rem;
        padding: 0.5rem 0.75rem;
    }
    
    .navbar-brand {
        font-size: 0.875rem !important;
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
        max-width: 100%;
        line-height: 1.2;
    }
    
    .navbar .user-area {
        width: 100%;
        margin-left: 0 !important;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 0.5rem;
        flex: 1 1 auto;
    }
    
    #userEmail {
        color: rgba(255,255,255,0.9);
        font-size: 0.75rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 150px;
        flex: 1 1 auto;
    }
    
    .navbar .user-area .btn {
        padding: 0.3rem 0.5rem;
        font-size: 0.75rem;
        white-space: nowrap;
        flex: 0 0 auto;
    }
    
    /* Smaller container padding on phones */
    .container {
        padding: 0.75rem;
    }
    
    /* Welcome section adjustments */
    .welcome-section,
    .page-description {
        padding: 1rem;
    }
    
    .welcome-section h2 {
        font-size: 1.25rem;
    }
    
    /* Card title adjustments */
    .card-title,
    .h5,
    .h6 {
        font-size: 0.9375rem !important;
    }
    
    /* Card text adjustments */
    .card-text {
        font-size: 0.8125rem;
    }
}
