/* ========================================
   Jejak Coach - Frontend App Styles
   Apple Design Inspired, Minimalist, Modern
   ======================================== */

/* CSS Variables */
:root {
    --jc-primary: #007AFF;
    --jc-secondary: #5856D6;
    --jc-accent: #FF9500;
    --jc-success: #34C759;
    --jc-warning: #FF9500;
    --jc-danger: #FF3B30;
    --jc-info: #5AC8FA;

    --jc-bg: #F2F2F7;
    --jc-surface: #FFFFFF;
    --jc-text: #1C1C1E;
    --jc-text-secondary: #8E8E93;
    --jc-text-tertiary: #AEAEB2;
    --jc-border: #E5E5EA;
    --jc-divider: #F2F2F7;

    --jc-sidebar-width: 260px;
    --jc-sidebar-collapsed: 0px;
    --jc-header-height: 56px;
    --jc-radius: 12px;
    --jc-radius-sm: 8px;
    --jc-radius-lg: 16px;
    --jc-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --jc-shadow-lg: 0 4px 16px rgba(0,0,0,0.08);
    --jc-transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);

    --jc-font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Reset & Base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body.jc-app {
    font-family: var(--jc-font); background: var(--jc-bg); color: var(--jc-text);
    line-height: 1.5; -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale; overflow-x: hidden; margin: 0; padding: 0;
}
a { color: var(--jc-primary); text-decoration: none; }
a:hover { opacity: 0.85; }
img { max-width: 100%; height: auto; }
input, textarea, select, button { font-family: var(--jc-font); font-size: 16px; }

/* ==================== LOADING SCREEN ==================== */
.jc-loading-screen {
    position: fixed; inset: 0; z-index: 9999; background: var(--jc-surface);
    display: flex; align-items: center; justify-content: center;
    transition: opacity 0.3s; flex-direction: column;
}
.jc-loading-screen.jc-hidden { opacity: 0; pointer-events: none; }
.jc-loading-content { text-align: center; }
.jc-loading-logo { max-height: 100px; width: auto; margin-bottom: 24px; }
.jc-loading-spinner {
    width: 32px; height: 32px; border: 3px solid var(--jc-border); border-top-color: var(--jc-primary);
    border-radius: 50%; animation: jc-spin 0.8s linear infinite; margin: 0 auto 12px;
}
.jc-loading-text { color: var(--jc-text-secondary); font-size: 14px; }
@keyframes jc-spin { to { transform: rotate(360deg); } }

/* ==================== APP LAYOUT ==================== */
.jc-layout { display: flex; min-height: 100vh; }

/* Sidebar */
.jc-sidebar {
    width: var(--jc-sidebar-width); background: var(--jc-surface); border-right: 1px solid var(--jc-border);
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 100; display: flex; flex-direction: column;
    transition: transform var(--jc-transition); overflow-y: auto;
}
.jc-sidebar.jc-collapsed { transform: translateX(-100%); }
.jc-sidebar-header {
    padding: 20px; display: flex; align-items: center; gap: 12px;
    border-bottom: 1px solid var(--jc-divider);
}
.jc-sidebar-logo { height: 32px; width: auto; }
.jc-sidebar-title { font-size: 16px; font-weight: 700; color: var(--jc-text); }

.jc-sidebar-nav { flex: 1; padding: 12px; }
.jc-nav-item {
    display: flex; align-items: center; gap: 12px; padding: 10px 14px;
    border-radius: var(--jc-radius-sm); color: var(--jc-text-secondary);
    font-size: 14px; font-weight: 500; transition: all 0.15s;
    cursor: pointer; margin-bottom: 2px;
}
.jc-nav-item:hover { background: var(--jc-bg); color: var(--jc-text); }
.jc-nav-item.active { background: rgba(0,122,255,0.08); color: var(--jc-primary); font-weight: 600; }
.jc-nav-item svg, .jc-nav-item i { width: 20px; height: 20px; flex-shrink: 0; font-size: 20px; line-height: 1; }
.jc-nav-divider { height: 1px; background: var(--jc-divider); margin: 8px 14px; }

