:root {
  --background: #f7f8f5;
  --surface: #ffffff;
  --foreground: #1c2318;
  --muted: #6b7566;
  --border: #e3e6dd;
  --brand: #3f6b3a;
  --brand-hover: #345a30;
  --brand-soft: #e8f0e4;
  --danger: #b3432f;
  --danger-soft: #fbe9e5;
  --warn: #a3720a;
  --warn-soft: #fbf0d9;

  --chart-grid: #e1e0d9;
  --chart-axis: #c3c2b7;
  --chart-muted: #898781;
  --chart-series-1: #2a78d6;
  --chart-series-2: #eb6834;
  --status-good-text: #006300;
  --status-critical: #d03b3b;
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: #14170f;
    --surface: #1c2118;
    --foreground: #ecefe7;
    --muted: #9aa393;
    --border: #2c3225;
    --brand: #6fa565;
    --brand-hover: #7fb474;
    --brand-soft: #223022;
    --danger: #e0705a;
    --danger-soft: #331d18;
    --warn: #d9a53a;
    --warn-soft: #332b14;

    --chart-grid: #2c2c2a;
    --chart-axis: #383835;
    --chart-muted: #898781;
    --chart-series-1: #3987e5;
    --chart-series-2: #d95926;
    --status-good-text: #0ca30c;
    --status-critical: #e66767;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--background);
  color: var(--foreground);
  font-family: "Cairo", "Segoe UI", Tahoma, sans-serif;
  font-size: 14px;
}
a { color: inherit; text-decoration: none; }
table { border-collapse: collapse; width: 100%; }

.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--surface);
  border-inline-end: 1px solid var(--border);
  padding: 16px;
  display: flex;
  flex-direction: column;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; margin-bottom: 24px; }
.sidebar-brand .logo { width: 42px; height: 42px; border-radius: 8px; background: #fff; display: flex; align-items: center; justify-content: center; overflow: hidden; flex-shrink: 0; }
.sidebar-brand .logo img { width: 100%; height: 100%; object-fit: contain; }
.sidebar-brand .title { font-size: 13px; font-weight: 700; }
.sidebar-brand .subtitle { font-size: 11px; color: var(--muted); }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px; font-size: 14px; font-weight: 500; color: var(--muted);
}
.nav a:hover { background: color-mix(in srgb, var(--brand-soft) 50%, transparent); color: var(--foreground); }
.nav a.active { background: var(--brand-soft); color: var(--brand); }

.nav-group summary {
  display: flex; align-items: center; gap: 10px; cursor: pointer; list-style: none;
  padding: 10px 12px; border-radius: 8px; font-size: 14px; font-weight: 500; color: var(--muted);
}
.nav-group summary::-webkit-details-marker { display: none; }
.nav-group summary:hover { background: color-mix(in srgb, var(--brand-soft) 50%, transparent); color: var(--foreground); }
.nav-group summary .nav-caret { margin-inline-start: auto; font-size: 11px; transition: transform .15s; }
.nav-group[open] summary .nav-caret { transform: rotate(90deg); }
.nav-group.has-active summary { color: var(--brand); font-weight: 700; }
.nav-sub { display: flex; flex-direction: column; gap: 2px; margin-inline-start: 14px; padding-inline-start: 12px; border-inline-start: 2px solid var(--border); margin-top: 2px; }
.nav-sub a {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 8px; font-size: 13px; font-weight: 500; color: var(--muted);
}
.nav-sub a:hover { background: color-mix(in srgb, var(--brand-soft) 50%, transparent); color: var(--foreground); }
.nav-sub a.active { background: var(--brand-soft); color: var(--brand); }

.sidebar-footer { margin-top: auto; padding-top: 16px; display: flex; flex-direction: column; gap: 12px; }
.lang-switch { display: flex; gap: 4px; background: var(--background); border-radius: 8px; padding: 4px; }
.lang-switch a { flex: 1; text-align: center; padding: 6px 0; border-radius: 6px; font-size: 12px; font-weight: 600; color: var(--muted); }
.lang-switch a.active { background: var(--brand); color: #fff; }
.user-card { background: var(--background); border-radius: 8px; padding: 10px 12px; }
.user-card .name { font-size: 14px; font-weight: 500; }
.user-card .role { font-size: 12px; color: var(--muted); }

.btn { display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; padding: 10px 16px; font-size: 14px; font-weight: 600; cursor: pointer; border: none; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-hover); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--muted); }
.btn-outline:hover { color: var(--foreground); }
.btn-outline.danger:hover { border-color: var(--danger); color: var(--danger); }
.btn-block { width: 100%; }

