/* توحيد ارتفاع جميع الحقول في order-form-row */

.order-form-row input[type="text"],
.order-form-row select {
    height: 38px !important;
    min-height: 38px !important;
    max-height: 38px !important;
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
    box-sizing: border-box;
}


/* تثبيت رأس الجدول للعملاء */


/* عنصر خارجي لتثبيت رأس الجدول عند التمرير العمودي والأفقي */

.table-container {
    max-width: 100vw;
    height: 70vh;
    overflow: auto;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.10);
    margin: 2rem auto;
    position: relative;
}

.scroll-x table {
    border-collapse: collapse;
    width: max-content;
    min-width: 100%;
}

.scroll-x thead th {
    position: sticky;
    top: 0;
    background: #2d3e50;
    color: #fff;
    z-index: 999;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
    font-weight: 600;
    text-align: center;
    border-bottom: 2px solid #ffb347;
    border-right: 1px solid #e0e0e0;
    border-left: 1px solid #e0e0e0;
    height: 48px;
    min-width: 120px;
    vertical-align: middle;
    background-clip: padding-box;
    width: 120px;
}


/* إصلاح sticky للـ thead */

.scroll-x thead {
    display: table-header-group;
}

.scroll-x {
    overflow-x: auto;
    max-width: 100vw;
}

th.sortable {
    cursor: pointer;
    position: relative;
    user-select: none;
    transition: background 0.2s;
}

th.sortable:hover {
    background: #415a77;
}

.sort-arrow {
    font-size: 0.9em;
    margin-right: 2px;
    color: #ffb347;
    vertical-align: middle;
}

body {
    font-family: 'Cairo', Arial, sans-serif;
    background: #f4f6fa;
    margin: 0;
}

.navbar {
    background: #2d3e50;
    color: #fff;
    padding: 0.5rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100vw;
    box-sizing: border-box;
    position: relative;
    min-height: 60px;
}

.navbar h1 {
    margin: 0;
    font-size: 1.5rem;
    flex: 1 1 auto;
    text-align: left;
    direction: ltr;
}

.nav-links {
    list-style: none;
    display: flex;
    gap: 2rem;
    margin: 0;
    padding: 0;
    flex: 0 0 auto;
    direction: rtl;
}

.nav-links li {
    display: inline-block;
}

.nav-links a {
    color: #fff;
    text-decoration: none;
    font-size: 1.1rem;
    transition: color 0.2s;
    padding: 0.2rem 0.7rem;
    border-radius: 4px;
}

.nav-links a.active,
.nav-links a:focus {
    background: #ffb347;
    color: #2d3e50;
}

.nav-links a:hover {
    color: #ffb347;
}


/* Dropdown submenu styles (RTL friendly) */

.nav-links li {
    position: relative;
}

.nav-links .submenu,
.nav-links .subsubmenu {
    display: none;
    position: absolute;
    right: 0;
    /* align to right for RTL */
    top: 100%;
    background: #2d3e50;
    padding: 0.5rem 0;
    border-radius: 6px;
    min-width: 160px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
    z-index: 2000;
}

.nav-links .submenu li,
.nav-links .subsubmenu li {
    display: block;
    padding: 0;
}

.nav-links .submenu a,
.nav-links .subsubmenu a {
    display: block;
    padding: 0.5rem 1rem;
    color: #fff;
    white-space: nowrap;
}

.nav-links .submenu a:hover,
.nav-links .subsubmenu a:hover {
    background: #ffb347;
    color: #2d3e50;
}


/* Show submenu when parent has .open (toggled by JS) */

.nav-links li.open>.submenu {
    display: block !important;
}

.nav-links li.open>.submenu li.open>.subsubmenu {
    display: block;
}


/* Specific rule for bot-data menu */

.nav-links li.bot-data.open>.submenu {
    display: block !important;
    visibility: visible !important;
}


/* Make bot-data button yellow only when menu is open */

.nav-links li.bot-data.open>a {
    background: #ffb347 !important;
    color: #2d3e50 !important;
}


