/* ========================================
   Al Media CRM - Main Stylesheet v2
   ======================================== */

:root {
    --dark-navy: #0D2B45;
    --petroleum: #2F7C95;
    --light-blue: #7FAFBF;
    --white: #FFFFFF;
    --bg: #F0F4F7;
    --sidebar-width: 260px;
    --topbar-height: 60px;
    --text-dark: #1a2e3d;
    --text-muted: #6b8a9a;
    --border: #d4e3eb;
    --shadow: 0 2px 8px rgba(13,43,69,0.08);
    --shadow-md: 0 4px 16px rgba(13,43,69,0.12);
    --radius: 8px;
    --radius-lg: 12px;
}

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

body {
    font-family: 'Tajawal', 'Cairo', Arial, sans-serif;
    background: var(--bg);
    color: var(--text-dark);
    direction: rtl;
    font-size: 14px;
    line-height: 1.6;
}

a { text-decoration: none; color: inherit; }
img { max-width: 100%; }

/* ========================================
   Layout
   ======================================== */
.layout { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--dark-navy);
    position: fixed;
    top: 0; right: 0;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.sidebar-logo {
    padding: 20px 16px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.sidebar-logo img {
    width: 38px; height: 38px;
    object-fit: contain;
    border-radius: 8px;
    background: rgba(255,255,255,0.1);
    padding: 4px;
    flex-shrink: 0;
}

.sidebar-logo-text { color: var(--white); min-width: 0; }
.sidebar-logo-text strong { display: block; font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-logo-text span { font-size: 11px; color: var(--light-blue); opacity: 0.8; }

.sidebar-nav { padding: 8px 0; flex: 1; }

.nav-section-title {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(127,175,191,0.5);
    padding: 12px 16px 5px;
    font-weight: 600;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    color: rgba(255,255,255,0.7);
    transition: all 0.2s;
    cursor: pointer;
    font-size: 13.5px;
    border-right: 3px solid transparent;
}

.nav-item:hover { background: rgba(47,124,149,0.2); color: var(--white); border-right-color: var(--petroleum); }
.nav-item.active { background: rgba(47,124,149,0.25); color: var(--white); border-right-color: var(--light-blue); }
.nav-item svg { flex-shrink: 0; width: 18px; height: 18px; }

/* Main Content */
.main-content {
    flex: 1;
    margin-right: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-width: 0;
}

/* Topbar */
.topbar {
    height: var(--topbar-height);
    background: var(--white);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
    gap: 8px;
}

.topbar-right { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-title { font-size: 15px; font-weight: 700; color: var(--dark-navy); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-menu { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.topbar-user { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.topbar-user-avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--petroleum); color: white; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; flex-shrink: 0; }
.topbar-user-info { text-align: right; }
.topbar-user-name { font-size: 12px; font-weight: 600; color: var(--dark-navy); white-space: nowrap; }
.topbar-user-role { font-size: 11px; color: var(--text-muted); white-space: nowrap; }

.topbar-btn {
    width: 34px; height: 34px;
    border-radius: 8px;
    background: transparent;
    border: 1px solid var(--border);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-muted);
    transition: all 0.2s;
    position: relative;
    flex-shrink: 0;
}
.topbar-btn:hover { background: var(--bg); color: var(--dark-navy); }

.badge-count {
    position: absolute; top: -4px; left: -4px;
    background: #e53e3e; color: white;
    font-size: 10px; width: 16px; height: 16px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700;
}

/* Page Content */
.page-content { padding: 20px; flex: 1; }

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}
.page-header h1 { font-size: 19px; font-weight: 700; color: var(--dark-navy); }
.page-header p { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

/* ========================================
   Cards
   ======================================== */
.card {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    overflow: hidden;
}

.card-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}
.card-title { font-size: 14px; font-weight: 700; color: var(--dark-navy); }
.card-body { padding: 18px; }

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 16px 18px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}
.stat-card::before {
    content: '';
    position: absolute; top: 0; right: 0;
    width: 4px; height: 100%;
    background: var(--petroleum);
    border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
}
.stat-card.navy::before   { background: var(--dark-navy); }
.stat-card.light::before  { background: var(--light-blue); }
.stat-card.danger::before { background: #e53e3e; }
.stat-card.success::before{ background: #38a169; }
.stat-card.warning::before{ background: #d69e2e; }

.stat-label { font-size: 12px; color: var(--text-muted); font-weight: 500; margin-bottom: 6px; }
.stat-value { font-size: 22px; font-weight: 800; color: var(--dark-navy); line-height: 1; }
.stat-sub { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* ========================================
   Tables - Responsive
   ======================================== */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; width: 100%; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }

table th {
    background: #f7fafc;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 12px;
    padding: 10px 12px;
    text-align: right;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

table td {
    padding: 10px 12px;
    border-bottom: 1px solid #edf2f7;
    color: var(--text-dark);
    vertical-align: middle;
}

table tbody tr:hover { background: #f7fafc; }
table tbody tr:last-child td { border-bottom: none; }

/* ========================================
   Badges
   ======================================== */
.badge {
    display: inline-flex; align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px; font-weight: 600;
    white-space: nowrap;
}
.badge-success   { background: #c6f6d5; color: #276749; }
.badge-danger    { background: #fed7d7; color: #9b2c2c; }
.badge-warning   { background: #fefcbf; color: #744210; }
.badge-info      { background: #bee3f8; color: #2a69ac; }
.badge-primary   { background: #bee3f8; color: #1a4971; }
.badge-secondary { background: #e2e8f0; color: #4a5568; }
.badge-low       { background: #e2e8f0; color: #4a5568; }
.badge-medium    { background: #fefcbf; color: #744210; }
.badge-high      { background: #fed7d7; color: #9b2c2c; }

/* ========================================
   Buttons
   ======================================== */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 14px;
    border-radius: var(--radius);
    font-size: 13px; font-weight: 600;
    cursor: pointer; border: none;
    transition: all 0.2s;
    white-space: nowrap;
    font-family: inherit;
    text-align: center;
}
.btn-primary { background: var(--petroleum); color: white; }
.btn-primary:hover { background: #265f75; }
.btn-dark { background: var(--dark-navy); color: white; }
.btn-dark:hover { background: #091f33; }
.btn-outline { background: transparent; color: var(--petroleum); border: 1.5px solid var(--petroleum); }
.btn-outline:hover { background: var(--petroleum); color: white; }
.btn-danger { background: #e53e3e; color: white; }
.btn-danger:hover { background: #c53030; }
.btn-success { background: #38a169; color: white; }
.btn-success:hover { background: #276749; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 6px; background: transparent; border: 1px solid var(--border); color: var(--text-muted); border-radius: var(--radius); }
.btn-icon:hover { background: var(--bg); color: var(--dark-navy); }

/* ========================================
   Forms
   ======================================== */
.form-group { margin-bottom: 14px; }

.form-label { display: block; font-size: 13px; font-weight: 600; color: var(--text-dark); margin-bottom: 5px; }

.form-control {
    width: 100%; padding: 9px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 13.5px; font-family: inherit;
    color: var(--text-dark); background: var(--white);
    transition: border-color 0.2s; direction: rtl;
}
.form-control:focus { outline: none; border-color: var(--petroleum); box-shadow: 0 0 0 3px rgba(47,124,149,0.1); }

.form-row   { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }

/* ========================================
   Alerts
   ======================================== */
.alert {
    padding: 12px 16px; border-radius: var(--radius);
    margin-bottom: 16px; font-size: 13.5px;
    display: flex; align-items: flex-start; gap: 10px;
}
.alert-success { background: #c6f6d5; color: #276749; border: 1px solid #9ae6b4; }
.alert-danger  { background: #fed7d7; color: #9b2c2c; border: 1px solid #fc8181; }
.alert-warning { background: #fefcbf; color: #744210; border: 1px solid #f6e05e; }
.alert-info    { background: #bee3f8; color: #2a69ac; border: 1px solid #90cdf4; }

/* ========================================
   Modals
   ======================================== */
.modal-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(13,43,69,0.5);
    z-index: 2000; align-items: center; justify-content: center;
    padding: 16px;
}
.modal-overlay.active { display: flex; }
.modal {
    background: white; border-radius: var(--radius-lg);
    width: 100%; max-width: 600px;
    max-height: 90vh; overflow-y: auto;
    box-shadow: var(--shadow-md);
}
.modal-header {
    padding: 16px 18px; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; background: white; z-index: 1;
}
.modal-title { font-size: 15px; font-weight: 700; color: var(--dark-navy); }
.modal-close { background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 20px; line-height: 1; padding: 4px; }
.modal-body { padding: 18px; }
.modal-footer { padding: 14px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-start; gap: 10px; flex-wrap: wrap; }

/* ========================================
   Dashboard Grid
   ======================================== */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
    margin-bottom: 20px;
}
.dashboard-grid .full { grid-column: 1 / -1; }

/* ========================================
   Filter Bar
   ======================================== */
.filter-bar {
    display: flex; align-items: center; gap: 10px;
    flex-wrap: wrap; margin-bottom: 16px;
    padding: 12px 14px;
    background: white; border-radius: var(--radius);
    border: 1px solid var(--border);
}
.filter-bar .form-control { min-width: 120px; }

/* ========================================
   Report / Detail View - Full Width
   ======================================== */
.report-detail, .detail-card {
    width: 100%;
}
.report-text {
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.8;
    padding: 14px;
    background: var(--bg);
    border-radius: var(--radius);
    font-size: 13.5px;
}

/* ========================================
   Login Page
   ======================================== */
.login-page {
    min-height: 100vh; background: var(--dark-navy);
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
}
.login-card {
    background: white; border-radius: var(--radius-lg);
    padding: 36px 32px; width: 100%; max-width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-logo { text-align: center; margin-bottom: 24px; }
.login-logo img { width: 76px; height: 76px; object-fit: contain; }
.login-logo h1 { font-size: 22px; font-weight: 800; color: var(--dark-navy); margin-top: 12px; }
.login-logo p { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

/* ========================================
   Utilities
   ======================================== */
.text-muted    { color: var(--text-muted); }
.text-danger   { color: #e53e3e; }
.text-success  { color: #38a169; }
.text-center   { text-align: center; }
.fw-bold       { font-weight: 700; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.gap-2 { gap: 8px; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }

.no-data { text-align: center; padding: 36px 20px; color: var(--text-muted); font-size: 14px; }

.avatar-circle {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--petroleum); color: white;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 700; flex-shrink: 0;
}

/* ========================================
   QR Print Page
   ======================================== */
@media print {
    .sidebar, .topbar, .no-print { display: none !important; }
    .main-content { margin-right: 0 !important; }
    .qr-grid { grid-template-columns: repeat(3, 1fr) !important; }
}

.qr-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 20px; }
.qr-card { background: white; border: 2px solid var(--dark-navy); border-radius: var(--radius); padding: 16px; text-align: center; }
.qr-card img { width: 160px; height: 160px; }
.qr-card h3 { font-size: 14px; margin-top: 10px; color: var(--dark-navy); }
.qr-card p  { font-size: 12px; color: var(--text-muted); }

/* ========================================
   Sidebar Toggle Button
   ======================================== */
.sidebar-toggle {
    display: none;
    background: none; border: none;
    cursor: pointer; color: var(--dark-navy);
    padding: 6px;
    border-radius: 6px;
}
.sidebar-toggle:hover { background: var(--bg); }

/* ========================================
   RESPONSIVE - Mobile First
   ======================================== */

/* Tablet */
@media (max-width: 900px) {
    .dashboard-grid { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Mobile */
@media (max-width: 768px) {
    /* Sidebar hidden by default on mobile */
    .sidebar { transform: translateX(100%); }
    .sidebar.open { transform: translateX(0); box-shadow: -8px 0 30px rgba(0,0,0,0.3); }
    .main-content { margin-right: 0; }

    /* Show toggle button */
    .sidebar-toggle { display: flex; align-items: center; justify-content: center; }

    /* Hide user info text on very small screens */
    .topbar-user-info { display: none; }

    /* Page content smaller padding */
    .page-content { padding: 12px; }

    /* Stack forms */
    .form-row, .form-row-3 { grid-template-columns: 1fr; gap: 0; }

    /* Stats: 2 columns on mobile */
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .stat-card { padding: 12px 14px; }
    .stat-value { font-size: 18px; }

    /* Dashboard: single column */
    .dashboard-grid { grid-template-columns: 1fr; gap: 12px; }

    /* Filter bar stacks vertically */
    .filter-bar { flex-direction: column; align-items: stretch; gap: 8px; }
    .filter-bar .btn { width: 100%; justify-content: center; }
    .filter-bar .form-control { width: 100%; }

    /* Buttons in page header stack */
    .page-header { flex-direction: column; align-items: flex-start; gap: 8px; }
    .page-header .btn { width: 100%; justify-content: center; }

    /* Tables scroll horizontally */
    .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    table th, table td { padding: 8px 10px; font-size: 12px; }

    /* Modal full screen on mobile */
    .modal-overlay { padding: 0; align-items: flex-end; }
    .modal { max-width: 100%; border-radius: var(--radius-lg) var(--radius-lg) 0 0; max-height: 92vh; }

    /* Card body smaller padding */
    .card-body { padding: 14px; }
    .card-header { padding: 12px 14px; }

    /* Login card smaller padding */
    .login-card { padding: 28px 20px; }

    /* Overlay */
    .sidebar-overlay {
        display: none; position: fixed; inset: 0;
        background: rgba(0,0,0,0.5); z-index: 999;
    }
    .sidebar-overlay.active { display: block; }

    /* Stack buttons group */
    .btn-group { flex-direction: column; }
    .btn-group .btn { width: 100%; justify-content: center; }
}

/* Small phones */
@media (max-width: 400px) {
    .stats-grid { grid-template-columns: 1fr; }
    .topbar { padding: 0 10px; }
    .topbar-title { font-size: 13px; }
    .stat-value { font-size: 20px; }
}
