/* ===============================
   الأساسيات + الخطوط + الجودة
================================*/

*,
*::before,
*::after {
    box-sizing: border-box;
}

:root {
    --blue-main: #1d4ed8;
    --blue-dark: #1e3a8a;
    --blue-light: #eef4ff;

    --border-color: #d1d5db;
    --text-main: #0f172a;
    --bg-body: #e8f0ff;
    --card-bg: #ffffff;

    --radius: 0.65rem;
    --shadow: 0 6px 20px rgba(0,0,0,0.08);

    /* خط احترافي - Tajawal */
    --font-main: 'Tajawal', -apple-system, BlinkMacSystemFont, sans-serif;
}

body {
    margin: 0;
    font-family: var(--font-main);
    background: linear-gradient(180deg, var(--bg-body), #fff);
    color: var(--text-main);
    direction: rtl;
    font-size: 16px;
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 {
    font-family: var(--font-main);
    font-weight: 700;
    letter-spacing: -0.02em;
}

/* ===============================
   الهيكل العام
================================*/

.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ===============================
   Auth Section - اللوجو والعناوين
================================*/

.auth-wrapper {
    max-width: 500px;
    margin: 2rem auto;
    padding: 1rem;
}

.logo-center {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-logo {
    width: 120px;
    height: 120px;
    object-fit: contain;
    margin: 0 auto 1rem;
    display: block;
    border-radius: 50%;
    border: 3px solid var(--blue-main);
    padding: 8px;
    background: #fff;
    box-shadow: 0 4px 12px rgba(29, 78, 216, 0.2);
}

.auth-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--blue-dark);
    margin: 1rem 0 0.5rem;
    line-height: 1.4;
}

.auth-subtitle {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--blue-main);
    margin: 0.5rem 0;
}

.auth-subtitle-en {
    font-size: 0.95rem;
    font-weight: 600;
    color: #6b7280;
    margin: 0.5rem 0;
    letter-spacing: 1px;
}

/* ===============================
   الهيدر - محدث
================================*/

.app-header {
    background: linear-gradient(90deg, var(--blue-dark), var(--blue-main));
    color: #fff;
    padding: 1.2rem 1.5rem;
    box-shadow: 0 3px 12px rgba(0,0,0,0.25);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.app-logo {
    width: 80px;
    height: 80px;
    object-fit: contain;
    border-radius: 50%;
    border: 3px solid #e0e7ff;
    background: #fff;
    padding: 6px;
}

.header-text {
    display: flex;
    flex-direction: column;
}

.ministry-title {
    font-size: 1rem;
    opacity: 0.95;
    font-weight: 600;
}

.system-title {
    font-size: 1.4rem;
    font-weight: 700;
    margin-top: 0.2rem;
}

.system-title-en {
    font-size: 0.85rem;
    opacity: 0.9;
    font-weight: 500;
    letter-spacing: 1px;
    margin-top: 0.2rem;
}

/* معلومات المستخدم في الهيدر - محدث */
.user-info-header {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-details {
    text-align: right;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.user-name-top {
    font-size: 1.1rem;
    font-weight: 700;
    color: #fff;
}

.user-role-top {
    font-size: 0.85rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.85);
}

/* ===============================
   المحتوى الرئيسي
================================*/

.app-main {
    flex: 1;
    padding: 1.5rem;
}

/* ===============================
   Card
================================*/

.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow);
}

/* ===============================
   Tabs
================================*/

.tabs {
    display: flex;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid #e5e7eb;
}

.tab-button {
    flex: 1;
    padding: 0.8rem;
    border: none;
    background: none;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    position: relative;
    transition: color 0.2s;
}

.tab-button:hover {
    color: var(--blue-main);
}

.tab-button.active {
    color: var(--blue-main);
}

.tab-button.active::after {
    content: "";
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 100%;
    height: 3px;
    background: var(--blue-main);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ===============================
   Form Elements
================================*/

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.4rem;
    font-weight: 600;
    color: var(--text-main);
}

.form-group input,
.form-group select,
.form-group textarea,
.form-control {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus,
.form-control:focus {
    outline: none;
    border-color: var(--blue-main);
    box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.1);
}