/* Prevent bot-data button from getting active/focus styles when not open */

.nav-links li.bot-data:not(.open)>a {
    background: transparent !important;
    color: #fff !important;
}

.nav-links li.bot-data:not(.open)>a:focus {
    background: transparent !important;
    color: #fff !important;
}


/* stronger rule for bot submenu to avoid being hidden by other CSS */

.navbar h1 {
    margin: 0;
    font-size: 1.5rem;
}

.nav-links {
    list-style: none;
    display: flex;
    gap: 2rem;
    margin: 0;
    padding: 0;
}

.nav-links li {
    display: inline;
}

.nav-links a {
    color: #fff;
    text-decoration: none;
    font-size: 1.1rem;
    transition: color 0.2s;
}

.nav-links a:hover {
    color: #ffb347;
}

.container {
    max-width: 1100px;
    margin: 2rem auto;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.10);
    padding: 2.5rem 2rem;
}

.header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.search-input {
    width: 100%;
    padding: 0.7rem 1rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    margin-bottom: 1.5rem;
    font-size: 1rem;
    background: #f9f9f9;
    transition: border 0.2s;
}

.search-input:focus {
    border: 1.5px solid #2d3e50;
    outline: none;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
    background: #fff;
}

th,
td {
    border: 1px solid #e0e0e0;
    padding: 10px 8px;
    text-align: center;
    font-size: 1rem;
}

th {
    background: #2d3e50;
    color: #fff;
    font-weight: 600;
}

tr:nth-child(even) {
    background: #f9f9f9;
}

.add-btn {
    background: #2d3e50;
    color: #fff;
    padding: 10px 22px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.2s, color 0.2s;
    margin-bottom: 1rem;
}

.add-btn:hover {
    background: #ffb347;
    color: #2d3e50;
}

.action-btn {
    background: #fff;
    color: #2d3e50;
    border: 1px solid #2d3e50;
    border-radius: 4px;
    padding: 5px 12px;
    margin: 0 2px;
    cursor: pointer;
    font-size: 0.95rem;
    transition: background 0.2s, color 0.2s;
}

.action-btn:hover {
    background: #2d3e50;
    color: #fff;
}

.scroll-x {
    overflow-x: auto;
}


/* محاذاة أزرار الإجراءات لليمين في تخطيط RTL */

.actions-cell {
    text-align: right;
    white-space: nowrap;
}

.actions-cell .action-btn {
    margin-left: 6px;
    margin-right: 0;
}


/* Modal Styles */

.modal {
    display: none;
    /* will be switched to 'flex' by JS when opening */
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100vw;
    /* full width for modal */
    height: 100vh;
    overflow: auto;
    background: rgba(0, 0, 0, 0.25);
    /* align modal-content to the right for RTL */
    align-items: flex-start;
    /* align from top so modal sits a bit down from top */
    justify-content: flex-end;
    /* push modal-content to the right edge */
}

.modal-content {
    background: #fff;
    margin: 5% 0 0 0;
    /* top spacing only; horizontal centering removed so flex-end can align it right */
    padding: 1.25rem 1.25rem;
    border-radius: 10px;
    width: 100%;
    max-width: 380px;
    /* smaller modal width */
    position: relative;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    max-height: 84vh;
    /* keep modal within viewport */
    overflow: auto;
    /* allow internal scrolling */
    margin-right: 0.6rem;
    /* space from right edge */
    direction: rtl;
    /* ensure internal flow starts from right */
    text-align: right;
    /* align text and inputs start from right */
}

.close {
    color: #aaa;
    position: absolute;
    top: 18px;
    right: 18px;
    /* moved to right for RTL layout */
    left: auto;
    font-size: 2rem;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.2s;
    z-index: 5;
    /* ensure it doesn't hide other interactive controls */
}

.close:hover {
    color: #2d3e50;
}

