/* ===== نظام أستلر - تصميم مطابق لـ Streamlit ===== */

:root {
    --primary: #ff4b4b;
    --primary-dark: #bd0000;
    --secondary: #6c757d;
    --success: #09ab3b;
    --danger: #ff4b4b;
    --warning: #ffa421;
    --info: #0068c9;
    --dark: #0e1117;
    --text: #fafafa;
    --bg: #0e1117;
    --bg-secondary: #262730;
    --border: #3c3f4a;
    --white: #ffffff;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    --radius: 4px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Source Sans Pro', sans-serif;
    background: var(--bg);
    color: var(--text);
    direction: rtl;
    line-height: 1.6;
}

/* ===== Layout Wide like Streamlit ===== */
.app-container {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 280px;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    position: fixed;
    height: 100vh;
    overflow-y: hidden;
    z-index: 1000;
    padding: 2rem 0;
}

/* Sidebar scrollbar */
.sidebar::-webkit-scrollbar {
    width: 8px;
}

.sidebar::-webkit-scrollbar-track {
    background: var(--bg);
    border-radius: 4px;
}

.sidebar::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 4px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: var(--primary-dark);
}

.sidebar-header {
    padding: 0 1.5rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
    color: var(--primary);
}

.sidebar-menu {
    padding: 1rem 0;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.5rem;
    color: var(--text);
    text-decoration: none;
    border-right: 3px solid transparent;
    font-size: 0.95rem;
    opacity: 0.7;
}

.menu-item i {
    width: 20px;
    text-align: center;
}

.menu-item:hover {
    opacity: 1;
    background: rgba(255, 75, 75, 0.1);
    border-right-color: var(--primary);
}

.menu-item.active {
    background: rgba(255, 75, 75, 0.15);
    border-right-color: var(--primary);
    opacity: 1;
    font-weight: 600;
}

.main-content {
    flex: 1;
    margin-right: 280px;
    padding: 2rem 3rem;
    width: calc(100% - 280px);
}

/* ===== Page Header ===== */
.page-header {
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.page-title {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text);
    margin: 0 0 0.5rem 0;
}

.page-caption {
    color: var(--secondary);
    font-size: 0.9rem;
}

.header-right {
    margin-top: 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.welcome-text {
    color: var(--secondary);
    font-size: 0.9rem;
}

.welcome-text i {
    color: var(--primary);
}

/* ===== Buttons Streamlit Style ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    font-weight: 500;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    text-decoration: none;
    background: var(--bg-secondary);
    color: var(--text);
}

.btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.btn-primary {
    background: var(--primary);
    color: var(--white);
    border-color: var(--primary);
}

.btn-primary:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
    color: var(--white);
}

.btn-danger {
    background: transparent;
    border-color: var(--danger);
    color: var(--danger);
}

.btn-danger:hover {
    background: var(--danger);
    color: var(--white);
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
}

.btn-outline {
    background: transparent;
}

/* ===== Cards / Containers ===== */
.card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
    padding: 1.5rem;
}

