/* =============================================
   Absensi Wajah - Main Stylesheet
   Modern, clean design with dark blue theme
   ============================================= */

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

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #3b82f6;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --bg: #f8fafc;
    --bg-card: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
    --shadow-lg: 0 10px 25px rgba(0,0,0,.1);
    --radius: 12px;
    --radius-sm: 8px;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Navbar ---- */
.navbar {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.nav-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    text-decoration: none !important;
}

.nav-brand i { font-size: 1.5rem; }

.nav-menu {
    display: flex;
    list-style: none;
    gap: 4px;
}

.nav-menu a {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    text-decoration: none !important;
    font-weight: 500;
    transition: all .15s;
}

.nav-menu a:hover,
.nav-menu a.active {
    background: #eff6ff;
    color: var(--primary);
}

.nav-toggle { display: none; background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text); }

@media (max-width: 768px) {
    .nav-toggle { display: block; }
    .nav-menu {
        display: none;
        position: absolute;
        top: 64px;
        left: 0; right: 0;
        background: var(--bg-card);
        flex-direction: column;
        padding: 10px;
        border-bottom: 1px solid var(--border);
        box-shadow: var(--shadow-lg);
    }
    .nav-menu.active { display: flex; }
}

/* ---- Main ---- */
.main-content { flex: 1; padding: 2rem 0; }

.container { max-width: 1200px; margin: 0 auto; padding: 0 20px; }

.page-header { margin-bottom: 2rem; text-align: center; }
.page-header h1 { font-size: 1.75rem; font-weight: 700; margin-bottom: .5rem; }
.page-header p { color: var(--text-muted); }

/* ---- Hero ---- */
.hero {
    background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 50%, #3b82f6 100%);
    color: white;
    padding: 4rem 20px;
    text-align: center;
}

.hero-content h1 {
    font-size: 2.5rem;
    font-weight: 800;
    margin-bottom: 1rem;
    line-height: 1.2;
}

.hero-content p {
    font-size: 1.2rem;
    opacity: .9;
    max-width: 600px;
    margin: 0 auto 2rem;
}

.hero-buttons { display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap; }

/* ---- Features ---- */
.features { padding: 4rem 0; }
.section-title { text-align: center; font-size: 1.75rem; margin-bottom: 2rem; }

.feature-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
}

.feature-card {
    background: var(--bg-card);
    padding: 2rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    transition: all .2s;
}

.feature-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.feature-icon { width: 48px; height: 48px; background: #eff6ff; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 1.5rem; color: var(--primary); margin-bottom: 1rem; }
.feature-card h3 { font-size: 1.1rem; margin-bottom: .5rem; }
.feature-card p { color: var(--text-muted); font-size: .9rem; }

/* ---- How It Works ---- */
.how-it-works { padding: 4rem 0; background: var(--bg-card); }

.steps {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 0;
    flex-wrap: wrap;
}

.step { text-align: center; flex: 1; min-width: 150px; }
.step-number { width: 40px; height: 40px; background: var(--primary); color: white; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; margin: 0 auto .5rem; }
.step h4 { font-size: .95rem; margin-bottom: .25rem; }
.step p { color: var(--text-muted); font-size: .85rem; }

.step-connector {
    width: 40px;
    height: 2px;
    background: var(--border);
    margin-top: 20px;
    flex-shrink: 0;
}

@media (max-width: 768px) {
    .steps { flex-direction: column; align-items: center; }
    .step-connector { width: 2px; height: 20px; margin: 0; }
}

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: .9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s;
    text-decoration: none !important;
}

.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }

.btn-secondary { background: #e2e8f0; color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: #cbd5e1; }

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

.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }

.btn-lg { padding: 14px 28px; font-size: 1.05rem; }
.btn-sm { padding: 6px 14px; font-size: .8rem; }
.btn-block { width: 100%; justify-content: center; }

/* ---- Forms ---- */
.form-group { margin-bottom: 1rem; flex: 1; }
.form-group label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .35rem; color: var(--text); }
.form-group input,
.form-group select {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: .9rem;
    transition: border-color .15s;
    background: white;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}

.form-row { display: flex; gap: 1rem; align-items: end; }
@media (max-width: 600px) { .form-row { flex-direction: column; } }

/* ---- Cards ---- */
.register-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
}

@media (max-width: 768px) {
    .register-layout { grid-template-columns: 1fr; }
}