.form-group textarea,
textarea.form-control {
    resize: vertical;
    min-height: 80px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

/* ===============================
   Buttons
================================*/

.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.btn.primary {
    background: var(--blue-main);
    color: #fff;
}

.btn.primary:hover {
    background: var(--blue-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(29, 78, 216, 0.3);
}

.btn.success {
    background: #10b981;
    color: #fff;
}

.btn.success:hover {
    background: #059669;
}

.btn.danger {
    background: #ef4444;
    color: #fff;
}

.btn.danger:hover {
    background: #dc2626;
}

.btn.full {
    width: 100%;
}

.btn.small {
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
}

/* ===============================
   Messages
================================*/

.message {
    padding: 0.75rem;
    border-radius: var(--radius);
    margin-top: 1rem;
    display: none;
}

.message.visible {
    display: block;
}

.message.success {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #10b981;
}

.message.error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #ef4444;
}

.message.info {
    background: #dbeafe;
    color: #1e40af;
    border: 1px solid #3b82f6;
}

/* ===============================
   Hidden
================================*/

.hidden {
    display: none !important;
}

/* ===============================
   Dashboard
================================*/

.dashboard {
    display: grid;
    grid-template-columns: 250px 1fr;
    gap: 1.5rem;
    min-height: calc(100vh - 150px);
}

/* ===============================
   Sidebar
================================*/

.sidebar {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    height: fit-content;
}

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.nav-item {
    padding: 0.8rem;
    border: none;
    background: none;
    text-align: right;
    font-size: 1rem;
    font-weight: 600;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.nav-item:hover {
    background: var(--blue-light);
    color: var(--blue-main);
}

.nav-item.active {
    background: var(--blue-main);
    color: #fff;
}

.nav-item.danger {
    color: #ef4444;
    margin-top: 1rem;
}

.nav-item.danger:hover {
    background: #fee2e2;
}

/* ===============================
   Content Area
================================*/

.content {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow);
}

.screen {
    display: none;
}

.screen:not(.hidden) {
    display: block;
}

.inner-card {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-top: 1.5rem;
}

.inner-card h3 {
    margin-top: 0;
    color: var(--blue-dark);
}

/* ===============================
   Tables (Basic)
================================*/

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

table thead {
    background: var(--blue-dark);
    color: #fff;
}

table th {
    padding: 0.75rem;
    text-align: center;
    font-weight: 600;
}

table td {
    padding: 0.75rem;
    border-bottom: 1px solid #e5e7eb;
    text-align: center;
}

table tbody tr:hover {
    background: var(--blue-light);
}

/* ===============================
   MODERN TABLE - للجدول العصري
================================*/

.table-wrapper {
    overflow-x: auto;
    margin-top: 1rem;
    border-radius: var(--radius);
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.modern-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    font-size: 0.95rem;
}

.modern-table thead {
    background: linear-gradient(90deg, var(--blue-dark), var(--blue-main));
    color: #fff;
}

.modern-table thead th {
    padding: 1rem 0.75rem;
    text-align: center;
    font-weight: 600;
    white-space: nowrap;
    border-left: 1px solid rgba(255,255,255,0.1);
}

.modern-table thead th:first-child {
    border-right: none;
}

.modern-table tbody tr {
    transition: all 0.2s;
}

.modern-table tbody tr:hover {
    background: var(--blue-light);
    transform: scale(1.002);
}

.modern-table tbody td {
    padding: 0.85rem 0.75rem;
    text-align: center;
    border-bottom: 1px solid #e5e7eb;
    vertical-align: middle;
}

.modern-table tbody tr:last-child td {
    border-bottom: none;
}

.modern-table tbody td:last-child {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
}

/* ===============================
   MODAL - للتعديل
================================*/

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    backdrop-filter: blur(4px);
}

.modal.hidden {
    display: none;
}

.modal-dialog {
    background: var(--card-bg);
    border-radius: var(--radius);
    width: 90%;
    max-width: 700px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-50px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 2px solid #e5e7eb;
    background: var(--blue-light);
}

.modal-header h3 {
    margin: 0;
    color: var(--blue-dark);
}

.modal-close {
    background: none;
    border: none;
    font-size: 2rem;
    color: #6b7280;
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
}

.modal-close:hover {
    background: #ef4444;
    color: #fff;
    transform: rotate(90deg);
}

.modal-dialog form {
    padding: 1.5rem;
}

/* ===============================
   QR CODE MODAL - جديد
================================*/

.qr-dialog {
    max-width: 500px;
}

.qr-content {
    padding: 2rem;
    text-align: center;
}

.qr-info {
    margin-bottom: 1.5rem;
}

.qr-info h4 {
    font-size: 1.3rem;
    color: var(--blue-dark);
    margin: 0;
    font-weight: 700;
}

.qr-container {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    border-radius: var(--radius);
    margin: 1rem 0;
    box-shadow: inset 0 2px 8px rgba(0,0,0,0.05);
    min-height: 340px;
}

.qr-container canvas {
    border: 8px solid #fff;
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(30, 58, 138, 0.2);
}

.qr-container img {
    border: 8px solid #fff;
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(30, 58, 138, 0.2);
}

/* ===============================
   Search Input
================================*/

.search-input {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--blue-main);
    border-radius: var(--radius);
    font-size: 1rem;
    margin-bottom: 1rem;
    font-family: inherit;
}

.search-input:focus {
    outline: none;
    border-color: var(--blue-dark);
    box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.1);
}

/* ===============================
   Assets Forms
================================*/

.asset-group {
    margin-bottom: 1rem;
}

.asset-group summary {
    cursor: pointer;
    user-select: none;
    padding: 0.8rem;
    background: var(--blue-light);
    border-radius: var(--radius);
    font-weight: 600;
    color: var(--blue-dark);
}

.asset-group summary:hover {
    background: #dbeafe;
}

.asset-form {
    padding: 1rem;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: var(--radius);
    margin-top: 0.5rem;
}

/* ===============================
   Utilities
================================*/

.text-center {
    text-align: center;
}

.mt-1 {
    margin-top: 1rem;
}

.mb-1 {
    margin-bottom: 1rem;
}

.p-1 {
    padding: 1rem;
}

.bold {
    font-weight: 700;
}

/* ===============================
   Scrollbar Styling
================================*/

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f5f9;
}

::-webkit-scrollbar-thumb {
    background: var(--blue-main);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--blue-dark);
}

/* ===============================
   Responsive Design
================================*/

@media (max-width: 1024px) {
    .dashboard {
        grid-template-columns: 200px 1fr;
    }

    .app-logo {
        width: 70px;
        height: 70px;
    }

    .system-title {
        font-size: 1.2rem;
    }
}

@media (max-width: 768px) {
    .dashboard {
        grid-template-columns: 1fr;
    }

    .sidebar {
        margin-bottom: 1rem;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .modern-table {
        font-size: 0.85rem;
    }

    .modern-table thead th,
    .modern-table tbody td {
        padding: 0.6rem 0.5rem;
    }

    .modal-dialog {
        width: 95%;
        max-height: 95vh;
    }

    .qr-dialog {
        max-width: 95%;
    }

    .qr-container {
        padding: 1rem;
        min-height: 280px;
    }

    .qr-container canvas {
        max-width: 250px;
        max-height: 250px;
        width: 100% !important;
        height: auto !important;
    }

    .app-header {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }

    .logo-area {
        flex-direction: column;
    }

    .app-logo {
        width: 60px;
        height: 60px;
    }

    .ministry-title {
        font-size: 0.9rem;
    }

    .system-title {
        font-size: 1rem;
    }

    .system-title-en {
        font-size: 0.75rem;
    }
    
    .user-details {
        text-align: center;
    }
}

@media (max-width: 480px) {
    .app-header {
        padding: 0.8rem;
    }

    .auth-logo {
        width: 100px;
        height: 100px;
    }

    .auth-title {
        font-size: 1.2rem;
    }

    .auth-subtitle {
        font-size: 1rem;
    }

    .content {
        padding: 1rem;
    }

    .btn {
        padding: 0.6rem 1rem;
        font-size: 0.9rem;
    }

    .btn.small {
        padding: 0.35rem 0.6rem;
        font-size: 0.75rem;
    }

    .modern-table tbody td:last-child {
        flex-direction: column;
        gap: 0.3rem;
    }
    
    .user-name-top {
        font-size: 1rem;
    }
    
    .user-role-top {
        font-size: 0.75rem;
    }

    .qr-content {
        padding: 1rem;
    }

    .qr-info h4 {
        font-size: 1.1rem;
    }

    .qr-container canvas {
        max-width: 200px;
        max-height: 200px;
    }
}
/* ===============================
   Employees Screen - Responsive Fit Fix
   (تعديل خاص بجدول العاملين فقط لتجنب Scroll أفقي)
================================*/

/* اجعل الجدول يلتزم بعرض الحاوية ويكسر الكلمات */
#employeesScreen .table-wrapper {
    max-width: 100%;
    overflow-x: hidden; /* منع ظهور شريط تمرير أفقي داخل الصفحة */
}

#employeesTable {
    width: 100%;
    table-layout: fixed; /* توزيع الأعمدة على العرض المتاح */
}