.form-group {
    margin-bottom: 1.1rem;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.form-group label {
    margin-bottom: 0.3rem;
    font-size: 1rem;
    color: #2d3e50;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 0.6rem 0.8rem;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 1rem;
    background: #f9f9f9;
    resize: none;
}


/* layout for order-form rows: align multiple controls in a responsive RTL grid */

.order-form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.4rem 0.6rem;
    align-items: center;
    margin-bottom: 0.5rem;
}


/* Top row inside first fieldset: fixed columns to reduce horizontal whitespace */

.modal-content fieldset:first-of-type .order-form-row {
    grid-template-columns: 120px 1fr 120px 1fr;
    /* right-to-left: label/input/label/input */
    gap: 0.4rem 0.6rem;
}


/* Responsive: stack fields vertically on narrow screens */

@media (max-width: 700px) {
    .modal-content fieldset:first-of-type .order-form-row,
    .order-form-row {
        grid-template-columns: 1fr;
    }
    .modal-content {
        width: calc(100% - 1rem);
        max-width: calc(100% - 1rem);
        margin-right: 0.4rem;
    }
}


/* Reduce width of specific fields to approximately one-third of the available row */

#edit_order_number,
#edit_order_date,
#edit_customer_select,
#edit_goods_buying_status,
#edit_goods_brand_type,
#edit_agreement_status {
    width: 33% !important;
    min-width: 80px;
    /* floor so they don't become too small */
    box-sizing: border-box;
}


/* On small screens these should be full-width */

@media (max-width: 700px) {
    #edit_order_number,
    #edit_order_date,
    #edit_customer_select,
    #edit_goods_buying_status,
    #edit_goods_brand_type,
    #edit_agreement_status {
        width: 100% !important;
    }
}

.order-form-row label {
    justify-self: end;
    /* labels to the right in RTL */
    margin: 0 0.2rem;
}

.order-form-row input[type="text"],
.order-form-row input[type="date"],
.order-form-row input[type="number"],
.order-form-row select,
.order-form-row textarea {
    width: 100%;
    box-sizing: border-box;
}

.form-group input:focus,
.form-group textarea:focus {
    border: 1.5px solid #2d3e50;
    outline: none;
}


/* Undo toast */

.undo-toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(45, 62, 80, 0.98);
    color: #fff;
    padding: 12px 16px;
    border-radius: 8px;
    display: flex;
    gap: 12px;
    align-items: center;
    z-index: 2000;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
}

.undo-toast .undo-btn {
    background: #ffb347;
    border: none;
    color: #2d3e50;
    padding: 6px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
}


/* Sort arrow visual states */

.sort-arrow.is-asc::after {
    content: '\25B2';
    /* ▲ */
    color: #ffb347;
}

.sort-arrow.is-desc::after {
    content: '\25BC';
    /* ▼ */
    color: #ffb347;
}


/* Toast notifications */

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 14px;
    border-radius: 8px;
    color: #fff;
    z-index: 3000;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
    display: flex;
    gap: 12px;
    align-items: center;
    font-weight: 600;
}

.toast-success {
    background: #28a745;
}

.toast-error {
    background: #dc3545;
}


/* Mobile Responsive Design - محسن للموبايل */


/* إضافة viewport meta في كل صفحة */