.register-form-card,
.camera-card,
.attendance-card,
.settings-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    padding: 1.5rem;
}

/* ---- Camera ---- */
.camera-container {
    position: relative;
    background: #1e293b;
    border-radius: var(--radius);
    overflow: hidden;
    aspect-ratio: 4/3;
    max-height: 400px;
}

.camera-container video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.camera-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.face-guide {
    width: 200px;
    height: 240px;
    border: 3px solid rgba(37, 99, 235, .6);
    border-radius: 50%;
    box-shadow: 0 0 0 9999px rgba(0,0,0,.3);
}

.captured-photo {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #1e293b;
}

.captured-photo img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.camera-controls {
    display: flex;
    gap: .5rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

.status-message {
    margin-top: .75rem;
    padding: 10px;
    border-radius: var(--radius-sm);
    font-size: .85rem;
    font-weight: 500;
}

.status-message:empty { display: none; }

.status-message.info { background: #eff6ff; color: var(--primary); }
.status-message.success { background: #ecfdf5; color: var(--success); }
.status-message.error { background: #fef2f2; color: var(--danger); }

/* ---- Attendance ---- */
.attendance-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.mode-selector {
    display: flex;
    background: #f1f5f9;
    border-radius: var(--radius-sm);
    padding: 4px;
}

.mode-btn {
    padding: 10px 24px;
    border: none;
    background: transparent;
    border-radius: 6px;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s;
    font-size: .9rem;
}

.mode-btn.active {
    background: var(--primary);
    color: white;
}

.gps-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: .85rem;
}

.gps-status.valid { color: var(--success); }
.gps-status.invalid { color: var(--danger); }
.gps-status.loading { color: var(--warning); }

.result-panel {
    margin-top: 1.5rem;
    padding: 1.5rem;
    background: #ecfdf5;
    border-radius: var(--radius);
    border: 1px solid var(--success);
}

.today-logs {
    margin-top: 2rem;
}

.today-logs h3 { margin-bottom: 1rem; }

/* ---- Stats ---- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 1rem;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    background: #eff6ff;
    color: var(--primary);
}

.stat-present .stat-icon { background: #ecfdf5; color: var(--success); }
.stat-late .stat-icon { background: #fffbeb; color: var(--warning); }
.stat-absent .stat-icon { background: #fef2f2; color: var(--danger); }

.stat-info { display: flex; flex-direction: column; }
.stat-value { font-size: 1.75rem; font-weight: 700; }
.stat-label { font-size: .8rem; color: var(--text-muted); }

/* ---- Table ---- */
.table-responsive { overflow-x: auto; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.data-table th {
    background: #f8fafc;
    padding: 12px 16px;
    text-align: left;
    font-size: .8rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
}

.data-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-size: .9rem;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover { background: #f8fafc; }

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: .75rem;
    font-weight: 600;
}

.badge-present { background: #ecfdf5; color: #059669; }
.badge-late { background: #fffbeb; color: #d97706; }
.badge-absent { background: #fef2f2; color: #dc2626; }

.thumb-img {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    object-fit: cover;
    cursor: pointer;
    border: 1px solid var(--border);
}

/* ---- Filter Bar ---- */
.filter-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    gap: 1rem;
    flex-wrap: wrap;
}

.date-filter {
    display: flex;
    align-items: center;
    gap: .5rem;
}

.date-filter input {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
}

.filter-actions { display: flex; gap: .5rem; }

/* ---- Tabs ---- */
.dashboard-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--border);
}

.tab-btn {
    padding: 10px 20px;
    border: none;
    background: transparent;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all .15s;
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-content { display: block; }

/* ---- Settings ---- */
.settings-card { margin-bottom: 1.5rem; }
.settings-card h3 { margin-bottom: 1rem; font-size: 1.1rem; }

.locations-list { margin-bottom: 1rem; }

.location-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: #f8fafc;
    border-radius: var(--radius-sm);
    margin-bottom: .5rem;
    font-size: .9rem;
}

.inline-form .form-row { align-items: end; }

/* ---- Toast ---- */
.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 14px 20px;
    border-radius: var(--radius);
    color: white;
    font-weight: 600;
    font-size: .9rem;
    z-index: 9999;
    transform: translateY(100px);
    opacity: 0;
    transition: all .3s;
    max-width: 400px;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.warning { background: var(--warning); color: var(--text); }

/* ---- Footer ---- */
.footer {
    text-align: center;
    padding: 1.5rem;
    color: var(--text-muted);
    font-size: .85rem;
    border-top: 1px solid var(--border);
}

/* ---- Utilities ---- */
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }

/* =============================================
   MOBILE RESPONSIVE ENHANCEMENTS
   ============================================= */

/* Touch-friendly targets (min 44px) */
@media (pointer: coarse) {
    .btn { min-height: 44px; }
    .nav-menu a { min-height: 44px; padding: 12px 16px; }
    .tab-btn { min-height: 44px; padding: 12px 16px; }
    .mode-btn { min-height: 44px; padding: 12px 20px; }
    .form-group input,
    .form-group select { min-height: 44px; font-size: 16px; }
    .date-filter input { min-height: 44px; font-size: 16px; }
}

/* Small screens (max-width: 640px) */
@media (max-width: 640px) {
    .nav-brand { font-size: 1.1rem; }
    .nav-brand i { font-size: 1.3rem; }

    .main-content { padding: 1rem 0; }
    .container { padding: 0 14px; }

    .hero { padding: 2.5rem 14px; }
    .hero-content h1 { font-size: 1.75rem; }
    .hero-content p { font-size: 1rem; }
    .hero-buttons { flex-direction: column; align-items: center; }
    .hero-buttons .btn { width: 100%; max-width: 280px; }

    .section-title { font-size: 1.5rem; }
    .feature-grid { grid-template-columns: 1fr; gap: 1rem; }
    .feature-card { padding: 1.5rem; }

    .step { min-width: 100%; margin-bottom: 1rem; }

    .page-header h1 { font-size: 1.5rem; }

    .register-form-card,
    .camera-card,
    .attendance-card,
    .settings-card { padding: 1rem; border-radius: 10px; }

    .camera-container { max-height: 320px; }
    .face-guide { width: 140px; height: 180px; border-width: 2px; }

    .camera-controls { flex-direction: column; }
    .camera-controls .btn { width: 100%; justify-content: center; }

    .attendance-header { flex-direction: column; align-items: stretch; }
    .mode-selector { width: 100%; }
    .mode-btn { flex: 1; justify-content: center; }
    .gps-status { justify-content: center; }

    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .stat-card { padding: 1rem; }
    .stat-value { font-size: 1.5rem; }
    .stat-label { font-size: .75rem; }

    .dashboard-tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .tab-btn { white-space: nowrap; flex: 0 0 auto; }

    .filter-bar { flex-direction: column; align-items: stretch; }
    .filter-actions { justify-content: stretch; }
    .filter-actions .btn { flex: 1; justify-content: center; }

    .inline-form .form-row { flex-direction: column; align-items: stretch; }
    .inline-form .form-row .btn { width: 100%; }

    .toast { left: 14px; right: 14px; bottom: 14px; max-width: none; text-align: center; }
    .footer { padding: 1rem; font-size: .75rem; }
}

/* Data table card-view on mobile */
@media (max-width: 768px) {
    .data-table thead { display: none; }
    .data-table tr {
        display: block;
        background: var(--bg-card);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        padding: 12px;
        margin-bottom: .75rem;
        box-shadow: var(--shadow);
    }
    .data-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 6px 0;
        border-bottom: 1px solid #f1f5f9;
        font-size: .85rem;
    }
    .data-table td:last-child { border-bottom: none; }
    .data-table td::before {
        content: attr(data-label);
        font-weight: 700;
        color: var(--text-muted);
        font-size: .75rem;
        text-transform: uppercase;
        margin-right: 1rem;
    }
}

/* iPhone safe-area insets */
@supports (padding-top: env(safe-area-inset-top)) {
    .navbar { padding-top: env(safe-area-inset-top); }
    .footer { padding-bottom: calc(1rem + env(safe-area-inset-bottom)); }
    .toast { bottom: calc(14px + env(safe-area-inset-bottom)); }
}

/* Very small screens (max-width: 360px) */
@media (max-width: 360px) {
    .hero-content h1 { font-size: 1.5rem; }
    .btn-lg { padding: 12px 20px; font-size: .95rem; }
    .stat-value { font-size: 1.25rem; }
    .camera-container { max-height: 260px; }
    .face-guide { width: 120px; height: 150px; }
    .stats-grid { grid-template-columns: 1fr 1fr; gap: .75rem; }
    .stat-card { flex-direction: column; text-align: center; gap: .5rem; padding: .75rem; }
}