/* ============================================================
   ALGOSTEP — Dashboard
   ============================================================ */

:root {
  --ink:      #0A0611;
  --panel:    #120C1E;
  --panel-2:  #171029;
  --line:     rgba(255,255,255,.09);
  --line-soft:rgba(255,255,255,.05);
  --violet:   #7C4DFF;
  --violet-hi:#A67BFF;
  --violet-deep:#4A1FB8;
  --text:     #EFEAF8;
  --muted:    #A196B8;
  --dim:      #6F6488;
  --mint:     #6EE7A8;
  --amber:    #FFC46B;
  --rose:     #FF7A93;
  --sky:      #6BC7FF;
  --font-ar:  'IBM Plex Sans Arabic','Tajawal',system-ui,sans-serif;
  --font-mono:'JetBrains Mono',ui-monospace,monospace;
  --ease: cubic-bezier(.22,.61,.36,1);
}

*, *::before, *::after { box-sizing: border-box; }
html { touch-action: pan-x pan-y; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--ink); color: var(--text);
  font-family: var(--font-ar); font-size: 15px; line-height: 1.7;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
body::before {
  content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background: radial-gradient(800px 400px at 85% -10%, rgba(124,77,255,.16), transparent 60%);
}
.wrap { position: relative; z-index: 1; width: min(1320px, 100% - 36px); margin-inline: auto; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--violet-hi); outline-offset: 2px; border-radius: 6px; }
.mono { font-family: var(--font-mono); }
.muted { color: var(--muted); }

/* ---------- Top bar (صفحات فرعية فقط) ---------- */
.dash-top {
  position: sticky; top: 0; z-index: 50;
  background: rgba(10,6,17,.8); backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line-soft);
}
.dash-top-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 0; }
.dash-back {
  display: inline-flex; align-items: center; gap: 9px; padding: 9px 16px;
  border: 1px solid var(--line); border-radius: 999px; font-size: .86rem; transition: .2s;
}
.dash-back:hover { border-color: var(--violet); color: var(--violet-hi); }
.dash-title { font-weight: 800; font-size: 1.05rem; }
.rt-dot { display: inline-flex; align-items: center; gap: 7px; font-size: .74rem; color: var(--dim); font-family: var(--font-mono); }
.rt-dot i { width: 7px; height: 7px; border-radius: 50%; background: var(--mint); box-shadow: 0 0 0 0 rgba(110,231,168,.6); animation: pulse 2.2s infinite; }
.rt-dot.off i { background: var(--rose); animation: none; }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px rgba(110,231,168,0); } 100% { box-shadow: 0 0 0 0 rgba(110,231,168,0); } }

/* ---------- Hub (البوكسات) ---------- */
.hub { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 56px 0; }
.hub-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; flex-wrap: wrap; margin-bottom: 34px; }
.hub-head h1 { margin: 0; font-size: clamp(1.8rem,4vw,2.6rem); font-weight: 800; }
.hub-head .sub { color: var(--muted); font-size: .95rem; }
.hub-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 18px; }
.hub-box {
  position: relative; display: flex; flex-direction: column; gap: 12px;
  padding: 28px 26px; min-height: 176px;
  background: linear-gradient(160deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line); border-radius: 22px;
  transition: transform .22s var(--ease), border-color .22s, box-shadow .3s;
}
.hub-box:hover { transform: translateY(-4px); border-color: rgba(124,77,255,.5); box-shadow: 0 24px 50px -28px rgba(124,77,255,.55); }
.hub-box .ic { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; background: rgba(124,77,255,.14); color: var(--violet-hi); font-size: 1.1rem; }
.hub-box h2 { margin: 0; font-size: 1.12rem; font-weight: 800; }
.hub-box p { margin: 0; color: var(--muted); font-size: .86rem; }
.hub-box .n { margin-top: auto; font-family: var(--font-mono); font-size: 1.5rem; font-weight: 700; }
.hub-badge {
  position: absolute; top: 18px; inset-inline-end: 18px; min-width: 26px; height: 26px; padding: 0 8px;
  border-radius: 999px; background: var(--rose); color: #2A0410; font-weight: 800; font-size: .78rem;
  display: grid; place-items: center; box-shadow: 0 0 0 4px rgba(255,122,147,.14);
}
.hub-badge.hide { display: none; }
.hub-foot { margin-top: 30px; display: flex; justify-content: space-between; gap: 14px; flex-wrap: wrap; font-size: .82rem; color: var(--dim); }