.card-header {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    color: var(--text);
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.card-header i {
    color: var(--primary);
    margin-left: 0.5rem;
}

/* ===== Metrics like Streamlit ===== */
.metrics-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.metric-card {
    background: var(--bg-secondary);
    padding: 1.25rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.metric-label {
    color: var(--secondary);
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.metric-value {
    font-size: 2.25rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
}

.metric-delta {
    color: var(--secondary);
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

/* ===== Forms ===== */
.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text);
    font-size: 0.875rem;
}

.form-control {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    background: var(--bg);
    color: var(--text);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

/* ===== Tables Streamlit Style ===== */
.table-container {
    width: 100%;
    overflow-x: auto;
    /* Enable horizontal scroll */
    -webkit-overflow-scrolling: touch;
    /* Smooth scrolling on mobile */
    margin-bottom: 1rem;
}

.table-container table {
    width: max-content;
    /* Allow table to expand beyond container */
    min-width: 100%;
    /* But at least 100% */
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.85rem;
    /* Smaller font for compact design */
}

thead {
    background: rgba(255, 75, 75, 0.1);
    border-bottom: 2px solid var(--border);
}

th {
    padding: 0.5rem 0.75rem;
    /* Reduced padding */
    text-align: right;
    font-weight: 600;
    color: var(--text);
    font-size: 0.8rem;
    /* Smaller header font */
    text-transform: uppercase;
    letter-spacing: 0.05em;
    vertical-align: middle;
    white-space: nowrap;
    /* Prevent wrapping */
    border-left: 1px solid rgba(60, 63, 74, 0.5);
    /* Vertical separator */
}

th:first-child {
    border-left: none;
    /* Remove border from first column */
}

td {
    padding: 0.5rem 0.75rem;
    /* Reduced padding */
    border-bottom: 1px solid rgba(60, 63, 74, 0.8);
    /* Slightly more visible border */
    border-left: 1px solid rgba(60, 63, 74, 0.5);
    /* Vertical separator */
    font-size: 0.85rem;
    color: var(--text);
    vertical-align: middle;
    white-space: nowrap;
    /* Prevent wrapping */
}

td:first-child {
    border-left: none;
    /* Remove border from first column */
}

/* Fix number direction for phones, prices, etc */
td[dir="ltr"],
.number-ltr {
    direction: ltr;
    text-align: right;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover {
    background: rgba(255, 75, 75, 0.05);
}

/* Custom Scrollbar for Tables and Site */
.table-container::-webkit-scrollbar,
body::-webkit-scrollbar {
    height: 8px;
    width: 8px;
}

.table-container::-webkit-scrollbar-track,
body::-webkit-scrollbar-track {
    background: var(--bg);
    border-radius: 4px;
}

.table-container::-webkit-scrollbar-thumb,
body::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 4px;
}

.table-container::-webkit-scrollbar-thumb:hover,
body::-webkit-scrollbar-thumb:hover {
    background: var(--primary-dark);
}

/* ===== Alerts Streamlit Style ===== */
.alert {
    padding: 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    border-right: 4px solid;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.alert-success {
    background: rgba(9, 171, 59, 0.1);
    border-color: var(--success);
    color: var(--success);
}

.alert-danger {
    background: rgba(255, 75, 75, 0.1);
    border-color: var(--danger);
    color: var(--danger);
}

.alert-warning {
    background: rgba(255, 164, 33, 0.1);
    border-color: var(--warning);
    color: var(--warning);
}

.alert-info {
    background: rgba(0, 104, 201, 0.1);
    border-color: var(--info);
    color: var(--info);
}

/* ===== Tabs Streamlit Style ===== */
.tabs {
    display: flex;
    gap: 0.25rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1.5rem;
}

.tab {
    padding: 0.75rem 1.5rem;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text);
    opacity: 0.7;
}

.tab:hover {
    opacity: 1;
}

.tab.active {
    border-bottom-color: var(--primary);
    opacity: 1;
    font-weight: 600;
}

/* ===== Divider ===== */
.divider {
    height: 1px;
    background: var(--border);
    margin: 2rem 0;
}

/* ===== Badges ===== */
.badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 3px;
}

.badge-success {
    background: var(--success);
    color: var(--white);
}

.badge-secondary {
    background: var(--secondary);
    color: var(--white);
}

/* ===== Login Page ===== */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
}

.login-card {
    background: var(--bg-secondary);
    padding: 2.5rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    width: 100%;
    max-width: 420px;
}

.login-logo {
    font-size: 4rem;
    text-align: center;
    margin-bottom: 1rem;
}

.login-title {
    text-align: center;
    color: var(--text);
    margin-bottom: 0.5rem;
    font-size: 1.5rem;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .sidebar {
        width: 240px;
    }

    .main-content {
        margin-right: 240px;
        padding: 2rem;
    }

    .metrics-row {
        grid-template-columns: 1fr;
    }
}

/* ===== Utilities ===== */
.mb-1 {
    margin-bottom: 0.5rem;
}

.mb-2 {
    margin-bottom: 1rem;
}

.text-center {
    text-align: center;
}

.text-muted {
    color: var(--secondary);
}

/* ===== Modal Dialogs ===== */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    /* Dark overlay */
    overflow: auto;
    animation: fadeIn 0.2s;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.modal-content {
    background-color: var(--bg-secondary);
    margin: 5% auto;
    padding: 2rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 90%;
    max-width: 600px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    position: relative;
    animation: slideDown 0.3s;
}

@keyframes slideDown {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.close {
    color: #aaa;
    float: left;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 20px;
    transition: color 0.2s;
}

.close:hover,
.close:focus {
    color: var(--primary);
}

.modal h3 {
    margin-top: 0;
    margin-bottom: 1.5rem;
    color: var(--text);
}

/* ===== Tab Content ===== */
.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.3s;
}

/* ===== Button Secondary ===== */
.btn-secondary {
    background: var(--bg);
    border-color: var(--border);
    color: var(--text);
}

.btn-secondary:hover {
    background: var(--bg-secondary);
    border-color: var(--primary);
    color: var(--primary);
}

/* Ensure <a> buttons match <button> buttons exactly */
a.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none !important;
    vertical-align: middle;
    cursor: pointer;
    box-sizing: border-box;
    /* Crucial for height matching */
}

/* Specific fix for btn-sm dimensions */
.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
    line-height: 1.5;
    border-radius: 0.2rem;
    /* Remove fixed height to allow content to dictate, but ensure padding is identical */
    height: auto;
    min-height: 31px;
    /* Ensure a minimum clickable area */
}

/* Ensure no extra margins on icons inside links */
a.btn i {
    margin-left: 0.25rem;
}

/* Sidebar Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .sidebar {
        width: 260px;
        transform: translateX(100%);
        /* Right to left off-screen */
        right: 0;
        left: auto;
        transition: transform 0.3s ease-in-out;
        box-shadow: -2px 0 5px rgba(0, 0, 0, 0.2);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .main-content {
        margin-right: 0;
        width: 100%;
        padding: 1.5rem 1rem;
    }

    .mobile-menu-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        background: transparent;
        border: 1px solid var(--border);
        border-radius: var(--radius);
        color: var(--text);
        font-size: 1.2rem;
        width: 40px;
        height: 40px;
        cursor: pointer;
        transition: all 0.2s;
    }

    .mobile-menu-btn:hover {
        border-color: var(--primary);
        color: var(--primary);
    }

    /* Adjust page header title size */
    .page-title {
        font-size: 1.5rem;
        margin: 0;
    }

    .page-header {
        display: flex;
        flex-direction: column;
        gap: 1rem;
        align-items: flex-start;
    }

    .header-right {
        margin-top: 0.5rem;
        width: 100%;
        justify-content: space-between;
    }

    /* Login card response */
    .login-card {
        padding: 1.5rem;
        margin: 1rem;
        max-width: 100%;
    }

    /* Metrics grid 1 column */
    .metrics-row {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    /* Table font size */
    th,
    td {
        padding: 0.5rem;
        font-size: 0.8rem;
    }

    /* Adjust form grid */
    .form-row {
        grid-template-columns: 1fr;
    }
}

/* Desktop */
@media (min-width: 769px) {
    .mobile-menu-btn {
        display: none;
    }

    .sidebar {
        right: 0;
        top: 0;
    }

    .main-content {
        margin-right: 280px;
        margin-left: 0;
    }
}