/* === Reset & Base === */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary: #2D3361;
    --primary-light: #4A55A2;
    --accent: #7C3AED;
    --bg: #F0F2F5;
    --card-bg: #FFFFFF;
    --text: #1E1E2E;
    --text-secondary: #6B6F82;
    --text-tertiary: #9CA0B0;
    --border: #E6E8EC;
    --border-light: #F1F2F6;
    --success: #10B981;
    --warning: #F59E0B;
    --danger: #EF4444;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 2px 8px rgba(45, 51, 97, 0.06);
    --shadow-lg: 0 8px 30px rgba(45, 51, 97, 0.10);
    --font: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', 'PingFang SC', 'Noto Sans CJK SC', 'Microsoft YaHei', sans-serif;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    padding-bottom: 76px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.container {
    max-width: 480px;
    margin: 0 auto;
    padding: 16px;
}

/* === School Header === */
.school-header {
    position: sticky;
    top: 0;
    z-index: 99;
    background: rgba(255,255,255,0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-light);
}

.school-header-logo {
    width: 26px;
    height: 26px;
    flex-shrink: 0;
}

.school-header-name {
    height: 18px;
    width: auto;
}

/* === School Brand (login page) === */
.school-brand {
    padding: 36px 0 24px;
}

.school-logo {
    width: 80px;
    height: 80px;
    display: block;
    margin: 0 auto 12px;
    filter: drop-shadow(0 4px 12px rgba(45,51,97,0.10));
}

.school-name-img {
    height: 38px;
    width: auto;
    display: block;
    margin: 0 auto;
}

/* === Top Navigation === */
.top-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255,255,255,0.95);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border-light);
    z-index: 100;
    padding: 6px 0;
    padding-bottom: max(6px, env(safe-area-inset-bottom));
}

.nav-inner {
    max-width: 480px;
    margin: 0 auto;
    display: flex;
    justify-content: space-around;
}

.nav-link {
    text-decoration: none;
    color: var(--text-tertiary);
    font-size: 13px;
    font-weight: 500;
    padding: 8px 20px;
    border-radius: 24px;
    transition: all 0.25s ease;
    letter-spacing: 0.3px;
}

.nav-link.active {
    color: var(--primary);
    background: rgba(45, 51, 97, 0.08);
    font-weight: 600;
}

/* === Cards === */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-light);
    transition: box-shadow 0.2s ease;
}

/* === Flash Messages === */
.flash-message {
    padding: 12px 18px;
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
    font-size: 14px;
    text-align: center;
    font-weight: 500;
    animation: slideDown 0.3s ease;
}

.flash-success {
    background: #ECFDF5;
    color: #065F46;
    border: 1px solid #A7F3D0;
}

.flash-error {
    background: #FEF2F2;
    color: #991B1B;
    border: 1px solid #FECACA;
}

.flash-info {
    background: #EFF6FF;
    color: #1E40AF;
    border: 1px solid #BFDBFE;
}

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

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 14px 24px;
    border-radius: var(--radius-sm);
    border: none;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    width: 100%;
    letter-spacing: 0.3px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: white;
    box-shadow: 0 4px 14px rgba(45, 51, 97, 0.20);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(45, 51, 97, 0.25);
}

.btn-primary:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(45, 51, 97, 0.15);
}

.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-outline {
    background: transparent;
    border: 2px solid var(--primary);
    color: var(--primary);
}

.btn-outline:hover {
    background: rgba(45, 51, 97, 0.05);
}

.btn-like {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 13px;
    width: auto;
    transition: all 0.2s ease;
}

.btn-like:hover {
    border-color: var(--danger);
    color: var(--danger);
}

.btn-like.liked {
    background: #FFF5F5;
    border-color: var(--danger);
    color: var(--danger);
}

/* === Forms === */
.form-group {
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text);
}

.form-input, .form-select, .form-textarea {
    width: 100%;
    padding: 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 16px;
    background: #FAFBFC;
    transition: all 0.2s ease;
    font-family: var(--font);
    color: var(--text);
}

.form-input:hover, .form-select:hover, .form-textarea:hover {
    border-color: #C8CBD8;
    background: #FFFFFF;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none;
    border-color: var(--primary);
    background: #FFFFFF;
    box-shadow: 0 0 0 4px rgba(45, 51, 97, 0.08);
}

.form-textarea {
    min-height: 90px;
    resize: vertical;
}

.file-input-wrapper {
    position: relative;
}

.file-input-wrapper input[type="file"] {
    width: 100%;
    padding: 32px 16px;
    border: 2px dashed #C8CBD8;
    border-radius: var(--radius-sm);
    background: #FAFBFC;
    font-size: 14px;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s ease;
    color: var(--text-tertiary);
}

.file-input-wrapper input[type="file"]:hover {
    border-color: var(--primary-light);
    background: #F8F9FF;
}

