/* لوحة — أنماط التطبيق فوق tokens.css.
   القشرة: شريط جانبي يمين (RTL) + مساحة عمل. كل عنصر grid/flex متداخل يحمل
   min-width:0 — درس «المفقعة». الفحص البصري على 390 و1440 قبل أي تسليم. */

body { min-height: 100dvh; }

/* ═══ القشرة ═══ */
.frame { display: grid; grid-template-columns: 244px minmax(0, 1fr); min-height: 100dvh; }
.side {
  border-inline-end: 1px solid var(--line-2);
  padding: 24px 16px 18px;
  display: flex; flex-direction: column; gap: 3px;
  background: var(--bg-2);
  position: sticky; top: 0; height: 100dvh; overflow-y: auto;
}
.logo { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; min-width: 0; }
.logo .mark {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; flex: none;
  background: linear-gradient(145deg, var(--mint), var(--primary)); color: var(--on-primary);
  font-weight: 700; font-size: 17px;
}
.logo .l-name { min-width: 0; }
.logo .l-name b { font-size: 16.5px; display: block; line-height: 1.4; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logo .l-name small { display: block; color: var(--text-3); font-size: 11.5px; }

.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 10px 13px; border-radius: 11px;
  color: var(--text-2); font-size: 14.5px; font-weight: 600; cursor: pointer;
  border: 0; background: none; font-family: inherit; text-align: start; width: 100%;
  transition: background 0.15s, color 0.15s; min-width: 0;
}
.nav-item:hover { background: var(--surface-2); }
.nav-item.on { background: var(--mint-glow); color: var(--primary-ink); }
.nav-item svg { width: 18px; height: 18px; flex: none; }
.nav-item .n-count {
  margin-inline-start: auto; font-size: 11.5px; color: var(--text-3);
  font-variant-numeric: tabular-nums; direction: ltr;
}
.side-sep { border: 0; border-top: 1px solid var(--line-2); margin: 12px 4px; }

.side-foot { margin-top: auto; display: grid; gap: 8px; padding-top: 14px; }
.team-box {
  border: 1px dashed var(--line); border-radius: 13px; padding: 12px 13px;
  font-size: 12.5px; color: var(--text-2); line-height: 1.7; cursor: pointer;
  background: none; font-family: inherit; text-align: start;
  transition: border-color 0.2s;
}
.team-box:hover { border-color: var(--primary); }
.team-box b { color: var(--text); display: block; }
.from-bithrah {
  display: flex; align-items: center; gap: 8px; color: var(--text-3); font-size: 12.5px;
  text-decoration: none; padding: 6px 4px;
}
.from-bithrah:hover { color: var(--text-2); }
.from-bithrah img { flex: none; filter: drop-shadow(0 4px 12px rgba(0, 212, 184, 0.25)); }

/* ═══ مساحة العمل ═══ */
.mainc { padding: 24px 32px 60px; max-width: 1120px; width: 100%; margin: 0 auto; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; min-width: 0; }
.topbar h1 { font-size: 24px; font-weight: 700; line-height: 1.4; }
.born {
  font-size: 12.5px; color: var(--text-2); background: var(--glass); border: 1px solid var(--line-2);
  border-radius: 999px; padding: 5px 14px; line-height: 1.7;
  max-width: 46ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
}
.born b { color: var(--gold); font-weight: 600; }
.top-actions { margin-inline-start: auto; display: flex; gap: 8px; align-items: center; }

.btn {
  border: 0; cursor: pointer; font-family: inherit; text-align: center;
  font-size: 14.5px; font-weight: 700; border-radius: 999px; padding: 11px 20px;
  transition: transform 0.15s, box-shadow 0.2s, border-color 0.2s;
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
}
.btn svg { width: 16px; height: 16px; }
.btn.primary {
  background: linear-gradient(160deg, var(--mint), var(--primary)); color: var(--on-primary);
  box-shadow: 0 8px 22px var(--mint-glow);
}
.btn.primary:hover { transform: translateY(-1px); }
.btn.primary:active { transform: scale(0.985); }
.btn.ghost { background: var(--surface); border: 1px solid var(--line); color: var(--text); }
.btn.ghost:hover { border-color: var(--text-3); }
.btn.quiet { background: none; color: var(--text-2); padding: 8px 12px; }
.btn.quiet:hover { color: var(--text); }
.btn.danger { background: none; border: 1px solid var(--line); color: var(--danger); }
.btn.small { font-size: 13px; padding: 7px 14px; }
.btn:disabled { opacity: 0.55; cursor: default; transform: none; }

.icon-btn {
  border: 0; background: none; cursor: pointer; color: var(--text-3); padding: 6px;
  border-radius: 9px; display: grid; place-items: center; transition: color 0.15s, background 0.15s;
}
.icon-btn:hover { color: var(--text); background: var(--surface-2); }
.icon-btn.danger:hover { color: var(--danger); }
.icon-btn svg { width: 17px; height: 17px; }