.main { flex: 1; padding: 24px 28px; min-width: 0; }
.page-header { margin-bottom: 14px; }
.page-header h1 { font-size: 18px; font-weight: 700; margin: 0; }
.page-header p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.page-header-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 16px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* بطاقات إحصائية غنية (أيقونة + لون + تذييل) - كثافة مطابقة لمرجع Art.8 */
.stat-card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin-bottom: 12px; }
.stat-card {
  position: relative;
  min-height: 66px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--tone, var(--brand));
  border-radius: 12px;
  padding: 7px 9px 6px;
  overflow: hidden;
}
.stat-card-icon {
  position: absolute; top: 7px; inset-inline-end: 7px;
  width: 20px; height: 20px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--tone, var(--brand)) 16%, transparent);
  font-size: 11px;
}
.stat-card-label { font-size: 10px; color: var(--tone, var(--brand)); font-weight: 800; padding-inline-end: 26px; line-height: 1.25; min-height: 18px; display: flex; align-items: center; }
.stat-card-value { font-size: 15px; font-weight: 900; margin-top: 1px; letter-spacing: -0.2px; line-height: 1.1; }
.stat-card-foot { font-size: 9.5px; color: var(--tone, var(--brand)); font-weight: 700; margin-top: 4px; padding-top: 4px; border-top: 1px solid var(--border); }

/* بطاقات KPI بأيقونة ملوّنة ومؤشر اتجاه - صف المؤشرات العلوي بالداشبورد */
.kpi-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; margin-bottom: 14px; }
.kpi-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; display: block; text-decoration: none; color: inherit; }
.kpi-card-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.kpi-icon { width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 18px; background: color-mix(in srgb, var(--tone, var(--brand)) 16%, transparent); }
.kpi-delta { font-size: 11px; font-weight: 800; }
.kpi-value { font-size: 19px; font-weight: 900; line-height: 1.15; }
.kpi-label { font-size: 11.5px; color: var(--muted); margin-top: 2px; font-weight: 600; }
.kpi-foot { font-size: 10px; color: var(--muted); margin-top: 4px; }

/* إحصائية مصغّرة (شبكة 2×2) لألواح الملخصات التنفيذية */
.mini-stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mini-stat { display: block; text-decoration: none; color: inherit; border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; background: var(--background); }
.mini-stat-icon { font-size: 14px; color: var(--tone, var(--muted)); }
.mini-stat-value { font-size: 15px; font-weight: 800; margin-top: 3px; }
.mini-stat-label { font-size: 10.5px; color: var(--muted); margin-top: 1px; }

/* سجل نشاط مصغّر */
.activity-list { display: flex; flex-direction: column; }
.activity-row { display: grid; grid-template-columns: auto minmax(0,1fr) auto auto; gap: 10px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.activity-row:last-child { border-bottom: none; }
.activity-badge { padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; background: color-mix(in srgb, var(--tone, var(--brand)) 16%, transparent); color: var(--tone, var(--brand)); white-space: nowrap; }
.activity-title { font-weight: 600; color: var(--foreground); }
.activity-meta { font-size: 11px; color: var(--muted); margin-top: 1px; }
.activity-value { font-weight: 700; white-space: nowrap; }
.activity-time { font-size: 11px; color: var(--muted); white-space: nowrap; }
.panel-link { display: block; text-align: center; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); font-size: 12px; font-weight: 700; color: var(--brand); }
.panel-empty { text-align: center; color: var(--muted); font-size: 13px; padding: 24px 0; }

/* توزيع القيمة بنسب مئوية */
.dist-row { padding: 7px 0; border-bottom: 1px solid var(--border); }
.dist-row:last-child { border-bottom: none; }
.dist-row-head { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 5px; }
.dist-row-name { font-weight: 600; color: var(--foreground); }
.dist-row-value { font-weight: 700; color: var(--tone, var(--brand)); white-space: nowrap; }
.dist-bar-track { height: 6px; background: var(--background); border-radius: 999px; overflow: hidden; }
.dist-bar-fill { height: 100%; background: var(--tone, var(--brand)); border-radius: 999px; }
.dist-row-pct { font-size: 10px; color: var(--muted); margin-top: 3px; }

