/* ========================================
   Portal — End User Styles
   Grid-based app launcher with search
   Dark / Light theme support via data-theme
   ======================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ---- Dark Theme (default) ---- */
:root {
    --bg: #0c1222;
    --bg-surface: #141c2e;
    --bg-card: rgba(255, 255, 255, 0.04);
    --border: rgba(255, 255, 255, 0.06);
    --text: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --text-primary: #f8fafc;
    --accent: #6366f1;
    --accent-glow: rgba(99, 102, 241, 0.12);
    --accent-border: rgba(99, 102, 241, 0.5);
    --navbar-bg: #0f1629;
    --navbar-text: #f8fafc;
    --header-bg: rgba(12, 18, 34, 0.85);
    --search-focus-shadow: rgba(99, 102, 241, 0.12);
    --kbd-bg: rgba(255, 255, 255, 0.06);
    --kbd-border: rgba(255, 255, 255, 0.1);
    --hover-overlay: rgba(255, 255, 255, 0.08);
    --card-overlay: linear-gradient(180deg, rgba(255, 255, 255, 0.08) 0%, transparent 60%);
    --card-shadow: rgba(0, 0, 0, 0.4);
    --spinner-track: rgba(255, 255, 255, 0.08);
    --scrollbar-thumb: rgba(255, 255, 255, 0.1);
    --dropdown-bg: #1e293b;
    --dropdown-border: rgba(255, 255, 255, 0.08);
    --dropdown-hover: rgba(255, 255, 255, 0.06);
    --dropdown-text: #f1f5f9;
    --dropdown-divider: rgba(255, 255, 255, 0.08);
    --radius: 16px;
    --radius-sm: 12px;
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---- Light Theme ---- */
[data-theme="light"] {
    --bg: #f1f5f9;
    --bg-surface: #ffffff;
    --bg-card: rgba(0, 0, 0, 0.02);
    --border: rgba(0, 0, 0, 0.08);
    --text: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --text-primary: #0f172a;
    --accent: #4f46e5;
    --accent-glow: rgba(79, 70, 229, 0.10);
    --accent-border: rgba(79, 70, 229, 0.45);
    --navbar-bg: #ffffff;
    --navbar-text: #0f172a;
    --header-bg: rgba(241, 245, 249, 0.88);
    --search-focus-shadow: rgba(79, 70, 229, 0.10);
    --kbd-bg: rgba(0, 0, 0, 0.04);
    --kbd-border: rgba(0, 0, 0, 0.10);
    --hover-overlay: rgba(0, 0, 0, 0.05);
    --card-overlay: linear-gradient(180deg, rgba(255, 255, 255, 0.25) 0%, transparent 60%);
    --card-shadow: rgba(0, 0, 0, 0.12);
    --spinner-track: rgba(0, 0, 0, 0.06);
    --scrollbar-thumb: rgba(0, 0, 0, 0.12);
    --dropdown-bg: #ffffff;
    --dropdown-border: rgba(0, 0, 0, 0.08);
    --dropdown-hover: rgba(0, 0, 0, 0.04);
    --dropdown-text: #0f172a;
    --dropdown-divider: rgba(0, 0, 0, 0.08);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    transition: background-color 0.35s ease, color 0.35s ease;
}

/* ---- Header / Search ---- */
.portal-header {
    position: sticky;
    top: 0;
    z-index: 100;
    padding: 16px 24px;
    background: var(--header-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    transition: background 0.35s ease, border-color 0.35s ease;
}

.header-inner {
    max-width: 1200px;
    margin: 0 auto;
}

.search-box {
    position: relative;
    display: flex;
    align-items: center;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 0 16px;
    transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
    max-width: 560px;
    margin: 0 auto;
}

.search-box:focus-within {
    border-color: var(--accent-border);
    box-shadow: 0 0 0 4px var(--search-focus-shadow);
}

.search-icon {
    color: var(--text-muted);
    font-size: 0.9rem;
    flex-shrink: 0;
}

.search-box input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    padding: 13px 12px;
    font-family: inherit;
    font-size: 0.95rem;
    color: var(--text);
}

.search-box input::placeholder {
    color: var(--text-muted);
}

.search-kbd {
    background: var(--kbd-bg);
    border: 1px solid var(--kbd-border);
    border-radius: 6px;
    padding: 2px 8px;
    font-family: inherit;
    font-size: 0.7rem;
    color: var(--text-muted);
    flex-shrink: 0;
}

.search-clear {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    flex-shrink: 0;
}

.search-clear:hover {
    background: var(--hover-overlay);
    color: var(--text);
}

/* ---- Main ---- */
.portal-main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
}

/* ---- Group ---- */
.portal-group {
    margin-bottom: 36px;
}

.group-header {
    display: flex;
    align-items: center;
    margin-bottom: 16px;
    padding: 0 4px;
}
.group-header > *:not(:last-child) {
    margin-right: 12px;
}

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

.group-title h2 {
    font-size: 1.05rem;
    font-weight: 600;
    line-height: 1.2;
    margin-block-end: 0;
}

