@import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@300;400;500;700;800;900&display=swap');

:root {
    /* Calm professional palette */
    --primary: #3b5b7a;
    --primary-dark: #2f4961;
    --accent: #6c7f99;

    --success: #2f7d5c;
    --warning: #b28752;
    --danger: #b85c5c;
    --info: #4f7f9f;

    --secondary: #6b7280;
    --sidebar-bg: #243447;
    --sidebar-active: #31485f;

    --bg: #eef2f5;
    --surface: #ffffff;
    --surface-2: #f6f8fa;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --border: #cfd8e3;

    --radius: 16px;
    --radius-lg: 22px;
    --shadow-sm: 0 1px 2px rgba(31, 41, 55, 0.06);
    --shadow-md: 0 8px 20px rgba(31, 41, 55, 0.08);
    --shadow-lg: 0 16px 32px rgba(31, 41, 55, 0.12);
    --ring: 0 0 0 4px color-mix(in srgb, var(--primary) 14%, transparent);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    user-select: none; /* لمنع تحديد النص عند اللمس المتكرر */
}

input, textarea, select {
    user-select: auto; /* السماح بتحديد النص في حقول الإدخال */
}

body {
    font-family: 'Tajawal', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg);
    color: var(--text-main);
    line-height: 1.6;
    overflow-x: hidden;
    direction: rtl;
}

.app-wrapper {
    display: flex;
    min-height: 100vh;
    padding: 16px;
    gap: 16px;
}