/* شرائح ملخصة أسفل الرسم البياني */
.chip-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 8px; }
.chip { border: 1px solid var(--border); border-radius: 10px; padding: 5px; text-align: center; }
.chip-label { font-size: 9.5px; color: var(--muted); }
.chip-value { font-size: 12.5px; font-weight: 800; color: var(--foreground); margin-top: 2px; }

/* شريط تنبيهات بشكل نقاط عد */
.alert-strip { display: flex; align-items: center; justify-content: space-between; border: 1px solid var(--border); border-radius: 10px; padding: 7px 12px; margin-bottom: 6px; font-size: 12.5px; font-weight: 700; background: var(--surface); }
.alert-strip:last-child { margin-bottom: 0; }
.alert-pill { min-width: 24px; height: 22px; padding: 0 6px; border-radius: 999px; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 12px; background: var(--brand-soft); color: var(--brand); }
.card-table { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }
.card-table-header { border-bottom: 1px solid var(--border); padding: 10px 16px; font-size: 13px; font-weight: 600; }
.coa-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.coa-tab {
  display: flex; align-items: center; gap: 8px; padding: 9px 16px; border-radius: 999px;
  border: 1.5px solid var(--border); background: var(--surface); color: var(--foreground);
  font-family: inherit; font-size: 13px; font-weight: 600; cursor: pointer; transition: background .15s, border-color .15s, color .15s;
}
.coa-tab:hover { border-color: var(--coa-tab-color, var(--brand)); }
.coa-tab .coa-tab-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--coa-tab-color, #64748b); flex-shrink: 0; }
.coa-tab .coa-tab-count { color: var(--muted); font-weight: 500; font-size: 12px; }
.coa-tab.active { background: var(--coa-tab-color, var(--brand)); border-color: var(--coa-tab-color, var(--brand)); color: #fff; }
.coa-tab.active .coa-tab-dot { background: #fff; }
.coa-tab.active .coa-tab-count { color: rgba(255,255,255,.85); }

table.data th { text-align: start; font-size: 12px; font-weight: 500; color: var(--muted); background: color-mix(in srgb, var(--background) 60%, transparent); padding: 9px 14px; border-bottom: 1px solid var(--border); }
table.data td { padding: 8px 14px; border-bottom: 1px solid var(--border); font-size: 13px; }
table.data tr:last-child td { border-bottom: none; }
table.data .empty { text-align: center; padding: 24px; color: var(--muted); }

.grid { display: grid; gap: 12px; align-items: start; }
.grid-stats { grid-template-columns: repeat(4, 1fr); }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-charts { grid-template-columns: 1.4fr 1fr; }
@media (max-width: 900px) { .grid-stats { grid-template-columns: repeat(2, 1fr); } .grid-charts, .grid-2 { grid-template-columns: 1fr; } }

.grid.dash-grid { align-items: stretch; }
.dash-grid .card { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.dash-grid .panel-link { margin-top: auto; }
.dash-grid .panel-body-split { display: flex; flex-direction: column; gap: 10px; }

.stat-tile { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 20px; }
.stat-tile .label { font-size: 13px; color: var(--muted); }
.stat-tile .value { font-size: 22px; font-weight: 700; margin-top: 8px; }
.stat-tile .delta { font-size: 12px; font-weight: 500; margin-top: 6px; }

.badge { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 500; }
.badge-good { background: var(--brand-soft); color: var(--brand); }
.badge-low { background: var(--danger-soft); color: var(--danger); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }

.expiry-alert-card { display: flex; flex-direction: column; gap: 0; }
.expiry-alert-row { display: grid; grid-template-columns: 1.6fr .9fr .9fr .7fr auto; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--border); font-size: 13px; }
.expiry-alert-row:first-of-type { border-top: none; }
.expiry-alert-row .name { font-weight: 500; }
.expiry-alert-row .muted { color: var(--muted); font-size: 12px; }
.expiry-alert-more { text-align: center; padding-top: 10px; font-size: 12px; }

.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 5px; }
.form-group input, .form-group select {
  width: 100%; border: 1px solid var(--border); background: var(--background);
  border-radius: 8px; padding: 9px 12px; font-size: 13px; color: var(--foreground); font-family: inherit;
}
.form-group input:focus, .form-group select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 20%, transparent); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.form-section { border-bottom: 1px solid var(--border); padding-bottom: 16px; margin-bottom: 16px; }
.form-section-title { margin: 0 0 12px; font-size: 13px; font-weight: 700; color: var(--brand); }