.group-subtitle {
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* ---- Grid ---- */
.grid {
    display: flex;
    flex-wrap: wrap;
    margin: -6px;
}

.grid > * {
    flex: 0 0 calc(16.666% - 12px); /* 6 columns */
    margin: 6px;
}

@media (max-width: 1200px) {
    .grid > * {
        flex: 0 0 calc(20% - 12px); /* 5 columns */
    }
}

@media (max-width: 992px) {
    .grid > * {
        flex: 0 0 calc(25% - 12px); /* 4 columns */
    }
}

@media (max-width: 768px) {
    .grid {
        margin: -5px;
    }
    .grid > * {
        flex: 0 0 calc(33.333% - 10px); /* 3 columns */
        margin: 5px;
    }
}

@media (max-width: 480px) {
    .grid {
        margin: -4px;
    }
    .grid > * {
        flex: 0 0 calc(33.333% - 8px); /* 3 columns */
        margin: 4px;
    }
}

@media (min-width: 1400px) {
    .grid > * {
        flex: 0 0 calc(12.5% - 12px); /* 8 columns */
    }
}

@supports (display: grid) {
    .grid {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 12px;
        margin: 0;
    }
    
    .grid > * {
        flex: unset;
        max-width: none;
        margin: 0;
    }
    
    @media (max-width: 768px) {
        .grid {
            grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
            gap: 10px;
            margin: 0;
        }
        .grid > * {
            margin: 0;
        }
    }
    
    @media (max-width: 480px) {
        .grid {
            grid-template-columns: repeat(3, 1fr);
            gap: 8px;
            margin: 0;
        }
        .grid > * {
            margin: 0;
        }
    }

    @media (min-width: 1400px) {
        .grid {
            grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
            margin: 0;
        }
        .grid > * {
            margin: 0;
        }
    }
}

/* ---- App Card ---- */
.app-card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 24px 12px 18px;
    border-radius: var(--radius);
    background: linear-gradient(145deg, var(--card-bg), var(--card-bg-dark));
    color: #fff;
    text-decoration: none;
    transition: transform var(--transition), box-shadow var(--transition);
    overflow: hidden;
    min-height: 130px;
    animation: cardFadeIn 0.4s ease both;
}

.app-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--card-overlay);
    pointer-events: none;
    border-radius: var(--radius);
}

.app-card:hover {
    transform: translateY(-4px) scale(1.03);
    box-shadow: 0 12px 32px var(--card-shadow);
}

.app-card:active {
    transform: translateY(-1px) scale(1.01);
}

/* Light theme: subtle card border for definition */
[data-theme="light"] .app-card {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 0 0 1px rgba(0, 0, 0, 0.04);
}

[data-theme="light"] .app-card:hover {
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.06);
}

/* Highlight pulse ring */
.app-card.card-highlight::after {
    content: '';
    position: absolute;
    top: 8px;
    right: 8px;
    width: 8px;
    height: 8px;
    background: #fbbf24;
    border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(251, 191, 36, 0.5);
    animation: pulse 2s ease-in-out infinite;
}

.card-icon {
    font-size: 2rem;
    margin-bottom: 10px;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
    position: relative;
    z-index: 1;
}

.card-label {
    font-size: 0.78rem;
    font-weight: 600;
    line-height: 1.3;
    position: relative;
    z-index: 1;
    word-break: break-word;
    max-width: 100%;
}

.card-sublabel {
    font-size: 0.65rem;
    opacity: 0.7;
    margin-top: 2px;
    line-height: 1.2;
    position: relative;
    z-index: 1;
    word-break: break-word;
}

.card-ext {
    position: absolute;
    top: 8px;
    left: 8px;
    font-size: 0.55rem;
    opacity: 0.5;
    z-index: 1;
}

/* ---- States ---- */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    color: var(--text-muted);
}
.loading-state > *:not(:last-child) {
    margin-bottom: 16px;
}

.loading-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--spinner-track);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.no-results {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    color: var(--text-muted);
    text-align: center;
}
.no-results > *:not(:last-child) {
    margin-bottom: 8px;
}

.no-results i {
    font-size: 2rem;
    opacity: 0.3;
    margin-bottom: 8px;
}

.no-results p {
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.no-results span {
    font-size: 0.85rem;
}

.error-state {
    text-align: center;
    padding: 80px 20px;
    color: var(--text-muted);
}

.error-state i {
    font-size: 2.5rem;
    opacity: 0.3;
    margin-bottom: 12px;
    display: block;
}

.error-state p {
    font-size: 0.95rem;
}

/* ---- Animations ---- */
@keyframes cardFadeIn {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.96);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(251, 191, 36, 0.5);
    }

    70% {
        box-shadow: 0 0 0 6px rgba(251, 191, 36, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(251, 191, 36, 0);
    }
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 3px;
}

/* ---- Responsive ---- */