/* ═══ المؤشرات ═══ */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 13px; margin-bottom: 15px; }
.kpi {
  background: var(--glass); border: 1px solid var(--line-2); border-radius: 18px; padding: 15px 18px;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); min-width: 0;
  animation: rise 0.5s cubic-bezier(0.2, 0.7, 0.2, 1) both;
  animation-delay: calc(var(--d, 0) * 60ms);
}
.kpi .k-label { color: var(--text-2); font-size: 12.5px; }
.kpi .k-value {
  font-size: 26px; font-weight: 700; line-height: 1.5;
  font-variant-numeric: tabular-nums; direction: ltr; text-align: right;
  transition: color 0.3s;
}
.kpi .k-value small { font-size: 12.5px; color: var(--text-2); font-weight: 400; }
.kpi .k-value.bump { color: var(--primary); }
.kpi:first-child .k-value { color: var(--gold); }
.kpi:first-child .k-value.bump { color: var(--primary); }
.kpi .k-sub { font-size: 11.5px; color: var(--text-3); }

/* ═══ الألواح والرسوم ═══ */
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 13px; margin-bottom: 15px; }
.panel {
  background: var(--glass); border: 1px solid var(--line-2); border-radius: 18px; padding: 18px 20px;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); min-width: 0;
  animation: rise 0.55s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
.panel h2 { font-size: 15px; font-weight: 700; margin-bottom: 13px; }
.panel .p-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; min-width: 0; }
.panel .p-head h2 { margin: 0; }

.bars { display: flex; align-items: flex-end; gap: 9px; height: 150px; padding-top: 6px; min-width: 0; }
.bar { flex: 1; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 6px; min-width: 0; }
.bar i {
  width: 100%; border-radius: 8px 8px 3px 3px; min-height: 2px;
  background: linear-gradient(180deg, var(--mint), var(--primary));
  opacity: 0.85; transition: height 0.5s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.bar.hot i { opacity: 1; box-shadow: 0 0 18px var(--mint-glow); }
.bar span { font-size: 10.5px; color: var(--text-3); white-space: nowrap; overflow: hidden; max-width: 100%; text-overflow: ellipsis; }
.bar b { font-size: 11px; font-variant-numeric: tabular-nums; direction: ltr; color: var(--text-2); font-weight: 600; }

/* ═══ شرائح الحالة والعدادات ═══ */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.chip {
  font-size: 12.5px; font-weight: 700; border-radius: 999px; padding: 5px 14px;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--text-2);
  cursor: pointer; font-family: inherit; transition: border-color 0.15s, background 0.15s;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip .c-n { font-variant-numeric: tabular-nums; direction: ltr; font-size: 11.5px; color: var(--text-3); }
.chip:hover { border-color: var(--text-3); }
.chip.on { background: var(--mint-glow); color: var(--primary-ink); border-color: var(--primary); }
.chip.s0 { color: var(--gold); }
.chip.s1 { color: var(--primary-ink); }

.st {
  font-size: 11.5px; font-weight: 700; border-radius: 999px; padding: 3px 11px; white-space: nowrap;
  background: var(--surface-2); color: var(--text-2); border: 0; cursor: pointer; font-family: inherit;
}
.st.k0 { background: var(--gold-glow); color: var(--gold); }
.st.k1 { background: var(--mint-glow); color: var(--primary-ink); }
.st.k2 { background: var(--surface-2); color: var(--text-2); }

/* ═══ الجداول ═══ */
.table-wrap { overflow-x: auto; min-width: 0; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data th { text-align: right; color: var(--text-3); font-weight: 600; font-size: 12px; padding: 0 8px 10px; white-space: nowrap; }
.data td { padding: 10px 8px; border-top: 1px solid var(--line-3); max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; }
.data td.acts .icon-btn { display: inline-grid; vertical-align: middle; }
.data td.num { font-variant-numeric: tabular-nums; direction: ltr; text-align: right; font-weight: 700; }
.data td.acts { white-space: nowrap; width: 1%; }
.data tr.row-new td { animation: flash 1.2s ease-out; }
@keyframes flash { from { background: var(--mint-glow); } to { background: transparent; } }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 13px; flex-wrap: wrap; min-width: 0; }
.search {
  display: flex; align-items: center; gap: 8px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 999px; padding: 8px 15px; min-width: 0; flex: 1;
  max-width: 320px;
}
.search svg { width: 15px; height: 15px; color: var(--text-3); flex: none; }
.search input {
  border: 0; background: none; color: var(--text); font-family: inherit; font-size: 14px;
  outline: none; width: 100%; min-width: 0;
}

.empty { color: var(--text-2); text-align: center; padding: 34px 10px; font-size: 14.5px; line-height: 1.8; }
.empty b { display: block; font-size: 16px; color: var(--text); }

/* ═══ النماذج والمودال ═══ */
.overlay {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 18px;
  background: color-mix(in srgb, var(--bg) 62%, transparent);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  animation: fade 0.2s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r);
  box-shadow: var(--shadow); width: 100%; max-width: 460px; max-height: 88dvh;
  display: flex; flex-direction: column;
  animation: rise 0.3s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.modal.wide { max-width: 640px; }
.m-head { display: flex; align-items: center; gap: 10px; padding: 18px 22px 0; }
.m-head h2 { font-size: 17.5px; font-weight: 700; line-height: 1.4; }
.m-head .icon-btn { margin-inline-start: auto; }
.m-body { padding: 14px 22px 22px; overflow-y: auto; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 13px; min-width: 0; }
.field > span { font-size: 13px; color: var(--text-2); font-weight: 600; }
.field > span .req { color: var(--danger); }
.field input, .field select, .field textarea {
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
  font-family: inherit; font-size: 16px; border-radius: var(--r-sm); padding: 12px 14px;
  appearance: none; min-width: 0; width: 100%;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.field textarea { min-height: 84px; resize: vertical; line-height: 1.6; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--mint-glow);
}
.field input[inputmode='decimal'], .field input[type='date'] {
  direction: ltr; text-align: left; font-variant-numeric: tabular-nums;
}
.field.check { flex-direction: row; align-items: center; gap: 10px; }
.field.check input { width: 19px; height: 19px; accent-color: var(--primary); }
.field.check > span { font-size: 14.5px; color: var(--text); }
.field-error { color: var(--danger); font-size: 13px; line-height: 1.7; margin: 2px 0 8px; }

/* منسدلة البحث لعلاقات ref */
.refbox { position: relative; min-width: 0; }
.ref-list {
  position: absolute; top: calc(100% + 4px); right: 0; left: 0; z-index: 5;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm);
  box-shadow: var(--shadow); max-height: 210px; overflow-y: auto; padding: 5px;
}
.ref-item {
  padding: 9px 12px; border-radius: 9px; cursor: pointer; font-size: 14.5px;
  border: 0; background: none; font-family: inherit; width: 100%; text-align: start; color: var(--text);
}
.ref-item:hover, .ref-item.hl { background: var(--mint-glow); }
.ref-empty { padding: 10px 12px; color: var(--text-3); font-size: 13px; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 14px; }
.form-grid .field.wide { grid-column: 1 / -1; }