.file-input-wrapper input[type="file"]::file-selector-button {
    background: var(--primary);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    margin-right: 12px;
    cursor: pointer;
    font-weight: 500;
    font-size: 13px;
}

/* === Check-in Card === */
.checkin-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-light);
    transition: transform 0.15s ease, box-shadow 0.2s ease;
}

.checkin-card:hover {
    box-shadow: 0 4px 16px rgba(45, 51, 97, 0.08);
}

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

.checkin-user {
    font-weight: 600;
    font-size: 15px;
    color: var(--text);
}

.checkin-time {
    font-size: 12px;
    color: var(--text-tertiary);
    font-weight: 500;
}

.checkin-stats {
    display: flex;
    gap: 16px;
    margin-bottom: 10px;
    font-size: 13px;
    color: var(--text-secondary);
}

.checkin-content {
    font-size: 14px;
    margin-bottom: 12px;
    line-height: 1.6;
    color: var(--text);
}

.checkin-image {
    width: 100%;
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
    max-height: 300px;
    object-fit: cover;
    border: 1px solid var(--border-light);
}

.checkin-actions {
    display: flex;
    gap: 8px;
    padding-top: 10px;
    border-top: 1px solid var(--border-light);
}

/* === Auth Forms === */
.auth-container {
    padding-top: 20px;
}

.auth-tabs {
    display: flex;
    margin-bottom: 24px;
    background: #F1F2F6;
    border-radius: var(--radius-sm);
    padding: 3px;
}

.auth-tab {
    flex: 1;
    text-align: center;
    padding: 10px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    border: none;
    background: transparent;
    border-radius: 8px;
    transition: all 0.25s ease;
}

.auth-tab.active {
    color: var(--primary);
    background: white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.auth-form {
    display: none;
}

.auth-form.active {
    display: block;
}

/* === Leaderboard === */
.leaderboard-tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 16px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
}

.lb-tab {
    flex-shrink: 0;
    padding: 8px 18px;
    border-radius: 24px;
    border: 1px solid var(--border);
    background: var(--card-bg);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s ease;
    color: var(--text-secondary);
}

.lb-tab:hover {
    border-color: var(--primary-light);
    color: var(--primary);
}

.lb-tab.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.lb-entry {
    display: flex;
    align-items: center;
    padding: 14px 0;
    border-bottom: 1px solid var(--border-light);
}

.lb-entry:last-child { border-bottom: none; }

.lb-rank {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-weight: 700;
    font-size: 14px;
    margin-right: 14px;
    background: var(--bg);
    color: var(--text-secondary);
    flex-shrink: 0;
}

.lb-rank.top1 {
    background: linear-gradient(135deg, #FEF3C7, #FDE68A);
    color: #D97706;
    box-shadow: 0 2px 8px rgba(217,119,6,0.15);
}

.lb-rank.top2 {
    background: #F3F4F6;
    color: #6B7280;
}

.lb-rank.top3 {
    background: #FEF2F2;
    color: #DC2626;
}

.lb-user {
    flex: 1;
    font-weight: 600;
    font-size: 15px;
}

.lb-value {
    font-size: 14px;
    color: var(--primary);
    font-weight: 600;
    background: rgba(45, 51, 97, 0.06);
    padding: 4px 12px;
    border-radius: 20px;
}

/* === Badge Wall === */
.badge-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}

.badge-item {
    text-align: center;
    padding: 14px 6px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-light);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.badge-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(45, 51, 97, 0.08);
}

.badge-icon {
    font-size: 30px;
    display: block;
    margin-bottom: 6px;
}

.badge-name {
    font-size: 11px;
    color: var(--text-secondary);
    word-break: keep-all;
    line-height: 1.3;
    font-weight: 500;
}

.badge-empty {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
}

/* === Profile === */
.profile-header {
    text-align: center;
    padding: 28px 0 20px;
}

.profile-avatar {
    width: 76px;
    height: 76px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 30px;
    font-weight: 600;
    margin: 0 auto 14px;
    box-shadow: 0 4px 16px rgba(45, 51, 97, 0.20);
}

.profile-stats {
    display: flex;
    justify-content: space-around;
    margin-bottom: 24px;
    padding: 4px 0;
}

.stat-item {
    text-align: center;
}

.stat-number {
    font-size: 24px;
    font-weight: 700;
    color: var(--primary);
    line-height: 1.2;
}

.stat-label {
    font-size: 12px;
    color: var(--text-tertiary);
    margin-top: 2px;
    font-weight: 500;
}

/* === Weekly Report === */
.report-card {
    background: linear-gradient(135deg, #EEF2FF 0%, #E0E7FF 100%);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 12px;
    border: 1px solid rgba(45, 51, 97, 0.06);
}

.report-title {
    font-size: 17px;
    font-weight: 700;
    margin-bottom: 14px;
    color: var(--primary);
}

.report-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 14px;
}

