/* Global Design System & CSS Variables */
:root {
    --bg-primary: #0f1117;
    --bg-secondary: #181b24;
    --bg-card: rgba(30, 34, 48, 0.7);
    --bg-glass: rgba(24, 27, 36, 0.85);
    --border-color: rgba(255, 255, 255, 0.1);
    --border-highlight: rgba(124, 58, 237, 0.4);
    
    --text-main: #f3f4f6;
    --text-muted: #9ca3af;
    --text-light: #6b7280;

    --accent-purple: #8b5cf6;
    --accent-indigo: #6366f1;
    --accent-emerald: #10b981;
    --accent-rose: #f43f5e;
    --accent-amber: #f59e0b;

    --gradient-brand: linear-gradient(135deg, #8b5cf6 0%, #6366f1 100%);
    --gradient-card: linear-gradient(135deg, rgba(139, 92, 246, 0.05) 0%, rgba(99, 102, 241, 0.02) 100%);

    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-full: 9999px;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.5);

    --header-height: 60px;
    --font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-primary);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    padding-top: var(--header-height);
    line-height: 1.5;
}

/* Universal Top Header & Navigation */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 1000;
}

.brand-title {
    font-size: 1.25rem;
    font-weight: 700;
    background: var(--gradient-brand);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
}

/* Universal Door Navigation Icon */
.door-nav-btn {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    width: 42px;
    height: 42px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    outline: none;
    box-shadow: var(--shadow-sm);
}

.door-nav-btn:hover, .door-nav-btn:active {
    background: rgba(139, 92, 246, 0.2);
    border-color: var(--accent-purple);
    color: var(--accent-purple);
    transform: scale(1.05);
}

.door-icon {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Universal Slide-Out Overlay Drawer */
.door-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(6px);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1050;
}

.door-overlay.active {
    opacity: 1;
    visibility: visible;
}

.door-drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 85%;
    max-width: 340px;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1060;
    box-shadow: var(--shadow-lg);
}

.door-overlay.active .door-drawer {
    transform: translateX(0);
}

.drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 20px;
}

.drawer-user-info {
    display: flex;
    flex-direction: column;
}

.drawer-user-name {
    font-weight: 600;
    font-size: 1.1rem;
}

.drawer-user-branding {
    font-size: 0.8rem;
    color: var(--accent-purple);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 700;
}

.drawer-close-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 4px 8px;
}

.drawer-nav-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex: 1;
    overflow-y: auto;
}

.drawer-nav-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-main);
    text-decoration: none;
    font-weight: 500;
    transition: all 0.2s ease;
}

.drawer-nav-item:hover, .drawer-nav-item.active {
    background: rgba(139, 92, 246, 0.15);
    border-color: var(--accent-purple);
    color: #ffffff;
}

.drawer-nav-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-purple);
}

.drawer-footer {
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

.btn-logout {
    width: 100%;
    padding: 12px;
    background: rgba(244, 63, 94, 0.15);
    border: 1px solid rgba(244, 63, 94, 0.3);
    color: var(--accent-rose);
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.btn-logout:hover {
    background: rgba(244, 63, 94, 0.25);
}

/* Page Layout Container */
.container {
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
    padding: 20px 16px;
    flex: 1;
}

/* Card & UI Components */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(8px);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    font-size: 0.95rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
}

.btn-primary {
    background: var(--gradient-brand);
    color: #ffffff;
    box-shadow: 0 4px 14px rgba(139, 92, 246, 0.4);
}

.btn-primary:hover, .btn-primary:active {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(139, 92, 246, 0.6);
}

.btn-secondary {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-main);
}

.btn-secondary:hover {
    border-color: var(--text-muted);
}

.form-group {
    margin-bottom: 18px;
}

.form-label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-muted);
}

.form-input, .form-select, .form-textarea {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-main);
    font-size: 1rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s ease;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
    border-color: var(--accent-purple);
}

/* Sub-App Grid Dashboard Tiles */
.subapp-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.subapp-tile {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    text-decoration: none;
    color: var(--text-main);
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.subapp-tile::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--gradient-brand);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.subapp-tile:hover {
    transform: translateY(-4px);
    border-color: var(--accent-purple);
    box-shadow: 0 12px 30px rgba(139, 92, 246, 0.2);
}

.subapp-tile:hover::before {
    opacity: 1;
}

.subapp-icon-wrapper {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    background: rgba(139, 92, 246, 0.15);
    color: var(--accent-purple);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.subapp-name {
    font-size: 1.2rem;
    font-weight: 700;
}

.subapp-desc {
    font-size: 0.88rem;
    color: var(--text-muted);
}

/* PWA Toast Notification */
.pwa-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--bg-secondary);
    border: 1px solid var(--accent-purple);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.6);
    border-radius: var(--radius-full);
    padding: 12px 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    z-index: 2000;
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.pwa-toast.visible {
    transform: translateX(-50%) translateY(0);
}

.pwa-toast-btn {
    background: var(--accent-purple);
    color: #ffffff;
    border: none;
    padding: 6px 14px;
    border-radius: var(--radius-full);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
}
