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

:root {
    --bg: #F6F7FB;
    --bg-soft: #EEF0F6;
    --card: #FFFFFF;
    --card-hover: #FBFBFE;
    --sidebar: #FFFFFF;
    --text: #1B1C2E;
    --text-2: #55566E;
    --text-3: #9798AC;
    --border: #E8E9F2;
    --primary: #6C5CE7;
    --primary-2: #8E7CF5;
    --primary-soft: #EFEDFE;
    --success: #00B894;
    --danger: #E8504F;
    --shadow-sm: 0 1px 2px rgba(27,28,46,.04), 0 2px 8px rgba(27,28,46,.04);
    --shadow-md: 0 4px 12px rgba(27,28,46,.06), 0 12px 32px rgba(27,28,46,.06);
    --shadow-lg: 0 20px 60px rgba(27,28,46,.12);
    --radius: 18px;
    --radius-sm: 12px;
    --font-ar: 'Cairo', 'Tajawal', sans-serif;
    --font-en: 'Inter', sans-serif;
}

html { font-size: 15px; }

body {
    font-family: var(--font-ar);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

body, input, textarea, button { font-family: var(--font-ar); }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #D5D7E5; border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary-2); }

/* ============ APP LAYOUT ============ */
.app { display: flex; min-height: 100vh; }

/* ============ SIDEBAR ============ */
.sidebar {
    width: 272px;
    background: var(--sidebar);
    border-left: 1px solid var(--border);
    padding: 24px 18px;
    position: fixed;
    inset-block: 0;
    display: flex;
    flex-direction: column;
    z-index: 200;
    transition: transform .3s ease;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 10px 24px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
}

.brand-mark {
    width: 46px;
    height: 46px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--primary), #9B6CF5);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 20px;
    box-shadow: 0 8px 20px rgba(108,92,231,.35);
    flex-shrink: 0;
}

.brand-text { display: flex; flex-direction: column; }
.brand-name { font-weight: 800; font-size: 21px; letter-spacing: -.02em; }
.brand-dot { color: var(--primary); }
.brand-sub { font-size: 11px; color: var(--text-3); font-weight: 500; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 13px 14px;
    color: var(--text-2);
    text-decoration: none;
    border-radius: var(--radius-sm);
    margin-bottom: 6px;
    font-weight: 600;
    font-size: 14px;
    transition: all .2s ease;
    position: relative;
}

.nav-item i { font-size: 16px; width: 20px; text-align: center; opacity: .85; }

.nav-item:hover { background: var(--bg-soft); color: var(--text); }

.nav-item.active {
    background: var(--primary-soft);
    color: var(--primary);
}

.nav-item.active::before {
    content: '';
    position: absolute;
    right: -18px;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 24px;
    border-radius: 4px;
    background: var(--primary);
}

.sidebar-foot { margin-top: auto; }

.foot-card {
    background: linear-gradient(135deg, var(--primary-soft), #F5F3FF);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border: 1px solid rgba(108,92,231,.15);
}

.foot-card i { font-size: 22px; color: var(--primary); }
.foot-card div { display: flex; flex-direction: column; }
.foot-card strong { font-size: 13px; color: var(--primary); }
.foot-card span { font-size: 11px; color: var(--text-3); }

/* ============ MAIN ============ */
.main-content {
    flex: 1;
    margin-right: 272px;
    padding: 0 40px 40px;
    min-height: 100vh;
    max-width: 1200px;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 28px 0 24px;
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 50;
}

.menu-toggle {
    display: none;
    background: none;
    border: 1px solid var(--border);
    width: 42px;
    height: 42px;
    border-radius: var(--radius-sm);
    color: var(--text-2);
    font-size: 17px;
    cursor: pointer;
}

.topbar h1 { font-size: 24px; font-weight: 800; letter-spacing: -.01em; flex: 1; }

.header-actions { display: flex; align-items: center; }

.stats-badge {
    background: var(--card);
    border: 1px solid var(--border);
    padding: 9px 18px;
    border-radius: 100px;
    font-size: 12.5px;
    font-weight: 700;
    color: var(--text-2);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 8px;
}

.stats-badge::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 0 3px rgba(0,184,148,.15);
}