.report-item {
    background: rgba(255,255,255,0.75);
    backdrop-filter: blur(4px);
    padding: 14px 10px;
    border-radius: var(--radius-sm);
    text-align: center;
}

.report-item .label {
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.report-item .value {
    font-size: 20px;
    font-weight: 700;
    color: var(--primary);
}

.report-trend-up { color: var(--success); font-weight: 600; }
.report-trend-down { color: var(--danger); font-weight: 600; }
.report-trend-same { color: var(--text-secondary); font-weight: 600; }

/* === Toast / Celebration === */
.toast-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    z-index: 200;
    justify-content: center;
    align-items: center;
}

.toast-overlay.show { display: flex; }

.toast-box {
    background: white;
    border-radius: 20px;
    padding: 32px 28px;
    text-align: center;
    max-width: 320px;
    width: 90%;
    animation: popIn 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 20px 60px rgba(0,0,0,0.20);
}

.toast-icon { font-size: 56px; margin-bottom: 14px; display: block; }

.toast-title {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 6px;
    color: var(--text);
}

.toast-desc {
    font-size: 16px;
    color: var(--text-secondary);
    margin-bottom: 4px;
    line-height: 1.5;
    font-weight: 500;
}

@keyframes popIn {
    from { transform: scale(0.7); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* === Page Title === */
.page-title {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
}

/* === Status Banner (feed top) === */
.status-banner-today {
    background: linear-gradient(135deg, #ECFDF5, #D1FAE5);
    border: 1px solid #A7F3D0;
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    margin-bottom: 14px;
    font-size: 14px;
    font-weight: 500;
}

.status-banner-miss {
    background: linear-gradient(135deg, #FEF3C7, #FDE68A);
    border: 1px solid #FCD34D;
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    margin-bottom: 14px;
    font-size: 14px;
    font-weight: 500;
}

.status-banner-info {
    background: linear-gradient(135deg, #FFF7ED, #FFEDD5);
    border: 1px solid #FED7AA;
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    margin-bottom: 14px;
    font-size: 14px;
    font-weight: 500;
}

/* === Empty state === */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.empty-state .icon {
    font-size: 48px;
    margin-bottom: 14px;
    display: block;
}

/* === Image preview === */
.image-preview {
    margin-top: 10px;
    display: none;
}

.image-preview.show { display: block; }

.image-preview img {
    max-width: 100%;
    max-height: 200px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

/* === Name Picker (duplicate code) === */
.name-option {
    display: block;
    cursor: pointer;
    padding: 14px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 10px;
    transition: all 0.2s ease;
}

.name-option:hover {
    border-color: var(--primary-light);
    background: #F8F9FF;
}

.name-option input[type="radio"]:checked + *,
.name-option:has(input:checked) {
    border-color: var(--primary);
    background: #F0F1FF;
}

/* === Misc === */
.text-center { text-align: center; }
.text-light { color: var(--text-secondary); }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.hidden { display: none !important; }

/* === Pull to refresh hint === */
.pull-hint {
    text-align: center;
    padding: 8px;
    font-size: 12px;
    color: var(--text-tertiary);
}

/* === Divider === */
.divider {
    height: 1px;
    background: var(--border-light);
    margin: 16px 0;
}

/* === Badge Detail Modal === */
.badge-detail-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.45);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 300;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.badge-detail-overlay.show { display: flex; }

.badge-detail-box {
    background: white;
    border-radius: 20px;
    padding: 32px 28px 24px;
    text-align: center;
    max-width: 320px;
    width: 100%;
    animation: popIn 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 20px 60px rgba(0,0,0,0.20);
}

.badge-detail-emoji {
    font-size: 56px;
    margin-bottom: 8px;
    display: block;
    line-height: 1.2;
}

.badge-detail-name {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 2px;
    color: var(--text);
}

.badge-detail-group {
    font-size: 12px;
    color: var(--primary);
    font-weight: 600;
    margin-bottom: 16px;
    background: rgba(45, 51, 97, 0.06);
    display: inline-block;
    padding: 3px 12px;
    border-radius: 12px;
}

.badge-detail-desc {
    font-size: 16px;
    color: var(--text);
    margin-bottom: 6px;
    font-weight: 500;
    line-height: 1.5;
}

.badge-detail-hint {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 8px;
    line-height: 1.5;
    padding: 0 8px;
}

.badge-detail-time {
    font-size: 12px;
    color: var(--text-tertiary);
    margin-bottom: 18px;
    padding-top: 10px;
    border-top: 1px solid var(--border-light);
}

.badge-item.clickable {
    cursor: pointer;
}

.badge-item.clickable:active {
    transform: scale(0.94);
}
