/* =====================================================================
   نظام إدارة مطبخ الأسر المنتجة - نسخة الويب
   هوية بصرية: طيني دافئ (primary) + أخضر أعشاب (secondary) على خلفية فاتحة دافئة
   ===================================================================== */

/* حماية شاملة: أي صورة في أي مكان بالموقع لا يجوز أبداً أن تتجاوز إطارها،
   مهما كان حجمها أو أبعادها الأصلية (خصوصاً صور الجوال/آيفون عالية الدقة).
   هذه قاعدة أساسية عامة؛ أي تنسيق أدق (object-fit, ارتفاع ثابت...) أعلى منها
   في التحديد (specificity) يبقى فعّالاً فوقها كالمعتاد. */
img { max-width: 100%; height: auto; }

/* إصلاح مشكلة شهيرة في تخطيطات Grid: دون min-width:0 قد يرفض العمود الانكماش
   تحت الحجم الطبيعي لمحتواه (كصورة كبيرة)، فيدفع التخطيط للتمدد خارج الإطار
   المرئي رغم أن الصورة نفسها "تبدو" محصورة — هذا يمنع ذلك نهائياً. */
.grid > * { min-width: 0; }

:root {
    --primary: #B4532A;
    --primary-light: #D0703F;
    --secondary: #5C7457;
    --success: #047857;
    --danger: #DC2626;
    --warning: #B45309;
    --dark: #2B2018;
    --bg: #FAF7F2;
    --surface: #FFFFFF;
    --border: #E8E0D4;
    --row-alt: #F8FAFC;
    --text-muted: #526071;
    --radius: 14px;
    --radius-sm: 9px;
    --shadow: 0 2px 10px rgba(30, 41, 59, 0.06);
    --shadow-md: 0 8px 24px rgba(30, 41, 59, 0.10);
    --sidebar-w: 260px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--dark);
    font-family: 'Tajawal', 'Cairo', Tahoma, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; color: inherit; }
ul { list-style: none; margin: 0; padding: 0; }

h1, h2, h3, h4 { font-family: 'Cairo', 'Tajawal', sans-serif; font-weight: 700; margin: 0 0 8px; color: var(--dark); }

/* ---------------------------------------------------------------- layout */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    background: var(--primary);
    color: #fff;
    flex-shrink: 0;
    position: fixed;
    inset-inline-start: 0;
    top: 0;
    bottom: 0;
    overflow-y: auto;
    z-index: 40;
    transition: transform .25s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 22px 20px;
    font-size: 18px;
    font-weight: 800;
    border-bottom: 1px solid rgba(255,255,255,.12);
}
.sidebar-brand span.emoji { font-size: 26px; }

.sidebar nav { padding: 14px 10px; }
.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    color: rgba(255,255,255,.85);
    font-weight: 600;
    margin-bottom: 4px;
    transition: background .15s, color .15s;
}
.sidebar nav a:hover { background: rgba(255,255,255,.10); color: #fff; }
.sidebar nav a.active { background: rgba(255,255,255,.18); color: #fff; }
.sidebar nav .icon { width: 20px; display: inline-flex; align-items: center; justify-content: center; }
.ico { flex-shrink: 0; vertical-align: middle; }
.badge-count .ico { width: 12px; height: 12px; }
.btn .ico { width: 16px; height: 16px; margin-inline-end: 4px; }

.sidebar .badge-count {
    margin-inline-start: auto;
    background: var(--danger);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    border-radius: 999px;
    padding: 1px 7px;
}

.main {
    flex: 1;
    margin-inline-start: var(--sidebar-w);
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 14px 26px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 30;
}
.topbar h1 { font-size: 20px; margin: 0; }
.topbar .user-chip { display: flex; align-items: center; gap: 10px; font-weight: 600; color: var(--text-muted); }
.topbar .user-chip .avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center;
    font-weight: 700;
}
.sidebar-toggle { display: none; background: none; border: none; font-size: 22px; color: var(--dark); cursor: pointer; min-width: 44px; min-height: 44px; padding: 0 8px; }

.content { padding: 24px 26px 60px; }

/* ---------------------------------------------------------------- cards */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 20px;
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 10px; }
.card-header h2, .card-header h3 { margin: 0; font-size: 17px; }

