Spaces:
Sleeping
Sleeping
Download app/ui/_styles.py from QDB95/qdb-knowledge-bot: direct link, hf CLI and curl.
- Browser
- Download file 24.3 kB
-
https://huggingface.co/spaces/QDB95/qdb-knowledge-bot/resolve/main/app/ui/_styles.py
- Command line
-
hf download hf://spaces/QDB95/qdb-knowledge-bot/app/ui/_styles.py
-
curl -L -o _styles.py https://huggingface.co/spaces/QDB95/qdb-knowledge-bot/resolve/main/app/ui/_styles.py
24.3 kB
| """Centralized CSS + UI primitives for the QDB Knowledge Bot. | |
| Importing `inject_styles()` once per page applies the full design system. | |
| """ | |
| import base64 | |
| from functools import lru_cache | |
| from pathlib import Path | |
| import streamlit as st | |
| _LOGO_PATH = Path(__file__).parent / "qdbank_logo.jpeg" | |
| def _logo_data_uri() -> str: | |
| """Load the QDB logo as a base64 data URI for inline HTML use.""" | |
| if not _LOGO_PATH.exists(): | |
| return "" | |
| data = base64.b64encode(_LOGO_PATH.read_bytes()).decode() | |
| return f"data:image/jpeg;base64,{data}" | |
| _CSS = """ | |
| <style> | |
| @import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700;800&family=Inter:wght@400;500;600;700&display=swap'); | |
| /* ============== CSS Variables (QDB brand — multi-color from logo) ============== */ | |
| :root { | |
| --qdb-primary: #5B4FBE; /* deep purple-blue (main from logo) */ | |
| --qdb-primary-dark: #4439A0; | |
| --qdb-primary-light: #7D6FD8; | |
| --qdb-purple: #8E5DD9; /* violet from logo */ | |
| --qdb-cyan: #3DA5E0; /* sky blue from logo */ | |
| --qdb-green: #22B574; /* fresh green from logo */ | |
| --qdb-gold: #F5B72D; /* warm accent */ | |
| --qdb-gold-light: #FBD56B; | |
| --qdb-bg: #FAFAFA; | |
| --qdb-surface: #FFFFFF; | |
| --qdb-surface-2: #F5F5F7; | |
| --qdb-text: #1A1A1A; | |
| --qdb-text-muted: #6B7280; | |
| --qdb-border: #E5E7EB; | |
| --qdb-success: #10B981; | |
| --qdb-warning: #F59E0B; | |
| --qdb-error: #EF4444; | |
| --shadow-sm: 0 1px 2px rgba(0,0,0,0.04); | |
| --shadow-md: 0 4px 12px rgba(0,0,0,0.08); | |
| --shadow-lg: 0 12px 32px rgba(0,0,0,0.12); | |
| --radius-sm: 8px; | |
| --radius-md: 12px; | |
| --radius-lg: 16px; | |
| --radius-xl: 24px; | |
| } | |
| /* ============== Reset / Global ============== */ | |
| html, body, [class*="css"] { | |
| font-family: 'Inter', 'Cairo', -apple-system, BlinkMacSystemFont, sans-serif; | |
| color: var(--qdb-text); | |
| } | |
| .arabic, [dir="rtl"] { | |
| font-family: 'Cairo', 'Inter', sans-serif; | |
| direction: rtl; | |
| text-align: right; | |
| } | |
| /* Hide Streamlit default chrome */ | |
| #MainMenu, footer, header[data-testid="stHeader"] {visibility: hidden;} | |
| .stDeployButton {display: none;} | |
| /* ============== App Container ============== */ | |
| .main .block-container { | |
| padding-top: 1rem; | |
| padding-bottom: 6rem; | |
| max-width: 760px; | |
| } | |
| /* ============== Sidebar (compact, ChatGPT-style) ============== */ | |
| section[data-testid="stSidebar"] { | |
| background: #FAFAFA; | |
| border-right: 1px solid var(--qdb-border); | |
| width: 260px !important; | |
| min-width: 260px !important; | |
| } | |
| section[data-testid="stSidebar"] > div { | |
| padding-top: 1rem; | |
| display: flex; | |
| flex-direction: column; | |
| height: 100vh; | |
| } | |
| /* Sidebar collapse button — bigger so it's findable */ | |
| button[data-testid="baseButton-headerNoPadding"] { | |
| background: var(--qdb-surface) !important; | |
| border: 1px solid var(--qdb-border) !important; | |
| border-radius: 8px !important; | |
| padding: 6px !important; | |
| } | |
| .qdb-sidebar-user { | |
| display: flex; | |
| gap: 10px; | |
| align-items: center; | |
| padding: 10px 12px; | |
| background: var(--qdb-surface); | |
| border: 1px solid var(--qdb-border); | |
| border-radius: var(--radius-sm); | |
| margin-bottom: 12px; | |
| } | |
| .qdb-sidebar-user-avatar { | |
| width: 32px; height: 32px; | |
| border-radius: 50%; | |
| background: linear-gradient(135deg, var(--qdb-primary), var(--qdb-primary-light)); | |
| color: white; | |
| display: flex; align-items: center; justify-content: center; | |
| font-weight: 700; font-size: 13px; | |
| flex-shrink: 0; | |
| } | |
| .qdb-sidebar-user-name { | |
| font-size: 13px; font-weight: 600; line-height: 1.2; | |
| overflow: hidden; text-overflow: ellipsis; white-space: nowrap; | |
| } | |
| .qdb-sidebar-user-email { | |
| font-size: 11px; color: var(--qdb-text-muted); margin-top: 2px; | |
| overflow: hidden; text-overflow: ellipsis; white-space: nowrap; | |
| } | |
| /* ============== Top Bar (header) ============== */ | |
| .qdb-topbar { | |
| display: flex; | |
| justify-content: space-between; | |
| align-items: center; | |
| padding: 12px 8px; | |
| margin-bottom: 1.5rem; | |
| border-bottom: 1px solid var(--qdb-border); | |
| } | |
| .qdb-topbar-brand { | |
| display: flex; align-items: center; gap: 12px; | |
| } | |
| .qdb-topbar-logo { | |
| width: 36px; height: 36px; | |
| background: linear-gradient(135deg, var(--qdb-primary), var(--qdb-primary-dark)); | |
| color: var(--qdb-gold); | |
| border-radius: 8px; | |
| display: flex; align-items: center; justify-content: center; | |
| font-weight: 800; font-size: 13px; letter-spacing: -0.5px; | |
| } | |
| .qdb-topbar-title { | |
| font-size: 15px; font-weight: 700; color: var(--qdb-text); line-height: 1.1; | |
| } | |
| .qdb-topbar-sub { | |
| font-size: 11px; color: var(--qdb-text-muted); margin-top: 2px; | |
| } | |
| .qdb-topbar-user { | |
| display: flex; align-items: center; gap: 8px; | |
| padding: 6px 12px; | |
| background: var(--qdb-surface); | |
| border: 1px solid var(--qdb-border); | |
| border-radius: 999px; | |
| cursor: default; | |
| } | |
| .qdb-topbar-userbadge { | |
| width: 24px; height: 24px; | |
| border-radius: 50%; | |
| background: linear-gradient(135deg, var(--qdb-primary), var(--qdb-primary-light)); | |
| color: white; | |
| display: flex; align-items: center; justify-content: center; | |
| font-weight: 700; font-size: 11px; | |
| } | |
| .qdb-topbar-username { | |
| font-size: 13px; font-weight: 600; | |
| } | |
| .qdb-topbar-userrole { | |
| font-size: 10px; | |
| color: var(--qdb-text-muted); | |
| padding: 1px 6px; | |
| background: var(--qdb-surface-2); | |
| border-radius: 999px; | |
| font-weight: 600; | |
| } | |
| /* ============== Brand Header ============== */ | |
| .qdb-brand { | |
| display: flex; | |
| align-items: center; | |
| gap: 12px; | |
| padding: 16px; | |
| background: linear-gradient(135deg, var(--qdb-primary) 0%, var(--qdb-purple) 100%); | |
| border-radius: var(--radius-md); | |
| margin-bottom: 1.5rem; | |
| box-shadow: 0 4px 16px rgba(91, 79, 190, 0.25); | |
| } | |
| .qdb-brand-logo { | |
| width: 44px; height: 44px; | |
| background: white; | |
| border-radius: 10px; | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| font-weight: 800; | |
| background-image: linear-gradient(135deg, var(--qdb-cyan) 0%, var(--qdb-green) 50%, var(--qdb-purple) 100%); | |
| -webkit-background-clip: text; | |
| background-clip: text; | |
| color: transparent; | |
| -webkit-text-fill-color: transparent; | |
| font-size: 16px; | |
| letter-spacing: -0.5px; | |
| background-color: white; | |
| box-shadow: inset 0 0 0 2px rgba(255,255,255,0.5); | |
| } | |
| .qdb-brand-text { | |
| color: white; | |
| font-weight: 700; | |
| font-size: 16px; | |
| line-height: 1.2; | |
| } | |
| .qdb-brand-subtitle { | |
| color: rgba(255,255,255,0.7); | |
| font-size: 11px; | |
| font-weight: 400; | |
| margin-top: 2px; | |
| } | |
| /* ============== Page Title ============== */ | |
| .qdb-page-title { | |
| font-size: 28px; | |
| font-weight: 700; | |
| color: var(--qdb-text); | |
| margin-bottom: 4px; | |
| letter-spacing: -0.5px; | |
| } | |
| .qdb-page-subtitle { | |
| font-size: 14px; | |
| color: var(--qdb-text-muted); | |
| margin-bottom: 2rem; | |
| } | |
| /* ============== Chat Messages ============== */ | |
| [data-testid="stChatMessage"] { | |
| background: transparent !important; | |
| padding: 0 !important; | |
| margin-bottom: 16px !important; | |
| } | |
| [data-testid="stChatMessageContent"] { | |
| background: var(--qdb-surface); | |
| border: 1px solid var(--qdb-border); | |
| border-radius: var(--radius-md); | |
| padding: 16px 18px !important; | |
| box-shadow: var(--shadow-sm); | |
| transition: box-shadow 0.2s; | |
| } | |
| [data-testid="stChatMessageContent"]:hover { | |
| box-shadow: var(--shadow-md); | |
| } | |
| /* User message — distinct color */ | |
| [data-testid="stChatMessage"]:has([aria-label="user"]) [data-testid="stChatMessageContent"] { | |
| background: linear-gradient(135deg, var(--qdb-primary) 0%, var(--qdb-primary-light) 100%); | |
| color: white; | |
| border: none; | |
| } | |
| [data-testid="stChatMessage"]:has([aria-label="user"]) [data-testid="stChatMessageContent"] * { | |
| color: white !important; | |
| } | |
| /* Avatar styling */ | |
| [data-testid="stChatMessageAvatarUser"], | |
| [data-testid="stChatMessageAvatarAssistant"] { | |
| background: var(--qdb-primary) !important; | |
| border: 2px solid var(--qdb-gold); | |
| } | |
| /* ============== Chat Input (sticky bottom, ChatGPT-style) ============== */ | |
| [data-testid="stChatInput"] { | |
| border-radius: var(--radius-xl) !important; | |
| border: 1px solid var(--qdb-border) !important; | |
| box-shadow: 0 4px 24px rgba(0,0,0,0.08) !important; | |
| padding: 4px !important; | |
| transition: border-color 0.2s, box-shadow 0.2s; | |
| background: var(--qdb-surface) !important; | |
| } | |
| [data-testid="stChatInput"]:focus-within { | |
| border-color: var(--qdb-primary) !important; | |
| box-shadow: 0 0 0 3px rgba(27, 77, 92, 0.1), 0 4px 24px rgba(0,0,0,0.08) !important; | |
| } | |
| [data-testid="stChatInput"] textarea { | |
| font-size: 15px !important; | |
| padding: 14px 18px !important; | |
| } | |
| /* Make the chat input area float/sticky at the bottom */ | |
| section.main > div[data-testid="stBottomBlockContainer"], | |
| [data-testid="stBottom"] { | |
| background: linear-gradient(to top, var(--qdb-bg) 60%, rgba(250,250,250,0)) !important; | |
| padding: 1rem 0 1.5rem 0 !important; | |
| } | |
| /* ============== Citations ============== */ | |
| .qdb-citations { | |
| margin-top: 12px; | |
| padding: 12px 14px; | |
| background: var(--qdb-surface-2); | |
| border-left: 3px solid var(--qdb-gold); | |
| border-radius: var(--radius-sm); | |
| } | |
| .qdb-citation-item { | |
| display: flex; | |
| align-items: center; | |
| gap: 8px; | |
| padding: 6px 0; | |
| font-size: 13px; | |
| color: var(--qdb-text); | |
| } | |
| .qdb-citation-num { | |
| background: var(--qdb-primary); | |
| color: white; | |
| width: 20px; height: 20px; | |
| border-radius: 50%; | |
| display: inline-flex; | |
| align-items: center; | |
| justify-content: center; | |
| font-size: 11px; | |
| font-weight: 600; | |
| flex-shrink: 0; | |
| } | |
| .qdb-citation-source { font-weight: 600; } | |
| .qdb-citation-section { color: var(--qdb-text-muted); } | |
| .qdb-citation-score { | |
| margin-left: auto; | |
| background: var(--qdb-success); | |
| color: white; | |
| padding: 2px 8px; | |
| border-radius: 999px; | |
| font-size: 11px; | |
| font-weight: 600; | |
| } | |
| /* ============== Stat Cards (sidebar) ============== */ | |
| .qdb-stat { | |
| background: var(--qdb-surface); | |
| border: 1px solid var(--qdb-border); | |
| border-radius: var(--radius-md); | |
| padding: 14px; | |
| margin-bottom: 8px; | |
| transition: transform 0.15s, box-shadow 0.15s; | |
| } | |
| .qdb-stat:hover { | |
| transform: translateY(-1px); | |
| box-shadow: var(--shadow-md); | |
| } | |
| .qdb-stat-label { | |
| font-size: 11px; | |
| color: var(--qdb-text-muted); | |
| font-weight: 500; | |
| text-transform: uppercase; | |
| letter-spacing: 0.5px; | |
| margin-bottom: 4px; | |
| } | |
| .qdb-stat-value { | |
| font-size: 22px; | |
| font-weight: 700; | |
| color: var(--qdb-primary); | |
| line-height: 1; | |
| } | |
| .qdb-stat-icon { | |
| float: right; | |
| color: var(--qdb-gold); | |
| font-size: 20px; | |
| margin-top: -4px; | |
| } | |
| /* ============== User Badge (sidebar) ============== */ | |
| .qdb-user-badge { | |
| display: flex; | |
| align-items: center; | |
| gap: 12px; | |
| padding: 12px; | |
| background: var(--qdb-surface); | |
| border: 1px solid var(--qdb-border); | |
| border-radius: var(--radius-md); | |
| margin-bottom: 12px; | |
| } | |
| .qdb-user-avatar { | |
| width: 40px; height: 40px; | |
| border-radius: 50%; | |
| background: linear-gradient(135deg, var(--qdb-primary), var(--qdb-primary-light)); | |
| color: white; | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| font-weight: 700; | |
| font-size: 16px; | |
| flex-shrink: 0; | |
| } | |
| .qdb-user-name { font-weight: 600; font-size: 14px; line-height: 1.2; } | |
| .qdb-user-email { font-size: 11px; color: var(--qdb-text-muted); margin-top: 2px; } | |
| .qdb-user-role { | |
| display: inline-block; | |
| background: var(--qdb-gold); | |
| color: var(--qdb-primary-dark); | |
| padding: 1px 8px; | |
| border-radius: 999px; | |
| font-size: 10px; | |
| font-weight: 700; | |
| margin-top: 4px; | |
| text-transform: uppercase; | |
| letter-spacing: 0.5px; | |
| } | |
| /* ============== Buttons ============== */ | |
| .stButton > button { | |
| border-radius: var(--radius-sm) !important; | |
| font-weight: 600 !important; | |
| transition: all 0.15s !important; | |
| border: 1px solid var(--qdb-border) !important; | |
| padding: 8px 16px !important; | |
| } | |
| .stButton > button:hover { | |
| transform: translateY(-1px); | |
| box-shadow: var(--shadow-md); | |
| } | |
| .stButton > button[kind="primary"] { | |
| background: linear-gradient(135deg, var(--qdb-primary) 0%, var(--qdb-primary-dark) 100%) !important; | |
| color: white !important; | |
| border: none !important; | |
| } | |
| .stButton > button[kind="primary"]:hover { | |
| background: linear-gradient(135deg, var(--qdb-primary-dark) 0%, var(--qdb-primary) 100%) !important; | |
| box-shadow: 0 6px 16px rgba(139, 21, 56, 0.25); | |
| } | |
| /* Link button (Microsoft sign in) */ | |
| a[data-testid="stLinkButton"] { | |
| background: linear-gradient(135deg, #2F2F2F 0%, #1A1A1A 100%) !important; | |
| color: white !important; | |
| border: none !important; | |
| border-radius: var(--radius-sm) !important; | |
| padding: 14px 24px !important; | |
| font-weight: 600 !important; | |
| font-size: 15px !important; | |
| box-shadow: var(--shadow-md) !important; | |
| transition: all 0.15s !important; | |
| text-decoration: none !important; | |
| } | |
| a[data-testid="stLinkButton"]:hover { | |
| transform: translateY(-1px); | |
| box-shadow: var(--shadow-lg) !important; | |
| } | |
| /* ============== Tabs ============== */ | |
| .stTabs [data-baseweb="tab-list"] { | |
| gap: 4px; | |
| background: var(--qdb-surface-2); | |
| padding: 4px; | |
| border-radius: var(--radius-md); | |
| } | |
| .stTabs [data-baseweb="tab"] { | |
| border-radius: var(--radius-sm) !important; | |
| padding: 8px 16px !important; | |
| font-weight: 500 !important; | |
| color: var(--qdb-text-muted) !important; | |
| background: transparent !important; | |
| } | |
| .stTabs [data-baseweb="tab"][aria-selected="true"] { | |
| background: var(--qdb-surface) !important; | |
| color: var(--qdb-primary) !important; | |
| box-shadow: var(--shadow-sm); | |
| } | |
| /* ============== File Uploader ============== */ | |
| [data-testid="stFileUploader"] section { | |
| border: 2px dashed var(--qdb-border) !important; | |
| border-radius: var(--radius-md) !important; | |
| background: var(--qdb-surface-2) !important; | |
| transition: all 0.2s; | |
| } | |
| [data-testid="stFileUploader"] section:hover { | |
| border-color: var(--qdb-primary) !important; | |
| background: var(--qdb-surface) !important; | |
| } | |
| /* ============== Expander ============== */ | |
| .streamlit-expanderHeader { | |
| background: var(--qdb-surface-2) !important; | |
| border-radius: var(--radius-sm) !important; | |
| font-weight: 600 !important; | |
| color: var(--qdb-text) !important; | |
| } | |
| /* ============== Welcome (centered, ChatGPT-style) ============== */ | |
| .qdb-welcome { | |
| text-align: center; | |
| padding: 4rem 1rem 2rem 1rem; | |
| } | |
| .qdb-welcome-logo { | |
| width: 64px; height: 64px; | |
| background: linear-gradient(135deg, var(--qdb-primary), var(--qdb-primary-dark)); | |
| color: var(--qdb-gold); | |
| border-radius: 16px; | |
| display: inline-flex; | |
| align-items: center; | |
| justify-content: center; | |
| font-weight: 800; | |
| font-size: 22px; | |
| margin-bottom: 1.5rem; | |
| box-shadow: var(--shadow-md); | |
| } | |
| .qdb-welcome-title { | |
| font-size: 28px; | |
| font-weight: 700; | |
| color: var(--qdb-text); | |
| margin-bottom: 8px; | |
| letter-spacing: -0.5px; | |
| } | |
| .qdb-welcome-sub { | |
| font-size: 15px; | |
| color: var(--qdb-text-muted); | |
| margin-bottom: 2.5rem; | |
| } | |
| /* Suggestion buttons in welcome */ | |
| .qdb-welcome ~ div .stButton > button, | |
| [data-testid="stHorizontalBlock"] .stButton > button { | |
| text-align: right !important; | |
| background: var(--qdb-surface) !important; | |
| border: 1px solid var(--qdb-border) !important; | |
| color: var(--qdb-text) !important; | |
| padding: 14px 16px !important; | |
| height: auto !important; | |
| min-height: 80px !important; | |
| white-space: normal !important; | |
| line-height: 1.5 !important; | |
| transition: all 0.15s !important; | |
| } | |
| [data-testid="stHorizontalBlock"] .stButton > button:hover { | |
| border-color: var(--qdb-primary) !important; | |
| background: var(--qdb-surface-2) !important; | |
| box-shadow: var(--shadow-md) !important; | |
| transform: translateY(-1px); | |
| } | |
| /* ============== Login Hero ============== */ | |
| .qdb-login-hero { | |
| text-align: center; | |
| padding: 3rem 2rem; | |
| background: linear-gradient(135deg, var(--qdb-primary) 0%, var(--qdb-primary-dark) 100%); | |
| border-radius: var(--radius-xl); | |
| color: white; | |
| margin-bottom: 2rem; | |
| box-shadow: var(--shadow-lg); | |
| position: relative; | |
| overflow: hidden; | |
| } | |
| .qdb-login-hero::before { | |
| content: ""; | |
| position: absolute; | |
| top: -50%; right: -10%; | |
| width: 300px; height: 300px; | |
| background: radial-gradient(circle, var(--qdb-gold) 0%, transparent 70%); | |
| opacity: 0.15; | |
| } | |
| .qdb-login-logo { | |
| width: 80px; height: 80px; | |
| background: var(--qdb-gold); | |
| border-radius: 20px; | |
| display: inline-flex; | |
| align-items: center; | |
| justify-content: center; | |
| font-weight: 800; | |
| color: var(--qdb-primary-dark); | |
| font-size: 32px; | |
| margin-bottom: 1.5rem; | |
| box-shadow: 0 8px 24px rgba(0,0,0,0.2); | |
| } | |
| .qdb-login-title { | |
| font-size: 32px; | |
| font-weight: 800; | |
| margin-bottom: 8px; | |
| color: white; | |
| } | |
| .qdb-login-subtitle { | |
| color: rgba(255,255,255,0.85); | |
| font-size: 15px; | |
| margin-bottom: 0; | |
| } | |
| .qdb-login-feature { | |
| display: flex; | |
| gap: 12px; | |
| align-items: flex-start; | |
| padding: 16px; | |
| background: var(--qdb-surface-2); | |
| border-radius: var(--radius-md); | |
| margin-bottom: 8px; | |
| } | |
| .qdb-login-feature-icon { | |
| font-size: 20px; | |
| flex-shrink: 0; | |
| } | |
| .qdb-login-feature-title { font-weight: 600; font-size: 14px; } | |
| .qdb-login-feature-desc { font-size: 12px; color: var(--qdb-text-muted); margin-top: 2px; } | |
| /* ============== Source Card (admin) ============== */ | |
| .qdb-source-card { | |
| background: var(--qdb-surface); | |
| border: 1px solid var(--qdb-border); | |
| border-radius: var(--radius-md); | |
| padding: 14px 16px; | |
| margin-bottom: 8px; | |
| display: flex; | |
| align-items: center; | |
| gap: 12px; | |
| transition: all 0.15s; | |
| } | |
| .qdb-source-card:hover { | |
| border-color: var(--qdb-primary-light); | |
| box-shadow: var(--shadow-md); | |
| } | |
| .qdb-source-icon { | |
| width: 40px; height: 40px; | |
| background: linear-gradient(135deg, var(--qdb-primary), var(--qdb-primary-light)); | |
| border-radius: var(--radius-sm); | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| color: white; | |
| font-size: 18px; | |
| flex-shrink: 0; | |
| } | |
| .qdb-source-name { font-weight: 600; font-size: 14px; line-height: 1.3; word-break: break-word; } | |
| .qdb-source-meta { font-size: 12px; color: var(--qdb-text-muted); margin-top: 2px; } | |
| /* ============== Loading dots ============== */ | |
| @keyframes qdb-pulse { | |
| 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } | |
| 40% { opacity: 1; transform: scale(1); } | |
| } | |
| .qdb-loading { | |
| display: inline-flex; | |
| gap: 4px; | |
| } | |
| .qdb-loading span { | |
| width: 8px; height: 8px; | |
| border-radius: 50%; | |
| background: var(--qdb-primary); | |
| animation: qdb-pulse 1.4s infinite ease-in-out; | |
| } | |
| .qdb-loading span:nth-child(2) { animation-delay: 0.2s; } | |
| .qdb-loading span:nth-child(3) { animation-delay: 0.4s; } | |
| /* ============== Toast / Alerts ============== */ | |
| div[data-testid="stAlert"] { | |
| border-radius: var(--radius-md) !important; | |
| border: none !important; | |
| box-shadow: var(--shadow-sm); | |
| } | |
| /* ============== Section divider ============== */ | |
| .qdb-divider { | |
| height: 1px; | |
| background: linear-gradient(90deg, transparent, var(--qdb-border), transparent); | |
| margin: 1.5rem 0; | |
| } | |
| /* ============== Empty state ============== */ | |
| .qdb-empty { | |
| text-align: center; | |
| padding: 3rem 2rem; | |
| background: var(--qdb-surface); | |
| border: 2px dashed var(--qdb-border); | |
| border-radius: var(--radius-lg); | |
| color: var(--qdb-text-muted); | |
| } | |
| .qdb-empty-icon { font-size: 48px; opacity: 0.4; margin-bottom: 1rem; } | |
| .qdb-empty-title { font-weight: 600; font-size: 16px; color: var(--qdb-text); margin-bottom: 4px; } | |
| .qdb-empty-desc { font-size: 13px; } | |
| /* ============== Mobile responsive ============== */ | |
| @media (max-width: 768px) { | |
| .main .block-container { padding: 1rem; } | |
| .qdb-page-title { font-size: 22px; } | |
| .qdb-login-title { font-size: 24px; } | |
| .qdb-login-hero { padding: 2rem 1.5rem; } | |
| } | |
| </style> | |
| """ | |
| def inject_styles() -> None: | |
| """Inject the QDB design system CSS into the current Streamlit page.""" | |
| st.markdown(_CSS, unsafe_allow_html=True) | |
| def brand_header() -> None: | |
| """Render the QDB sidebar brand block.""" | |
| logo = _logo_data_uri() | |
| logo_html = ( | |
| f'<img src="{logo}" alt="QDB" style="width:44px; height:44px; ' | |
| f'background:white; border-radius:10px; padding:4px; object-fit:contain;" />' | |
| if logo else '<div class="qdb-brand-logo">QDB</div>' | |
| ) | |
| st.markdown( | |
| f""" | |
| <div class="qdb-brand"> | |
| {logo_html} | |
| <div> | |
| <div class="qdb-brand-text">مساعد المعرفة</div> | |
| <div class="qdb-brand-subtitle">مؤسسة بنك تنمية المهارات</div> | |
| </div> | |
| </div> | |
| """, | |
| unsafe_allow_html=True, | |
| ) | |
| def logo_html(size_px: int = 64, with_bg: bool = True) -> str: | |
| """Reusable HTML snippet rendering the official QDB logo at a given size.""" | |
| logo = _logo_data_uri() | |
| if not logo: | |
| return f'<div class="qdb-brand-logo" style="width:{size_px}px;height:{size_px}px;font-size:{int(size_px*0.4)}px;">QDB</div>' | |
| bg = "background:white; padding:8px;" if with_bg else "" | |
| return ( | |
| f'<img src="{logo}" alt="QDB" ' | |
| f'style="width:{size_px}px; height:{size_px}px; {bg} ' | |
| f'border-radius:{int(size_px*0.22)}px; object-fit:contain; box-shadow:0 4px 12px rgba(0,0,0,0.08);" />' | |
| ) | |
| def page_header(title: str, subtitle: str = "") -> None: | |
| """Render a styled page title + subtitle.""" | |
| st.markdown( | |
| f""" | |
| <div class="qdb-page-title">{title}</div> | |
| <div class="qdb-page-subtitle">{subtitle}</div> | |
| """, | |
| unsafe_allow_html=True, | |
| ) | |
| def stat_card(label: str, value: str | int, icon: str = "") -> None: | |
| """Render a single stat card.""" | |
| st.markdown( | |
| f""" | |
| <div class="qdb-stat"> | |
| <span class="qdb-stat-icon">{icon}</span> | |
| <div class="qdb-stat-label">{label}</div> | |
| <div class="qdb-stat-value">{value}</div> | |
| </div> | |
| """, | |
| unsafe_allow_html=True, | |
| ) | |
| def user_badge(name: str, email: str, is_admin: bool) -> None: | |
| """Render the user badge in the sidebar.""" | |
| initial = (name or email)[0].upper() | |
| role_html = '<div class="qdb-user-role">مشرف</div>' if is_admin else "" | |
| st.markdown( | |
| f""" | |
| <div class="qdb-user-badge"> | |
| <div class="qdb-user-avatar">{initial}</div> | |
| <div style="min-width:0; flex:1;"> | |
| <div class="qdb-user-name">{name}</div> | |
| <div class="qdb-user-email">{email}</div> | |
| {role_html} | |
| </div> | |
| </div> | |
| """, | |
| unsafe_allow_html=True, | |
| ) | |
| def citation_block(citations: list[dict]) -> None: | |
| """Render a styled citations block. | |
| Built as a single-line HTML string and rendered via st.html() to avoid | |
| Streamlit's markdown processor treating indented HTML as a code block. | |
| """ | |
| if not citations: | |
| return | |
| items = [] | |
| for i, c in enumerate(citations, 1): | |
| sec = c.get("section", "") | |
| score = c.get("score", 0) | |
| section_html = f'<span class="qdb-citation-section"> — {sec}</span>' if sec else "" | |
| items.append( | |
| f'<div class="qdb-citation-item">' | |
| f'<span class="qdb-citation-num">{i}</span>' | |
| f'<span class="qdb-citation-source">{c["source_file"]}</span>' | |
| f'{section_html}' | |
| f'<span class="qdb-citation-score">{score:.0%}</span>' | |
| f'</div>' | |
| ) | |
| html = f'<div class="qdb-citations">{"".join(items)}</div>' | |
| try: | |
| st.html(html) | |
| except AttributeError: | |
| st.markdown(html, unsafe_allow_html=True) | |
| def empty_state(icon: str, title: str, description: str) -> None: | |
| """Render a friendly empty state.""" | |
| st.markdown( | |
| f""" | |
| <div class="qdb-empty"> | |
| <div class="qdb-empty-icon">{icon}</div> | |
| <div class="qdb-empty-title">{title}</div> | |
| <div class="qdb-empty-desc">{description}</div> | |
| </div> | |
| """, | |
| unsafe_allow_html=True, | |
| ) | |
| def divider() -> None: | |
| st.markdown('<div class="qdb-divider"></div>', unsafe_allow_html=True) | |