/* نظام التكلفة — شركة المجد */
:root {
  --bg: #f4f6fa; --card: #fff; --ink: #172033; --ink2: #4a5468; --muted: #8a93a6; --line: #e6e9f0; --line2: #f0f2f6;
  --pri: #1e4fd8; --pri-d: #173fb0; --pri-soft: #eaf0ff;
  --ok: #12805c; --ok-soft: #e4f6ee; --bad: #c8321f; --bad-soft: #fdecea; --warn: #9a6400; --warn-soft: #fff5dc;
  --side: #0f1b33; --side-ink: #b8c3da;
  --r: 12px; --shadow: 0 1px 2px rgba(16,24,40,.05), 0 2px 8px rgba(16,24,40,.04);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: "Tajawal", "Segoe UI", Tahoma, sans-serif; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.55; }
a { color: var(--pri); text-decoration: none; }
a:hover { text-decoration: underline; }
.ic { width: 18px; height: 18px; flex: none; }

/* ---------- layout ---------- */
.layout { display: flex; min-height: 100vh; }
.side { width: 236px; flex: none; background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; gap: 10px; align-items: center; padding: 20px 18px; color: #fff; text-decoration: none !important; }
.brand b { display: block; font-size: 16px; }
.brand small { color: var(--side-ink); font-size: 12px; }
.logo { width: 38px; height: 38px; border-radius: 10px; background: linear-gradient(135deg, #3b6cff, #1e4fd8); display: grid; place-items: center; font-weight: 800; font-size: 20px; color: #fff; }
.side nav { padding: 6px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.side nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: var(--side-ink); text-decoration: none; font-weight: 500; }
.side nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.side nav a.on { background: rgba(59,108,255,.18); color: #fff; }
.side nav .nav-cta { background: var(--pri); color: #fff; justify-content: center; margin-bottom: 10px; font-weight: 700; }
.side nav .nav-cta:hover { background: #2d5ff0; }
.nav-sep { font-size: 12px; color: #6f7c97; padding: 16px 12px 4px; }
.me { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.08); }
.me b { display: block; color: #fff; font-size: 14px; }
.me small { font-size: 12px; }
.me form { margin-right: auto; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: #24324f; color: #fff; display: grid; place-items: center; font-weight: 700; }
.icon-btn { background: none; border: 0; color: var(--side-ink); cursor: pointer; padding: 6px; border-radius: 6px; }
.icon-btn:hover { color: #fff; background: rgba(255,255,255,.08); }
.main { flex: 1; min-width: 0; padding: 26px 32px 60px; max-width: 1500px; }
.main.solo { margin: 0 auto; max-width: 440px; padding-top: 10vh; }

/* ---------- page header ---------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { font-size: 24px; margin: 0; font-weight: 800; }
.page-head .sub { color: var(--muted); margin-top: 2px; }
.crumb { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: 14px; margin-bottom: 6px; }
h2 { font-size: 17px; margin: 0 0 12px; font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- cards ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 18px 20px; margin-bottom: 18px; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush .card-head { padding: 16px 20px 0; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi small { color: var(--muted); display: block; font-size: 13px; }
.kpi b { font-size: 21px; font-weight: 800; font-variant-numeric: tabular-nums; }
.kpi .unit { font-size: 13px; color: var(--muted); font-weight: 500; }
.kpi.hl { background: var(--pri-soft); border-color: #cfdcff; }
.kpi.hl b { color: var(--pri-d); }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 7px; height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid transparent; font: inherit; font-weight: 700; font-size: 14px; cursor: pointer; text-decoration: none !important; white-space: nowrap; transition: background .15s, border-color .15s; }
.btn.primary { background: var(--pri); color: #fff; }
.btn.primary:hover { background: var(--pri-d); }
.btn.success { background: var(--ok); color: #fff; }
.btn.success:hover { background: #0d6a4b; }
.btn.light { background: #fff; color: var(--ink); border-color: var(--line); }
.btn.light:hover { border-color: #c9cfdb; background: #fafbfd; }
.btn.ghost { background: transparent; color: var(--ink2); }
.btn.ghost:hover { background: var(--line2); }
.btn.danger { background: #fff; color: var(--bad); border-color: #f3c7c1; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.sm { height: 32px; padding: 0 11px; font-size: 13px; border-radius: 8px; }
.btn.lg { height: 48px; padding: 0 24px; font-size: 16px; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.group-label { font-size: 12px; color: var(--muted); margin-left: 4px; }

/* ---------- tables ---------- */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 14px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line2); }
th { background: #f8f9fc; color: var(--ink2); font-weight: 700; font-size: 13px; border-bottom: 1px solid var(--line); }
tbody tr:hover td { background: #fafbff; }
tr.total td, tr.total th { background: #f8f9fc; font-weight: 800; border-top: 1px solid var(--line); }
td.num, th.num { text-align: left; direction: ltr; font-variant-numeric: tabular-nums; }
td.strong { font-weight: 700; }
.col-hl { background: #f5f8ff; }
tbody tr:hover td.col-hl { background: #eef3ff; }

/* ---------- badges, chips ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 99px; font-size: 12.5px; font-weight: 700; background: var(--line2); color: var(--ink2); }
.badge.blue { background: var(--pri-soft); color: var(--pri-d); }
.badge.green { background: var(--ok-soft); color: var(--ok); }
.badge.amber { background: var(--warn-soft); color: var(--warn); }
.badge.red { background: var(--bad-soft); color: var(--bad); }
.up { color: var(--bad); font-weight: 700; }
.down { color: var(--ok); font-weight: 700; }

/* ---------- status stepper ---------- */
.steps { display: flex; gap: 0; margin: 4px 0 20px; overflow-x: auto; }
.step { flex: 1; min-width: 100px; text-align: center; position: relative; font-size: 13px; color: var(--muted); padding-top: 30px; }
.step::before { content: ""; position: absolute; top: 11px; right: -50%; left: 50%; height: 3px; background: var(--line); z-index: 0; }
.step:first-child::before { display: none; }
.step .dot { position: absolute; top: 2px; right: calc(50% - 11px); width: 22px; height: 22px; border-radius: 50%; background: #fff; border: 3px solid var(--line); z-index: 1; }
.step.done { color: var(--ink2); }
.step.done .dot { background: var(--pri); border-color: var(--pri); }
.step.done::before, .step.cur::before { background: var(--pri); }
.steps { overflow: hidden; }
.step.cur { color: var(--pri-d); font-weight: 800; }
.step.cur .dot { border-color: var(--pri); box-shadow: 0 0 0 4px var(--pri-soft); }

/* ---------- forms ---------- */
input, select, textarea { font: inherit; padding: 9px 12px; border: 1px solid var(--line); border-radius: 9px; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--pri); box-shadow: 0 0 0 3px var(--pri-soft); }
input.ltr, textarea.ltr { direction: ltr; text-align: left; }
input.cell { padding: 6px 9px; width: 100%; min-width: 70px; }
label.field { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 13.5px; color: var(--ink2); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; }
.radio-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.radio-cards label { display: flex; gap: 10px; align-items: flex-start; border: 1.5px solid var(--line); border-radius: 10px; padding: 12px 14px; cursor: pointer; }
.radio-cards label:has(input:checked) { border-color: var(--pri); background: var(--pri-soft); }
.radio-cards input { margin-top: 4px; }
.radio-cards b { display: block; }
.radio-cards small { color: var(--muted); }

/* ---------- drop zone ---------- */
.drop { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center; border: 2px dashed #c3cde0; border-radius: 16px; padding: 44px 20px; background: #fbfcff; cursor: pointer; transition: .15s; }
.drop:hover, .drop.over { border-color: var(--pri); background: var(--pri-soft); }
.drop .ic { width: 42px; height: 42px; color: var(--pri); }
.drop b { font-size: 17px; }
.drop input { display: none; }
.drop.busy { opacity: .6; pointer-events: none; }

/* ---------- messages ---------- */
.toast { padding: 12px 16px; border-radius: 10px; margin-bottom: 14px; font-weight: 600; border: 1px solid transparent; transition: opacity .4s; }
.toast.success { background: var(--ok-soft); color: var(--ok); border-color: #bfe6d4; }
.toast.error { background: var(--bad-soft); color: var(--bad); border-color: #f5c9c3; }
.toast.hide { opacity: 0; }
.note { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); margin-bottom: 12px; font-weight: 500; }
.note.info { background: var(--pri-soft); color: var(--pri-d); }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .ic { width: 40px; height: 40px; margin-bottom: 6px; }

.split { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 1000px) { .split { grid-template-columns: 1fr; } }
@media (max-width: 800px) {
  .layout { flex-direction: column; }
  .side { width: 100%; height: auto; position: static; }
  .side nav { flex-direction: row; flex-wrap: wrap; }
  .nav-sep, .me { display: none; }
  .main { padding: 18px 16px 40px; }
}

/* ---------- print ---------- */
.printonly { display: none; }
@media print {
  .side, .toolbar, .noprint, .toast, .btns { display: none !important; }
  .printonly { display: inline; }
  body { background: #fff; font-size: 13px; }
  .main { padding: 0; }
  .card { border: 0; box-shadow: none; padding: 0; }
  input.cell { border: 0; padding: 0; }
}

/* ---------- forms & editable tables ---------- */
.field > span { display: block; }
.field input, .field select, .field textarea { width: 100%; }
.field.wide { grid-column: 1 / -1; }
.req { color: var(--bad); font-style: normal; }
.err { color: var(--bad); font-weight: 600; display: block; }
.field.has-error input, .field.has-error select { border-color: var(--bad); }
.check-field { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--ink2); align-self: end; padding-bottom: 10px; }
.check-field input { width: 18px; height: 18px; }
.formset td { padding: 7px 8px; vertical-align: top; }
.formset td input, .formset td select { width: 100%; min-width: 80px; padding: 7px 9px; }
.formset td select { min-width: 150px; }
.formset tr.deleted td { opacity: .45; text-decoration: line-through; background: var(--bad-soft); }
.formset tr.row-error td { background: #fff8f7; }
.del-cell { text-align: center; }
.del { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; color: var(--muted); cursor: pointer; border: 1px solid transparent; background: none; }
.del:hover { color: var(--bad); background: var(--bad-soft); }
.del input { display: none; }
.del:has(input:checked) { color: #fff; background: var(--bad); }
.savebar { position: sticky; bottom: 0; z-index: 5; display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap;
  background: rgba(255,255,255,.96); backdrop-filter: blur(6px); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 16px; box-shadow: 0 -4px 16px rgba(16,24,40,.06); margin-top: 6px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; flex-wrap: wrap; }
.tabs a { padding: 10px 16px; color: var(--ink2); font-weight: 700; border-bottom: 3px solid transparent; margin-bottom: -1px; text-decoration: none; }
.tabs a.on { color: var(--pri); border-bottom-color: var(--pri); }
.tabs a:hover { color: var(--pri); }
.row-actions { text-align: left; white-space: nowrap; }
.kpi.bad { background: var(--bad-soft); border-color: #f5c9c3; } .kpi.bad b { color: var(--bad); }

/* ---------- confirmation modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(15,27,51,.45); display: grid; place-items: center; z-index: 100; padding: 16px; }
.modal-back[hidden] { display: none; }
.modal { background: #fff; border-radius: 16px; padding: 24px; width: 100%; max-width: 420px; box-shadow: 0 20px 50px rgba(15,27,51,.25); }
.modal p { font-size: 16px; font-weight: 600; margin: 12px 0 20px; line-height: 1.7; }
.modal-icon { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; background: var(--pri-soft); color: var(--pri); }
.modal-icon.danger { background: var(--bad-soft); color: var(--bad); }
.modal-icon .ic { width: 24px; height: 24px; }
.btn.danger-solid { background: var(--bad); color: #fff; }
.btn.danger-solid:hover { background: #a82716; }

/* ---------- clickable stepper + checklist ---------- */
button.step { background: none; border: 0; font: inherit; cursor: pointer; }
.step.clickable:hover { color: var(--pri); }
.step.clickable:hover .dot { border-color: var(--pri); }
.checklist { display: grid; gap: 8px; }
.check-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.check-row.ok { background: #fbfdfc; }
.check-row.next { border-color: var(--pri); background: var(--pri-soft); }
.check-dot { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; flex: none; font-weight: 800; font-size: 13px; background: var(--line2); color: var(--muted); }
.check-row.ok .check-dot { background: var(--ok); color: #fff; }
.check-row.next .check-dot { background: var(--pri); color: #fff; }
.check-dot .ic { width: 15px; height: 15px; }
.check-body { flex: 1; min-width: 0; }
.check-body b { display: block; }
.check-body small { color: var(--muted); }