@media (max-width: 768px) {
    /* إعادة ضبط الأساسيات */
    * {
        box-sizing: border-box;
    }
    body {
        margin: 0;
        padding: 0;
        overflow-x: hidden;
        font-size: 14px;
    }
    /* Navigation محسن للموبايل */
    .navbar {
        padding: 0.5rem;
        flex-direction: column;
        gap: 0.5rem;
        width: 100%;
        min-height: auto;
        overflow: visible;
        box-sizing: border-box;
    }
    .nav-links,
    .nav-menu {
        flex-direction: column;
        width: 100%;
        gap: 0.3rem;
        list-style: none;
        margin: 0;
        padding: 0;
        box-sizing: border-box;
    }
    .nav-links li,
    .nav-menu li {
        width: 100%;
        text-align: center;
        margin: 0;
        box-sizing: border-box;
    }
    .nav-links a,
    .nav-menu a {
        display: block;
        padding: 0.7rem 0.8rem;
        border-radius: 4px;
        background: rgba(255, 255, 255, 0.1);
        text-decoration: none;
        color: #fff;
        font-size: 0.9rem;
        transition: background 0.3s;
        width: 100%;
        box-sizing: border-box;
        margin: 0.1rem 0;
    }
    .nav-links a:hover,
    .nav-menu a:hover {
        background: rgba(255, 255, 255, 0.2);
    }
    /* Dropdown/Submenu محسن */
    .dropdown-menu,
    .submenu {
        position: static;
        display: none;
        width: 100%;
        box-shadow: none;
        background: rgba(0, 0, 0, 0.3);
        margin-top: 0.3rem;
        border-radius: 4px;
        padding: 0.3rem;
        box-sizing: border-box;
    }
    .dropdown:hover .dropdown-menu,
    .dropdown.active .dropdown-menu,
    .bot-data:hover .submenu,
    .bot-data.active .submenu,
    .bot-data.open .submenu {
        display: block;
    }
    .dropdown-menu a,
    .submenu a {
        background: rgba(255, 255, 255, 0.08);
        margin: 0.2rem 0;
        padding: 0.5rem 0.6rem;
        border-radius: 3px;
        font-size: 0.85rem;
        width: 100%;
        box-sizing: border-box;
    }
    .dropdown-menu a:hover,
    .submenu a:hover {
        background: rgba(255, 255, 255, 0.15);
    }
    /* إصلاح قائمة بيانات البوت للموبايل */
    .nav-links li.bot-data {
        width: 100% !important;
        position: relative;
    }
    .nav-links li.bot-data>a {
        width: 100% !important;
        display: block !important;
        box-sizing: border-box !important;
        text-align: center;
    }
    .nav-links li.bot-data.open>.submenu {
        display: block !important;
        position: static !important;
        width: 100% !important;
        background: rgba(0, 0, 0, 0.3) !important;
        margin-top: 0.3rem !important;
        border-radius: 4px !important;
        padding: 0.3rem !important;
        box-sizing: border-box !important;
    }
    .nav-links li.bot-data .submenu a {
        background: rgba(255, 255, 255, 0.08) !important;
        margin: 0.2rem 0 !important;
        padding: 0.5rem 0.6rem !important;
        border-radius: 3px !important;
        font-size: 0.85rem !important;
        width: 100% !important;
        box-sizing: border-box !important;
        display: block !important;
    }
    /* Tables محسن للموبايل */
    .table-container {
        height: auto;
        max-height: 60vh;
        margin: 1rem 0.5rem;
        border-radius: 8px;
        width: calc(100% - 1rem);
        overflow: auto;
        -webkit-overflow-scrolling: touch;
    }
    .scroll-x {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        width: 100%;
    }
    .scroll-x table {
        min-width: 800px;
        font-size: 0.85rem;
        width: 100%;
    }
    .scroll-x thead th {
        min-width: 100px;
        padding: 0.6rem 0.4rem;
        font-size: 0.8rem;
        white-space: nowrap;
        text-align: center;
    }
    .scroll-x tbody td {
        padding: 0.6rem 0.4rem;
        font-size: 0.8rem;
        white-space: nowrap;
        text-align: center;
    }
    /* جداول الداشبورد خاصة للموبايل */
    #recentOrdersTable,
    #recentMessagesTable {
        min-width: 100%;
        font-size: 0.8rem;
    }
    #recentOrdersTable th,
    #recentOrdersTable td,
    #recentMessagesTable th,
    #recentMessagesTable td {
        padding: 0.5rem 0.3rem;
        min-width: 80px;
        max-width: 120px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    #recentOrdersTable td:nth-child(6),
    #recentOrdersTable td:nth-child(7),
    #recentMessagesTable td:nth-child(2) {
        max-width: 100px;
    }
    /* Buttons محسن للموبايل */
    .btn {
        padding: 0.9rem 1.2rem;
        font-size: 0.95rem;
        width: 100%;
        margin-bottom: 0.6rem;
        min-height: 44px;
        touch-action: manipulation;
        border: none;
        border-radius: 6px;
        cursor: pointer;
    }
    .action-btn {
        padding: 0.5rem 0.8rem;
        margin: 0.2rem;
        font-size: 0.8rem;
        min-height: 36px;
        min-width: 60px;
        border-radius: 4px;
    }
    /* Containers محسن للموبايل */
    .customers-container,
    .orders-container,
    .agents-container,
    .warehouses-container,
    .countries-container,
    .container {
        margin: 0.5rem;
        padding: 1.2rem;
        border-radius: 8px;
        width: calc(100% - 1rem);
        box-sizing: border-box;
        overflow-x: hidden;
    }
    /* Dashboard Stats للموبايل */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.8rem;
        padding: 0 0.5rem;
    }
    .stat-card {
        padding: 1rem;
        min-height: 80px;
        display: flex;
        flex-direction: column;
        justify-content: center;
        text-align: center;
    }
    .stat-card h3 {
        font-size: 1.2rem;
        margin: 0.5rem 0;
    }
    .stat-card p {
        font-size: 0.85rem;
        margin: 0;
    }
    /* Recent sections للموبايل */
    .recent-section {
        margin: 1rem 0.5rem;
        background: #fff;
        border-radius: 8px;
        padding: 1rem;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }
    .recent-section h2 {
        font-size: 1.1rem;
        margin-bottom: 1rem;
        text-align: center;
    }
    /* Forms محسن للموبايل */
    .modal-content {
        width: 95%;
        max-width: 95vw;
        margin: 5% auto;
        padding: 1.2rem;
        max-height: 85vh;
        overflow-y: auto;
        border-radius: 8px;
        box-sizing: border-box;
    }
    .form-group {
        margin-bottom: 1.2rem;
        width: 100%;
    }
    .form-group label {
        display: block;
        margin-bottom: 0.5rem;
        font-weight: 600;
        font-size: 0.9rem;
    }
    .form-group input,
    .form-group select,
    .form-group textarea {
        width: 100%;
        padding: 0.9rem;
        font-size: 1rem;
        box-sizing: border-box;
        border: 1px solid #ddd;
        border-radius: 6px;
        min-height: 44px;
        touch-action: manipulation;
    }
    .form-group textarea {
        min-height: 80px;
        resize: vertical;
    }
    /* Order form specific للموبايل */
    .order-form-row {
        display: flex;
        flex-direction: column;
        gap: 1rem;
        width: 100%;
    }
    .order-form-row input,
    .order-form-row select {
        width: 100%;
        height: auto !important;
        min-height: 44px !important;
        max-height: none !important;
        padding: 0.9rem;
        font-size: 1rem;
        box-sizing: border-box;
    }
    /* تحسين مظهر قسم العميل للموبايل */
    .order-form-row div[style*="flex-direction:column"] {
        width: 100% !important;
    }
    .order-form-row div[style*="flex-wrap:wrap"] {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 0.5rem !important;
        width: 100% !important;
    }
    .order-form-row div[style*="flex-wrap:wrap"] input {
        flex: 1 1 calc(50% - 0.25rem) !important;
        min-width: 120px !important;
        margin: 0 !important;
    }
    /* Toast notifications للموبايل */
    .toast {
        bottom: 20px;
        left: 10px;
        right: 10px;
        transform: none;
        text-align: center;
        font-size: 0.9rem;
        padding: 1rem;
        border-radius: 6px;
        z-index: 9999;
    }
}