/* ---------- Cards / panels ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 24px; min-width: 0; overflow: hidden; }
.panel + .panel { margin-top: 18px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.panel-head h3 { margin: 0; font-size: 1.02rem; font-weight: 800; }
.page { padding: 28px 0 70px; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px,1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 20px; }
.kpi .k { font-size: .8rem; color: var(--dim); }
.kpi .v { font-family: var(--font-mono); font-size: 1.6rem; font-weight: 700; }
.kpi .v small { font-size: .8rem; color: var(--muted); }

.grid-2 { display: grid; grid-template-columns: 1.5fr 1fr; gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3,1fr); gap: 18px; }
.grid-2 > *, .grid-3 > * { min-width: 0; }

/* ===== حاوية الرسوم البيانية — تمنع تمدد الـ canvas اللانهائي ===== */
.chart-box { position: relative; width: 100%; height: 260px; }
.chart-box.tall { height: 300px; }
.chart-box > canvas { display: block; width: 100% !important; height: 100% !important; }

/* ---------- Forms ---------- */
.f-label { display: block; font-size: .84rem; font-weight: 600; margin-bottom: 7px; }
.f-input, .f-select, .f-area {
  width: 100%; padding: 11px 15px; border-radius: 12px;
  background: rgba(255,255,255,.04); border: 1px solid var(--line);
  color: var(--text); font: inherit; font-size: .92rem; transition: .18s;
}
.f-area { min-height: 96px; resize: vertical; }
.f-input:focus, .f-select:focus, .f-area:focus { outline: none; border-color: var(--violet); box-shadow: 0 0 0 3px rgba(124,77,255,.16); }
.f-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px,1fr)); gap: 14px; }
.f-group { margin-bottom: 15px; }
.f-hint { font-size: .76rem; color: var(--dim); margin-top: 5px; }
option { background: #171029; color: var(--text); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 20px; border-radius: 999px; border: 1px solid transparent;
  font: inherit; font-size: .88rem; font-weight: 700; cursor: pointer; transition: .18s var(--ease);
}
.btn:active { transform: scale(.97); }
.btn-primary { background: linear-gradient(135deg, var(--violet), var(--violet-deep)); color: #fff; box-shadow: 0 10px 26px -12px rgba(124,77,255,.7); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn-ghost:hover { border-color: var(--violet); color: var(--violet-hi); }
.btn-danger { background: rgba(255,122,147,.12); color: var(--rose); border-color: rgba(255,122,147,.3); }
.btn-mint { background: rgba(110,231,168,.12); color: var(--mint); border-color: rgba(110,231,168,.3); }
.btn-sm { padding: 7px 14px; font-size: .8rem; }
.btn-icon { width: 34px; height: 34px; padding: 0; border-radius: 11px; }
.btn[disabled] { opacity: .45; pointer-events: none; }

/* ---------- Tables ---------- */
.tbl-wrap { overflow-x: auto; border-radius: 16px; border: 1px solid var(--line); }
table.tbl { width: 100%; border-collapse: collapse; min-width: 760px; }
table.tbl th, table.tbl td { padding: 13px 15px; text-align: start; border-bottom: 1px solid var(--line-soft); font-size: .88rem; vertical-align: middle; }
table.tbl th { background: rgba(255,255,255,.03); color: var(--dim); font-size: .78rem; font-weight: 600; position: sticky; top: 0; }
table.tbl tbody tr { transition: background .16s; }
table.tbl tbody tr:hover { background: rgba(124,77,255,.05); }
table.tbl tbody tr:last-child td { border-bottom: 0; }
table.tbl tr.is-new { box-shadow: inset 3px 0 0 var(--violet); }
.row-actions { display: flex; gap: 6px; flex-wrap: nowrap; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 999px; font-size: .75rem; font-weight: 700; white-space: nowrap; }
.pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-new       { background: rgba(107,199,255,.12); color: var(--sky); }
.pill-contacted { background: rgba(166,123,255,.14); color: var(--violet-hi); }
.pill-meeting   { background: rgba(255,196,107,.13); color: var(--amber); }
.pill-accepted  { background: rgba(110,231,168,.13); color: var(--mint); }
.pill-rejected  { background: rgba(255,122,147,.11); color: var(--rose); }
.pill-open      { background: rgba(110,231,168,.13); color: var(--mint); }
.pill-soon      { background: rgba(255,196,107,.13); color: var(--amber); }
.pill-closed    { background: rgba(255,122,147,.11); color: var(--rose); }
.pill-muted     { background: rgba(255,255,255,.06); color: var(--muted); }

.avatar { width: 38px; height: 38px; border-radius: 12px; object-fit: cover; background: linear-gradient(135deg, var(--violet-deep), #1B1230); display: grid; place-items: center; font-family: var(--font-mono); font-size: .9rem; color: #fff; flex: none; }
.who { display: flex; align-items: center; gap: 11px; }
.who .nm { font-weight: 700; font-size: .9rem; }
.who .em { font-size: .76rem; color: var(--dim); font-family: var(--font-mono); }

/* ---------- Filters bar ---------- */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.filters .f-group { margin: 0; min-width: 150px; flex: 1 1 150px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.chip { padding: 7px 15px; border-radius: 999px; border: 1px solid var(--line); font-size: .8rem; color: var(--muted); transition: .18s; }
.chip:hover { border-color: var(--violet); color: var(--violet-hi); }
.chip.active { background: rgba(124,77,255,.16); border-color: var(--violet); color: #fff; }
.chip .n { font-family: var(--font-mono); opacity: .7; margin-inline-start: 5px; }

/* شريط الإجراءات الجماعية */
.bulkbar {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 60;
  transform: translateY(120%); transition: transform .3s var(--ease);
  background: rgba(18,12,30,.96); backdrop-filter: blur(18px);
  border-top: 1px solid var(--violet);
  padding: 14px 0 calc(14px + env(safe-area-inset-bottom));
}
.bulkbar.show { transform: none; }
.bulkbar .wrap { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }

/* ---------- Modal (bootstrap override) ---------- */
.modal-content { background: var(--panel); border: 1px solid var(--line); border-radius: 22px; color: var(--text); }
.modal-header, .modal-footer { border-color: var(--line-soft); }
.modal-title { font-weight: 800; font-size: 1.05rem; }
.btn-close { filter: invert(1) grayscale(1); opacity: .5; }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: 56px 20px; }
.empty .ic { width: 60px; height: 60px; border-radius: 18px; background: rgba(124,77,255,.12); color: var(--violet-hi); display: grid; place-items: center; font-size: 1.4rem; margin: 0 auto 16px; }
.empty h4 { font-weight: 800; margin-bottom: 6px; }
.empty p { color: var(--muted); font-size: .9rem; margin: 0 0 18px; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 24px; padding: 34px; }

/* ---------- Module builder (فورم الدورة) ---------- */
.mod-item { border: 1px solid var(--line); border-radius: 16px; padding: 16px; margin-bottom: 12px; background: rgba(255,255,255,.02); }
.mod-item .mod-top { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.mod-item .mod-top .f-input { flex: 1; }

/* ---------- Pagination ---------- */
.pager { display: flex; gap: 6px; justify-content: center; margin-top: 20px; flex-wrap: wrap; }
.pager a, .pager span { min-width: 36px; height: 36px; display: grid; place-items: center; border-radius: 11px; border: 1px solid var(--line); font-size: .84rem; font-family: var(--font-mono); }
.pager .on { background: var(--violet); border-color: var(--violet); color: #fff; }

@media (max-width: 900px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .wrap { width: calc(100% - 26px); }
  .chart-box { height: 230px; }
  .chart-box.tall { height: 260px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }