/**
 * TJTM V2 - Main Stylesheet
 * Mobile-first responsive design
 */

/* ============================================
   CSS Variables (Theme)
   ============================================ */
:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #eff6ff;
    --danger: #ef4444;
    --danger-light: #fee2e2;
    --success: #22c55e;
    --success-light: #dcfce7;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --bg: #f8fafc;
    --card: #ffffff;
    --text: #334155;
    --text-light: #64748b;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
    --radius: 12px;
    --radius-lg: 16px;
}

/* ============================================
   Reset & Base
   ============================================ */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    min-height: 100dvh;
}

/* ============================================
   Typography
   ============================================ */
h1, h2, h3, h4, h5, h6 {
    font-weight: 700;
    line-height: 1.2;
}

h1 { font-size: 1.5rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.125rem; }

a {
    color: var(--primary);
    text-decoration: none;
}

/* ============================================
   Utility Classes
   ============================================ */
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-muted { color: var(--text-light); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-primary { color: var(--primary); }
.font-bold { font-weight: 700; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }

/* ============================================
   Layout
   ============================================ */
.container {
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    padding: 1rem;
}

.container-wide {
    max-width: 900px;
}

.page-wrapper {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* ============================================
   Cards
   ============================================ */
.card {
    background: var(--card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1rem;
}

.card-header {
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.card-title {
    font-weight: 700;
    font-size: 1.1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* ============================================
   Header
   ============================================ */
.header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 1.25rem 1rem;
    text-align: center;
}

.header h1 {
    margin: 0;
    font-size: 1.2rem;
}

.header p {
    margin: 0.25rem 0 0;
    opacity: 0.85;
    font-size: 0.875rem;
}

/* Sticky Header for Quiz */
.sticky-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(10px);
    border-bottom: 2px solid var(--border);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    box-shadow: var(--shadow);
}

.sticky-header .regu-badge {
    background: var(--primary-light);
    color: var(--primary);
    padding: 0.375rem 0.75rem;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.825rem;
    max-width: 50%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sticky-header .timer {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--primary);
    font-variant-numeric: tabular-nums;
}

.sticky-header .timer.danger {
    color: var(--danger);
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* ============================================
   Forms
   ============================================ */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    color: var(--text);
}

.form-input {
    width: 100%;
    padding: 0.875rem 1rem;
    font-size: 1rem;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: white;
}

.form-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.form-input:disabled {
    background: var(--bg);
    cursor: not-allowed;
}

.form-input::placeholder {
    color: var(--text-muted);
}

.form-input.input-center {
    text-align: center;
}

.form-input.input-lg {
    padding: 1rem 1.25rem;
    font-size: 1.125rem;
    font-weight: 600;
}

/* ============================================
   Buttons
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.875rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    filter: grayscale(50%);
}

.btn-full {
    width: 100%;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-dark);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-warning {
    background: var(--warning);
    color: white;
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--border);
    color: var(--text);
}

.btn-outline:hover:not(:disabled) {
    background: var(--bg);
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.btn-lg {
    padding: 1rem 1.5rem;
    font-size: 1.125rem;
}

/* Quiz Option Buttons */
.btn-option {
    width: 100%;
    padding: 1rem;
    margin-bottom: 0.75rem;
    background: white;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    text-align: left;
    font-size: 1rem;
    font-weight: 500;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.btn-option:hover:not(:disabled) {
    border-color: var(--primary);
    background: var(--primary-light);
}

.btn-option.selected {
    border-color: var(--primary);
    background: var(--primary);
    color: white;
}

.btn-option .option-letter {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    flex-shrink: 0;
}

.btn-option.selected .option-letter {
    background: white;
    color: var(--primary);
}

.btn-option .option-text {
    flex: 1;
}

/* ============================================
   Quiz Image
   ============================================ */
.img-wrapper {
    position: relative;
    width: 100%;
    background: var(--bg);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 1rem;
    border: 1px solid var(--border);
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.img-wrapper img {
    width: 100%;
    height: auto;
    display: block;
    object-fit: contain;
    max-height: 300px;
}

.img-wrapper .zoom-btn {
    position: absolute;
    bottom: 0.75rem;
    right: 0.75rem;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border: none;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10;
}

/* Lightbox */
.lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem;
}

.lightbox img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.lightbox .close-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    color: white;
    font-size: 2rem;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
}

/* ============================================
   Alerts
   ============================================ */
.alert {
    padding: 0.875rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.9rem;
    font-weight: 500;
}

.alert-success {
    background: var(--success-light);
    color: #166534;
}

.alert-error {
    background: var(--danger-light);
    color: #991b1b;
}

.alert-warning {
    background: var(--warning-light);
    color: #92400e;
}

.alert-info {
    background: var(--primary-light);
    color: var(--primary-dark);
}

/* ============================================
   Stats / Score Display
   ============================================ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.stat-item {
    background: white;
    padding: 1rem;
    border-radius: var(--radius);
    text-align: center;
    box-shadow: var(--shadow);
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--primary);
    line-height: 1;
}

.stat-value.success { color: var(--success); }
.stat-value.danger { color: var(--danger); }

.stat-label {
    font-size: 0.75rem;
    color: var(--text-light);
    margin-top: 0.375rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Score Display */
.score-display {
    text-align: center;
    padding: 2rem 1rem;
}

.score-display .score-value {
    font-size: 3.5rem;
    font-weight: 800;
    color: var(--primary);
    line-height: 1;
}

.score-display .score-label {
    font-size: 0.9rem;
    color: var(--text-light);
    margin-top: 0.5rem;
}

/* ============================================
   Loading Spinner
   ============================================ */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 999;
}

.loading-overlay .spinner {
    width: 40px;
    height: 40px;
    border-width: 3px;
    color: var(--primary);
}

.loading-overlay p {
    margin-top: 1rem;
    color: var(--text-light);
}

/* ============================================
   Login Page Specific
   ============================================ */
.login-container {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: linear-gradient(180deg, var(--primary-light) 0%, var(--bg) 100%);
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 2rem 1.5rem;
    text-align: center;
}

.login-card .logo {
    font-size: 3rem;
    margin-bottom: 0.5rem;
}

.login-card h1 {
    margin-bottom: 0.5rem;
    color: var(--primary);
}

.login-card .subtitle {
    color: var(--text-light);
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}

.login-steps {
    margin-top: 1.5rem;
}

.step-indicator {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.step-indicator .step {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--border);
    transition: all 0.3s;
}

.step-indicator .step.active {
    background: var(--primary);
    width: 30px;
    border-radius: 5px;
}

/* ============================================
   Result Page Specific
   ============================================ */
.result-container {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: linear-gradient(180deg, var(--success-light) 0%, var(--bg) 100%);
}

.result-card {
    width: 100%;
    max-width: 400px;
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 2rem 1.5rem;
    text-align: center;
}

.result-card .trophy {
    font-size: 4rem;
    margin-bottom: 0.5rem;
}

.result-card h1 {
    color: var(--success);
    margin-bottom: 0.25rem;
}

/* ============================================
   Admin Specific (akan dilengkapi)
   ============================================ */
.admin-nav {
    display: flex;
    background: white;
    border-bottom: 2px solid var(--border);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.admin-nav .tab {
    flex: 1;
    padding: 0.875rem 0.5rem;
    text-align: center;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.825rem;
    color: var(--text-light);
    border-bottom: 3px solid transparent;
    white-space: nowrap;
    transition: all 0.2s;
    min-width: max-content;
}

.admin-nav .tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.admin-nav .tab:hover {
    background: var(--bg);
}

/* Tables */
.table-wrapper {
    overflow-x: auto;
    margin: 0 -1.5rem;
    padding: 0 1.5rem;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

th, td {
    padding: 0.75rem 0.5rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    background: var(--bg);
    font-weight: 600;
    color: var(--text-light);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

tr:hover {
    background: var(--bg);
}

/* ============================================
   Quiz Progress Bar
   ============================================ */
.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 1rem;
}

.progress-bar .fill {
    height: 100%;
    background: var(--primary);
    border-radius: 3px;
    transition: width 0.3s ease;
}

/* ============================================
   Quiz Footer Navigation
   ============================================ */
.quiz-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 2px solid var(--border);
    padding: 1rem;
    display: flex;
    gap: 0.75rem;
    z-index: 100;
}

.quiz-footer .btn {
    flex: 1;
}

/* Add padding to body when footer is present */
body.has-quiz-footer {
    padding-bottom: 80px;
}

/* ============================================
   Responsive Adjustments
   ============================================ */
@media (min-width: 768px) {
    h1 { font-size: 1.75rem; }
    h2 { font-size: 1.5rem; }
    
    .container {
        padding: 1.5rem;
    }
    
    .card {
        padding: 2rem;
    }
    
    .login-card, .result-card {
        padding: 2.5rem 2rem;
    }
    
    .score-display .score-value {
        font-size: 4.5rem;
    }
}

/* Safe area for notched phones */
@supports (padding-top: env(safe-area-inset-top)) {
    .sticky-header {
        padding-top: env(safe-area-inset-top);
        height: calc(60px + env(safe-area-inset-top));
    }
    
    .quiz-footer {
        padding-bottom: calc(1rem + env(safe-area-inset-bottom));
    }
}