/* Sidebar Styling - Modern Blue Dark */
.sidebar {
    width: 260px;
    background-color: var(--sidebar-bg);
    color: white;
    padding: 14px 0;
    position: sticky;
    height: calc(100vh - 36px);
    right: 0;
    top: 18px;
    z-index: 1000;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow-y: auto; /* تم إضافة التمرير هنا */
    border: 1px solid rgba(255,255,255,0.12);
    background:
        radial-gradient(900px 520px at 30% 0%, rgba(108,127,153,0.22) 0%, rgba(108,127,153,0) 60%),
        linear-gradient(180deg, #1d2a3a 0%, #162131 100%);
}

.sidebar-menu {
    padding-bottom: 10px;
}

.sidebar-header {
    padding: 10px 20px 25px;
    text-align: center;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    margin-bottom: 15px;
}

.sidebar-logo {
    max-width: 90px;
    height: auto;
    margin-bottom: 10px;
    filter: drop-shadow(0 4px 6px rgba(0,0,0,0.2));
}

.menu-item {
    padding: 12px 20px;
    color: #cbd5e1;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: 500;
    margin: 4px 12px;
    border-radius: 10px;
    border: 1px solid transparent;
}

.menu-item + .menu-item { margin-top: 2px; }
.menu-item i { opacity: 0.95; }

.menu-item:hover {
    background: rgba(255,255,255,0.08);
    color: white;
    border-color: rgba(255,255,255,0.2);
}

.menu-item.active {
    background: linear-gradient(135deg, var(--primary) 0%, #5f7893 100%);
    color: white;
    box-shadow: 0 10px 22px rgba(36, 52, 71, 0.28);
    border-color: rgba(255,255,255,0.28);
}

.menu-item i {
    width: 24px;
    text-align: center;
    font-size: 1.2rem;
}

/* Main Content Area */
.main-content {
    flex: 1;
    margin-right: 0;
    padding: 0;
    transition: margin 0.3s;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.top-nav {
    background: var(--surface);
    padding: 12px 18px;
    border-radius: var(--radius-lg);
    margin-bottom: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
}

.nav-links {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.nav-links a {
    text-decoration: none;
    color: var(--text-main);
    font-weight: 700;
    font-size: 0.9rem;
    padding: 8px 12px;
    border-radius: 6px;
    transition: background 0.2s;
}

.nav-links a:hover { background: #f1f5f9; }

/* Top nav user area */
.top-nav-user { display: flex; align-items: center; gap: 14px; }
.top-nav-user-meta { display: flex; flex-direction: column; align-items: flex-end; }
.top-nav-user-name { font-weight: 900; font-size: 0.92rem; letter-spacing: 0.2px; }
.top-nav-user-role { font-size: 0.75rem; color: var(--text-muted); font-weight: 700; }
.top-nav-avatar {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    background: linear-gradient(135deg, #e0e7ff 0%, #bfdbfe 100%);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    font-size: 1.05rem;
    box-shadow: 0 10px 20px rgba(29,78,216,0.18);
}

/* Stats Grid - High Fidelity */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-bottom: 10px;
}

.stat-card {
    background: var(--surface);
    padding: 16px;
    border-radius: var(--radius);
    color: white;
    display: flex;
    flex-direction: column;
    justify-content: center;
    box-shadow: var(--shadow-md);
    position: relative;
    overflow: hidden;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    border: 1px solid rgba(255,255,255,0.16);
}

.stat-card:hover {
    transform: translateY(-5px) scale(1.02);
}

.stat-card::after {
    content: '';
    position: absolute;
    right: -10px;
    bottom: -10px;
    width: 100px;
    height: 100px;
    background: rgba(255,255,255,0.1);
    border-radius: 50%;
}

.stat-card.red { background: linear-gradient(135deg, #b86a6a, #9f5151); }
.stat-card.orange { background: linear-gradient(135deg, #b29368, #9a7f5a); }
.stat-card.green { background: linear-gradient(135deg, #4a8a70, #376b56); }
.stat-card.blue { background: linear-gradient(135deg, #5c7b99, #46617a); }

.stat-card h3 {
    font-size: 0.9rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
    opacity: 0.9;
}

.stat-card .value {
    font-size: 1.45rem;
    font-weight: 900;
    text-shadow: 0 2px 4px rgba(0,0,0,0.1);
    line-height: 1.2;
}

/* POS Grid Cards - Touch Friendly */
.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 15px;
    padding: 5px;
}

.product-card {
    background: white;
    border-radius: 12px;
    border: 1px solid #d5dee8;
    padding: 10px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
    min-height: 160px;
    max-height: 180px;
}

.product-card:hover, .product-card:active {
    transform: translateY(-3px);
    border-color: #9fb1c5;
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1);
}

.product-card-img {
    width: 70px;
    height: 70px;
    object-fit: cover;
    border-radius: 8px;
    background: #f8fafc;
}

.product-card-name {
    font-weight: 700;
    font-size: 0.85rem;
    height: 2.4em;
    overflow: hidden;
    line-height: 1.2;
}

.product-card-price {
    color: var(--primary);
    font-weight: 800;
    font-size: 0.95rem;
}

.product-card-qty {
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* Layout Blocks */
.content-block {
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid #d2dbe6;
    margin-bottom: 0;
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.block-header {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(180deg, #ffffff 0%, var(--surface-2) 100%);
    gap: 10px;
    flex-wrap: wrap;
}

.block-title {
    font-size: 1rem;
    font-weight: 800;
    line-height: 1.3;
}

/* Tables - Modern Styling */
.table-container { 
    width: 100%; 
    overflow-x: auto; 
    border-radius: 10px;
    border: 1px solid #d5dee8;
}

table { width: 100%; border-collapse: collapse; overflow: hidden; }
th {
    background: var(--surface-2);
    padding: 11px 12px;
    text-align: right;
    font-size: 0.85rem;
    color: #475569;
    font-weight: 800;
    border-bottom: 2px solid #d2dbe6;
}
td {
    padding: 10px 12px;
    border-bottom: 1px solid #e2e8f0;
    font-size: 0.95rem;
    transition: background 0.2s;
    color: #334155;
}
tr:hover td { background: #f8fafc; }
tr:last-child td { border-bottom: none; }

/* Data table helper (used by many pages) */
.data-table { width: 100%; border-collapse: collapse; }
.data-table thead th { background: #f8fafc; }
.data-table tbody tr:nth-child(even) td { background: #ffffff; }

/* Form Controls */
.form-group { margin-bottom: 18px; }
.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 700;
    font-size: 0.85rem;
}
input, select, textarea {
    width: 100%;
    padding: 9px 12px;
    border-radius: 8px;
    border: 1px solid #cfd8e3;
    font-family: inherit;
    font-size: 0.95rem;
    transition: border 0.2s, box-shadow 0.2s, background 0.2s;
    background: #fff;
}
input:focus, select:focus, textarea:focus {
    border-color: color-mix(in srgb, var(--primary) 70%, #ffffff);
    outline: none;
    box-shadow: var(--ring);
}
textarea { resize: vertical; min-height: 90px; }
input[readonly], textarea[readonly] { background: #f8fafc; color: #475569; }
input::placeholder, textarea::placeholder { color: #94a3b8; }

/* Small field variants often used inline */
.input-sm, .select-sm { padding: 6px 10px; border-radius: 8px; font-size: 0.9rem; }

/* Validation helpers (HTML5 required/invalid) */
input:invalid:not(:focus):not(:placeholder-shown),
textarea:invalid:not(:focus):not(:placeholder-shown),
select:invalid:not(:focus) {
    border-color: color-mix(in srgb, var(--danger) 65%, #ffffff);
}

/* Alerts (success/error/warning/info) */
.alert {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    border-radius: 10px;
    margin-bottom: 15px;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text-main);
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.alert i { margin-top: 2px; }
.alert-success {
    background: #ecfdf5;
    border-color: #a7f3d0;
    color: #065f46;
}
.alert-danger {
    background: #fef2f2;
    border-color: #fecaca;
    color: #7f1d1d;
}
.alert-warning {
    background: #fffbeb;
    border-color: #fde68a;
    color: #92400e;
}
.alert-info {
    background: #eff6ff;
    border-color: #bfdbfe;
    color: #1e3a8a;
}

/* Buttons */
.btn {
    padding: 8px 14px;
    border-radius: 8px;
    border: none;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
    font-size: 0.86rem;
    white-space: nowrap;
    min-height: 36px;
    justify-content: center;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #e2e8f0; color: var(--text-main); }
.btn-danger { background: var(--danger); color: white; }
.btn-success { background: var(--success); color: white; }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.btn-sm { padding: 6px 10px; border-radius: 10px; font-size: 0.8rem; gap: 6px; }

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, #58718a 100%);
    box-shadow: 0 8px 18px rgba(59, 91, 122, 0.22);
}
.btn-primary:hover {
    filter: brightness(0.98);
    box-shadow: 0 14px 26px rgba(37, 99, 235, 0.22);
}
.btn-secondary {
    background: linear-gradient(180deg, #f3f6f9 0%, #e6ecf2 100%);
    border: 1px solid #ccd6e2;
}
.btn-danger {
    background: linear-gradient(135deg, #c16969 0%, #a85252 100%);
}
.btn-success {
    background: linear-gradient(135deg, var(--success) 0%, #24644a 100%);
}

/* Optional color variants (desktop-like variety) */
.btn-info { background: linear-gradient(135deg, var(--info) 0%, #0284c7 100%); color: #fff; }
.btn-accent { background: linear-gradient(135deg, var(--accent) 0%, #a78bfa 100%); color: #fff; }

/* POS Container */
.pos-container {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 14px;
    height: calc(100vh - 200px);
}

.pos-fullscreen .app-wrapper { padding: 0; gap: 0; }
.pos-fullscreen .sidebar { display: none !important; }
.pos-fullscreen .top-nav { display: none !important; }
.pos-fullscreen .main-content { padding: 12px; }
.pos-fullscreen .pos-container { height: calc(100vh - 90px); }
.pos-fullscreen .pos-search-bar { margin-bottom: 12px; }

.pos-search-bar {
    display: flex;
    gap: 12px;
    align-items: center;
    background: rgba(255,255,255,0.92);
    border: 1px solid rgba(255,255,255,0.35);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 10px 12px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    margin-bottom: 10px;
}

.product-grid {
    padding: 18px !important;
    background: linear-gradient(180deg, #fbfdff 0%, #f8fafc 100%) !important;
}

.cart-area {
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.cart-area {
    display: flex;
    flex-direction: column;
    background: white;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    height: 100%;
    min-height: 420px;
}

.payment-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding: 12px;
    background: linear-gradient(180deg, #f8fafc 0%, #eef2f5 100%);
    border-top: 1px solid var(--border);
}

.pay-btn {
    height: 60px;
    border-radius: 14px;
    border: none;
    color: white;
    font-weight: 800;
    font-size: 0.95rem;
    cursor: pointer;
    transition: transform 0.1s;
    box-shadow: 0 10px 18px rgba(31, 41, 55, 0.10);
}

.pay-btn.cash { background: linear-gradient(135deg, #16a34a, #166534); } /* Green */
.pay-btn.knet { background: linear-gradient(135deg, #2563eb, #1e40af); } /* Blue */
.pay-btn.mixed { background: linear-gradient(135deg, #f59e0b, #854d0e); } /* Amber */
.pay-btn:active { transform: translateY(1px) scale(0.99); }

/* Cart item + qty buttons (POS) */
.cart-item{
    display:flex;
    gap:10px;
    margin-bottom:10px;
    padding:10px;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    background: #fff;
}
.cart-item-right{
    text-align:left;
    display:flex;
    flex-direction:column;
    justify-content:space-between;
    align-items:flex-end;
    min-width: 86px;
}
.cart-item-total{
    font-weight: 900;
    color: var(--primary);
    font-size: 1rem;
    line-height: 1.2;
}
.cart-remove{
    background: #fff;
    border: 1px solid #fecaca;
    color: #b85c5c;
    width: 34px;
    height: 30px;
    border-radius: 10px;
    cursor: pointer;
}
.cart-remove:hover{ filter: brightness(0.98); }
.qty-stepper{
    display:inline-flex;
    align-items:center;
    gap:6px;
    padding: 4px 6px;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    background: #f8fafc;
}
.qty-btn{
    width: 28px;
    height: 28px;
    border-radius: 10px;
    border: 1px solid transparent;
    cursor: pointer;
    display:flex;
    align-items:center;
    justify-content:center;
    box-shadow: 0 6px 14px rgba(31,41,55,0.10);
}
.qty-btn.minus{
    background: linear-gradient(135deg, #f1f5f9 0%, #e6ecf2 100%);
    color: #334155;
    border-color: #ccd6e2;
}
.qty-btn.plus{
    background: linear-gradient(135deg, #58718a 0%, var(--primary) 100%);
    color: #fff;
    border-color: rgba(255,255,255,0.25);
}
.qty-btn:active{ transform: translateY(1px) scale(0.99); }
.qty-value{
    display:inline-block;
    min-width: 36px;
    text-align:center;
    font-weight: 900;
    color: var(--text-main);
    font-size: 0.95rem;
}
.cart-unit-price{ margin-right: 8px; }

/* SweetAlert2 modern popup */
.swal-modern-popup {
    border-radius: 18px !important;
    box-shadow: 0 30px 70px rgba(2,6,23,0.35) !important;
    border: 1px solid rgba(15,23,42,0.08) !important;
    font-family: 'Tajawal', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif !important;
}

@media print {
    @page { margin: 0; size: auto; }
    .no-print { display: none !important; }
    .sidebar { display: none !important; }
    .main-content { margin: 0 !important; padding: 0 !important; }
    .content-block { border: 1px solid #eee !important; box-shadow: none !important; }
    .stat-card { 
        background: #fff !important; 
        color: #000 !important; 
        overflow: visible !important; 
        box-shadow: none !important;
    }
    .stat-card::after { display: none !important; }
}

@media (max-width: 1024px) {
    .app-wrapper { padding: 10px; gap: 10px; }
    .sidebar { width: 80px; height: calc(100vh - 20px); top: 10px; }
    .sidebar .sidebar-logo { max-width: 50px; }
    .sidebar .menu-item span { display: none; }
    .main-content { margin-right: 0; }
    .pos-container { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .top-nav { padding: 10px 12px; }
    .content-block { border-radius: 14px; }
    th, td { padding: 8px 9px; font-size: 0.86rem; }
}

@media (max-width: 768px) {
    .app-wrapper { flex-direction: column; padding: 8px; gap: 8px; }
    .sidebar {
        width: 100%;
        height: auto;
        position: static;
        border-radius: var(--radius);
        display: flex;
        flex-wrap: wrap;
        padding: 8px;
        gap: 6px;
    }
    .sidebar-header { display: none; }
    .sidebar-menu { display: flex; flex-wrap: wrap; gap: 6px; padding: 0; }
    .menu-item {
        flex: 1 1 auto;
        min-width: 80px;
        justify-content: center;
        padding: 8px 10px;
        border-radius: 10px;
    }
    .menu-item span { display: none; }
    .menu-item i { font-size: 1.1rem; margin: 0; }
    .main-content { padding: 0; }
    .top-nav {
        flex-direction: column;
        gap: 8px;
        padding: 10px;
        align-items: stretch;
    }
    .top-nav-user { justify-content: center; }
    .stats-grid { grid-template-columns: 1fr; gap: 8px; }
    .content-block { padding: 12px; }
    .form-grid { grid-template-columns: 1fr; }
    .table-container { overflow-x: auto; }
    th, td { white-space: nowrap; font-size: 0.8rem; padding: 6px 8px; }
    .modal-content { width: 95%; margin: 20px auto; padding: 16px; }
    .pos-container { grid-template-columns: 1fr; }
    .pos-right-panel { height: auto; }
    .btn { width: 100%; justify-content: center; }
    .actions-bar { flex-direction: column; }
    .search-filters { flex-direction: column; }
}

@media (max-width: 480px) {
    .app-wrapper { padding: 6px; gap: 6px; }
    .menu-item { min-width: 60px; padding: 6px 8px; }
    .top-nav-user-name { font-size: 0.8rem; }
    .top-nav-user-role { font-size: 0.65rem; }
    .stats-grid { gap: 6px; }
    .stat-card { padding: 10px 12px; }
    .stat-card .value { font-size: 1.4rem; }
    h1 { font-size: 1.3rem; }
    h2 { font-size: 1.1rem; }
    .content-block { padding: 10px; border-radius: 10px; }
    th, td { padding: 5px 6px; font-size: 0.75rem; }
    .btn-sm { padding: 5px 8px; font-size: 0.75rem; }
}
