/**
 * Judge Interface Mobile Responsiveness
 * Optimized for mobile devices (judges accessing via phones/tablets)
 */

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.pulse {
    animation: pulse 1.5s ease-in-out infinite;
}

/* ============================================
   DISPLAY UTILITY CLASSES
   ============================================ */
.d-none { display: none !important; }
.d-block { display: block !important; }
.d-flex { display: flex !important; }
.d-inline { display: inline !important; }
.d-inline-block { display: inline-block !important; }

.d-md-none { display: none !important; }
.d-md-block { display: block !important; }
.d-md-flex { display: flex !important; }

@media (max-width: 768px) {
    .d-md-none { display: block !important; }
    .d-md-block { display: none !important; }
    .d-md-flex { display: none !important; }
}

/* ============================================
   MOBILE BREAKPOINT (max-width: 768px)
   ============================================ */
@media (max-width: 768px) {
    
    /* --- Navbar Mobile --- */
    .navbar {
        padding: 0.5rem 0.75rem;
        flex-wrap: wrap;
    }
    
    .nav-brand {
        flex: 1;
    }
    
    .nav-brand .brand-text {
        font-size: 0.9rem;
    }
    
    .nav-logo {
        height: 28px;
    }
    
    .nav-links {
        display: none; /* Hidden on mobile, can add hamburger menu later */
    }
    
    .nav-user {
        gap: 0.5rem;
    }
    
    .nav-user .user-name {
        display: none; /* Hide username on small screens */
    }
    
    .nav-user .btn {
        padding: 0.4rem 0.6rem;
        font-size: 0.8rem;
    }
    
    /* --- Main Content Mobile --- */
    .main-content {
        padding: 0.5rem;
        padding-bottom: 2rem;
    }
    
    /* --- General Layout --- */
    .page-header {
        padding: 0.75rem 1rem;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    
    .page-title {
        font-size: 1.25rem;
    }
    
    .page-subtitle {
        font-size: 0.85rem;
    }
    
    .page-actions {
        width: 100%;
        display: flex;
        gap: 0.5rem;
    }
    
    .page-actions .btn {
        flex: 1;
        padding: 0.6rem 0.75rem;
        font-size: 0.85rem;
    }
    
    /* --- Cards --- */
    .card {
        margin: 0.5rem;
        border-radius: 8px;
    }
    
    .card-header {
        padding: 0.75rem 1rem;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    
    .card-title {
        font-size: 1rem;
    }
    
    .card-body {
        padding: 1rem;
    }
    
    /* --- Sessions Grid --- */
    .sessions-grid {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
        padding: 0.5rem;
    }
    
    .session-card {
        margin: 0;
    }
    
    .session-card .card-header {
        flex-direction: row;
        align-items: center;
        padding: 0.75rem 1rem;
    }
    
    .session-info {
        font-size: 0.9rem;
    }
    
    .session-info p {
        margin-bottom: 0.4rem;
    }
    
    .session-actions {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        margin-top: 0.75rem;
    }
    
    .session-actions .btn {
        width: 100%;
        padding: 0.875rem;
        font-size: 1rem;
        min-height: 48px;
    }
    
    .session-actions .btn-lg {
        padding: 1rem;
        font-size: 1.05rem;
        font-weight: 600;
    }
    
    /* --- Stats Bar --- */
    .stats-bar {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        padding: 0.75rem 1rem;
        margin: 0.5rem;
        background: var(--bg-secondary);
        border-radius: 8px;
        font-size: 0.9rem;
    }
    
    .stats-bar span {
        display: flex;
        justify-content: space-between;
    }
    
    /* --- Tables (Convert to Cards) --- */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* For submissions table on mobile */
    .submissions-list {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .submission-card {
        background: var(--bg-card);
        border: 1px solid var(--border);
        border-radius: 8px;
        padding: 1rem;
    }
    
    .submission-card-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 0.75rem;
        padding-bottom: 0.5rem;
        border-bottom: 1px solid var(--border);
    }
    
    .submission-card-title {
        font-weight: 600;
        font-size: 1rem;
    }
    
    .submission-card-body {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem;
        font-size: 0.85rem;
        margin-bottom: 0.75rem;
    }
    
    .submission-card-label {
        opacity: 0.6;
        font-size: 0.75rem;
    }
    
    .submission-card-value {
        font-weight: 500;
    }
    
    .submission-card-actions {
        display: flex;
        gap: 0.5rem;
    }
    
    .submission-card-actions .btn {
        flex: 1;
        padding: 0.6rem;
        font-size: 0.85rem;
    }
    
    /* --- Score Form Mobile --- */
    .score-form .table {
        display: block;
    }
    
    .score-form thead {
        display: none; /* Hide header on mobile */
    }
    
    .score-form tbody {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .score-form tbody tr {
        display: flex;
        flex-direction: column;
        background: var(--bg-secondary);
        border: 1px solid var(--border);
        border-radius: 8px;
        padding: 1rem;
        gap: 0.5rem;
    }
    
    .score-form tbody td {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        padding: 0;
        border: none;
    }
    
    .score-form tbody td:first-child {
        /* Criterion number */
        position: absolute;
        top: 0.5rem;
        right: 0.5rem;
        background: var(--cyan);
        color: #000;
        width: 24px;
        height: 24px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 0.75rem;
        font-weight: 600;
    }
    
    .score-form tbody td:nth-child(2) {
        /* Criterion name */
        font-weight: 600;
        font-size: 1rem;
        padding-right: 2rem;
        flex-wrap: wrap;
    }
    
    .score-form tbody td:nth-child(3) {
        /* Max marks - inline with label */
        font-size: 0.85rem;
        opacity: 0.7;
    }
    
    .score-form tbody td:nth-child(3)::before {
        content: "Max: ";
    }
    
    .score-form tbody td:nth-child(4) {
        /* Score input */
        margin-top: 0.5rem;
    }
    
    .score-form tbody td:nth-child(4) .form-control,
    .score-form tbody td:nth-child(4) select {
        width: 100%;
        min-height: 44px; /* Touch-friendly */
        font-size: 1rem;
    }
    
    /* Radio options mobile */
    .radio-options {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        width: 100%;
    }
    
    .radio-options label,
    .radio-card {
        background: var(--bg-card);
        border: 2px solid var(--border);
        border-radius: 8px;
        padding: 0.875rem 1rem;
        font-size: 0.95rem;
        min-height: 48px;
        display: flex;
        align-items: center;
        gap: 0.75rem;
        cursor: pointer;
        transition: all 0.2s;
    }
    
    .radio-options label:active,
    .radio-card:active {
        background: rgba(56, 217, 245, 0.1);
        border-color: var(--cyan);
    }
    
    .radio-options input[type="radio"]:checked + .radio-text,
    .radio-card input[type="radio"]:checked ~ * {
        font-weight: 600;
    }
    
    .radio-options input[type="radio"]:checked + .radio-text:before,
    .radio-card input[type="radio"]:checked ~ .radio-text:before {
        content: "✓ ";
        color: var(--success);
    }
    
    .radio-options input[type="radio"] {
        width: 24px;
        height: 24px;
        min-width: 24px;
        min-height: 24px;
    }
    
    .radio-text {
        flex: 1;
    }
    
    .radio-card:has(input[type="radio"]:checked) {
        border-color: var(--cyan);
        background: rgba(56, 217, 245, 0.08);
    }
    
    /* --- Timer Mobile --- */
    .timer-display {
        font-size: 2.5rem;
    }
    
    .timer-controls {
        justify-content: center;
    }
    
    .timer-controls .btn {
        min-width: 70px;
        padding: 0.6rem 0.75rem;
        font-size: 0.85rem;
    }
    
    /* Inline timer mobile */
    .inline-timer-display {
        font-size: 1.5rem;
    }
    
    .inline-timer .timer-controls {
        flex-wrap: wrap;
    }
    
    .inline-timer .btn {
        padding: 0.4rem 0.6rem;
        font-size: 0.75rem;
    }
    
    /* --- Rounds Section Mobile --- */
    .rounds-grid {
        flex-direction: column;
    }
    
    .round-card {
        max-width: 100%;
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 0.5rem;
        padding: 0.75rem;
    }
    
    .round-label {
        flex: 1;
        margin-bottom: 0;
    }
    
    .round-timer-display {
        font-size: 1.4rem;
        margin-bottom: 0;
        min-width: 90px;
        text-align: right;
    }
    
    .round-controls {
        width: 100%;
        margin-top: 0.5rem;
        justify-content: flex-end;
    }
    
    /* --- Signatures Mobile --- */
    .signatures-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .sig-canvas {
        height: 120px;
        touch-action: none;
    }
    
    /* --- Form Actions Mobile --- */
    .form-actions {
        flex-direction: column;
        gap: 0.75rem;
        padding-top: 1rem;
    }
    
    .form-actions .btn {
        width: 100%;
        padding: 0.875rem;
        font-size: 1rem;
    }
    
    /* --- Score Total Mobile --- */
    .score-form tfoot {
        display: block;
        margin-top: 1rem;
    }
    
    .score-form tfoot tr {
        display: flex;
        justify-content: space-between;
        align-items: center;
        background: var(--cyan);
        color: #000;
        padding: 1rem;
        border-radius: 8px;
        font-size: 1.1rem;
    }
    
    .score-form tfoot td {
        border: none;
        padding: 0;
    }
    
    /* Sticky total bar for mobile */
    .sticky-total {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--cyan);
        color: #000;
        padding: 0.75rem 1rem;
        display: flex;
        justify-content: space-between;
        align-items: center;
        font-size: 1.1rem;
        font-weight: 600;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.3);
        z-index: 100;
    }
    
    .sticky-total .total-label {
        font-size: 0.9rem;
    }
    
    .sticky-total .total-value {
        font-size: 1.2rem;
    }
    
    /* Add padding to body to account for sticky bar */
    body.has-sticky-total {
        padding-bottom: 60px;
    }
    
    /* --- Textarea Mobile --- */
    textarea.form-control {
        min-height: 100px;
        font-size: 1rem;
    }
    
    /* --- Footer Mobile --- */
    .footer {
        padding: 1rem 0.75rem;
    }
    
    .footer-content {
        flex-direction: column;
        gap: 1rem;
    }
    
    .footer-brand {
        text-align: center;
    }
    
    .footer-logo {
        height: 36px;
    }
    
    .footer-info {
        text-align: center;
    }
    
    .footer-contact {
        flex-direction: column;
        gap: 1rem;
    }
    
    .contact-section h4 {
        font-size: 0.85rem;
    }
    
    .contact-section p {
        font-size: 0.8rem;
    }
    
    .copyright {
        font-size: 0.7rem;
    }
    
    /* --- Select Dropdown Mobile --- */
    select.form-control {
        min-height: 44px;
        font-size: 1rem;
    }
    
    /* --- Number Input Mobile --- */
    input[type="number"].form-control {
        min-height: 44px;
        font-size: 1rem;
    }
}

/* ============================================
   SMALL MOBILE (max-width: 480px)
   ============================================ */
@media (max-width: 480px) {
    
    .page-title {
        font-size: 1.1rem;
    }
    
    .card-body {
        padding: 0.75rem;
    }
    
    /* Make buttons full width on very small screens */
    .btn-group {
        flex-direction: column;
        width: 100%;
    }
    
    .btn-group .btn {
        width: 100%;
        margin: 0;
        border-radius: 6px !important;
    }
    
    /* Smaller padding for tables converted to cards */
    .submission-card {
        padding: 0.75rem;
    }
    
    .score-form tbody tr {
        padding: 0.75rem;
    }
    
    /* Timer even smaller */
    .timer-display {
        font-size: 2rem;
    }
    
    .round-timer-display {
        font-size: 1.2rem;
    }
}

/* ============================================
   TOUCH DEVICE OPTIMIZATIONS
   ============================================ */
@media (hover: none) and (pointer: coarse) {
    
    /* Larger touch targets */
    .btn {
        min-height: 44px;
    }
    
    .btn-sm {
        min-height: 36px;
        padding: 0.5rem 0.75rem;
    }
    
    /* Better checkbox/radio touch targets */
    input[type="checkbox"],
    input[type="radio"] {
        min-width: 22px;
        min-height: 22px;
    }
    
    /* Radio options larger touch area */
    .radio-options label {
        min-height: 44px;
        display: flex;
        align-items: center;
    }
    
    /* Score select larger */
    .score-select {
        min-height: 44px;
    }
    
    /* Signature canvas optimized for touch */
    .sig-canvas {
        touch-action: none;
    }
}

/* ============================================
   LANDSCAPE ORIENTATION ON MOBILE
   ============================================ */
@media (max-width: 768px) and (orientation: landscape) {
    
    .sessions-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
    }
    
    .signatures-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .rounds-grid {
        flex-direction: row;
        flex-wrap: wrap;
    }
    
    .round-card {
        flex: 1;
        min-width: 200px;
    }
}

/* ============================================
   TABLET ADJUSTMENTS (769px - 1024px)
   ============================================ */
@media (min-width: 769px) and (max-width: 1024px) {
    
    .sessions-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }
    
    .signatures-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ============================================
   PRINT STYLES (For score sheets)
   ============================================ */
@media print {
    
    .page-header,
    .timer-card,
    .form-actions,
    .btn {
        display: none !important;
    }
    
    .card {
        border: 1px solid #000;
        break-inside: avoid;
    }
    
    .score-form tbody tr {
        break-inside: avoid;
    }
    
    .sig-canvas {
        border: 1px solid #000;
    }
}