/* Small Mobile (Portrait phones) - محسن للهواتف الصغيرة */

@media (max-width: 480px) {
    body {
        font-size: 13px;
    }
    .navbar {
        padding: 0.5rem;
        gap: 0.8rem;
    }
    .nav-links a,
    .nav-menu a {
        padding: 0.7rem 0.8rem;
        font-size: 0.9rem;
    }
    /* جداول أصغر للهواتف الصغيرة */
    .table-container {
        height: auto;
        max-height: 50vh;
        margin: 0.5rem 0.2rem;
        width: calc(100% - 0.4rem);
    }
    .scroll-x table {
        font-size: 0.75rem;
        min-width: 600px;
    }
    .scroll-x thead th {
        padding: 0.4rem 0.2rem;
        font-size: 0.7rem;
        min-width: 70px;
    }
    .scroll-x tbody td {
        padding: 0.4rem 0.2rem;
        font-size: 0.7rem;
    }
    /* جداول الداشبورد للهواتف الصغيرة */
    #recentOrdersTable,
    #recentMessagesTable {
        font-size: 0.7rem;
    }
    #recentOrdersTable th,
    #recentOrdersTable td,
    #recentMessagesTable th,
    #recentMessagesTable td {
        padding: 0.3rem 0.2rem;
        min-width: 60px;
        max-width: 80px;
        font-size: 0.7rem;
    }
    /* حاويات أصغر */
    .customers-container,
    .orders-container,
    .agents-container,
    .warehouses-container,
    .countries-container,
    .container {
        margin: 0.3rem;
        padding: 0.8rem;
        width: calc(100% - 0.6rem);
    }
    /* نماذج أصغر */
    .modal-content {
        width: 98%;
        padding: 0.8rem;
        margin: 2% auto;
    }
    .form-group input,
    .form-group select,
    .form-group textarea {
        padding: 0.7rem;
        font-size: 0.9rem;
        min-height: 40px;
    }
    .order-form-row input,
    .order-form-row select {
        min-height: 40px !important;
        font-size: 0.9rem;
        padding: 0.7rem;
    }
    /* إحصائيات عمود واحد */
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 0.5rem;
        padding: 0 0.3rem;
    }
    .stat-card {
        padding: 0.8rem;
        min-height: 70px;
    }
    .stat-card h3 {
        font-size: 1.1rem;
    }
    .stat-card p {
        font-size: 0.8rem;
    }
    /* أزرار أصغر */
    .action-btn {
        padding: 0.3rem 0.6rem;
        font-size: 0.7rem;
        min-height: 32px;
        min-width: 50px;
    }
    .btn {
        padding: 0.8rem;
        font-size: 0.9rem;
        min-height: 42px;
    }
    /* أقسام حديثة أصغر */
    .recent-section {
        margin: 0.8rem 0.3rem;
        padding: 0.8rem;
    }
    .recent-section h2 {
        font-size: 1rem;
        margin-bottom: 0.8rem;
    }
}