/* ============ PAGES ============ */
.page { display: none; }
.page.active { display: block; animation: fadeUp .35s ease; }

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

/* ============ STATS ============ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 20px;
    margin-bottom: 36px;
}

.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 18px;
    box-shadow: var(--shadow-sm);
    transition: transform .25s ease, box-shadow .25s ease;
}

.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
}

.stat-icon {
    width: 58px;
    height: 58px;
    border-radius: 16px;
    background: var(--scg);
    color: var(--sc);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}

.stat-card h3 { font-size: 30px; font-weight: 700; font-family: var(--font-en); letter-spacing: -.02em; }
.stat-card p { color: var(--text-3); font-size: 13px; font-weight: 600; margin-top: 2px; }

/* ============ SECTIONS ============ */
.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.section-head h2 { font-size: 17px; font-weight: 800; color: var(--text); }

.link-all {
    color: var(--primary);
    text-decoration: none;
    font-size: 13px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ============ CUSTOMER LIST ============ */
.customer-list { display: grid; gap: 12px; }

.customer-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    cursor: pointer;
    transition: all .2s ease;
    box-shadow: var(--shadow-sm);
}

.customer-card:hover {
    border-color: rgba(108,92,231,.4);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.customer-avatar {
    width: 52px;
    height: 52px;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--primary), #9B6CF5);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 17px;
    flex-shrink: 0;
    box-shadow: 0 6px 16px rgba(108,92,231,.25);
    overflow: hidden;
}

.customer-avatar img { width: 100%; height: 100%; object-fit: cover; }

.customer-info { flex: 1; min-width: 0; }

.customer-info h3 { font-size: 15px; font-weight: 700; margin-bottom: 3px; display: flex; align-items: center; gap: 8px; }

.customer-slug {
    font-size: 11px;
    color: var(--primary);
    background: var(--primary-soft);
    padding: 2px 8px;
    border-radius: 100px;
    font-weight: 700;
    direction: ltr;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.customer-info p { color: var(--text-3); font-size: 12.5px; display: flex; align-items: center; gap: 8px; }
.customer-info p i { font-size: 11px; opacity: .7; }

.customer-actions { display: flex; gap: 8px; }

/* ============ BUTTONS ============ */
.btn {
    padding: 12px 24px;
    border-radius: 14px;
    border: none;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all .2s ease;
    font-family: var(--font-ar);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), #8E7CF5);
    color: #fff;
    box-shadow: 0 8px 20px rgba(108,92,231,.3);
}

.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 12px 28px rgba(108,92,231,.38); }
.btn-primary:active { transform: translateY(0); }

.btn-ghost {
    background: var(--bg-soft);
    color: var(--text-2);
    border: 1px solid var(--border);
}

.btn-ghost:hover { background: #E4E6F1; color: var(--text); }

.btn-danger { background: rgba(232,80,79,.1); color: var(--danger); border: 1px solid rgba(232,80,79,.2); }
.btn-danger:hover { background: var(--danger); color: #fff; }

.btn-sm { padding: 8px 14px; font-size: 12.5px; border-radius: 10px; }
.btn-sm i { font-size: 13px; }

.btn-block { width: 100%; }

/* ============ FORM ============ */
.form-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 22px;
    padding: 36px;
    box-shadow: var(--shadow-sm);
    max-width: 900px;
}

.form-head { margin-bottom: 8px; }
.form-head h2 { display: flex; align-items: center; gap: 12px; font-size: 22px; font-weight: 800; }
.form-head h2 i { color: var(--primary); }
.form-head p { color: var(--text-3); font-size: 13px; margin-top: 6px; }

.form-section { margin-top: 30px; }

.section-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14.5px;
    font-weight: 800;
    color: var(--text-2);
    margin-bottom: 18px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.section-title i { color: var(--primary); }

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 18px;
}