.jc-sidebar-footer {
    padding: 16px 12px; border-top: 1px solid var(--jc-divider);
}
.jc-user-info {
    display: flex; align-items: center; gap: 10px; padding: 8px 14px;
    border-radius: var(--jc-radius-sm);
}
.jc-user-avatar {
    width: 36px; height: 36px; border-radius: 50%; object-fit: cover;
    background: var(--jc-bg); border: 2px solid var(--jc-border);
}
.jc-user-name { font-size: 13px; font-weight: 600; color: var(--jc-text); }
.jc-user-role { font-size: 11px; color: var(--jc-text-secondary); }

/* Sidebar Overlay (Mobile) */
.jc-sidebar-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 99;
    opacity: 0; pointer-events: none; transition: opacity var(--jc-transition);
}
.jc-sidebar-overlay.active { opacity: 1; pointer-events: all; }

/* Main Content */
.jc-main {
    flex: 1; margin-left: var(--jc-sidebar-width); min-height: 100vh;
    transition: margin-left var(--jc-transition);
}
.jc-main.jc-expanded { margin-left: 0; }

/* Header */
.jc-header {
    height: var(--jc-header-height); background: var(--jc-surface);
    border-bottom: 1px solid var(--jc-border); display: flex; align-items: center;
    padding: 0 20px; position: sticky; top: 0; z-index: 50;
    backdrop-filter: blur(20px); background: rgba(255,255,255,0.85);
}
.jc-menu-toggle {
    width: 36px; height: 36px; border: none; background: transparent; cursor: pointer;
    display: flex; align-items: center; justify-content: center; border-radius: var(--jc-radius-sm);
    color: var(--jc-text); transition: background 0.15s;
}
.jc-menu-toggle:hover { background: var(--jc-bg); }
.jc-header-title { font-size: 17px; font-weight: 600; margin-left: 12px; flex: 1; }
.jc-header-actions { display: flex; gap: 8px; align-items: center; }

/* Notification Bell */
.jc-notif-bell { position: relative; cursor: pointer; padding: 8px; }
.jc-notif-badge {
    position: absolute; top: 4px; right: 4px; width: 18px; height: 18px;
    background: var(--jc-danger); color: #fff; font-size: 10px; font-weight: 700;
    border-radius: 50%; display: flex; align-items: center; justify-content: center;
    border: 2px solid var(--jc-surface);
}

/* Page Content */
.jc-content { padding: 20px; max-width: 1200px; margin: 0 auto; }

/* ==================== COMPONENTS ==================== */

/* Cards */
.jc-card {
    background: var(--jc-surface); border-radius: var(--jc-radius); padding: 20px;
    box-shadow: var(--jc-shadow); margin-bottom: 16px;
}
.jc-card-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 16px; gap: 12px;
}
.jc-card-title { font-size: 17px; font-weight: 600; color: var(--jc-text); }
.jc-card-subtitle { font-size: 13px; color: var(--jc-text-secondary); margin-top: 2px; }

/* Progress Bar */
.jc-progress { height: 8px; background: var(--jc-bg); border-radius: 4px; overflow: hidden; }
.jc-progress-bar {
    height: 100%; border-radius: 4px; transition: width 0.6s ease;
    background: linear-gradient(90deg, var(--jc-primary), var(--jc-secondary));
}
.jc-progress-text { font-size: 13px; font-weight: 600; color: var(--jc-primary); margin-top: 6px; }