/* تنسيق خاص لجداول الداشبورد */

#recentOrdersTable td {
    max-width: 150px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#recentOrdersTable td[title] {
    cursor: help;
}

#recentOrdersTable th:nth-child(6),
#recentOrdersTable td:nth-child(6) {
    min-width: 120px;
    max-width: 150px;
}

#recentOrdersTable th:nth-child(7),
#recentOrdersTable td:nth-child(7) {
    min-width: 180px;
    max-width: 220px;
}


/* تنسيق خاص لجدول الرسائل */

#recentMessagesTable td:nth-child(1) {
    min-width: 140px;
    max-width: 160px;
}

#recentMessagesTable td:nth-child(2) {
    min-width: 200px;
    max-width: 300px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#recentMessagesTable td:nth-child(2)[title] {
    cursor: help;
}


/* تحسينات إضافية للموبايل - تمرير الجداول */

@media (max-width: 768px) {
    /* تحسين التمرير الأفقي */
    .table-container {
        position: relative;
    }
    .table-container::before {
        content: "← اسحب للمزيد";
        position: absolute;
        top: 10px;
        left: 10px;
        background: rgba(0, 0, 0, 0.7);
        color: white;
        padding: 0.3rem 0.6rem;
        border-radius: 4px;
        font-size: 0.7rem;
        z-index: 100;
        opacity: 0.8;
        pointer-events: none;
    }
    /* إخفاء النص بعد التمرير */
    .table-container.scrolled::before {
        display: none;
    }
    /* تحسين scroll indicators */
    .scroll-x {
        scrollbar-width: thin;
        scrollbar-color: #ccc transparent;
    }
    .scroll-x::-webkit-scrollbar {
        height: 6px;
    }
    .scroll-x::-webkit-scrollbar-track {
        background: #f1f1f1;
        border-radius: 3px;
    }
    .scroll-x::-webkit-scrollbar-thumb {
        background: #ccc;
        border-radius: 3px;
    }
    .scroll-x::-webkit-scrollbar-thumb:hover {
        background: #999;
    }
}