.form-group { display: flex; flex-direction: column; gap: 7px; }

.form-group label { font-size: 13px; color: var(--text-2); font-weight: 700; display: flex; align-items: center; gap: 2px; }

.form-group label .hint {
    font-size: 10.5px;
    color: var(--text-3);
    font-weight: 500;
    margin-right: 4px;
}

.form-group input {
    padding: 13px 16px;
    border-radius: 12px;
    border: 1.5px solid var(--border);
    background: var(--bg-soft);
    color: var(--text);
    font-size: 14px;
    transition: all .2s ease;
    width: 100%;
    font-family: var(--font-ar);
}

.form-group input::placeholder { color: #B6B8CE; }

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 4px rgba(108,92,231,.12);
}

.input-affix {
    display: flex;
    align-items: center;
    border-radius: 12px;
    border: 1.5px solid var(--border);
    background: var(--bg-soft);
    overflow: hidden;
    transition: all .2s ease;
    direction: ltr;
}

.input-affix:focus-within {
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 4px rgba(108,92,231,.12);
}

.input-affix .prefix {
    padding: 0 14px;
    color: var(--primary);
    font-weight: 700;
    font-size: 13px;
    background: var(--primary-soft);
    height: 100%;
    display: flex;
    align-items: center;
    white-space: nowrap;
    font-family: var(--font-en);
}

.input-affix input {
    border: none;
    background: transparent;
    box-shadow: none !important;
    font-family: var(--font-en);
    direction: ltr;
}

.input-affix input:focus { background: transparent; }

/* Theme Grid */
.theme-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 14px;
}

.theme-option {
    position: relative;
    border: 2px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
    cursor: pointer;
    padding: 0;
    background: none;
    text-align: center;
    transition: all .2s ease;
}

.theme-option:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.theme-option.selected { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(108,92,231,.15); }

.theme-preview {
    height: 96px;
    position: relative;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 12px;
}

.theme-preview .mini-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 2.5px solid #fff;
    box-shadow: 0 3px 8px rgba(0,0,0,.2);
}

.theme-preview .mini-bar {
    position: absolute;
    width: 60%;
    height: 7px;
    border-radius: 20px;
    background: rgba(255,255,255,.85);
    box-shadow: 0 2px 6px rgba(0,0,0,.1);
}

.theme-preview .mini-bar.b1 { top: 26%; }
.theme-preview .mini-bar.b2 { top: 44%; }
.theme-preview .mini-bar.b3 { top: 62%; }

.theme-check {
    position: absolute;
    top: 8px;
    left: 8px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    opacity: 0;
    transform: scale(.5);
    transition: all .2s ease;
}

.theme-option.selected .theme-check { opacity: 1; transform: scale(1); }

.theme-option .theme-name {
    padding: 10px 8px;
    font-size: 12px;
    font-weight: 700;
    color: var(--text-2);
    background: #fff;
}

/* Form Actions */
.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 34px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
    align-items: center;
}

/* ============ SEARCH BAR ============ */
.search-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    align-items: center;
}

.search-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--card);
    border: 1.5px solid var(--border);
    border-radius: 14px;
    padding: 0 16px;
    transition: all .2s ease;
}

.search-wrap i { color: var(--text-3); font-size: 14px; }

.search-wrap:focus-within { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(108,92,231,.1); }

.search-wrap input {
    flex: 1;
    padding: 13px 0;
    border: none;
    background: transparent;
    color: var(--text);
    font-size: 14px;
    font-family: var(--font-ar);
}

.search-wrap input:focus { outline: none; }