/* ═══ تنبيهات ═══ */
.toast {
  position: fixed; bottom: 22px; inset-inline-start: 50%; translate: 50% 0; z-index: 60;
  background: var(--surface); color: var(--text); border: 1px solid var(--line);
  border-radius: 999px; padding: 11px 22px; font-size: 14px; font-weight: 600;
  box-shadow: var(--shadow); animation: rise 0.3s cubic-bezier(0.2, 0.7, 0.2, 1);
  display: flex; align-items: center; gap: 9px; max-width: min(92vw, 480px);
}
.toast.ok svg { color: var(--primary); }
.toast.err { border-color: var(--danger); }
.toast svg { width: 16px; height: 16px; flex: none; }

.banner {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--gold-glow); border: 1px solid color-mix(in srgb, var(--gold) 40%, transparent);
  border-radius: var(--r-sm); padding: 11px 16px; margin-bottom: 16px; font-size: 13.5px; line-height: 1.7;
}
.banner b { color: var(--gold); }
.banner .btn { margin-inline-start: auto; }

.copybox {
  background: var(--bg); border: 1px dashed var(--line); border-radius: var(--r-sm);
  padding: 12px 14px; font-size: 13px; color: var(--text-2); line-height: 1.8;
  word-break: break-all; margin: 8px 0; direction: ltr; text-align: left;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

/* ═══ الجوال ═══ */
@media (max-width: 900px) {
  .frame { grid-template-columns: minmax(0, 1fr); }
  .side {
    position: sticky; top: 0; z-index: 30; height: auto; overflow: visible;
    flex-direction: row; align-items: center; gap: 6px;
    padding: 10px 14px; border-inline-end: 0; border-bottom: 1px solid var(--line-2);
    overflow-x: auto; scrollbar-width: none;
  }
  .side::-webkit-scrollbar { display: none; }
  .logo { margin: 0; flex: none; }
  .logo .l-name small { display: none; }
  .nav-item { width: auto; flex: none; padding: 8px 13px; font-size: 13.5px; }
  .nav-item .n-count { display: none; }
  .side-sep, .side-foot { display: none; }
  .mainc { padding: 18px 16px 80px; }
  .topbar h1 { font-size: 20px; }
  .born { max-width: 100%; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi .k-value { font-size: 22px; }
  .bars { height: 120px; }
  .mob-team { display: block; }
}
@media (min-width: 900.1px) { .mob-team { display: none; } }

/* ═══ الطباعة (تقرير A4) ═══ */
@media print {
  .side, .top-actions, .toolbar, .chips, .banner, .data td.acts, .data th.acts { display: none !important; }
  .frame { grid-template-columns: 1fr; }
  body { background: #fff; }
  .mainc { padding: 0; max-width: none; }
  .kpi, .panel { border: 1px solid #ddd; box-shadow: none; break-inside: avoid; }
  .data td { max-width: none; white-space: normal; }
}