/* تحسينات إضافية للشاشات الصغيرة جداً */

@media (max-width: 480px) {
    .navbar {
        padding: 0.3rem;
    }
    .nav-links a,
    .nav-menu a {
        padding: 0.6rem 0.5rem;
        font-size: 0.85rem;
    }
    .dropdown-menu a,
    .submenu a {
        padding: 0.4rem 0.5rem;
        font-size: 0.8rem;
    }
    /* إصلاح إضافي لقائمة بيانات البوت للشاشات الصغيرة جداً */
    .nav-links li.bot-data .submenu a {
        padding: 0.4rem 0.5rem !important;
        font-size: 0.8rem !important;
    }
}


/* تحسينات خاصة بصفحات الإدارة (الدول، إلخ) */

.page-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
    margin: 1rem 0;
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e9ecef;
}

.search-input {
    padding: 0.5rem;
    font-size: 1rem;
    border: 1px solid #ccc;
    border-radius: 6px;
    box-sizing: border-box;
    min-width: 250px;
    flex: 1;
    max-width: 400px;
}


/* تحسين أزرار الإضافة */

.btn-primary {
    background: linear-gradient(135deg, #007bff, #0056b3);
    color: #fff;
    border: none;
    padding: 0.8rem 1.5rem;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: 0 2px 8px rgba(0, 123, 255, 0.3);
    min-width: 180px;
    justify-content: center;
}

.btn-primary:hover {
    background: linear-gradient(135deg, #0056b3, #004085);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 123, 255, 0.3);
}

.btn-icon {
    font-size: 1.2rem;
    font-weight: bold;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}


/* تحسين الجداول للشاشات المختلفة */

.table-container {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    margin: 1rem 0;
}


/* جدول قابل للتمرير العمودي */

.scrollable-table {
    max-height: 70vh;
    overflow-y: auto;
    overflow-x: auto;
}


/* تحسين شريط التمرير */

.scrollable-table::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.scrollable-table::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.scrollable-table::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.scrollable-table::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

.main-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.main-table th {
    background: #2d3e50;
    color: #fff;
    padding: 0.8rem;
    text-align: center;
    font-weight: 600;
    border-bottom: 2px solid #34495e;
}

.main-table td {
    padding: 0.6rem;
    text-align: center;
    border-bottom: 1px solid #e9ecef;
}

.main-table tbody tr:hover {
    background: #f8f9fa;
}


/* تحسينات للموبايل للصفحات الإدارية */

@media (max-width: 768px) {
    .btn-primary {
        width: 100%;
        padding: 1rem 1.5rem;
        font-size: 1.1rem;
        min-width: auto;
    }
    .page-actions {
        flex-direction: column;
        gap: 0.8rem;
        padding: 0.8rem;
    }
    .search-input {
        width: 100%;
        max-width: none;
        min-width: auto;
    }
    .scrollable-table {
        max-height: 60vh;
    }
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .main-table {
        min-width: 600px;
        font-size: 0.8rem;
    }
    .main-table th,
    .main-table td {
        padding: 0.5rem 0.3rem;
        white-space: nowrap;
    }
    .container {
        padding: 0.5rem;
        margin: 0;
    }
}

@media (max-width: 480px) {
    .btn-primary {
        padding: 0.9rem 1.2rem;
        font-size: 1rem;
    }
    .scrollable-table {
        max-height: 50vh;
    }
    .main-table {
        font-size: 0.75rem;
    }
    .main-table th,
    .main-table td {
        padding: 0.4rem 0.2rem;
    }
    .page-actions {
        padding: 0.5rem;
    }
}