/* ============ MODAL ============ */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(27,28,46,.45);
    backdrop-filter: blur(6px);
    z-index: 500;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.modal.active { display: flex; animation: fadeIn .2s ease; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-content {
    background: var(--card);
    border-radius: 24px;
    padding: 36px;
    max-width: 560px;
    width: 100%;
    max-height: 88vh;
    overflow-y: auto;
    position: relative;
    box-shadow: var(--shadow-lg);
    animation: popIn .3s cubic-bezier(.16,1,.3,1);
}

@keyframes popIn {
    from { opacity: 0; transform: translateY(16px) scale(.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-close {
    position: absolute;
    top: 18px;
    left: 18px;
    background: var(--bg-soft);
    border: none;
    color: var(--text-2);
    font-size: 18px;
    cursor: pointer;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    transition: all .2s ease;
}

.modal-close:hover { background: rgba(232,80,79,.12); color: var(--danger); }

.modal-body h2 { font-size: 20px; font-weight: 800; margin-bottom: 18px; padding-right: 44px; }

.qr-section {
    text-align: center;
    padding: 24px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 18px;
    margin: 16px 0;
}

.qr-section canvas, .qr-section img { max-width: 210px; margin: 0 auto; }

.link-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px 16px;
    margin: 16px 0;
    direction: ltr;
}

.link-box .link-text {
    flex: 1;
    font-size: 13.5px;
    color: var(--primary);
    font-weight: 700;
    font-family: var(--font-en);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.link-box .btn { background: var(--primary); color: #fff; }

.modal-quick-actions { display: flex; gap: 10px; margin: 16px 0; }

.modal-quick-actions .btn { flex: 1; }

.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13.5px;
    gap: 12px;
}

.detail-row:last-child { border-bottom: none; }

.detail-row .label { color: var(--text-3); flex-shrink: 0; }
.detail-row .value { font-weight: 600; text-align: left; direction: ltr; }

.social-links { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }

.social-link {
    width: 44px;
    height: 44px;
    border-radius: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    font-size: 18px;
    transition: transform .2s ease;
}

.social-link:hover { transform: scale(1.12) translateY(-2px); }

/* ============ TOAST ============ */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text);
    color: #fff;
    padding: 14px 28px;
    border-radius: 14px;
    font-size: 13.5px;
    font-weight: 600;
    z-index: 1000;
    transition: transform .4s cubic-bezier(.68,-.55,.27,1.55);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 10px;
}

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

.toast.error { background: var(--danger); }

.toast::before {
    content: '\f058';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    font-size: 16px;
}

.toast.error::before { content: '\f06a'; }

/* ============ EMPTY STATE ============ */
.empty-state {
    text-align: center;
    padding: 56px 20px;
    color: var(--text-3);
    background: var(--card);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
}

.empty-state i { font-size: 40px; margin-bottom: 14px; opacity: .4; display: block; }
.empty-state p { font-size: 14px; font-weight: 600; }

/* ============ LOADING ============ */
.loading-row {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: var(--text-3);
    gap: 10px;
    font-size: 13.5px;
}

.spinner-ring {
    width: 20px;
    height: 20px;
    border: 2.5px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

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

/* ============ RESPONSIVE ============ */
@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-110%);
        width: 280px;
        box-shadow: var(--shadow-lg);
    }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-right: 0; padding: 0 20px 30px; }
    .menu-toggle { display: flex; align-items: center; justify-content: center; }
    .stats-grid { grid-template-columns: 1fr; }
    .form-card { padding: 24px 20px; }
    .theme-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
    .customer-card { flex-wrap: wrap; gap: 12px; }
    .customer-actions { width: 100%; }
    .customer-actions .btn { flex: 1; }
    .form-actions { flex-direction: column-reverse; }
    .form-actions .btn { width: 100%; }
}

@media (min-width: 901px) {
    .sidebar { transform: none; }
}

/* Toast icon tweaks */
.toast::before { margin-left: 4px; }