#employeesTable th,
#employeesTable td {
    white-space: normal;      /* السماح بلفّ النص */
    word-break: break-word;   /* كسر الكلمات الطويلة */
}

/* تقليل المسافات والخط على الشاشات المتوسطة */
@media (max-width: 1200px) {
    #employeesTable {
        font-size: 0.9rem;
    }
    #employeesTable th,
    #employeesTable td {
        padding: 0.65rem 0.5rem;
    }
}

/* إخفاء بعض الأعمدة غير الأساسية على الشاشات الصغيرة لتفادي التمرير الأفقي */
@media (max-width: 992px) {
    /* الأعمدة المخفية: البريد(3) - القطاع(5) - الإدارة المركزية(6) - الإدارة العامة(7) - الإدارة الفرعية(8) - العنوان(10) */
    #employeesTable thead th:nth-child(3),
    #employeesTable tbody td:nth-child(3),
    #employeesTable thead th:nth-child(5),
    #employeesTable tbody td:nth-child(5),
    #employeesTable thead th:nth-child(6),
    #employeesTable tbody td:nth-child(6),
    #employeesTable thead th:nth-child(7),
    #employeesTable tbody td:nth-child(7),
    #employeesTable thead th:nth-child(8),
    #employeesTable tbody td:nth-child(8),
    #employeesTable thead th:nth-child(10),
    #employeesTable tbody td:nth-child(10) {
        display: none;
    }

    /* تثبيت عرض عمود الإجراءات */
    #employeesTable thead th:last-child,
    #employeesTable tbody td:last-child {
        min-width: 140px;
    }
}

/* على الموبايل: إخفاء أعمدة إضافية لتكون القراءة مريحة */
@media (max-width: 768px) {
    /* إخفاء (الوظيفة 4) عند الضرورة */
    #employeesTable thead th:nth-child(4),
    #employeesTable tbody td:nth-child(4) {
        display: none;
    }

    #employeesTable thead th:last-child,
    #employeesTable tbody td:last-child {
        min-width: 150px;
    }
}


/* ===============================
   Store Balances Screen (UI)
   =============================== */
#storeBalancesScreen h2 {
  margin-bottom: 1rem;
}

#storeBalancesScreen .inner-card h3 {
  margin-top: 0;
}

#storeBalancesScreen .stock-balance-input {
  width: 140px;
  padding: 0.45rem 0.6rem;
  font-size: 0.95rem;
  text-align: center;
  display: inline-block;
}

#storeBalancesScreen .table-wrapper {
  overflow-x: auto;
}

#storeBalancesScreen .actions-row {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 12px;
}

#storeBalancesScreen .message {
  font-weight: 600;
}


/* ==========================
   STATS DASHBOARD
   ========================== */
.dash-cards{
  display:grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap:12px;
  margin: 12px 0 18px;
}

.dash-card{
  padding:14px;
  border:1px solid #e5e5e5;
  border-radius:12px;
  background:#fff;
}

.dash-title{ font-size:14px; opacity:.85; }
.dash-value{ font-size:28px; font-weight:700; margin-top:6px; }

.dash-grid{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap:12px;
}

@media(max-width: 900px){
  .dash-grid{ grid-template-columns: 1fr; }
}

.dash-panel{
  padding:14px;
  border:1px solid #e5e5e5;
  border-radius:12px;
  background:#fff;
  margin-bottom:12px;
}

.dash-table{
  width:100%;
  border-collapse:collapse;
  margin-top:10px;
}

.dash-table th, .dash-table td{
  border-bottom:1px solid #eee;
  padding:8px;
  text-align:right;
  font-size:13px;
}


.hint-text{
  font-size: 13px;
  color: #6b7280;
  margin: 0.5rem 0 1rem;
  line-height: 1.8;
}


/* Employees Pagination */
.pagination-controls{
  display:flex;
  gap:10px;
  align-items:center;
  justify-content:center;
  margin-top:12px;
  flex-wrap:wrap;
}
.page-indicator{
  font-weight:700;
  padding:6px 10px;
  border:1px solid #e5e5e5;
  border-radius:10px;
  background:#fff;
}


.store-records-filters {
    margin-top: 1rem;
    padding: 1rem 1rem 0.35rem;
}

.compact-card {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.store-filter-actions {
    display: flex;
    justify-content: flex-start;
}

.btn.secondary {
    background: #eef2ff;
    color: var(--blue-dark);
    border: 1px solid #c7d2fe;
}

.btn.secondary:hover {
    background: #dbeafe;
}