/* Buttons */
.jc-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 20px; border: none; border-radius: var(--jc-radius-sm);
    font-size: 15px; font-weight: 600; cursor: pointer; transition: all 0.15s;
    text-decoration: none; line-height: 1.4;
}
.jc-btn-primary { background: var(--jc-primary); color: #fff; }
.jc-btn-primary:hover { background: #0066D6; color: #fff; }
.jc-btn-secondary { background: var(--jc-bg); color: var(--jc-text); }
.jc-btn-secondary:hover { background: var(--jc-border); }
.jc-btn-success { background: var(--jc-success); color: #fff; }
.jc-btn-danger { background: var(--jc-danger); color: #fff; }
.jc-btn-outline {
    background: transparent; border: 1.5px solid var(--jc-border); color: var(--jc-text);
}
.jc-btn-outline:hover { border-color: var(--jc-primary); color: var(--jc-primary); }
.jc-btn-sm { padding: 6px 14px; font-size: 13px; }
.jc-btn-lg { padding: 14px 28px; font-size: 16px; }
.jc-btn-block { width: 100%; }
.jc-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Form Elements */
.jc-form-group { margin-bottom: 20px; }
.jc-label {
    display: block; font-size: 14px; font-weight: 500; color: var(--jc-text);
    margin-bottom: 6px;
}
.jc-input, .jc-textarea, .jc-select {
    width: 100%; padding: 12px 16px; border: 1.5px solid var(--jc-border);
    border-radius: var(--jc-radius-sm); font-size: 16px; color: var(--jc-text);
    background: var(--jc-surface); transition: border-color 0.15s;
    -webkit-appearance: none;
}
.jc-input:focus, .jc-textarea:focus, .jc-select:focus {
    outline: none; border-color: var(--jc-primary);
    box-shadow: 0 0 0 3px rgba(0,122,255,0.12);
}
.jc-input::placeholder { color: var(--jc-text-tertiary); }
.jc-textarea { min-height: 100px; resize: vertical; }
.jc-input-error { border-color: var(--jc-danger) !important; }
.jc-error-text { color: var(--jc-danger); font-size: 12px; margin-top: 4px; }

/* Badge */
.jc-badge {
    display: inline-flex; align-items: center; padding: 4px 10px;
    border-radius: 20px; font-size: 12px; font-weight: 600;
}
.jc-badge-success { background: rgba(52,199,89,0.12); color: #1B8A3A; }
.jc-badge-warning { background: rgba(255,149,0,0.12); color: #C77800; }
.jc-badge-danger { background: rgba(255,59,48,0.12); color: #D70015; }
.jc-badge-info { background: rgba(0,122,255,0.12); color: #0055CC; }
.jc-badge-default { background: var(--jc-bg); color: var(--jc-text-secondary); }

/* List Items */
.jc-list { list-style: none; }
.jc-list-item {
    display: flex; align-items: center; gap: 14px; padding: 14px 0;
    border-bottom: 1px solid var(--jc-divider); cursor: pointer; transition: opacity 0.15s;
}
.jc-list-item:last-child { border-bottom: none; }
.jc-list-item:hover { opacity: 0.8; }
.jc-list-icon {
    width: 44px; height: 44px; border-radius: var(--jc-radius-sm);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; font-size: 20px;
}
.jc-list-content { flex: 1; min-width: 0; }
.jc-list-title { font-size: 15px; font-weight: 500; color: var(--jc-text); }
.jc-list-subtitle { font-size: 13px; color: var(--jc-text-secondary); margin-top: 2px; }
.jc-list-meta { font-size: 12px; color: var(--jc-text-tertiary); flex-shrink: 0; }

/* Toast Notification */
.jc-toast {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(100px);
    background: var(--jc-text); color: #fff; padding: 12px 24px;
    border-radius: var(--jc-radius); font-size: 14px; font-weight: 500;
    z-index: 10000; opacity: 0; transition: all 0.3s; box-shadow: var(--jc-shadow-lg);
    max-width: 90%; text-align: center;
}
.jc-toast.jc-show { transform: translateX(-50%) translateY(0); opacity: 1; }
.jc-toast.jc-toast-success { background: var(--jc-success); }
.jc-toast.jc-toast-error { background: var(--jc-danger); }

/* Empty State */
.jc-empty {
    text-align: center; padding: 48px 24px; color: var(--jc-text-secondary);
}
.jc-empty-icon { font-size: 48px; margin-bottom: 16px; opacity: 0.3; }
.jc-empty-title { font-size: 17px; font-weight: 600; color: var(--jc-text); margin-bottom: 8px; }
.jc-empty-text { font-size: 14px; }

/* Skeleton Loader */
.jc-skeleton {
    background: linear-gradient(90deg, var(--jc-bg) 25%, #E8E8ED 50%, var(--jc-bg) 75%);
    background-size: 200% 100%; animation: jc-shimmer 1.5s infinite; border-radius: var(--jc-radius-sm);
}
@keyframes jc-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.jc-skeleton-text { height: 14px; margin-bottom: 8px; }
.jc-skeleton-title { height: 20px; width: 60%; margin-bottom: 12px; }
.jc-skeleton-avatar { width: 48px; height: 48px; border-radius: 50%; }

/* Grid */
.jc-grid { display: grid; gap: 16px; }
.jc-grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.jc-grid-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.jc-grid-4 { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }

/* ==================== AUTH PAGES ==================== */
.jc-auth-page { background: var(--jc-bg); }
.jc-auth-container {
    min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
}
.jc-auth-card {
    background: var(--jc-surface); border-radius: var(--jc-radius-lg); padding: 40px;
    box-shadow: var(--jc-shadow-lg); width: 100%; max-width: 440px;
}
.jc-auth-logo { text-align: center; margin-bottom: 32px; }
.jc-auth-logo img { max-height: 48px; }
.jc-auth-title { font-size: 24px; font-weight: 700; text-align: center; margin-bottom: 8px; color: var(--jc-text); }
.jc-auth-subtitle { font-size: 14px; color: var(--jc-text-secondary); text-align: center; margin-bottom: 32px; }
.jc-auth-footer { text-align: center; margin-top: 24px; font-size: 14px; color: var(--jc-text-secondary); }
.jc-auth-footer a { color: var(--jc-primary); font-weight: 500; }

/* ==================== MEMBER CARD ==================== */
.jc-member-card {
    background: linear-gradient(135deg, var(--jc-primary), var(--jc-secondary));
    border-radius: var(--jc-radius-lg); padding: 28px; color: #fff;
    position: relative; overflow: hidden; max-width: 420px; margin: 0 auto;
    box-shadow: 0 8px 32px rgba(0,122,255,0.25);
}
.jc-member-card::before {
    content: ''; position: absolute; top: -50%; right: -50%;
    width: 100%; height: 100%; background: rgba(255,255,255,0.05);
    border-radius: 50%; transform: rotate(-15deg);
}
.jc-member-card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; position: relative; }
.jc-member-card-logo { height: 28px; filter: brightness(10); }
.jc-member-card-badge { background: rgba(255,255,255,0.2); padding: 4px 12px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.jc-member-card-photo {
    width: 72px; height: 72px; border-radius: 50%; border: 3px solid rgba(255,255,255,0.3);
    object-fit: cover; margin-bottom: 16px; position: relative;
}
.jc-member-card-name { font-size: 20px; font-weight: 700; margin-bottom: 4px; position: relative; }
.jc-member-card-ic { font-size: 14px; opacity: 0.8; margin-bottom: 16px; position: relative; }
.jc-member-card-info { display: flex; gap: 24px; font-size: 12px; opacity: 0.7; position: relative; }
.jc-member-card-qr {
    position: absolute; bottom: 28px; right: 28px; width: 80px; height: 80px;
    background: #fff; border-radius: 8px; padding: 4px;
}
.jc-member-card-qr img { width: 100%; height: 100%; }

/* ==================== VERIFICATION PAGE ==================== */
.jc-verify-container { max-width: 480px; margin: 0 auto; text-align: center; padding: 48px 24px; }
.jc-verify-success { color: var(--jc-success); }
.jc-verify-icon { font-size: 64px; margin-bottom: 16px; }

/* ==================== RESPONSIVE ==================== */
@media (max-width: 768px) {
    .jc-sidebar { transform: translateX(-100%); }
    .jc-sidebar.jc-open { transform: translateX(0); }
    .jc-main { margin-left: 0 !important; }
    .jc-content { padding: 12px; }
    .jc-auth-card { padding: 28px 20px; }
    .jc-card { padding: 14px; }
    .jc-grid-2, .jc-grid-3, .jc-grid-4 { grid-template-columns: 1fr; }
    .jc-member-card { max-width: 100%; }
    .jc-member-card-qr { width: 64px; height: 64px; bottom: 20px; right: 20px; }
    /* Buttons in task/milestone rows: stack on small screens */
    .jc-card [style*="display:flex"][style*="gap:12px"] { flex-wrap: wrap; }
    .jc-btn-sm { padding: 6px 10px; font-size: 12px; }
    /* Modals responsive */
    .jc-modal, [style*="max-width:480px"], [style*="max-width:520px"] { margin: 20px auto !important; max-width: 95vw !important; }
    /* Header title truncation */
    .jc-header-title { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    /* Milestone grid single column on mobile */
    [style*="grid-template-columns:repeat(auto-fill"] { grid-template-columns: 1fr !important; }
    /* Form tables */
    .form-table th, .form-table td { display: block; width: 100%; padding: 4px 0; }
}

@media (max-width: 400px) {
    .jc-content { padding: 8px; }
    .jc-card { padding: 12px; margin-bottom: 10px; }
    h1 { font-size: 20px !important; }
    .jc-btn { padding: 10px 16px; font-size: 13px; }
    .jc-sidebar { width: 85vw; }
}

@media (min-width: 769px) {
    .jc-menu-toggle-desktop { display: flex; }
}

/* PWA Standalone Mode */
@media (display-mode: standalone) {
    .jc-header { padding-top: env(safe-area-inset-top); height: calc(var(--jc-header-height) + env(safe-area-inset-top)); }
    .jc-sidebar { padding-top: env(safe-area-inset-top); }
    .jc-content { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
}

/* Responsive Tables */
.jc-table-wrap { overflow-x: auto; }
.jc-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.jc-table th { text-align: left; font-weight: 600; color: var(--jc-text-secondary); font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; padding: 10px 14px; border-bottom: 2px solid var(--jc-border); }
.jc-table td { padding: 12px 14px; border-bottom: 1px solid var(--jc-divider); }
.jc-table tr:hover { background: rgba(0,122,255,0.02); }

/* Modal/Dialog */
.jc-modal-overlay { position: fixed; inset: 0; z-index: 1000; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; padding: 20px; }
.jc-modal { background: var(--jc-surface); border-radius: var(--jc-radius-lg); padding: 28px; width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto; box-shadow: var(--jc-shadow-lg); }
.jc-modal-title { font-size: 18px; font-weight: 700; margin-bottom: 16px; }

/* Tabs */
.jc-tabs { display: flex; gap: 4px; background: var(--jc-bg); padding: 4px; border-radius: var(--jc-radius-sm); margin-bottom: 20px; }
.jc-tab { flex: 1; padding: 8px 16px; border: none; background: transparent; border-radius: 6px; font-size: 14px; font-weight: 500; color: var(--jc-text-secondary); cursor: pointer; transition: all 0.15s; text-align: center; }
.jc-tab.active { background: var(--jc-surface); color: var(--jc-text); box-shadow: 0 1px 3px rgba(0,0,0,0.08); }

/* File Upload Zone */
.jc-upload-zone { border: 2px dashed var(--jc-border); border-radius: var(--jc-radius); padding: 32px; text-align: center; cursor: pointer; transition: all 0.2s; }
.jc-upload-zone:hover { border-color: var(--jc-primary); background: rgba(0,122,255,0.02); }
.jc-upload-zone.dragging { border-color: var(--jc-primary); background: rgba(0,122,255,0.06); }
.jc-upload-icon { font-size: 32px; margin-bottom: 12px; }
.jc-upload-text { font-size: 14px; color: var(--jc-text-secondary); }

/* Floating Action Button */
.jc-fab { position: fixed; bottom: 24px; right: 24px; width: 56px; height: 56px; border-radius: 50%; background: var(--jc-primary); color: #fff; border: none; box-shadow: 0 4px 16px rgba(0,122,255,0.3); cursor: pointer; font-size: 24px; display: flex; align-items: center; justify-content: center; z-index: 50; transition: transform 0.15s, box-shadow 0.15s; }
.jc-fab:hover { transform: scale(1.1); box-shadow: 0 6px 20px rgba(0,122,255,0.4); }

/* Animations */
@keyframes jc-fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.jc-card { animation: jc-fadeIn 0.3s ease; }

/* Video container responsive */
.jc-video-wrap { position: relative; padding-bottom: 56.25%; border-radius: var(--jc-radius); overflow: hidden; }
.jc-video-wrap iframe, .jc-video-wrap video { position: absolute; width: 100%; height: 100%; border: 0; }

/* Checkbox custom */
.jc-checkbox { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; }
.jc-checkbox input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--jc-primary); }

/* QR Code container */
.jc-qr-display { background: #fff; padding: 12px; border-radius: var(--jc-radius-sm); display: inline-block; box-shadow: var(--jc-shadow); }
.jc-qr-display img { display: block; }

/* Print */
@media print {
    .jc-sidebar, .jc-header, .jc-menu-toggle, .jc-fab, .jc-sidebar-overlay { display: none !important; }
    .jc-main { margin-left: 0 !important; }
    .jc-card { box-shadow: none; border: 1px solid #ddd; }
}