/* أربعة مربعات صفحة الأصناف: منحنى تدفق / دونات / حالة المخزون / الأصناف الأكثر مبيعاً */
.items-viz-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; align-items: stretch; }
.items-viz-grid .card { display: flex; flex-direction: column; min-height: 0; padding: 12px 14px; }

.flow-hit { cursor: crosshair; }
.flow-tooltip {
  position: fixed; z-index: 60; background: var(--foreground); color: var(--surface);
  border-radius: 8px; padding: 8px 10px; font-size: 11.5px; line-height: 1.6; white-space: pre-line;
  pointer-events: none; max-width: 240px; box-shadow: 0 6px 18px rgba(0,0,0,.2); opacity: 0; transition: opacity .1s;
}
.flow-tooltip.visible { opacity: 1; }

.donut-wrap { display: flex; align-items: center; gap: 18px; flex: 1; }
.donut-chart.chart-svg.chart-svg { flex: 0 0 auto; width: 120px; max-width: 120px; height: 120px; }
.donut-seg { cursor: pointer; transition: filter .15s, opacity .15s; }
.donut-seg:hover { filter: brightness(1.15); }
.donut-seg.dimmed { opacity: .3; }
.donut-legend { flex: 1; min-width: 0; }
.donut-legend-item { display: flex; align-items: center; gap: 8px; padding: 5px 0; font-size: 12px; cursor: pointer; border-bottom: 1px dashed var(--border); }
.donut-legend-item:last-child { border-bottom: none; }
.donut-legend-item .dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.donut-legend-item .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.donut-legend-item .pct { font-weight: 700; color: var(--muted); }
.donut-legend-item.dimmed { opacity: .35; }
.donut-reset { display: none; font-size: 11px; color: var(--brand); font-weight: 700; cursor: pointer; margin-top: 8px; text-align: center; }
.donut-reset.visible { display: block; }

.gauge-wrap { display: flex; flex-direction: column; align-items: center; flex: 1; justify-content: center; }
.gauge-chart { width: 100%; max-width: 180px; }
.gauge-caption { font-size: 12px; color: var(--muted); margin-top: -6px; }
.safety-critical { margin-top: 8px; width: 100%; }
.safety-critical-title { font-size: 11px; font-weight: 700; color: var(--muted); margin-bottom: 4px; }
.safety-critical-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 0; border-top: 1px dashed var(--border); font-size: 12px; }
.safety-critical-row .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.safety-order-btn { flex: 0 0 auto; font-size: 11px; font-weight: 700; color: #fff; background: var(--brand); border-radius: 999px; padding: 4px 10px; white-space: nowrap; }
.safety-order-btn:hover { background: var(--brand-hover); }
.safety-all-good { text-align: center; color: var(--brand); font-weight: 700; font-size: 13px; padding: 10px 0; }

.radar-chart { width: 100%; max-width: 210px; margin: 0 auto; display: block; }

/* شريط حالة المخزون الواضح (نفد/منخفض/جيد) - بديل مبسّط ومفهوم فوراً بدل عداد نصف دائري */
.stock-health-pct { font-size: 24px; font-weight: 900; color: var(--foreground); margin: 2px 0; }
.stock-health-bar { display: flex; width: 100%; height: 12px; border-radius: 999px; overflow: hidden; background: var(--background); margin: 6px 0 8px; }
.stock-health-seg { height: 100%; transition: width .2s; }
.stock-health-seg.good { background: var(--brand); }
.stock-health-seg.low { background: var(--warn); }
.stock-health-seg.out { background: var(--danger); }
.stock-health-legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--muted); margin-bottom: 0; }
.stock-health-legend b { color: var(--foreground); }
.stock-health-legend .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-inline-end: 5px; }
.stock-health-legend .dot.good { background: var(--brand); }
.stock-health-legend .dot.low { background: var(--warn); }
.stock-health-legend .dot.out { background: var(--danger); }

