/* 01 - الهوية وشريط التنقل المثبت */
:root { --accent: #146c43; --secondary: #ff9800; --header-height: 78px; }
header { position: sticky; top: 0; z-index: 20; min-height: 72px; border-block-end: 3px solid var(--accent); }
.identity { display: flex; align-items: center; gap: 12px; min-width: 0; overflow-wrap: anywhere; }
#logo { width: 50px; height: 50px; object-fit: contain; }
#email { unicode-bidi: isolate; }
#sidebar { position: sticky; top: var(--header-height); align-self: start; background: #173c34; min-height: calc(100dvh - var(--header-height)); }
.brand, .metric strong { color: var(--accent); }
#hamburger { display: none; }
.primary { background: #173c34; border-color: var(--accent); }
button { min-height: 44px; }
.toolbar select, .toolbar input { max-width: 100%; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); gap: 12px; }
.offer-card { min-width: 0; width: 100%; text-align: start; display: grid; gap: 8px; overflow-wrap: anywhere; }
.offer-card img, .detail-image { width: 100%; height: 100px; object-fit: contain; background: #f4f6f9; border-radius: 8px; }
.detail-image { height: 155px; }
.table-product { display: flex; gap: 8px; align-items: center; }
.table-product img { width: 36px; height: 36px; object-fit: contain; }
.campaign-card { border-inline-start: 3px solid var(--secondary); }
.scroll { max-width: 100%; overscroll-behavior-inline: contain; }

/* 02 - النوافذ العائمة ومحتواها القابل للتمرير */
.work-window { position: fixed; z-index: 30; width: min(610px, 92vw); height: min(530px, 76dvh); min-width: 285px; min-height: 180px; max-width: 100vw; max-height: 100dvh; display: flex; flex-direction: column; background: #fff; border: 1px solid #9aaebc; border-radius: 14px; overflow: hidden; box-shadow: 0 12px 37px #12243640; }
.window-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: #eaf1f5; padding: 8px; user-select: none; touch-action: none; cursor: move; flex-shrink: 0; }
.window-bar strong { overflow-wrap: anywhere; }
.window-bar .actions { flex-wrap: nowrap; }
.window-bar button { padding: 5px 10px; min-width: 36px; }
.window-content { padding: 16px; overflow: auto; flex: 1; overscroll-behavior: contain; }
.work-window.maximized { inset: var(--header-height) 0 58px !important; width: auto !important; height: auto !important; }
.window-tabs { position: fixed; bottom: 0; inset-inline: 0; z-index: 10000; display: flex; gap: 8px; overflow-x: auto; background: #173c34; padding: 6px; }
.window-tabs button { flex: 0 0 auto; max-width: 70vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.resize-grip { position: absolute; right: 0; bottom: 0; width: 22px; height: 22px; cursor: nwse-resize; touch-action: none; border-radius: 0; min-height: 0; padding: 0; }
.detail-list { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; overflow-wrap: anywhere; }
.detail-list dd { margin: 0; }
@media (max-width:750px) {
  header { gap: 8px; }
  #hamburger:not([hidden]) { display: block; }
  #sidebar { position: fixed; inset-inline-start: 0; top: var(--header-height); bottom: 0; width: min(290px, 88vw); z-index: 25; overflow: auto; display: none; }
  #sidebar.open { display: block; }
  #sidebar nav { display: grid; }
  #sidebar nav button { white-space: normal; }
  .identity { width: 100%; }
  .work-window, .work-window.maximized { inset: 0 0 58px !important; width: 100% !important; height: auto !important; max-height: none; border-radius: 0; }
  .resize-grip, .window-max { display: none; }
  .login { padding: 16px 8px; }
}

/* 03 - اختيار الشركة وحالة النوافذ المفتوحة */
#companySelect { min-height: 44px; max-width: min(100%, 15rem); border: 1px solid #cbd5e1; border-radius: 8px; padding: 6px 9px; background: #fff; font: inherit; }
#gateStatus { line-height: 1.65; }
.window-tabs button[aria-pressed=true] { outline: 2px solid #70b8a0; outline-offset: -2px; }
.nav-icon { display: inline-block; min-width: 1.55em; }
.preview-cards { margin-block: 12px; }
.preview-cards .offer-card { border: 1px solid #dce3eb; border-radius: 10px; padding: 12px; }
#compare { margin-block-end: 12px; }

/* UI-SESSION-01-FIX: مؤشر صغير في أعلى الصفحة بدلاً من شاشة انتظار */
body.session-busy header::after { content:""; position:absolute; inset-inline-start:0; bottom:0; height:3px; width:24%; background:var(--accent,#146c43); animation:session-progress 1.2s ease-in-out infinite alternate; pointer-events:none; }
header { position:sticky; }
@keyframes session-progress { from { transform:translateX(0); } to { transform:translateX(300%); } }
@media (prefers-reduced-motion:reduce) { body.session-busy header::after { animation:none; width:100%; } }

/* BUILD-03/04: روابط معرفات العروض وجدول النشرات */
.offer-id-link { background:transparent; border:0; color:var(--accent); text-decoration:underline; padding:4px 6px; min-height:32px; font-weight:700; }
.offer-id-link:hover { text-decoration:none; }
.bulletin-layout-button { margin-block:12px; }
.bulletin-table-wrap { width:100%; max-width:100%; }
.bulletin-table-wrap table { min-width:720px; }

/* BUILD-03/05: نتائج بحث المنتجات */
.product-results { padding:12px; margin:12px 0; border:1px solid #dce3eb; border-radius:10px; background:#f8fafc; }
.product-result-grid { display:grid; grid-template-columns:repeat(auto-fill,minmax(min(100%,220px),1fr)); gap:8px; margin-top:10px; max-height:340px; overflow:auto; }
.product-result { display:flex; flex-direction:column; align-items:flex-start; gap:5px; text-align:start; overflow-wrap:anywhere; }
.product-result img { width:56px; height:56px; object-fit:contain; }
.product-result small { color:#64748b; }
/* BUILD-03/06: النوافذ فوق رأس الصفحة والشريط الجانبي، مع بقاء شريط النوافذ أعلى منها */
.work-window { z-index:30; }
.work-window.maximized { inset:0 0 58px !important; }
@media(max-width:750px) { .product-result-grid { max-height:250px; } }

/* 09 - OFFER-CREATE-01: نموذج إعداد العروض دون تفعيل الكتابة */
#createPanel{display:grid;gap:14px} .create-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px}.create-field{display:grid;gap:6px;font-weight:600}.create-field input,.create-field select{width:100%;min-width:0;padding:11px;border:1px solid #cbd5e1;border-radius:8px;background:white}.create-results{display:grid;gap:6px;max-height:260px;overflow:auto}.create-match{display:flex;align-items:center;gap:10px;text-align:start;overflow-wrap:anywhere}.create-match img{width:48px;height:48px;object-fit:contain}.create-chosen{padding:12px;border:1px solid #dce3eb;border-radius:10px}.create-chosen>img{width:95px;height:95px;object-fit:contain}.create-batch-row{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:10px;border-bottom:1px solid #e5eaf0;overflow-wrap:anywhere}@media(max-width:750px){.create-grid{grid-template-columns:1fr}.create-batch-row{flex-wrap:wrap}}

/* 10 - OFFER-CREATE-03: تنسيق مستقل لشاشة إدخال العروض */
#createPanel{display:block;min-width:0}#createPanel .create-section-title{font-size:18px;margin:24px 0 12px;color:#173c34}#createPanel .create-header-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:14px}#createPanel .create-time-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:14px;margin-top:14px}#createPanel .create-picker{border-top:1px solid #dce3eb;margin-top:22px;padding-top:4px}#createPanel .create-field{display:flex;flex-direction:column;gap:6px;min-width:0}#createPanel .create-field span{display:block}#createPanel .create-field input,#createPanel .create-field select{display:block;width:100%;min-width:0;min-height:43px}#createPanel .create-results{display:grid;gap:0;max-height:320px;overflow:auto;border:1px solid #dce3eb;border-radius:10px;margin-top:10px}#createPanel .create-results:empty{display:none}#createPanel .create-match-row{display:flex;gap:12px;align-items:center;padding:10px 12px;border-bottom:1px solid #e5eaf0;min-width:0}#createPanel .create-match-row:last-child{border-bottom:0}#createPanel .create-thumb{width:45px;height:45px;flex:0 0 45px;object-fit:contain;border-radius:6px;background:#f5f7f9}#createPanel .create-match-info{flex:1;min-width:0;display:grid;gap:4px;overflow-wrap:anywhere}#createPanel small{display:block;font-size:12px;color:#64748b;margin-top:3px}#createPanel .create-history-button{white-space:nowrap}#createPanel .create-table-scroll{width:100%;overflow-x:auto;border:1px solid #dce3eb;border-radius:10px}#createPanel .create-items-table{min-width:850px;width:100%;white-space:normal}#createPanel .create-items-table td{vertical-align:middle}#createPanel .create-items-table input{width:120px;max-width:100%;min-height:40px;padding:8px;border:1px solid #cbd5e1;border-radius:7px}#createPanel .create-product-cell{display:flex;align-items:center;gap:8px;min-width:180px}#createPanel .create-product-cell div{overflow-wrap:anywhere}#createPanel>button.primary{margin-top:14px}dialog.create-history-dialog{width:min(760px,94vw);max-height:82dvh;border:1px solid #aebfc9;border-radius:12px;padding:20px;box-shadow:0 20px 60px #0004;color:#203047}dialog.create-history-dialog::backdrop{background:#102a2870}.create-dialog-head{display:flex;justify-content:space-between;gap:12px;align-items:center}.create-history-dialog .create-table-scroll{overflow:auto;max-height:55dvh;margin:12px 0}@media(max-width:750px){#createPanel .create-header-grid,#createPanel .create-time-grid{grid-template-columns:1fr}#createPanel .create-match-row{flex-wrap:wrap}#createPanel .create-match-info{flex-basis:calc(100% - 65px)}#createPanel .create-history-button{flex:1}#createPanel .create-match-row>.primary{flex:1}}

/* 11 - OFFER-CREATE-04: خانات الساعة والدقيقة والثانية مع AM/PM */
#createPanel .create-segmented-time{display:flex;align-items:center;gap:6px;direction:ltr;border:1px solid #cbd5e1;border-radius:9px;padding:5px 8px;background:#fff;max-width:100%}#createPanel .create-segmented-time input{width:3.4em;min-width:0;max-width:3.4em;text-align:center;min-height:34px;padding:5px 2px;border:1px solid transparent;font-variant-numeric:tabular-nums}#createPanel .create-segmented-time input:focus{border-color:#146c43;outline:2px solid #146c4333}#createPanel .create-segmented-time select{width:5em;min-width:5em;min-height:34px;padding:4px;border:1px solid #cbd5e1}#createPanel .create-time-colon{font-weight:700}#createPanel .create-segmented-time input::placeholder{color:#718096}

/* 12 - UI-02A: إبقاء النوافذ فوق المحتوى وأسفل شريط إدارة النوافذ */
.work-window { z-index:10010; max-height:calc(100dvh - var(--header-height) - 64px); }
.work-window.maximized { inset:var(--header-height) 0 58px !important; }
.window-tabs { z-index:20000; }
#offerTab02 { display:block; min-width:0; }
#offerTab02[hidden] { display:none !important; }
#offerTab02 .detail-list { margin:18px 0; }
#offerTab02 .scroll { max-width:100%; }
@media(max-width:750px){.work-window,.work-window.maximized{inset:var(--header-height) 0 58px !important;max-height:none;} }

/* 13 - UI-02A-FIX-02: حرية تحريك النوافذ داخل كامل مساحة صفحة المتصفح */
.work-window { max-height:100dvh !important; z-index:30010; }
.work-window.maximized { inset:0 !important; max-height:100dvh !important; }
.window-tabs { z-index:20000; }
/* نافذة تفاصيل العرض المستقلة تستغل المساحة دون هيدر أو سايدبار أو فوتر */
body.offer-detail-tab-02 > header, body.offer-detail-tab-02 #sidebar, body.offer-detail-tab-02 > footer { display:none !important; }
body.offer-detail-tab-02 #app { display:block !important; }
body.offer-detail-tab-02 #app .content { width:100%;max-width:none;min-height:100dvh;padding:18px; }
body.offer-detail-tab-02 #heading, body.offer-detail-tab-02 #subtitle, body.offer-detail-tab-02 #readStatus, body.offer-detail-tab-02 #app .toolbar:has(#refresh) { display:none !important; }
body.offer-detail-tab-02 #offerTab02 { max-width:none;width:100%; }
#offerTab02 .product-card-action-02 { display:inline-block;white-space:nowrap;padding:9px 14px;border:1px solid #b8cbd4;border-radius:8px;background:#f2f7f6;color:#173c34;font-weight:600;cursor:pointer; }
#offerTab02 .product-card-action-02:hover { background:#e1efeb; }
@media(max-width:750px){.work-window,.work-window.maximized{inset:0 !important;max-height:100dvh !important;}}

/* UI-02B-06: نافذة بطاقة الصنف فوق الشريط السفلي دون حصر الحركة به */
.window-tabs {z-index:20000 !important;}
.work-window {z-index:30010;}
.draft-edit-overlay-02b {position:fixed;inset:0;z-index:29000;background:#14232b80;display:grid;place-items:center;padding:12px;}
.draft-edit-box-02b {background:white;color:#203047;border-radius:12px;padding:20px;width:min(960px,98vw);max-height:95dvh;overflow:auto;box-shadow:0 15px 45px #0005;}
.draft-edit-form-02b {display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:12px;margin:16px 0;}
.draft-edit-field-02b {display:grid;gap:6px;}
.draft-edit-field-02b input,.draft-edit-field-02b select,.draft-edit-item-02b input,.draft-edit-matches-02b input {width:100%;padding:9px;border:1px solid #c7d2dd;border-radius:6px;}
.draft-edit-item-02b {display:flex;align-items:center;gap:12px;flex-wrap:wrap;border-bottom:1px solid #e3e9ef;padding:12px 0;}
.draft-edit-item-02b label {display:grid;gap:4px;width:145px;}
.draft-edit-box-02b>input[type=search] {width:100%;padding:12px;margin-top:12px;}

/* UI-02B-FIX-01: محاذاة الصنف والأسعار في صف واحد مع اقتراحات اختيار الصنف */
.draft-edit-item-02b{display:grid;grid-template-columns:minmax(230px,2.4fr) minmax(105px,1fr) minmax(135px,1fr) minmax(135px,1fr) auto;gap:12px;align-items:end;flex-wrap:initial;overflow:visible}
.draft-edit-item-02b label{width:auto;min-width:0;display:grid;gap:6px;position:relative}
.draft-edit-item-02b label>span,.draft-edit-card-cell-02b>span,.draft-edit-remove-cell-02b>span{min-height:22px;display:block;font-size:.88rem}
.draft-edit-item-02b input,.draft-edit-item-02b button{min-height:42px;box-sizing:border-box}
.draft-edit-product-options-02b{position:absolute;top:100%;inset-inline:0;z-index:31000;background:white;max-height:210px;overflow:auto;border:1px solid #c7d2dd;box-shadow:0 8px 20px #0002;border-radius:6px}
.draft-edit-product-options-02b:empty{display:none}
.draft-edit-product-options-02b button{width:100%;text-align:start;display:block;border:0;background:white;padding:8px;min-height:36px;white-space:normal}
.draft-edit-product-options-02b button:hover{background:#eaf2f7}
.draft-edit-card-cell-02b,.draft-edit-remove-cell-02b{display:grid;gap:6px;align-content:end}
@media(max-width:760px){.draft-edit-item-02b{grid-template-columns:repeat(2,minmax(0,1fr))}.draft-edit-product-field-02b{grid-column:1/-1}}

/* UI-02B-FIX-02: فصل رمز الصنف عن اسمه ومحاذاة الحقول */
.draft-edit-item-02b{grid-template-columns:minmax(160px,1.4fr) minmax(180px,1.7fr) minmax(110px,1fr) minmax(105px,.9fr) minmax(105px,.9fr) auto;align-items:end}
.draft-edit-name-field-02b input[readonly],.draft-edit-price-field-02b input[readonly]{background:#f0f3f7;color:#314356;cursor:default}
@media(max-width:900px){.draft-edit-item-02b{grid-template-columns:repeat(2,minmax(0,1fr))}.draft-edit-product-field-02b,.draft-edit-name-field-02b{grid-column:auto}}

/* FIX02 — شريط أفقي مستقل عن التمرير الرأسي لبطاقة الصنف */
.catalog-scroll-rail-02{flex:0 0 22px;overflow-x:scroll;overflow-y:hidden;margin:0 18px 8px;min-width:0;scrollbar-width:auto;scrollbar-color:#8797a5 #edf2f6}
.catalog-scroll-rail-02>div{height:1px}
.catalog-scroll-rail-02::-webkit-scrollbar{height:14px}
.catalog-scroll-rail-02::-webkit-scrollbar-thumb{background:#8797a5;border-radius:7px}
.work-window:has(.catalog-scroll-rail-02) .window-content{min-height:0;min-width:0}