.grid { display: grid; gap: 18px; }
.sale-new-grid { grid-template-columns: 1.5fr 1fr; }
@media (max-width: 900px) { .sale-new-grid { grid-template-columns: 1fr; } }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: repeat(2,1fr);} }
@media (max-width: 640px) { .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; } }
.grid-split { grid-template-columns: 1fr 1.6fr; }
@media (max-width: 640px) { .grid-split { grid-template-columns: 1fr; } }

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}
.stat-card .label { color: var(--text-muted); font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.stat-card .value { font-size: 24px; font-weight: 800; color: var(--dark); }
.stat-card .icon-badge {
    position: absolute; inset-inline-end: 16px; top: 16px;
    width: 42px; height: 42px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center; font-size: 20px; color: #fff;
}
.stat-card.c-primary .icon-badge { background: var(--primary); }
.stat-card.c-success .icon-badge { background: var(--success); }
.stat-card.c-secondary .icon-badge { background: var(--secondary); }
.stat-card.c-warning .icon-badge { background: var(--warning); }
.stat-card .delta { font-size: 12px; font-weight: 700; }
.stat-card .delta.up { color: var(--success); }
.stat-card .delta.down { color: var(--danger); }

/* ---------------------------------------------------------------- buttons */
.btn {
    display: inline-flex; align-items: center; gap: 8px;
    border: none; border-radius: var(--radius-sm);
    padding: 10px 18px; font-weight: 700; font-size: 14px;
    cursor: pointer; transition: filter .15s, transform .05s;
    font-family: inherit;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: var(--secondary); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-light { background: var(--bg); color: var(--dark); border: 1px solid var(--border); }
.btn:hover { filter: brightness(0.93); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-icon { width: 36px; height: 36px; padding: 0; justify-content: center; }

/* ---------------------------------------------------------------- forms */
label { display: block; font-weight: 700; font-size: 13.5px; margin-bottom: 6px; color: var(--dark); }
.form-group { margin-bottom: 16px; }
input[type=text], input[type=number], input[type=date], input[type=time],
input[type=password], input[type=tel], input[type=email], input[type=search], input[type=url], select, textarea {
    width: 100%;
    padding: 11px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-family: inherit;
    font-size: 14.5px;
    color: var(--dark);
    transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
    outline: 3px solid var(--primary-light); outline-offset: 1px; border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(180, 83, 42, .12);
}

/* إخفاء أسهم الزيادة/النقصان (spin buttons) في كل حقول الأرقام بالموقع بالكامل:
   تحكّم المتصفح البصري في الفاصلة العشرية (step) شكل مزعج فقط، ولا علاقة له
   بالتحقق أو التقريب الفعلي — ذاك يتم بالكامل في كود PHP (float/round) بغض
   النظر عمّا يُكتب في الحقل. تكتب صاحبة المطبخ الرقم كما يناسبها بحرية تامة. */
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
input[type=number] {
    -moz-appearance: textfield;
    appearance: textfield;
}
textarea { resize: vertical; min-height: 90px; }
.form-row { display: flex; gap: 14px; flex-wrap: wrap; }
.form-row > * { flex: 1; min-width: 180px; }
.help-text { font-size: 12.5px; color: var(--text-muted); margin-top: 4px; }

/* ---------------------------------------------------------------- table */
.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data-table th {
    text-align: start; background: var(--bg); color: var(--text-muted);
    font-weight: 700; padding: 12px 14px; border-bottom: 2px solid var(--border);
    white-space: nowrap;
}
table.data-table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data-table tbody tr:nth-child(even) { background: var(--row-alt); }
table.data-table tbody tr:hover { background: #FAEBDD; }

.badge { display: inline-block; padding: 4px 11px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge-success { background: #D1FAE5; color: #047857; }
.badge-warning { background: #FEF3C7; color: #B45309; }
.badge-danger { background: #FEE2E2; color: #B91C1C; }
.badge-secondary { background: #E0E7FF; color: #3730A3; }
.badge-muted { background: #F1F5F9; color: #475569; }

/* ---------------------------------------------------------------- misc */
.flash-stack { position: fixed; top: 18px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; width: min(92%, 460px); }
.flash { padding: 13px 18px; border-radius: var(--radius-sm); font-weight: 700; box-shadow: var(--shadow-md); color: #fff; }
.flash-success { background: var(--success); }
.flash-danger { background: var(--danger); }
.flash-warning { background: var(--warning); }
.flash-info { background: var(--secondary); }

.empty-state { text-align: center; padding: 50px 20px; color: var(--text-muted); }
.empty-state .emoji { font-size: 42px; margin-bottom: 10px; }

.login-wrap {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: var(--bg);
    padding: 20px;
}
.login-card { background: var(--surface); border-radius: 18px; padding: 40px 34px; width: 100%; max-width: 380px; box-shadow: var(--shadow-md); text-align: center; }
.login-card .logo { font-size: 46px; margin-bottom: 6px; }

.pill-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.pill-tabs a { padding: 8px 16px; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); font-weight: 700; font-size: 13.5px; color: var(--text-muted); }
.pill-tabs a.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pill-tabs .pill-tab-wrap { display: inline-flex; align-items: stretch; border-radius: 999px; overflow: hidden; border: 1px solid var(--border); }
.pill-tabs .pill-tab-wrap a { border-radius: 0; border: none; }
.pill-delete-btn { border: none; background: var(--bg); color: var(--text-muted); padding: 0 12px; cursor: pointer; font-size: 12px; line-height: 1; border-inline-start: 1px solid var(--border); }
.pill-delete-btn:hover { color: #fff; background: #dc2626; }

.cart-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px dashed var(--border); }
.cart-row:last-child { border-bottom: none; }
.cart-row .thumb { width: 60px; height: 60px; flex-shrink: 0; border-radius: 8px; background: #f8f9fa; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.cart-row .thumb img { max-width: 100%; max-height: 100%; width: auto; height: auto; object-fit: contain; display: block; }
.cart-row .thumb .no-image { font-size: 22px; }
.cart-row .info { flex: 1; min-width: 0; }

.dish-card-mini { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; background: var(--surface); cursor: pointer; transition: box-shadow .15s, border-color .15s; display: flex; flex-direction: column; height: 100%; }
.dish-card-mini:hover { box-shadow: var(--shadow-md); border-color: var(--primary); }
.dish-card-mini .img-wrap { width: 100%; height: 110px; border-radius: 8px; margin-bottom: 8px; background: #f8f9fa; display: flex; align-items: center; justify-content: center; overflow: hidden; flex-shrink: 0; }
.dish-card-mini .img-wrap img { max-width: 100%; max-height: 100%; width: auto; height: auto; object-fit: contain; display: block; }
.dish-card-mini .img-wrap .no-image { font-size: 30px; }
.dish-card-mini .name { font-weight: 700; font-size: 13.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 2.5em; }
.dish-card-mini .price { color: var(--success); font-weight: 800; font-size: 13px; margin-top: auto; padding-top: 4px; }
.dish-card-mini .card-body { flex: 1; display: flex; flex-direction: column; }
.dish-card-mini .add-to-cart-btn { width: 100%; margin-top: 8px; justify-content: center; font-size: 13px; padding: 12px 7px; min-height: 44px; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.55); display: none; align-items: center; justify-content: center; z-index: 80; padding: 20px; }
.modal-backdrop.open { display: flex; }
.modal-box { background: var(--surface); border-radius: var(--radius); padding: 24px; width: 100%; max-width: 440px; box-shadow: var(--shadow-md); }

/* print invoice */
@media print {
    .no-print, .sidebar, .topbar { display: none !important; }
    .main { margin: 0 !important; }
    .content { padding: 0 !important; }
    body { background: #fff; }
    .invoice-sheet { box-shadow: none !important; border: none !important; }
}

/* ---------------------------------------------------------------- responsive */
@media (max-width: 900px) {
    .sidebar { transform: translateX(100%); }
    [dir="rtl"] .sidebar { transform: translateX(100%); }
    .sidebar.open { transform: translateX(0); }
    .main { margin-inline-start: 0; }
    .sidebar-toggle { display: block; }
    .content { padding: 16px; }
}


/* إمكانية الوصول: رابط تخطّي للمحتوى (يظهر عند التركيز بلوحة المفاتيح فقط) */
.skip-link { position: absolute; top: -60px; right: 8px; background: var(--dark); color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 1000; font-weight: 700; }
.skip-link:focus { top: 8px; }
:focus-visible { outline: 3px solid var(--primary-light); outline-offset: 2px; }

.pay-options { display:flex; flex-direction:column; gap:8px; }
.pay-opt { display:flex; align-items:center; gap:10px; padding:12px 14px; border:1px solid var(--border); border-radius: var(--radius-sm); cursor:pointer; font-weight:600; background: var(--surface); }
.pay-opt:has(input:checked) { border-color: var(--primary); background: #F5EEFB; }
.pay-opt input { width:auto; margin:0; }

/* شبكة بطاقات مركز الإعدادات (settings.php) — تبويبات تشبه لوحات المنصات
   التجارية المعروفة لتقليل الزحام بدل صفحة إعدادات طويلة واحدة. */
.settings-hub-grid { display:grid; grid-template-columns:repeat(3, 1fr); gap:16px; }
@media (max-width: 1024px) { .settings-hub-grid { grid-template-columns:repeat(2, 1fr); } }
@media (max-width: 640px) { .settings-hub-grid { grid-template-columns:1fr; } }
.settings-hub-tile { display:flex; flex-direction:column; align-items:flex-start; gap:8px; background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); padding:20px; text-decoration:none; color:inherit; transition:box-shadow .15s, border-color .15s, transform .15s; }
.settings-hub-tile:hover { box-shadow:var(--shadow-md); border-color:var(--primary); transform:translateY(-2px); }
.settings-hub-tile .emoji { font-size:30px; }
.settings-hub-tile .title { font-weight:800; font-size:15.5px; color:var(--dark); }
.settings-hub-tile .desc { font-size:12.5px; color:var(--text-muted); line-height:1.6; }

/* ---- شارات الأطباق (حار / مطبوخ / نيء): أيقونة + كلمة، لا لون وحده ---- */
.sr-only { position:absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip:rect(0,0,0,0); white-space:nowrap; border:0; }
.dish-badges { display:inline-flex; flex-wrap:wrap; gap:4px; }
.dish-badge { display:inline-flex; align-items:center; background:#FFF7ED; color:#7C2D12; border:1px solid #FED7AA; border-radius:999px; padding:1px 8px; font-size:11.5px; font-weight:800; line-height:1.6; white-space:nowrap; }
.dish-badge-raw { background:#EFF6FF; color:#1E3A8A; border-color:#BFDBFE; }
.dish-badge-cooked { background:#FEF3C7; color:#78350F; border-color:#FDE68A; }
.img-wrap { position:relative; }
.store-img > .dish-badges, .img-wrap > .dish-badges { position:absolute; bottom:6px; right:6px; z-index:1; }
.dish-menu-row-top > .dish-badges { margin-inline-start:6px; align-self:center; }

/* جدول الفواتير على الجوال: بطاقات بدل التمرير الأفقي، وزر الحذف مفصول عن بقية الإجراءات */
.danger-form { margin-inline-start: 14px; }
@media (max-width: 640px) {
    .sales-table thead { display: none; }
    .sales-table, .sales-table tbody, .sales-table tr, .sales-table td { display: block; width: 100%; }
    .sales-table tr { border: 1px solid var(--border); border-radius: 10px; margin-bottom: 12px; padding: 8px 12px; background: var(--surface); }
    .sales-table td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 6px 0; border: 0; white-space: normal !important; }
    .sales-table td::before { font-weight: 700; color: var(--text-muted); flex: 0 0 auto; }
    .sales-table td:nth-child(1)::before { content: "رقم الطلب"; }
    .sales-table td:nth-child(2)::before { content: "التاريخ"; }
    .sales-table td:nth-child(3)::before { content: "العميل"; }
    .sales-table td:nth-child(4)::before { content: "الموعد"; }
    .sales-table td:nth-child(5)::before { content: "الحالة"; }
    .sales-table td:nth-child(6)::before { content: "الإجمالي"; }
    .sales-table td:nth-child(7)::before { content: "صافي الربح"; }
    .sales-table td:last-child { flex-wrap: wrap; justify-content: flex-start; gap: 8px; padding-top: 10px; border-top: 1px solid var(--border); }
    .sales-table td:last-child::before { content: none; }
    .sales-table td:last-child .btn { min-height: 44px; }
    .sales-table td:last-child form { display: inline-flex !important; margin: 0; }
    .sales-table td:last-child .danger-form { margin-inline-start: auto; }
}
/* جدول بنود الفاتورة أعرض من الجوال: يُمرَّر داخل البطاقة بدل أن يوسّع الصفحة كلها */
@media (max-width: 640px) {
    .invoice-sheet { overflow-x: auto; }
    .sales-table .badge { white-space: nowrap; }
}
/* أخطاء الحقول (form_errors.js) */
.field-error { color: #b91c1c; font-size: 14px; margin-top: 4px; }
.form-error-summary { border: 1.5px solid #fca5a5; background: #fef2f2; color: #991b1b; padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; font-weight: 700; }
.form-error-summary:empty { display: none; }
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: #b91c1c; }

/* تبويبات التصنيفات بأسلوب القصص: دوائر أفقية قابلة للتمرير */
.story-tabs { display: flex; gap: 14px; overflow-x: auto; scroll-snap-type: x proximity; padding: 4px 2px 12px; margin-bottom: 14px; -webkit-overflow-scrolling: touch; }
.story-tab { flex: 0 0 auto; width: 72px; display: flex; flex-direction: column; align-items: center; gap: 6px; scroll-snap-align: start; text-decoration: none; color: var(--text-muted); }
.story-ring { width: 64px; height: 64px; border-radius: 50%; padding: 3px; border: 2px solid var(--border); display: flex; align-items: center; justify-content: center; overflow: hidden; background: var(--surface); }
.story-ring img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }
.story-all { font-weight: 800; font-size: 15px; color: var(--primary); }
.story-label { font-size: 12.5px; font-weight: 700; text-align: center; line-height: 1.3; max-width: 72px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.story-tab.active .story-ring { border-color: var(--primary); }
.story-tab.active .story-label { color: var(--primary); }
.story-tab:focus-visible { outline: 3px solid var(--primary-light); outline-offset: 2px; border-radius: 12px; }

/* الأكثر مبيعًا */
.best-strip { display: flex; gap: 12px; overflow-x: auto; scroll-snap-type: x proximity; padding-bottom: 8px; }
.best-strip .best-card { flex: 0 0 150px; scroll-snap-align: start; }

/* المنيو الطويل: أقسام قابلة للطي */
details.menu-category-group > summary.menu-category-title { cursor: pointer; list-style: none; min-height: 44px; }
details.menu-category-group > summary.menu-category-title::-webkit-details-marker { display: none; }
details.menu-category-group > summary.menu-category-title::before { content: '▾'; flex: 0 0 auto; height: auto; background: none; opacity: .7; margin-inline-end: 6px; }
details.menu-category-group:not([open]) > summary.menu-category-title::before { content: '◂'; }
.menu-count { font-weight: 600; color: var(--text-muted); font-size: 13px; }