/* جدول صفوف استلام/سحب متعددة الأصناف: رأس واحد فقط، بدون تكرار التسميات في كل سطر */
.stock-in-head { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr 34px; gap: 10px; padding: 0 0 6px; }
.stock-in-head span { font-size: 12px; font-weight: 700; color: var(--muted); }
.stock-in-head span:last-child { visibility: hidden; }
.stock-in-row { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr 34px; gap: 10px; align-items: center; margin-bottom: 8px; }
.stock-in-row select, .stock-in-row input {
  width: 100%; border: 1px solid var(--border); background: var(--background);
  border-radius: 8px; padding: 9px 12px; font-size: 13px; color: var(--foreground); font-family: inherit; margin: 0;
}
.stock-in-row input:disabled { color: var(--muted); }
.stock-in-row-remove {
  width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  color: var(--danger); font-size: 15px; font-weight: 700; cursor: pointer; flex-shrink: 0;
}
.stock-in-row-remove:hover { background: var(--danger-soft); }
.stock-in-add-btn {
  background: none; border: 1px dashed var(--border); border-radius: 8px; padding: 9px 14px;
  color: var(--brand); font-weight: 700; font-size: 13px; cursor: pointer; margin-top: 4px;
}

/* قائمة بحث الأصناف القابلة للتصفية بدل القائمة المنسدلة العادية */
.si-item-combo { position: relative; }
.si-item-search {
  width: 100%; border: 1px solid var(--border); background: var(--background);
  border-radius: 8px; padding: 9px 12px; font-size: 13px; color: var(--foreground); font-family: inherit; margin: 0;
}
.si-item-dropdown {
  display: none; position: absolute; z-index: 40; top: calc(100% + 4px); inset-inline-start: 0; inset-inline-end: 0;
  max-height: 260px; overflow-y: auto; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.18); padding: 4px;
}
.si-item-dropdown.open { display: block; }
.si-item-option { padding: 8px 10px; border-radius: 7px; cursor: pointer; font-size: 13px; }
.si-item-option:hover { background: var(--brand-soft); }
.si-item-option small { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; }
.si-item-empty { padding: 10px; text-align: center; color: var(--muted); font-size: 12px; }
.stock-in-add-btn:hover { background: var(--brand-soft); }
.stock-in-grand-total {
  display: flex; justify-content: space-between; align-items: center; margin: 14px 0; padding: 12px 16px;
  background: var(--background); border-radius: 10px; font-weight: 800; font-size: 15px;
}
@media (max-width: 900px) {
  .stock-in-head { display: none; }
  .stock-in-row { grid-template-columns: 1fr !important; }
}

/* أزرار طباعة/تصدير التقارير */
.report-actions { display: flex; gap: 10px; margin-bottom: 16px; }