/* Tablet */
@media (max-width: 768px) {
    .portal-header {
        padding: 12px 16px;
    }

    .portal-main {
        padding: 16px;
    }



    .app-card {
        padding: 20px 8px 14px;
        min-height: 110px;
        border-radius: var(--radius-sm);
    }

    .card-icon {
        font-size: 1.6rem;
        margin-bottom: 8px;
    }

    .card-label {
        font-size: 0.72rem;
    }

    .portal-group {
        margin-bottom: 28px;
    }
}

/* Phone */
@media (max-width: 480px) {
    .portal-header {
        padding: 10px 12px;
    }

    .search-box {
        border-radius: 12px;
    }

    .search-box input {
        font-size: 0.9rem;
        padding: 11px 10px;
    }

    .search-kbd {
        display: none;
    }

    .portal-main {
        padding: 12px;
    }



    .app-card {
        padding: 16px 6px 12px;
        min-height: 100px;
        border-radius: 12px;
    }

    .card-icon {
        font-size: 1.4rem;
        margin-bottom: 6px;
    }

    .card-label {
        font-size: 0.68rem;
    }

    .card-sublabel {
        font-size: 0.58rem;
    }

    .group-header {
        margin-bottom: 10px;
    }

    .group-icon {
        width: 30px;
        height: 30px;
        font-size: 0.8rem;
        border-radius: 8px;
    }

    .group-title h2 {
        font-size: 0.92rem;
    }

    .portal-group {
        margin-bottom: 24px;
    }
}

/* Large desktop */



/* ---- Navbar ---- */
.navbar {
    background-color: var(--navbar-bg) !important;
    color: var(--navbar-text) !important;
    border-bottom: 1px solid var(--border);
}

.navbar-brand,
.navbar-text,
.nav-link,
.d-flex {
    color: var(--navbar-text) !important;
}

@media (max-width: 768px) {
    .navbar-brand {
        font-size: 1em !important;
    }
}

/* ---- Top Header Bar ---- */
.header {
    height: 60px;
    background-color: var(--navbar-bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    margin-bottom: 0;
    transition: background-color 0.35s ease, border-color 0.35s ease;
}

.brand-text {
    color: var(--text-primary);
    font-weight: 600;
    font-size: 1rem;
    letter-spacing: 0.5px;
}

.controls-group {
    display: flex;
    align-items: center;
}
.controls-group > *:not(:last-child) {
    margin-right: 1rem;
}

.theme-toggle,
.lang-link {
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.85rem;
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.theme-toggle:hover,
.lang-link:hover {
    background-color: var(--hover-overlay);
    color: var(--text-primary);
}

.lang-link.active {
    font-weight: 700;
    border-radius: 6px;
    border: 1px solid #888888;
}

/* ---- Bootstrap Dropdown override ---- */
.dropdown-menu {
    background-color: var(--dropdown-bg) !important;
    border: 1px solid var(--dropdown-border) !important;
}

.dropdown-menu .dropdown-item {
    color: var(--dropdown-text) !important;
    transition: background-color 0.15s ease;
}

.dropdown-menu .dropdown-item:hover,
.dropdown-menu .dropdown-item:focus {
    background-color: var(--dropdown-hover) !important;
    color: var(--dropdown-text) !important;
}

.dropdown-menu .dropdown-divider {
    border-top-color: var(--dropdown-divider) !important;
}

.dropdown-menu .dropdown-item.text-danger {
    color: #ef4444 !important;
}

@media (max-width: 576px) {
    .controls-group {
        gap: 0.25rem;
    }

    .header {
        padding: 0 0.5rem;
    }

    .theme-toggle,
    .lang-link {
        padding: 5px;
    }
}

/* ---- Avatar invert for dark theme ---- */
[data-theme="dark"] img[src*="user-avatar-icon"] {
    filter: invert(1) brightness(1.5);
}

/* ---- Logo invert for light theme ---- */
[data-theme="light"] .header img[src*="logo"] {
    /*filter: brightness(0.2);*/
}

/* ---- Favorite Context Menu ---- */
.fav-context-menu {
    display: none;
    position: absolute;
    background: var(--dropdown-bg);
    border: 1px solid var(--dropdown-border);
    box-shadow: 0 4px 12px var(--card-shadow);
    border-radius: 8px;
    padding: 5px 0;
    z-index: 2000;
    min-width: 160px;
}

.fav-context-menu.active {
    display: block;
}

.fav-context-menu .context-item {
    padding: 10px 15px;
    font-size: 0.85rem;
    color: var(--text);
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 10px;
}

.fav-context-menu .context-item:hover {
    background: var(--dropdown-hover);
    color: var(--accent);
}

.fav-btn {
    position: absolute;
    bottom: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.2);
    color: rgba(255, 255, 255, 0.8);
    border: none;
    cursor: pointer;
    z-index: 5;
    transition: all 0.2s;
    opacity: 0;
}

.app-card:hover .fav-btn {
    opacity: 1;
}

.fav-btn:hover {
    background: rgba(0, 0, 0, 0.4);
    color: #fff;
    transform: scale(1.1);
}

.card-fav-star {
    position: absolute;
    top: 8px;
    right: 8px;
    color: #fbbf24;
    font-size: 0.75rem;
    filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.5));
}