/* ============================================
   SKPKLC PWA & Mobile App-Like UI Styles
   ============================================ */

/* === SAFE AREA INSETS (notched devices) === */
:root {
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --top-bar-height: 56px;
    --bottom-nav-height: 64px;
}

/* Prevent pull-to-refresh in standalone mode */
html {
    overscroll-behavior-y: contain;
}

/* Standalone mode adjustments */
@media all and (display-mode: standalone) {
    body {
        padding-top: var(--safe-top);
    }
}

/* ============================================
   TOP APP BAR (mobile only)
   ============================================ */
.pwa-top-bar {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--top-bar-height);
    background: var(--sidebar-bg, #1e293b);
    color: white;
    z-index: 1100;
    align-items: center;
    padding: 0 12px;
    gap: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    padding-top: var(--safe-top);
}

@media all and (display-mode: standalone) {
    .pwa-top-bar {
        height: calc(var(--top-bar-height) + var(--safe-top));
    }
}

.pwa-top-bar.hidden {
    transform: translateY(-100%);
}

.pwa-top-bar-menu {
    width: 40px;
    height: 40px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.pwa-top-bar-menu:hover,
.pwa-top-bar-menu:active {
    background: rgba(255, 255, 255, 0.2);
}

.pwa-top-bar-logo {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    object-fit: contain;
    background: white;
    padding: 2px;
    flex-shrink: 0;
}

.pwa-top-bar-title {
    flex: 1;
    font-size: 1.05rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: 0.2px;
}

.pwa-top-bar-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.pwa-top-bar-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    cursor: pointer;
    position: relative;
    transition: background 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.pwa-top-bar-btn:hover,
.pwa-top-bar-btn:active {
    background: rgba(255, 255, 255, 0.15);
}

.pwa-notif-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    min-width: 18px;
    height: 18px;
    background: #ef4444;
    border-radius: 9px;
    border: 2px solid var(--sidebar-bg, #1e293b);
    display: none;
    font-size: 0.65rem;
    font-weight: 700;
    color: #fff;
    line-height: 14px;
    text-align: center;
    padding: 0 3px;
}

.pwa-notif-badge.show {
    display: block;
    animation: notifPulse 2s ease-in-out infinite;
}

@keyframes notifPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

/* ============================================
   NOTIFICATION DROPDOWN PANEL
   ============================================ */
.notif-dropdown {
    display: none;
    position: fixed;
    top: var(--top-bar-height, 56px);
    right: 8px;
    width: 340px;
    max-width: calc(100vw - 16px);
    max-height: 420px;
    background: var(--card-bg, #fff);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
    z-index: 1600;
    overflow: hidden;
    flex-direction: column;
}

.notif-dropdown.show {
    display: flex;
}

/* Desktop: place the dropdown to the right of the fixed sidebar */
@media (min-width: 901px) {
    .notif-dropdown {
        top: 16px;
        left: 266px;
        right: auto;
        z-index: 2100;
    }
}

@media (min-width: 701px) and (max-width: 900px) {
    .notif-dropdown {
        top: 16px;
        left: 236px;
        right: auto;
        z-index: 2100;
    }
}

/* ============================================
   DESKTOP SIDEBAR NOTIFICATION BELL
   ============================================ */
.sidebar-notif-btn {
    display: none;
    position: relative;
    margin-left: auto;
    width: 40px;
    height: 40px;
    border: none;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    border-radius: 10px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    font-size: 1.05rem;
    flex-shrink: 0;
    transition: background 0.2s;
}

.sidebar-notif-btn:hover {
    background: rgba(255, 255, 255, 0.18);
}

/* Show only on desktop; mobile uses the top-bar bell */
@media (min-width: 701px) {
    .sidebar-notif-btn {
        display: inline-flex;
    }
}

.sidebar-notif-btn .pwa-notif-badge {
    top: 2px;
    right: 2px;
}

.notif-dropdown-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--gray-200, #e5e7eb);
    background: var(--gray-50, #f9fafb);
}

.notif-dropdown-title {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--gray-800, #1f2937);
}

.notif-mark-all {
    background: none;
    border: none;
    color: var(--primary, #2563eb);
    cursor: pointer;
    font-size: 0.85rem;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.2s;
}

.notif-mark-all:hover {
    background: rgba(37, 99, 235, 0.1);
}

.notif-dropdown-body {
    overflow-y: auto;
    flex: 1;
    max-height: 360px;
}

.notif-loading {
    padding: 24px;
    text-align: center;
    color: var(--gray-400, #9ca3af);
    font-size: 0.9rem;
}

.notif-empty {
    padding: 32px 16px;
    text-align: center;
    color: var(--gray-400, #9ca3af);
}

.notif-empty i {
    font-size: 2rem;
    margin-bottom: 8px;
    display: block;
}

.notif-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--gray-100, #f3f4f6);
    cursor: pointer;
    transition: background 0.15s;
    text-decoration: none;
    color: inherit;
}

.notif-item:hover {
    background: var(--gray-50, #f9fafb);
}

.notif-item.unread {
    background: rgba(37, 99, 235, 0.04);
}

.notif-item.unread::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--primary, #2563eb);
    border-radius: 0 3px 3px 0;
}

.notif-item {
    position: relative;
}

.notif-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.85rem;
    color: #fff;
}

.notif-icon.type-tugas { background: #3b82f6; }
.notif-icon.type-materi { background: #8b5cf6; }
.notif-icon.type-jadwal { background: #f59e0b; }
.notif-icon.type-agenda { background: #10b981; }
.notif-icon.type-feedback { background: #ec4899; }
.notif-icon.type-submit { background: #06b6d4; }
.notif-icon.type-security { background: #ef4444; }

.notif-content {
    flex: 1;
    min-width: 0;
}

.notif-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--gray-800, #1f2937);
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.notif-msg {
    font-size: 0.78rem;
    color: var(--gray-500, #6b7280);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.notif-time {
    font-size: 0.7rem;
    color: var(--gray-400, #9ca3af);
    margin-top: 2px;
}

/* Backdrop for closing dropdown on mobile */
.notif-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1599;
}

.notif-backdrop.show {
    display: block;
}

/* Show top bar on mobile */
@media (max-width: 700px) {
    .pwa-top-bar {
        display: flex;
        pointer-events: auto;
    }
}

/* ============================================
   BOTTOM NAVIGATION BAR (mobile only)
   ============================================ */
.pwa-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-height);
    background: var(--card-bg, white);
    z-index: 1100;
    align-items: stretch;
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.1);
    border-top: 1px solid var(--card-border, #e2e8f0);
    padding-bottom: var(--safe-bottom);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@media all and (display-mode: standalone) {
    .pwa-bottom-nav {
        height: calc(var(--bottom-nav-height) + var(--safe-bottom));
    }
}

.pwa-bottom-nav.hidden {
    transform: translateY(100%);
}

.pwa-bottom-nav-items {
    display: flex;
    align-items: stretch;
    justify-content: space-around;
    width: 100%;
    height: var(--bottom-nav-height);
    padding: 0;
    margin: 0;
    list-style: none;
}

.pwa-bottom-nav-item {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pwa-bottom-nav-item a,
.pwa-bottom-nav-item button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    width: 100%;
    height: 100%;
    text-decoration: none;
    color: var(--card-text, #94a3b8);
    font-size: 0.68rem;
    font-weight: 500;
    border: none;
    background: none;
    cursor: pointer;
    transition: color 0.2s;
    -webkit-tap-highlight-color: transparent;
    padding: 6px 4px;
    position: relative;
}

.pwa-bottom-nav-item a i,
.pwa-bottom-nav-item button i {
    font-size: 1.25rem;
    transition: transform 0.2s, color 0.2s;
    line-height: 1;
}

.pwa-bottom-nav-item a span,
.pwa-bottom-nav-item button span {
    line-height: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 70px;
}

.pwa-bottom-nav-item a.active,
.pwa-bottom-nav-item a:active {
    color: var(--biru-muda, #2563eb);
}

.pwa-bottom-nav-item a.active i {
    transform: scale(1.15);
}

.pwa-bottom-nav-item a.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 32px;
    height: 3px;
    background: var(--biru-muda, #2563eb);
    border-radius: 0 0 3px 3px;
}

.pwa-bottom-nav-item button.more-btn {
    color: var(--card-text, #94a3b8);
}

.pwa-bottom-nav-item a:hover,
.pwa-bottom-nav-item button:hover {
    color: var(--biru-muda, #2563eb);
}

.pwa-bottom-nav-item button.more-btn:active {
    color: var(--biru-muda, #2563eb);
}

/* Show bottom nav on mobile */
@media (max-width: 700px) {
    .pwa-bottom-nav {
        display: flex;
        pointer-events: auto;
        position: fixed;
    }
}

/* ============================================
   SIDEBAR DRAWER IMPROVEMENTS (mobile)
   ============================================ */
.sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1400;
    opacity: 0;
    transition: opacity 0.3s ease;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    pointer-events: none;
}

.sidebar-backdrop.show {
    display: block;
    opacity: 1;
    pointer-events: auto;
}

@media (max-width: 700px) {
    .sidebar {
        border-radius: 0 16px 16px 0;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.25);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .sidebar-close-btn {
        display: flex;
        position: absolute;
        top: 12px;
        right: 12px;
        width: 32px;
        height: 32px;
        border: none;
        background: rgba(255, 255, 255, 0.15);
        color: white;
        border-radius: 50%;
        align-items: center;
        justify-content: center;
        font-size: 0.9rem;
        cursor: pointer;
        z-index: 10;
        transition: background 0.2s;
        -webkit-tap-highlight-color: transparent;
    }

    .sidebar-close-btn:hover,
    .sidebar-close-btn:active {
        background: rgba(255, 255, 255, 0.3);
    }
}

@media (min-width: 701px) {
    .sidebar-close-btn {
        display: none;
    }
    .sidebar-backdrop {
        display: none !important;
    }
}

/* ============================================
   MAIN CONTENT ADJUSTMENTS FOR MOBILE
   ============================================ */
@media (max-width: 700px) {
    /* Account for top bar + bottom nav */
    .main {
        padding-top: calc(var(--top-bar-height) + 16px) !important;
        padding-bottom: calc(var(--bottom-nav-height) + 16px) !important;
    }

    @media all and (display-mode: standalone) {
        .main {
            padding-top: calc(var(--top-bar-height) + var(--safe-top) + 16px) !important;
            padding-bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + 16px) !important;
        }
    }

    /* Hide the old floating menu toggle - replaced by top bar */
    .menu-toggle {
        display: none !important;
    }

    /* Improve touch targets */
    .btn, button, a.btn {
        min-height: 44px;
    }

    .sidebar-menu a {
        min-height: 48px;
        padding: 12px 20px;
    }

    /* Smoother scrolling */
    .main {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }
}

/* ============================================
   NOTIFICATION PERMISSION BANNER
   ============================================ */
.pwa-notif-prompt {
    display: none;
    position: fixed;
    bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + 12px);
    left: 12px;
    right: 12px;
    background: white;
    border-radius: 12px;
    padding: 14px 16px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
    z-index: 1050;
    align-items: center;
    gap: 12px;
    animation: slideUpPrompt 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid #e2e8f0;
}

.pwa-notif-prompt.show {
    display: flex;
}

/* Desktop: sidebar (250px) is always visible - offset the prompt so it doesn't overlap */
@media (min-width: 901px) {
    .pwa-notif-prompt {
        left: calc(250px + 24px);
        right: 24px;
        bottom: 24px;
        max-width: 520px;
    }
}

/* Tablet: sidebar is 220px wide */
@media (min-width: 701px) and (max-width: 900px) {
    .pwa-notif-prompt {
        left: calc(220px + 20px);
        right: 20px;
        bottom: 20px;
    }
}

@keyframes slideUpPrompt {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.pwa-notif-prompt-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.pwa-notif-prompt-text {
    flex: 1;
    font-size: 0.875rem;
    color: #374151;
    line-height: 1.4;
}

.pwa-notif-prompt-text strong {
    display: block;
    font-size: 0.9375rem;
    color: #111827;
    margin-bottom: 2px;
}

.pwa-notif-prompt-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.pwa-notif-prompt-actions button {
    padding: 6px 14px;
    border-radius: 8px;
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.pwa-notif-allow {
    background: var(--primary, #2563eb);
    color: white;
}

.pwa-notif-allow:hover { background: #1e40af; }

.pwa-notif-dismiss {
    background: #f1f5f9;
    color: #64748b;
}

.pwa-notif-dismiss:hover { background: #e2e8f0; }

@media (max-width: 400px) {
    .pwa-notif-prompt {
        flex-wrap: wrap;
    }
    .pwa-notif-prompt-actions {
        width: 100%;
        justify-content: flex-end;
    }
}

/* When sidebar drawer is open on mobile, hide notification prompt to avoid overlap */
@media (max-width: 700px) {
    body.sidebar-open .pwa-notif-prompt {
        display: none !important;
    }
}

/* ============================================
   PWA INSTALL PROMPT
   ============================================ */
.pwa-install-banner {
    display: none;
    position: fixed;
    bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + 12px);
    left: 12px;
    right: 12px;
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
    color: white;
    border-radius: 12px;
    padding: 14px 16px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
    z-index: 1050;
    align-items: center;
    gap: 12px;
    animation: slideUpPrompt 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.pwa-install-banner.show {
    display: flex;
}

.pwa-install-banner-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    overflow: hidden;
    flex-shrink: 0;
    background: white;
    padding: 4px;
}

.pwa-install-banner-icon img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.pwa-install-banner-text {
    flex: 1;
    font-size: 0.875rem;
    line-height: 1.4;
}

.pwa-install-banner-text strong {
    display: block;
    font-size: 0.9375rem;
    margin-bottom: 2px;
}

.pwa-install-btn {
    padding: 8px 18px;
    background: var(--primary, #2563eb);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.8125rem;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
    flex-shrink: 0;
}

.pwa-install-btn:hover { background: #3b82f6; }

.pwa-install-close {
    width: 28px;
    height: 28px;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    cursor: pointer;
    flex-shrink: 0;
}

/* ============================================
   DARK THEME ADJUSTMENTS FOR BOTTOM NAV
   ============================================ */
:root:has(.main[style*="--main-bg"]) .pwa-bottom-nav,
body[style] .pwa-bottom-nav {
    background: var(--card-bg, white);
    border-top-color: var(--card-border, #e2e8f0);
}

/* ============================================
   PAGE TRANSITION EFFECT
   ============================================ */
.pwa-page-enter {
    animation: pageEnter 0.25s ease-out;
}

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

/* ============================================
   DESKTOP: No PWA mobile components
   ============================================ */
@media (min-width: 701px) {
    .pwa-top-bar,
    .pwa-bottom-nav,
    .pwa-install-banner {
        display: none !important;
    }
}

/* ============================================
   NOTIFICATION SETTINGS (Profile Page)
   ============================================ */
.notif-settings-content {
    max-width: 600px;
    margin: 0 auto;
}

.notif-status-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 8px 0;
}

.notif-status-info {
    display: flex;
    align-items: center;
    gap: 14px;
    flex: 1;
    min-width: 0;
}

.notif-status-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
    transition: all 0.3s;
}

.notif-status-icon.notif-status-green {
    background: #ecfdf5;
    color: #059669;
}

.notif-status-icon.notif-status-red {
    background: #fef2f2;
    color: #dc2626;
}

.notif-status-icon.notif-status-gray {
    background: #f3f4f6;
    color: #6b7280;
}

.notif-status-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.notif-status-text strong {
    font-size: 0.9375rem;
    color: var(--card-text, #111827);
}

.notif-status-text span {
    font-size: 0.8125rem;
    color: var(--gray-500, #6b7280);
    line-height: 1.4;
}

.notif-status-action {
    flex-shrink: 0;
}

.notif-toggle-btn {
    display: inline-flex;
    align-items: center;
    padding: 8px 20px;
    border-radius: 8px;
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    white-space: nowrap;
}

.notif-toggle-btn.notif-toggle-on {
    background: var(--primary, #2563eb);
    color: white;
}

.notif-toggle-btn.notif-toggle-on:hover {
    background: #1e40af;
}

.notif-toggle-btn.notif-toggle-off {
    background: #f3f4f6;
    color: #6b7280;
}

.notif-toggle-btn.notif-toggle-off:hover {
    background: #e5e7eb;
}

.notif-help-text {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-top: 12px;
    padding: 10px 14px;
    background: #fef3c7;
    border-radius: 8px;
    font-size: 0.8125rem;
    color: #92400e;
    line-height: 1.5;
}

.notif-help-text i {
    margin-top: 2px;
    flex-shrink: 0;
}

.notif-test-row {
    display: flex;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color, #e2e8f0);
}

.notif-test-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    background: #ecfdf5;
    color: #059669;
    border: 1px solid #a7f3d0;
    border-radius: 8px;
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.notif-test-btn:hover {
    background: #d1fae5;
    border-color: #6ee7b7;
}

.notif-test-btn:disabled {
    opacity: 0.7;
    cursor: default;
}

@media (max-width: 480px) {
    .notif-status-row {
        flex-direction: column;
        align-items: flex-start;
    }
    .notif-status-action {
        width: 100%;
    }
    .notif-toggle-btn {
        width: 100%;
        justify-content: center;
    }
}

/* ============================================
   LOGIN PAGE PWA adjustments
   ============================================ */
body.login-page .pwa-top-bar,
body.login-page .pwa-bottom-nav {
    display: none !important;
}

/* Login page install banner - positioned at bottom without bottom nav offset */
.pwa-install-banner-login {
    bottom: 12px !important;
    display: none;
}

.pwa-install-banner-login.show {
    display: flex;
}

@media (min-width: 701px) {
    .pwa-install-banner-login {
        max-width: 480px;
        left: 50% !important;
        right: auto !important;
        transform: translateX(-50%);
    }
}