/* منتقي تقارير المخزون التفصيلية */
.report-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.report-tab {
  padding: 9px 16px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface);
  font-size: 13px; font-weight: 700; color: var(--muted); white-space: nowrap;
}
.report-tab:hover { border-color: var(--brand); color: var(--brand); }
.report-tab.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.report-filter-form { display: flex; align-items: end; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.report-filter-form .form-group { margin-bottom: 0; min-width: 180px; }
.report-empty-state { text-align: center; padding: 60px 20px; color: var(--muted); }
.report-empty-icon { font-size: 40px; margin-bottom: 10px; opacity: .6; }
.report-print-meta { display: none; }

/* شريط علوي وقائمة جانبية منسدلة للجوال */
.mobile-topbar { display: none; }
.sidebar-backdrop { display: none; }
.sidebar-close-btn { display: none; }

@media (max-width: 768px) {
  .mobile-topbar {
    display: flex; align-items: center; gap: 12px; padding: 12px 16px;
    background: var(--surface); border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 60;
  }
  .mobile-menu-btn {
    width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--border); background: var(--background);
    font-size: 18px; line-height: 1; cursor: pointer; flex-shrink: 0; color: var(--foreground);
  }
  .mobile-topbar-title { font-size: 15px; font-weight: 700; }

  .sidebar {
    display: none; position: fixed; top: 0; bottom: 0; inset-inline-start: 0; width: 260px; max-width: 82vw;
    z-index: 100; box-shadow: 0 0 28px rgba(0,0,0,.25); overflow-y: auto;
  }
  body.sidebar-open .sidebar { display: flex; }
  .sidebar-brand { position: relative; }
  .sidebar-close-btn {
    display: flex; align-items: center; justify-content: center; width: 28px; height: 28px;
    border-radius: 8px; border: 1px solid var(--border); background: var(--background); font-size: 16px;
    cursor: pointer; color: var(--muted); position: absolute; top: -4px; inset-inline-end: -4px;
  }
  .sidebar-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 90; }
  body.sidebar-open .sidebar-backdrop { display: block; }

  .main { padding: 14px; width: 100%; }
  .page-header-row { flex-wrap: wrap; }

  .grid-stats, .grid-charts, .grid-2, .grid.dash-grid { grid-template-columns: 1fr !important; }
  .form-row { grid-template-columns: 1fr !important; }
  .items-viz-grid { grid-template-columns: 1fr !important; }
  .chip-row { grid-template-columns: repeat(2, 1fr) !important; }
  .expiry-alert-row { grid-template-columns: 1fr !important; gap: 3px; }
  .info-grid { grid-template-columns: 1fr !important; }

  .card-table { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table.data { min-width: 620px; }

  .report-filter-form { flex-direction: column; align-items: stretch; }
  .report-filter-form .form-group { min-width: 0; }
  .report-tabs { gap: 8px; }

  .stat-card-grid { grid-template-columns: repeat(2, 1fr); }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .mini-stat-grid { grid-template-columns: 1fr; }
}

@media (max-width: 1100px) and (min-width: 769px) {
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
}

@media print {
  .mobile-topbar, .sidebar-backdrop { display: none !important; }
  .sidebar, .no-print, .lang-switch { display: none !important; }
  .app-shell { display: block !important; }
  .main { padding: 0 !important; width: 100% !important; }
  body { background: #fff !important; }
  .card, .card-table { border: 1px solid #ccc !important; box-shadow: none !important; break-inside: avoid; }
  .stat-card { break-inside: avoid; }
  .report-print-meta { display: block !important; margin-bottom: 16px; font-size: 12px; color: #444; border-bottom: 2px solid #000; padding-bottom: 10px; }
  .report-print-meta strong { font-size: 16px; display: block; margin-bottom: 4px; }
}

.alert { border-radius: 8px; padding: 10px 14px; font-size: 14px; margin-bottom: 16px; }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-success { background: var(--brand-soft); color: var(--brand); }
.alert-info { background: var(--background); color: var(--foreground); }

.receivables-alert-banner {
  display: flex; align-items: center; gap: 10px; text-decoration: none;
  background: var(--warn-soft); color: var(--warn); border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
  border-radius: 10px; padding: 10px 16px; margin-bottom: 16px; font-size: 13px; font-weight: 600;
}
.receivables-alert-banner.is-overdue { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.receivables-alert-banner .icon { font-size: 16px; }
.receivables-alert-banner .text { flex: 1; }
.receivables-alert-banner .cta { font-weight: 800; white-space: nowrap; }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 32px; }
.login-card .logo { width: 84px; height: 84px; border-radius: 12px; background: #fff; display: flex; align-items: center; justify-content: center; overflow: hidden; margin: 0 auto 12px; }
.login-card .logo img { width: 100%; height: 100%; object-fit: contain; }
.login-card h1 { text-align: center; font-size: 18px; margin: 0; }
.login-card .subtitle { text-align: center; color: var(--muted); font-size: 13px; margin: 4px 0 24px; }

.chart-svg { width: 100%; height: auto; direction: ltr; }
.chart-empty { color: var(--muted); text-align: center; padding: 32px 0; }
.chart-legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.chart-legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-inline-end: 6px; }

.text-muted { color: var(--muted); }
.text-link:hover { color: var(--brand); }

dialog { border: 1px solid var(--border); border-radius: 16px; padding: 0; background: var(--surface); color: var(--foreground); max-width: 420px; width: 100%; }
dialog::backdrop { background: rgba(0,0,0,0.4); }
dialog .dialog-body { padding: 24px; }
dialog h2 { margin: 0 0 16px; font-size: 16px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
